From 02b9468308ca3e76a33d48fcfc2d4899dfe6787a Mon Sep 17 00:00:00 2001 From: Joscha Date: Sun, 6 Aug 2023 21:04:51 +0200 Subject: [PATCH] Always alternate queue priority background colors --- src/web/queue.rs | 19 ++++++++++++++++--- static/base.css | 7 ++----- templates/queue_table.html | 2 +- 3 files changed, 19 insertions(+), 9 deletions(-) diff --git a/src/web/queue.rs b/src/web/queue.rs index fc62984..0c702fb 100644 --- a/src/web/queue.rs +++ b/src/web/queue.rs @@ -12,10 +12,11 @@ struct Task { short: String, since: String, priority: i64, + odd: bool, } async fn get_queue(db: &SqlitePool) -> somehow::Result> { - sqlx::query!( + let mut tasks = sqlx::query!( "\ SELECT \ id, \ @@ -34,10 +35,22 @@ async fn get_queue(db: &SqlitePool) -> somehow::Result> { short: util::format_commit_short(&r.hash, &r.message), since: util::format_delta_from_now(r.date), priority: r.priority, + odd: false, }) - .err_into::() .try_collect::>() - .await + .await?; + + let mut last_priority = None; + let mut odd = false; + for task in tasks.iter_mut().rev() { + if last_priority.is_some() && last_priority != Some(task.priority) { + odd = !odd; + } + task.odd = odd; + last_priority = Some(task.priority); + } + + Ok(tasks) } #[derive(Template)] diff --git a/static/base.css b/static/base.css index 7c481ea..449d7d7 100644 --- a/static/base.css +++ b/static/base.css @@ -135,12 +135,9 @@ nav img { /* Queue */ -.queue td:nth-child(2) { - text-align: right; -} - +.queue td:nth-child(2), .queue td:nth-child(3) { - text-align: center; + text-align: right; } .queue .odd { diff --git a/templates/queue_table.html b/templates/queue_table.html index 21dba18..54be72d 100644 --- a/templates/queue_table.html +++ b/templates/queue_table.html @@ -8,7 +8,7 @@ {% for task in tasks %} - + {{ task.short }} {{ task.since }} {{ task.priority }}