Port worker page to maud

This commit is contained in:
Joscha 2024-05-12 13:31:43 +02:00
parent fb346a75d2
commit aed7498b29
2 changed files with 37 additions and 49 deletions

View file

@ -1,11 +1,11 @@
use std::sync::{Arc, Mutex}; use std::sync::{Arc, Mutex};
use askama::Template;
use axum::{ use axum::{
extract::State, extract::State,
http::StatusCode, http::StatusCode,
response::{IntoResponse, Response}, response::{IntoResponse, Response},
}; };
use maud::html;
use sqlx::SqlitePool; use sqlx::SqlitePool;
use crate::{ use crate::{
@ -29,16 +29,6 @@ enum Status {
Working { link: LinkRunShort, since: String }, Working { link: LinkRunShort, since: String },
} }
#[derive(Template)]
#[template(path = "pages/worker.html")]
struct Page {
base: Base,
name: String,
connected: String,
status: Status,
}
async fn status(status: &WorkerStatus, db: &SqlitePool, base: &Base) -> somehow::Result<Status> { async fn status(status: &WorkerStatus, db: &SqlitePool, base: &Base) -> somehow::Result<Status> {
Ok(match status { Ok(match status {
WorkerStatus::Idle => Status::Idle, WorkerStatus::Idle => Status::Idle,
@ -68,12 +58,41 @@ pub async fn get_worker_by_name(
}; };
let base = Base::new(config, Tab::None); let base = Base::new(config, Tab::None);
Ok(Page {
name: path.name,
connected: util::format_time(info.first_seen),
status: status(&info.status, &db, &base).await?,
base, let status = status(&info.status, &db, &base).await?;
Ok(base
.html(
&path.name,
html! {},
html! {
h2 { "Worker" }
div .commit-like .worker {
span .title { "worker " (path.name) }
dl {
dt { "Connected:" }
dd { (util::format_time(info.first_seen)) }
@match status {
Status::Idle => {
dt { "Working on:" }
dd { "nothing" }
} }
Status::Busy => {
dt { "Working on:" }
dd { "run for another server" }
}
Status::Working { link, since } => {
dt { "Working on:" }
dd { (link.html()) }
dt { "Working since:" }
dd { (since) }
}
}
}
}
},
)
.into_response()) .into_response())
} }

View file

@ -1,31 +0,0 @@
{% extends "base.html" %}
{% block title %}{{ name }}{% endblock %}
{% block body %}
<h2>Worker</h2>
<div class="commit-like worker">
<span class="title">worker {{ name }}</span>
<dl>
<dt>Connected:</dt>
<dd>{{ connected }}</dd>
{% match status %}
{% when Status::Idle %}
<dt>Working on:</dt>
<dd>nothing</dd>
{% when Status::Busy %}
<dt>Working on:</dt>
<dd>run for another server</dd>
{% when Status::Working with { link, since } %}
<dt>Working on:</dt>
<dd>{{ link|safe }}</dd>
<dt>Working since:</dt>
<dd>{{ since }}</dd>
{% endmatch %}
</dl>
</div>
{% endblock %}