Port run page to Page

This commit is contained in:
Joscha 2024-05-13 14:57:47 +02:00
parent 5c3ec1122e
commit d7c6a5beee

View file

@ -4,18 +4,14 @@ use axum::{
response::{IntoResponse, Response}, response::{IntoResponse, Response},
}; };
use futures::TryStreamExt; use futures::TryStreamExt;
use maud::html; use maud::{html, Markup};
use sqlx::SqlitePool; use sqlx::SqlitePool;
use crate::{ use crate::{
config::ServerConfig, config::ServerConfig,
server::{ server::{
util, util,
web::{ web::{components, page::Page, paths::PathRunById},
base::{Base, Tab},
components,
paths::PathRunById,
},
}, },
somehow, somehow,
}; };
@ -35,7 +31,7 @@ async fn from_finished_run(
id: &str, id: &str,
config: &'static ServerConfig, config: &'static ServerConfig,
db: &SqlitePool, db: &SqlitePool,
) -> somehow::Result<Option<Response>> { ) -> somehow::Result<Option<Markup>> {
let Some(run) = sqlx::query!( let Some(run) = sqlx::query!(
"\ "\
SELECT \ SELECT \
@ -96,65 +92,68 @@ async fn from_finished_run(
.try_collect::<Vec<_>>() .try_collect::<Vec<_>>()
.await?; .await?;
let base = Base::new(config, Tab::None);
let commit = components::link_commit(config, run.hash, &run.message, run.reachable); let commit = components::link_commit(config, run.hash, &run.message, run.reachable);
Ok(Some( let html = Page::new(config)
base.html( .title(format!(
&format!("Run of {}", util::format_commit_summary(&run.message)), "Run of {}",
html! {}, util::format_commit_summary(&run.message)
html! { ))
h2 { "Run" } .body(html! {
div .commit-like .run { h2 { "Run" }
span .title { "run " (run.id) } div .commit-like .run {
dl { span .title { "run " (run.id) }
dt { "Commit:" } dl {
dd { (commit)} dt { "Commit:" }
dd { (commit)}
dt { "Benchmark:" } dt { "Benchmark:" }
dd { (run.bench_method) } dd { (run.bench_method) }
dt { "Start:" } dt { "Start:" }
dd { (util::format_time(run.start)) } dd { (util::format_time(run.start)) }
dt { "End:" } dt { "End:" }
dd { (util::format_time(run.end)) } dd { (util::format_time(run.end)) }
dt { "Duration:" } dt { "Duration:" }
dd { (util::format_duration(run.end - run.start)) } dd { (util::format_duration(run.end - run.start)) }
dt { "Exit code:" } dt { "Exit code:" }
dd { (run.exit_code) } dd { (run.exit_code) }
}
}
})
.body(html! {
h2 { "Measurements" }
table {
thead {
tr {
th { "metric" }
th { "value" }
th { "unit" }
} }
} }
h2 { "Measurements" } tbody {
table { @for mm in measurements { tr {
thead { td { (mm.metric) }
tr { td { (mm.value) }
th { "metric" } td { (mm.unit) }
th { "value" } } }
th { "unit" }
}
}
tbody {
@for mm in measurements { tr {
td { (mm.metric) }
td { (mm.value) }
td { (mm.unit) }
} }
}
} }
h2 { "Output" } }
div .run-output { })
@for line in output { .body(html! {
pre { (line.text) } h2 { "Output" }
} div .run-output {
@for line in output {
pre { (line.text) }
} }
}, }
) })
.into_response(), .build();
))
Ok(Some(html))
} }
pub async fn get_run_by_id( pub async fn get_run_by_id(
@ -162,8 +161,8 @@ pub async fn get_run_by_id(
State(config): State<&'static ServerConfig>, State(config): State<&'static ServerConfig>,
State(db): State<SqlitePool>, State(db): State<SqlitePool>,
) -> somehow::Result<Response> { ) -> somehow::Result<Response> {
if let Some(response) = from_finished_run(&path.id, config, &db).await? { if let Some(markup) = from_finished_run(&path.id, config, &db).await? {
Ok(response) Ok(markup.into_response())
} else { } else {
// TODO Show unfinished runs // TODO Show unfinished runs
Ok(StatusCode::NOT_FOUND.into_response()) Ok(StatusCode::NOT_FOUND.into_response())