summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorKjetil Orbekk <kjetil.orbekk@gmail.com>2017-05-24 22:56:30 -0400
committerKjetil Orbekk <kjetil.orbekk@gmail.com>2017-05-24 22:56:30 -0400
commit192c187ebcaf20d2fc76c7a6e0a259f53dfe3404 (patch)
treedf5a6ea3815f1708176fddb3a39a53a3671a2160 /src
parent813996dd52a40124b453dfb35617036d1e88357b (diff)
system_status: Rendering the front page by section
Diffstat (limited to 'src')
-rw-r--r--src/main.rs79
-rw-r--r--src/render/mod.rs44
2 files changed, 21 insertions, 102 deletions
diff --git a/src/main.rs b/src/main.rs
index 3ee8e21..b4a8f38 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -6,8 +6,6 @@ extern crate log;
#[macro_use]
extern crate router;
extern crate env_logger;
-#[macro_use]
-extern crate horrorshow;
extern crate systemhttp;
extern crate iron_sessionstorage;
extern crate staticfile;
@@ -20,9 +18,8 @@ use iron::modifiers::Header;
use iron::headers::ContentType;
use iron::{Iron, Request, IronResult, Response, Chain};
use router::Router;
-use horrorshow::prelude::*;
-use horrorshow::Raw;
use systemhttp::systemd::unit;
+use systemhttp::render;
use staticfile::Static;
struct Aaa(String);
@@ -39,52 +36,9 @@ impl iron_sessionstorage::Value for Aaa {
}
}
-fn render_message(message: &str, units: &[unit::Unit]) -> String {
- (html!{
- : Raw("<!DOCTYPE html>");
- html {
- head {
- title: "Title";
- link(rel="stylesheet", type="text/css", href="static/main.css");
- }
- body {
- p {
- : message
- }
- h1 {
- : "Units"
- }
- table {
- tr {
- th {
- : "Unit"
- }
- th {
- : "Active"
- }
- }
- @ for unit in units {
- tr {
- td {
- : &unit.name
- }
- td {
- : format_args!("{} ({})",
- &unit.active_state,
- &unit.sub_state)
- }
- }
- }
- }
- }
- }
- })
- .into_string()
- .unwrap()
-}
fn hello(r: &mut Request) -> IronResult<Response> {
- let mut session_value = match try!(r.session().get::<Aaa>()) {
+ let mut _value = match try!(r.session().get::<Aaa>()) {
Some(aaa) => aaa,
None => Aaa("".to_owned()),
};
@@ -97,17 +51,26 @@ fn hello(r: &mut Request) -> IronResult<Response> {
let units = unit::get_units().unwrap();
- let res = Ok(Response::with((status::Ok,
- Header(ContentType::html()),
- render_message(&format!("Hello, {} ({})",
- name,
- session_value.0),
- &units))));
+ let sections = ["service", "timer", "socket", "target", "slice", "mount",
+ "path"];
+ let units_by_section = sections.iter().map(|&s| {
+ (s.to_owned(),
+ units.iter().filter(|&u| &u.type_ == s).collect::<Vec<&unit::Unit>>())
+ }).collect::<Vec<_>>();
+
+ // let res = Ok(Response::with((status::Ok,
+ // Header(ContentType::html()),
+ // render_message(&format!("Hello, {} ({})",
+ // name,
+ // session_value.0),
+ // &units))));
- info!("Updating session value. Current value: {}", session_value.0);
- session_value.0.push('a');
- try!(r.session().set(session_value));
- res
+ // info!("Updating session value. Current value: {}", session_value.0);
+ // session_value.0.push('a');
+ // try!(r.session().set(session_value));
+ Ok(Response::with((status::Ok,
+ Header(ContentType::html()),
+ render::system_status(&units_by_section))))
}
fn main() {
diff --git a/src/render/mod.rs b/src/render/mod.rs
index d391b6e..49c3086 100644
--- a/src/render/mod.rs
+++ b/src/render/mod.rs
@@ -63,47 +63,3 @@ pub fn system_status(sections: &[(String, Vec<&unit::Unit>)]) -> String {
};
render_in_page(b)
}
-
-pub fn render_message(message: &str, units: &[unit::Unit]) -> String {
- (html!{
- : Raw("<!DOCTYPE html>");
- html {
- head {
- title: "Title";
- link(rel="stylesheet", type="text/css", href="static/main.css");
- }
- body {
- p {
- : message
- }
- h1 {
- : "Units"
- }
- table {
- tr {
- th {
- : "Unit"
- }
- th {
- : "Active"
- }
- }
- @ for unit in units {
- tr {
- td {
- : &unit.name
- }
- td {
- : format_args!("{} ({})",
- &unit.active_state,
- &unit.sub_state)
- }
- }
- }
- }
- }
- }
- })
- .into_string()
- .unwrap()
-}