Show queued tasks
This commit is contained in:
parent
2c0a496897
commit
ad5da60b5a
8 changed files with 180 additions and 25 deletions
44
.sqlx/query-02a0484f131cdd7420fb073dec5c9ed2758e21a6bf74026ba3e19cba1d274536.json
generated
Normal file
44
.sqlx/query-02a0484f131cdd7420fb073dec5c9ed2758e21a6bf74026ba3e19cba1d274536.json
generated
Normal file
|
|
@ -0,0 +1,44 @@
|
||||||
|
{
|
||||||
|
"db_name": "SQLite",
|
||||||
|
"query": "SELECT id, hash, message, date AS \"date: time::OffsetDateTime\", priority FROM queue JOIN commits USING (hash) ORDER BY priority DESC, unixepoch(date) DESC, hash ASC ",
|
||||||
|
"describe": {
|
||||||
|
"columns": [
|
||||||
|
{
|
||||||
|
"name": "id",
|
||||||
|
"ordinal": 0,
|
||||||
|
"type_info": "Text"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "hash",
|
||||||
|
"ordinal": 1,
|
||||||
|
"type_info": "Text"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "message",
|
||||||
|
"ordinal": 2,
|
||||||
|
"type_info": "Text"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "date: time::OffsetDateTime",
|
||||||
|
"ordinal": 3,
|
||||||
|
"type_info": "Text"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "priority",
|
||||||
|
"ordinal": 4,
|
||||||
|
"type_info": "Int64"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"parameters": {
|
||||||
|
"Right": 0
|
||||||
|
},
|
||||||
|
"nullable": [
|
||||||
|
false,
|
||||||
|
false,
|
||||||
|
false,
|
||||||
|
false,
|
||||||
|
false
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"hash": "02a0484f131cdd7420fb073dec5c9ed2758e21a6bf74026ba3e19cba1d274536"
|
||||||
|
}
|
||||||
37
src/util.rs
37
src/util.rs
|
|
@ -22,20 +22,31 @@ pub fn time_to_offset_datetime(time: Time) -> somehow::Result<OffsetDateTime> {
|
||||||
.to_offset(UtcOffset::from_whole_seconds(time.offset)?))
|
.to_offset(UtcOffset::from_whole_seconds(time.offset)?))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn format_time(time: OffsetDateTime) -> somehow::Result<String> {
|
pub fn format_delta(delta: time::Duration) -> String {
|
||||||
let now = OffsetDateTime::now_utc();
|
let seconds = delta.unsigned_abs().as_secs();
|
||||||
let delta = time - now;
|
let seconds = seconds + 30 - (seconds + 30) % 60; // To nearest minute
|
||||||
|
let formatted = humantime::format_duration(Duration::from_secs(seconds));
|
||||||
let formatted_time = time.format(format_description!(
|
if delta.is_positive() {
|
||||||
"[year]-[month]-[day] [hour]:[minute]:[second] [offset_hour sign:mandatory][offset_minute]"
|
format!("in {formatted}")
|
||||||
))?;
|
|
||||||
let formatted_delta =
|
|
||||||
humantime::format_duration(Duration::from_secs(delta.unsigned_abs().as_secs()));
|
|
||||||
Ok(if delta.is_positive() {
|
|
||||||
format!("{formatted_time} (in {formatted_delta})")
|
|
||||||
} else {
|
} else {
|
||||||
format!("{formatted_time} ({formatted_delta} ago)")
|
format!("{formatted} ago")
|
||||||
})
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn format_delta_from_now(time: OffsetDateTime) -> String {
|
||||||
|
let now = OffsetDateTime::now_utc();
|
||||||
|
format_delta(time - now)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn format_time(time: OffsetDateTime) -> String {
|
||||||
|
let formatted_time = time
|
||||||
|
.format(format_description!(
|
||||||
|
"[year]-[month]-[day] [hour]:[minute]:[second] [offset_hour sign:mandatory][offset_minute]"
|
||||||
|
))
|
||||||
|
.expect("invalid date format");
|
||||||
|
|
||||||
|
let formatted_delta = format_delta_from_now(time);
|
||||||
|
format!("{formatted_time} ({formatted_delta})")
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn format_actor(author: IdentityRef<'_>) -> somehow::Result<String> {
|
pub fn format_actor(author: IdentityRef<'_>) -> somehow::Result<String> {
|
||||||
|
|
|
||||||
|
|
@ -14,6 +14,7 @@ pub enum Tab {
|
||||||
Queue,
|
Queue,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Clone)]
|
||||||
pub struct Base {
|
pub struct Base {
|
||||||
root: String,
|
root: String,
|
||||||
repo_name: String,
|
repo_name: String,
|
||||||
|
|
@ -43,6 +44,7 @@ pub async fn run(state: AppState) -> somehow::Result<()> {
|
||||||
.route("/commit/", get(commit::get))
|
.route("/commit/", get(commit::get))
|
||||||
.route("/commit/:hash", get(commit_hash::get))
|
.route("/commit/:hash", get(commit_hash::get))
|
||||||
.route("/queue/", get(queue::get))
|
.route("/queue/", get(queue::get))
|
||||||
|
.route("/queue/table", get(queue::get_table))
|
||||||
.fallback(get(r#static::static_handler))
|
.fallback(get(r#static::static_handler))
|
||||||
.with_state(state.clone());
|
.with_state(state.clone());
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -101,9 +101,9 @@ pub async fn get(
|
||||||
base: Base::new(config, Tab::Commit),
|
base: Base::new(config, Tab::Commit),
|
||||||
hash: commit.hash,
|
hash: commit.hash,
|
||||||
author: commit.author,
|
author: commit.author,
|
||||||
author_date: util::format_time(commit.author_date)?,
|
author_date: util::format_time(commit.author_date),
|
||||||
commit: commit.committer,
|
commit: commit.committer,
|
||||||
commit_date: util::format_time(commit.committer_date)?,
|
commit_date: util::format_time(commit.committer_date),
|
||||||
parents,
|
parents,
|
||||||
children,
|
children,
|
||||||
summary: util::format_commit_summary(&commit.message),
|
summary: util::format_commit_summary(&commit.message),
|
||||||
|
|
|
||||||
|
|
@ -1,18 +1,69 @@
|
||||||
use askama::Template;
|
use askama::Template;
|
||||||
use axum::{extract::State, response::IntoResponse};
|
use axum::{extract::State, response::IntoResponse};
|
||||||
|
use futures::TryStreamExt;
|
||||||
|
use sqlx::SqlitePool;
|
||||||
|
|
||||||
use crate::{config::Config, somehow};
|
use crate::{config::Config, somehow, util};
|
||||||
|
|
||||||
use super::{Base, Tab};
|
use super::{Base, Tab};
|
||||||
|
|
||||||
#[derive(Template)]
|
struct Task {
|
||||||
#[template(path = "queue.html")]
|
id: String,
|
||||||
struct CommitTemplate {
|
short: String,
|
||||||
base: Base,
|
since: String,
|
||||||
|
priority: i64,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn get(State(config): State<&'static Config>) -> somehow::Result<impl IntoResponse> {
|
async fn get_queue(db: &SqlitePool) -> somehow::Result<Vec<Task>> {
|
||||||
Ok(CommitTemplate {
|
sqlx::query!(
|
||||||
|
"\
|
||||||
|
SELECT \
|
||||||
|
id, \
|
||||||
|
hash, \
|
||||||
|
message, \
|
||||||
|
date AS \"date: time::OffsetDateTime\", \
|
||||||
|
priority \
|
||||||
|
FROM queue \
|
||||||
|
JOIN commits USING (hash) \
|
||||||
|
ORDER BY priority DESC, unixepoch(date) DESC, hash ASC \
|
||||||
|
"
|
||||||
|
)
|
||||||
|
.fetch(db)
|
||||||
|
.map_ok(|r| Task {
|
||||||
|
id: r.id,
|
||||||
|
short: util::format_commit_short(&r.hash, &r.message),
|
||||||
|
since: util::format_delta_from_now(r.date),
|
||||||
|
priority: r.priority,
|
||||||
|
})
|
||||||
|
.err_into::<somehow::Error>()
|
||||||
|
.try_collect::<Vec<_>>()
|
||||||
|
.await
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Template)]
|
||||||
|
#[template(path = "queue_table.html")]
|
||||||
|
struct QueueTableTemplate {
|
||||||
|
tasks: Vec<Task>,
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn get_table(State(db): State<SqlitePool>) -> somehow::Result<impl IntoResponse> {
|
||||||
|
let tasks = get_queue(&db).await?;
|
||||||
|
Ok(QueueTableTemplate { tasks })
|
||||||
|
}
|
||||||
|
#[derive(Template)]
|
||||||
|
#[template(path = "queue.html")]
|
||||||
|
struct QueueTemplate {
|
||||||
|
base: Base,
|
||||||
|
table: QueueTableTemplate,
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn get(
|
||||||
|
State(config): State<&'static Config>,
|
||||||
|
State(db): State<SqlitePool>,
|
||||||
|
) -> somehow::Result<impl IntoResponse> {
|
||||||
|
let tasks = get_queue(&db).await?;
|
||||||
|
Ok(QueueTemplate {
|
||||||
base: Base::new(config, Tab::Queue),
|
base: Base::new(config, Tab::Queue),
|
||||||
|
table: QueueTableTemplate { tasks },
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -37,6 +37,21 @@ details>summary {
|
||||||
margin-left: 0;
|
margin-left: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
table {
|
||||||
|
border-collapse: collapse;
|
||||||
|
}
|
||||||
|
|
||||||
|
thead tr,
|
||||||
|
tbody tr:hover {
|
||||||
|
background-color: #ddd;
|
||||||
|
}
|
||||||
|
|
||||||
|
th+th,
|
||||||
|
td+td {
|
||||||
|
padding-left: 2ch;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Nav bar */
|
/* Nav bar */
|
||||||
|
|
||||||
nav {
|
nav {
|
||||||
|
|
@ -117,3 +132,17 @@ nav img {
|
||||||
.commit pre {
|
.commit pre {
|
||||||
white-space: pre-wrap;
|
white-space: pre-wrap;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Queue */
|
||||||
|
|
||||||
|
.queue td:nth-child(2) {
|
||||||
|
text-align: right;
|
||||||
|
}
|
||||||
|
|
||||||
|
.queue td:nth-child(3) {
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.queue .odd {
|
||||||
|
background-color: #eee;
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,8 @@
|
||||||
{% extends "base.html" %}
|
{% extends "base.html" %}
|
||||||
|
|
||||||
{% block title %}queue{% endblock %}
|
{% block title %}queue ({{ table.tasks.len() }}){% endblock %}
|
||||||
|
|
||||||
{% block body %}
|
{% block body %}
|
||||||
<h2>Queue</h2>
|
<h2>Queue ({{ table.tasks.len() }})</h2>
|
||||||
<p>Sorry, nothing here yet.</p>
|
{{ table|safe }}
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
|
||||||
18
templates/queue_table.html
Normal file
18
templates/queue_table.html
Normal file
|
|
@ -0,0 +1,18 @@
|
||||||
|
<table class="queue">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>commit</th>
|
||||||
|
<th>since</th>
|
||||||
|
<th>prio</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
{% for task in tasks %}
|
||||||
|
<tr {% if task.priority % 2==1 %}class="odd" {% endif %}>
|
||||||
|
<td><a href="{{ task.id }}">{{ task.short }}</a></td>
|
||||||
|
<td>{{ task.since }}</td>
|
||||||
|
<td>{{ task.priority }}</td>
|
||||||
|
</tr>
|
||||||
|
{% endfor %}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
Loading…
Add table
Add a link
Reference in a new issue