Always alternate queue priority background colors

This commit is contained in:
Joscha 2023-08-06 21:04:51 +02:00
parent 6af47b8c30
commit 02b9468308
3 changed files with 19 additions and 9 deletions

View file

@ -12,10 +12,11 @@ struct Task {
short: String,
since: String,
priority: i64,
odd: bool,
}
async fn get_queue(db: &SqlitePool) -> somehow::Result<Vec<Task>> {
sqlx::query!(
let mut tasks = sqlx::query!(
"\
SELECT \
id, \
@ -34,10 +35,22 @@ async fn get_queue(db: &SqlitePool) -> somehow::Result<Vec<Task>> {
short: util::format_commit_short(&r.hash, &r.message),
since: util::format_delta_from_now(r.date),
priority: r.priority,
odd: false,
})
.err_into::<somehow::Error>()
.try_collect::<Vec<_>>()
.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)]

View file

@ -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 {

View file

@ -8,7 +8,7 @@
</thead>
<tbody>
{% for task in tasks %}
<tr {% if task.priority % 2==1 %}class="odd" {% endif %}>
<tr {% if task.odd %} class="odd" {% endif %}>
<td><a href="{{ task.id }}">{{ task.short }}</a></td>
<td>{{ task.since }}</td>
<td>{{ task.priority }}</td>