aboutsummaryrefslogtreecommitdiff
path: root/src/webui.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/webui.rs')
-rw-r--r--src/webui.rs63
1 files changed, 63 insertions, 0 deletions
diff --git a/src/webui.rs b/src/webui.rs
new file mode 100644
index 0000000..9e8b9c3
--- /dev/null
+++ b/src/webui.rs
@@ -0,0 +1,63 @@
+use crate::State;
+use axum::extract::State as S;
+use axum::response::Html;
+use serde_json::{Map, Value};
+use std::sync::Arc;
+use tokio::sync::RwLock;
+
+pub(crate) async fn webui(S(state): S<Arc<RwLock<State>>>) -> Html<String> {
+ let g = state.read().await;
+
+ let doc = markup::new! {
+ html {
+ head {
+ meta[charset="UTF-8"];
+ title { "" }
+ }
+ body {
+ section {
+ h2 { "Workers"}
+ ul { @for (id, w) in &g.workers {
+ li { div {
+ h3 { @w.name }
+ span { "ID: " @id } " "
+ @if w.accept > 0 {
+ span { "Accepting Jobs (" @w.accept ")" }
+ } else {
+ span { "Idle" }
+ }
+ }}
+ }}
+ }
+ section {
+ h2 { "Queued" }
+ ul { @for key in &g.queue {
+ li { @key }
+ }}
+ }
+ section {
+ h2 { "Loading" }
+ ul { @for key in &g.loading {
+ li { @key }
+ }}
+ }
+ section {
+ h2 { "Completed" }
+ ul { @for key in &g.complete {
+ li { @key }
+ }}
+ }
+ }
+ }
+ };
+ Html(doc.to_string())
+}
+
+markup::define!(
+ Task<'a>(key: &'a str, data: &'a Map<String, Value>) {
+ div.task {
+ h3 { @data["title"].as_str().unwrap_or(key) }
+ spawn.key { @key }
+ }
+ }
+);