Port queue page to Page

This commit is contained in:
Joscha 2024-05-13 14:54:53 +02:00
parent 8fe3fcad72
commit 5c3ec1122e

View file

@ -17,8 +17,8 @@ use crate::{
server::{ server::{
util, util,
web::{ web::{
base::{Base, Tab},
components, components,
page::{Page, Tab},
paths::{ paths::{
PathAdminQueueAddBatch, PathAdminQueueDecrease, PathAdminQueueDelete, PathAdminQueueAddBatch, PathAdminQueueDecrease, PathAdminQueueDelete,
PathAdminQueueIncrease, PathQueue, PathQueueDelete, PathQueueInner, PathAdminQueueIncrease, PathQueue, PathQueueDelete, PathQueueInner,
@ -240,33 +240,33 @@ pub async fn get_queue(
State(db): State<SqlitePool>, State(db): State<SqlitePool>,
State(workers): State<Arc<Mutex<Workers>>>, State(workers): State<Arc<Mutex<Workers>>>,
) -> somehow::Result<impl IntoResponse> { ) -> somehow::Result<impl IntoResponse> {
let base = Base::new(config, Tab::Queue);
let sorted_workers = sorted_workers(&workers); let sorted_workers = sorted_workers(&workers);
let workers = get_workers(config, &db, &sorted_workers).await?; let workers = get_workers(config, &db, &sorted_workers).await?;
let tasks = get_queue_data(config, &db, &sorted_workers).await?; let tasks = get_queue_data(config, &db, &sorted_workers).await?;
Ok(base.html( let html = Page::new(config)
&format!("queue ({})", tasks.len()), .title(format!("queue ({})", tasks.len()))
html! { .tab(Tab::Queue)
.head(html! {
script type="module" src=(config.path(QUEUE_JS)) {} script type="module" src=(config.path(QUEUE_JS)) {}
}, })
html! { .body(html!{
div #inner { (page_inner(workers, tasks)) } div #inner { (page_inner(workers, tasks)) }
form method="post" action=(config.path(PathAdminQueueAddBatch {})) { form method="post" action=(config.path(PathAdminQueueAddBatch {})) {
label { label {
"Batch size: " "Batch size: "
input name="amount" type="number" value="10" min="1"; input name="amount" type="number" value="10" min="1";
} } " "
" "
label { label {
"Priority: " "Priority: "
input #priority name="priority" type="number" value="-1" min="-2147483648" max="2147483647"; input #priority name="priority" type="number" value="-1" min="-2147483648" max="2147483647";
} } " "
" "
button { "Add batch to queue" } button { "Add batch to queue" }
} }
}, })
)) .build();
Ok(html)
} }
pub async fn get_queue_delete( pub async fn get_queue_delete(
@ -274,8 +274,6 @@ pub async fn get_queue_delete(
State(config): State<&'static ServerConfig>, State(config): State<&'static ServerConfig>,
State(db): State<SqlitePool>, State(db): State<SqlitePool>,
) -> somehow::Result<Response> { ) -> somehow::Result<Response> {
let base = Base::new(config, Tab::Queue);
let Some(r) = sqlx::query!( let Some(r) = sqlx::query!(
"\ "\
SELECT hash, message, reachable FROM commits \ SELECT hash, message, reachable FROM commits \
@ -292,20 +290,23 @@ pub async fn get_queue_delete(
let commit = components::link_commit(config, r.hash.clone(), &r.message, r.reachable); let commit = components::link_commit(config, r.hash.clone(), &r.message, r.reachable);
Ok(base let html = Page::new(config)
.html( .title(format!(
&format!("del {}", util::format_commit_short(&r.hash, &r.message)), "del {}",
html! {}, util::format_commit_short(&r.hash, &r.message)
html! { ))
h2 { "Delete commit from queue" } .tab(Tab::Queue)
p { "You are about to delete this commit from the queue:" } .body(html! {
p { (commit) } h2 { "Delete commit from queue" }
p { "All runs of this commit currently in progress will be aborted!" } p { "You are about to delete this commit from the queue:" }
form method="post" action=(config.path(PathAdminQueueDelete {})) { p { (commit) }
input name="hash" type="hidden" value=(r.hash); p { "All runs of this commit currently in progress will be aborted!" }
button { "Delete commit and abort runs" } form method="post" action=(config.path(PathAdminQueueDelete {})) {
} input name="hash" type="hidden" value=(r.hash);
}, button { "Delete commit and abort runs" }
) }
.into_response()) })
.build();
Ok(html.into_response())
} }