Port commit page
This commit is contained in:
parent
db0234b750
commit
373b3168f1
7 changed files with 111 additions and 19 deletions
|
|
@ -7,7 +7,14 @@ use serde::Deserialize;
|
|||
use sqlx::SqlitePool;
|
||||
use time::OffsetDateTime;
|
||||
|
||||
use crate::{config::Config, server::web::paths::PathAdminQueueAdd, somehow};
|
||||
use crate::{
|
||||
config::Config,
|
||||
server::web::{
|
||||
base::{Base, Tab},
|
||||
paths::{PathAdminQueueAdd, PathQueue},
|
||||
},
|
||||
somehow,
|
||||
};
|
||||
|
||||
#[derive(Deserialize)]
|
||||
pub struct FormAdminQueueAdd {
|
||||
|
|
@ -36,6 +43,6 @@ pub async fn post_admin_queue_add(
|
|||
.execute(&db)
|
||||
.await?;
|
||||
|
||||
// TODO Replace with typed link
|
||||
Ok(Redirect::to(&format!("{}queue/", config.web_base)))
|
||||
let link = Base::new(config, Tab::None).link(PathQueue {});
|
||||
Ok(Redirect::to(&format!("{link}")))
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
use askama::Template;
|
||||
use time::OffsetDateTime;
|
||||
|
||||
use crate::server::util;
|
||||
|
||||
|
|
@ -51,6 +52,25 @@ impl LinkRunShort {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Template)]
|
||||
#[template(
|
||||
ext = "html",
|
||||
source = "<a href=\"{{ link }}\">Run from {{ date }}</a>"
|
||||
)]
|
||||
pub struct LinkRunDate {
|
||||
link: Link,
|
||||
date: String, // TODO base.date(...)?
|
||||
}
|
||||
|
||||
impl LinkRunDate {
|
||||
pub fn new(base: &Base, id: String, start: OffsetDateTime) -> Self {
|
||||
Self {
|
||||
link: base.link(PathRunById { id }),
|
||||
date: util::format_time(start),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Template)]
|
||||
#[template(ext = "html", source = "<a href=\"{{ link }}\">{{ name }}</a>")]
|
||||
pub struct LinkWorker {
|
||||
|
|
|
|||
|
|
@ -0,0 +1 @@
|
|||
pub mod commit;
|
||||
|
|
@ -7,19 +7,26 @@ use axum::{
|
|||
use futures::TryStreamExt;
|
||||
use sqlx::SqlitePool;
|
||||
|
||||
use crate::{config::Config, server::util, somehow};
|
||||
|
||||
use super::{
|
||||
base::{Base, Link, Tab},
|
||||
link::LinkCommit,
|
||||
paths::{PathAdminQueueAdd, PathCommitByHash},
|
||||
use crate::{
|
||||
config::Config,
|
||||
server::{
|
||||
util,
|
||||
web::{
|
||||
base::{Base, Link, Tab},
|
||||
link::{LinkCommit, LinkRunDate},
|
||||
paths::{PathAdminQueueAdd, PathCommitByHash},
|
||||
},
|
||||
},
|
||||
somehow,
|
||||
};
|
||||
|
||||
#[derive(Template)]
|
||||
#[template(path = "commit.html")]
|
||||
struct CommitTemplate {
|
||||
#[template(path = "pages/commit.html")]
|
||||
struct Page {
|
||||
link_admin_queue_add: Link,
|
||||
base: Base,
|
||||
|
||||
summary: String,
|
||||
hash: String,
|
||||
author: String,
|
||||
author_date: String,
|
||||
|
|
@ -27,9 +34,9 @@ struct CommitTemplate {
|
|||
commit_date: String,
|
||||
parents: Vec<LinkCommit>,
|
||||
children: Vec<LinkCommit>,
|
||||
summary: String,
|
||||
message: String,
|
||||
reachable: i64,
|
||||
runs: Vec<LinkRunDate>,
|
||||
}
|
||||
|
||||
pub async fn get_commit_by_hash(
|
||||
|
|
@ -88,9 +95,25 @@ pub async fn get_commit_by_hash(
|
|||
.try_collect::<Vec<_>>()
|
||||
.await?;
|
||||
|
||||
Ok(CommitTemplate {
|
||||
let runs = sqlx::query!(
|
||||
"\
|
||||
SELECT \
|
||||
id, \
|
||||
start AS \"start: time::OffsetDateTime\" \
|
||||
FROM runs WHERE hash = ? \
|
||||
",
|
||||
path.hash
|
||||
)
|
||||
.fetch(&db)
|
||||
.map_ok(|r| LinkRunDate::new(&base, r.id, r.start))
|
||||
.try_collect::<Vec<_>>()
|
||||
.await?;
|
||||
|
||||
Ok(Page {
|
||||
link_admin_queue_add: base.link(PathAdminQueueAdd {}),
|
||||
base,
|
||||
|
||||
summary: util::format_commit_summary(&commit.message),
|
||||
hash: commit.hash,
|
||||
author: commit.author,
|
||||
author_date: util::format_time(commit.author_date),
|
||||
|
|
@ -98,9 +121,9 @@ pub async fn get_commit_by_hash(
|
|||
commit_date: util::format_time(commit.committer_date),
|
||||
parents,
|
||||
children,
|
||||
summary: util::format_commit_summary(&commit.message),
|
||||
message: commit.message.trim_end().to_string(),
|
||||
reachable: commit.reachable,
|
||||
runs,
|
||||
}
|
||||
.into_response())
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue