Skip to content

Commit

Permalink
Build Queue
Browse files Browse the repository at this point in the history
  • Loading branch information
Kixiron authored and Joshua Nelson committed Jul 13, 2020
1 parent 3d3b7cd commit f3c27ab
Show file tree
Hide file tree
Showing 4 changed files with 146 additions and 48 deletions.
2 changes: 1 addition & 1 deletion src/build_queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
37 changes: 19 additions & 18 deletions src/web/releases.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand Down Expand Up @@ -692,25 +688,30 @@ pub fn activity_handler(req: &mut Request) -> IronResult<Response> {
.into_response(req)
}

pub fn build_queue_handler(req: &mut Request) -> IronResult<Response> {
let queue = extension!(req, BuildQueue);
#[derive(Debug, Clone, PartialEq, Serialize)]
struct BuildQueuePage {
description: Cow<'static, str>,
queue: Vec<QueuedCrate>,
}

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<Response> {
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)]
Expand Down
29 changes: 0 additions & 29 deletions templates/releases_queue.hbs

This file was deleted.

126 changes: 126 additions & 0 deletions tera-templates/releases/build_queue.html
Original file line number Diff line number Diff line change
@@ -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 -%}
<div class="container">
<div class="recent-releases-container">

<div class="release">
{% set queue_length = queue | length -%}
{%- if queue_length == 0 -%}
<strong>There is nothing in queue</strong>
{%- else -%}
<strong>Queue</strong>
{%- endif %}
</div>

<ol class="queue-list">
{% for crate in queue -%}
<li>
<a href="https://crates.io/crates/{{ crate.name }}">
{{ crate.name }} {{ crate.version }}
</a>

{% if crate.priority != 0 -%}
(priority: {{ crate.priority }})
{%- endif %}
</li>
{%- endfor %}
</ol>
</div>
</div>
{%- endblock body -%}

{%- block javascript -%}
<script type="text/javascript" charset="utf-8">
function getKey(ev) {
if ("key" in ev && typeof ev.key != "undefined") {
return ev.key;
}
return String.fromCharCode(ev.charCode || ev.keyCode);
}

document.getElementById("i-am-feeling-lucky-button").onclick = function () {
var form = document.getElementsByClassName("landing-search-form");
var input = document.createElement('input');
input.type = 'hidden';
input.name = 'i-am-feeling-lucky';
input.value = 1;
document.getElementsByClassName("landing-search-form")[0].appendChild(input);
return true;
};

function handleShortcut(ev) {
if (ev.ctrlKey || ev.altKey || ev.metaKey || document.activeElement.tagName === "INPUT") {
return;
}
switch (getKey(ev)) {
case "s":
case "S":
ev.preventDefault();
document.getElementById("search").focus();
break;
}
}

document.onkeypress = handleShortcut;
document.onkeydown = handleShortcut;

var active = null;

function handleKey(ev) {
if (ev.ctrlKey || ev.altKey || ev.metaKey || document.activeElement.tagName === "INPUT") {
return;
}
if (ev.which === 40) { // Down arrow
ev.preventDefault();
if (active === null) {
active = document.getElementsByClassName("recent-releases-container")[0].getElementsByTagName("li")[0];
} else if (active.nextElementSibling) {
active.classList.remove("selected");
active = active.nextElementSibling;
}
active.classList.add("selected");
} else if (ev.which === 38) { // Up arrow
ev.preventDefault();
if (active === null) {
active = document.getElementsByClassName("recent-releases-container")[0].getElementsByTagName("li")[0];
} else if (active.previousElementSibling) {
active.classList.remove("selected");
active = active.previousElementSibling;
}
active.classList.add("selected");
active.focus();
} else if (ev.which === 13) { // Return
if (active !== null) {
document.location.href = active.getElementsByTagName("a")[0].href;
}
} else {
switch (getKey(ev)) {
case "s":
case "S":
ev.preventDefault();
document.getElementsByClassName("search-input-nav")[0].focus();
break;
}
}
}
document.onkeypress = handleKey;
document.onkeydown = handleKey;
var crates =
Array.prototype.slice.call(document.getElementsByClassName("recent-releases-container")[0].getElementsByTagName("li"));
for (var i = 0; i < crates.length; ++i) {
crates[i].addEventListener("mouseover", function (event) {
this.classList.remove("selected"); active = null;
}); crates[i].addEventListener("mouseout", function (event) {
this.classList.remove("selected"); active = null;
});
}
</script>
{%- endblock javascript -%}

0 comments on commit f3c27ab

Please sign in to comment.