aboutsummaryrefslogtreecommitdiff
path: root/src/webui.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/webui.rs')
-rw-r--r--src/webui.rs35
1 files changed, 26 insertions, 9 deletions
diff --git a/src/webui.rs b/src/webui.rs
index ca314c9..e292676 100644
--- a/src/webui.rs
+++ b/src/webui.rs
@@ -1,6 +1,7 @@
use crate::{
State,
helper::{Css, Javascript},
+ webui_ws::TaskState,
};
use axum::extract::State as S;
use axum::response::Html;
@@ -46,9 +47,9 @@ pub(crate) async fn webui(S(state): S<Arc<RwLock<State>>>) -> Html<String> {
}}
}
section.tasks {
- @Taskbin { title: "Queued", state: "queue", set: &g.queue, default, g }
- @Taskbin { title: "Loading", state: "loading", set: &g.loading, default, g }
- @Taskbin { title: "Completed", state: "complete", set: &g.complete, default, g }
+ @Taskbin { title: "Queued", state: TaskState::Queue, set: &g.queue, default, g }
+ @Taskbin { title: "Loading", state: TaskState::Loading, set: &g.loading, default, g }
+ @Taskbin { title: "Completed", state: TaskState::Complete, set: &g.complete, default, g }
}
}
}
@@ -57,18 +58,17 @@ pub(crate) async fn webui(S(state): S<Arc<RwLock<State>>>) -> Html<String> {
}
markup::define!(
- Taskbin<'a>(title: &'a str, state: &'a str, set: &'a HashSet<String>, g: &'a State, default: &'a Map<String, Value>) {
- div[id=format!("bin-{state}")] {
+ Taskbin<'a>(title: &'a str, state: TaskState, set: &'a HashSet<String>, g: &'a State, default: &'a Map<String, Value>) {
+ div[id=taskbin_id(*state)] {
h2 { @title }
p.count { @set.len() " tasks" }
- @let class = format!("task {state}");
ul { @for key in set.iter().take(128) {
- li { @Task { key, data: g.metadata.get(key).unwrap_or(&default), class: &class } }
+ li { @Task { key, data: g.metadata.get(key).unwrap_or(&default), state: *state } }
}}
}
}
- Task<'a>(key: &'a str, data: &'a Map<String, Value>, class: &'a str) {
- div[class=class, id=key, style=task_style(data)] {
+ Task<'a>(key: &'a str, data: &'a Map<String, Value>, state: TaskState) {
+ div[class=task_class(*state, data), id=key, style=task_style(data)] {
// @if let Some(url) = data.get("thumbnail").and_then(Value::as_str) {
// img[src=url, loading="lazy"];
// }
@@ -103,6 +103,23 @@ fn task_style(data: &Map<String, Value>) -> Option<String> {
.map(|p| format!("background-size: {:.02}%;", p * 100.))
}
+fn taskbin_id(state: TaskState) -> &'static str {
+ match state {
+ TaskState::Queue => "bin-queue",
+ TaskState::Loading => "bin-loading",
+ TaskState::Complete => "bin-complete",
+ }
+}
+fn task_class(state: TaskState, data: &Map<String, Value>) -> &'static str {
+ match state {
+ TaskState::Queue => "task queue",
+ TaskState::Loading => "task loading",
+ TaskState::Complete if data.get("failed").and_then(Value::as_bool).unwrap_or(false) => {
+ "task complete-failed"
+ }
+ TaskState::Complete => "task complete",
+ }
+}
fn worker_class(w: &crate::Worker) -> &'static str {
if w.accept > 0 {
"worker accepting"