improve index page
This commit is contained in:
@@ -15,20 +15,82 @@ struct State {
|
|||||||
#[get("/")]
|
#[get("/")]
|
||||||
async fn index(data: web::Data<State>) -> impl Responder {
|
async fn index(data: web::Data<State>) -> impl Responder {
|
||||||
let workers = data.workers.lock().unwrap();
|
let workers = data.workers.lock().unwrap();
|
||||||
let jobs = data.jobs.lock().unwrap();
|
let jobs = data.running_jobs.lock().unwrap();
|
||||||
|
|
||||||
let s: String = workers
|
let jobs_html: String = String::from("<table class=\"table is-hoverable\">")
|
||||||
.iter()
|
+ "<thead><tr><th><td>ID</td><td>command</td><td>status</td></th></tr></thead><tbody>"
|
||||||
.map(|w| w.to_string())
|
+ &jobs
|
||||||
.collect::<Vec<String>>()
|
.iter()
|
||||||
.join("\n");
|
.map(|j| {
|
||||||
|
format!(
|
||||||
|
"<tr><th></th><td>{}</td><td>{}</td><td>{}</td></tr>",
|
||||||
|
j.id, j.cmd, j.status
|
||||||
|
)
|
||||||
|
})
|
||||||
|
.collect::<Vec<String>>()
|
||||||
|
.join("\n")
|
||||||
|
+ "</tbody></table>";
|
||||||
|
|
||||||
let s: String = s + &jobs
|
let workers_html: String = String::from("<table class=\"table is-hoverable\">")
|
||||||
.iter()
|
+ "<thead><tr><th><td>ID</td></th></tr></thead><tbody>"
|
||||||
.map(|j| serde_json::to_string(&j).unwrap())
|
+ &workers
|
||||||
.collect::<Vec<String>>()
|
.iter()
|
||||||
.join("\n");
|
.map(|w| format!("<tr><th></th><td>{}</td></tr>", w))
|
||||||
HttpResponse::Ok().body(s)
|
.collect::<Vec<String>>()
|
||||||
|
.join("\n")
|
||||||
|
+ "</tbody></table>";
|
||||||
|
|
||||||
|
let debug_html = r#"<style>
|
||||||
|
*:not(path):not(g) {{
|
||||||
|
color: hsla(210, 100%, 100%, 0.9) !important;
|
||||||
|
background: hsla(210, 100%, 50%, 0.5) !important;
|
||||||
|
outline: solid 0.25rem hsla(210, 100%, 100%, 0.5) !important;
|
||||||
|
|
||||||
|
box-shadow: none !important;
|
||||||
|
}}
|
||||||
|
</style>"#;
|
||||||
|
let debug_html = "";
|
||||||
|
|
||||||
|
let page = format!(
|
||||||
|
r#"
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||||
|
<title>Hello Bulma!</title>
|
||||||
|
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bulma@0.9.4/css/bulma.min.css">
|
||||||
|
{}
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<section class="section">
|
||||||
|
<div class="container">
|
||||||
|
<div class="columns">
|
||||||
|
<div class="column">
|
||||||
|
<div class="block">
|
||||||
|
<h1 class="title">
|
||||||
|
Jobs
|
||||||
|
</h1>
|
||||||
|
{}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="column">
|
||||||
|
<div class="block">
|
||||||
|
<h1 class="title">
|
||||||
|
Workers
|
||||||
|
</h1>
|
||||||
|
{}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
|
"#,
|
||||||
|
debug_html, jobs_html, workers_html
|
||||||
|
);
|
||||||
|
HttpResponse::Ok().body(page)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[get("/register")]
|
#[get("/register")]
|
||||||
|
|||||||
Reference in New Issue
Block a user