From f3c27ab1ce506d6b719d529b2758e858d89d7a95 Mon Sep 17 00:00:00 2001 From: Chase Wilson Date: Fri, 3 Jul 2020 16:34:15 -0500 Subject: [PATCH] Build Queue --- src/build_queue.rs | 2 +- src/web/releases.rs | 37 +++---- templates/releases_queue.hbs | 29 ------ tera-templates/releases/build_queue.html | 126 +++++++++++++++++++++++ 4 files changed, 146 insertions(+), 48 deletions(-) delete mode 100644 templates/releases_queue.hbs create mode 100644 tera-templates/releases/build_queue.html diff --git a/src/build_queue.rs b/src/build_queue.rs index e3c36b92c..b8cbe6116 100644 --- a/src/build_queue.rs +++ b/src/build_queue.rs @@ -3,7 +3,7 @@ use crate::db::Pool; use crate::error::Result; use log::error; -#[derive(Debug, Eq, PartialEq, serde::Serialize)] +#[derive(Debug, Clone, Eq, PartialEq, serde::Serialize)] pub(crate) struct QueuedCrate { #[serde(skip)] id: i32, diff --git a/src/web/releases.rs b/src/web/releases.rs index 2589f77dc..04fd93205 100644 --- a/src/web/releases.rs +++ b/src/web/releases.rs @@ -1,14 +1,10 @@ //! Releases web handlers use crate::{ + build_queue::QueuedCrate, db::Pool, impl_webpage, - web::{ - error::Nope, - match_version, - page::{Page, WebPage}, - redirect_base, - }, + web::{error::Nope, match_version, page::WebPage, redirect_base}, BuildQueue, }; use chrono::{DateTime, NaiveDateTime, Utc}; @@ -692,25 +688,30 @@ pub fn activity_handler(req: &mut Request) -> IronResult { .into_response(req) } -pub fn build_queue_handler(req: &mut Request) -> IronResult { - let queue = extension!(req, BuildQueue); +#[derive(Debug, Clone, PartialEq, Serialize)] +struct BuildQueuePage { + description: Cow<'static, str>, + queue: Vec, +} + +impl_webpage! { + BuildQueuePage = "releases/build_queue.html", +} - let mut crates = ctry!(req, queue.queued_crates()); - for krate in &mut crates { +pub fn build_queue_handler(req: &mut Request) -> IronResult { + let mut queue = ctry!(req, extension!(req, BuildQueue).queued_crates()); + for krate in queue.iter_mut() { // The priority here is inverted: in the database if a crate has a higher priority it // will be built after everything else, which is counter-intuitive for people not // familiar with docs.rs's inner workings. krate.priority = -krate.priority; } - let is_empty = crates.is_empty(); - Page::new(crates) - .title("Build queue") - .set("description", "List of crates scheduled to build") - .set_bool("queue_empty", is_empty) - .set_true("show_releases_navigation") - .set_true("releases_queue_tab") - .to_resp("releases_queue") + BuildQueuePage { + description: Cow::Borrowed("List of crates scheduled to build"), + queue, + } + .into_response(req) } #[cfg(test)] diff --git a/templates/releases_queue.hbs b/templates/releases_queue.hbs deleted file mode 100644 index 438f997e3..000000000 --- a/templates/releases_queue.hbs +++ /dev/null @@ -1,29 +0,0 @@ -{{> header}} - -
-
- -
- {{#if varsb.queue_empty}} - There is nothing in queue - {{else}} - Queue - {{/if}} -
- -
    - {{#each content}} -
  1. - - {{this.name}} {{this.version}} - - {{#if this.priority}} - (priority: {{this.priority}}) - {{/if}} -
  2. - {{/each}} -
-
-
- -{{> footer}} diff --git a/tera-templates/releases/build_queue.html b/tera-templates/releases/build_queue.html new file mode 100644 index 000000000..b92857109 --- /dev/null +++ b/tera-templates/releases/build_queue.html @@ -0,0 +1,126 @@ +{%- extends "base.html" -%} +{%- import "releases/header.html" as release_macros -%} + +{%- block title -%}Build Queue - Docs.rs{%- endblock title -%} + +{%- block header -%} + {{ release_macros::header(title="Build Queue", description=description, tab="queue") }} +{%- endblock header -%} + +{%- block body -%} +
+
+ +
+ {% set queue_length = queue | length -%} + {%- if queue_length == 0 -%} + There is nothing in queue + {%- else -%} + Queue + {%- endif %} +
+ +
    + {% for crate in queue -%} +
  1. + + {{ crate.name }} {{ crate.version }} + + + {% if crate.priority != 0 -%} + (priority: {{ crate.priority }}) + {%- endif %} +
  2. + {%- endfor %} +
+
+
+{%- endblock body -%} + +{%- block javascript -%} + +{%- endblock javascript -%}