blob: f7ad1d145cd429deaf66e3b81768587245035ed2 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
|
use systemd::unit;
use horrorshow::prelude::*;
use horrorshow::Raw;
fn render_in_page<'a>(content: Box<RenderBox + 'a>) -> String {
(html!{
: Raw("<!DOCTYPE html>");
html {
head {
title: "Systemhttpd";
link(rel="stylesheet", type="text/css", href="static/main.css");
}
body {
: content
}
}
}).into_string().unwrap()
}
fn unit_table<'a>(units: &'a [&unit::Unit]) -> Box<RenderBox + 'a> {
fn render_unit<'a>(unit: &'a unit::Unit) -> Box<RenderBox + 'a> {
box_html! {
tr {
td {
a(href=format_args!("/status/{}", &unit.name)) {
: &unit.name
}
}
td {
: format_args!("{} ({})",
&unit.active_state,
&unit.sub_state)
}
}
}
}
box_html! {
table {
tr {
th {
: "Unit"
}
th {
: "Active"
}
}
@ for unit in units {
: render_unit(unit)
}
}
}
}
pub fn system_status(sections: &[(String, Vec<&unit::Unit>)]) -> String {
let b =
box_html! {
@ for &(ref type_, ref units) in sections {
h1 {
: type_
}
: unit_table(&units)
}
};
render_in_page(b)
}
|