add managed state for conditional template element rendering
This commit is contained in:
parent
6f03063f8d
commit
476eaa540e
|
@ -1,16 +1,30 @@
|
|||
use rocket::get;
|
||||
use peach_stats::sbot;
|
||||
use rocket::{get, State};
|
||||
use rocket_dyn_templates::{tera::Context, Template};
|
||||
|
||||
use crate::routes::authentication::Authenticated;
|
||||
use crate::RocketConfig;
|
||||
|
||||
// HELPERS AND ROUTES FOR /status/scuttlebutt
|
||||
|
||||
#[get("/scuttlebutt")]
|
||||
pub fn scuttlebutt_status(_auth: Authenticated) -> Template {
|
||||
pub fn scuttlebutt_status(_auth: Authenticated, config: &State<RocketConfig>) -> Template {
|
||||
let mut context = Context::new();
|
||||
// retrieve go-sbot systemd process stats
|
||||
let sbot_stats = sbot::sbot_stats().ok();
|
||||
context.insert("sbot_stats", &sbot_stats);
|
||||
context.insert("flash_name", &None::<()>);
|
||||
context.insert("flash_msg", &None::<()>);
|
||||
context.insert("title", &Some("Scuttlebutt Status"));
|
||||
|
||||
// define back arrow url based on mode
|
||||
if config.standalone_mode {
|
||||
// return to home page
|
||||
context.insert("back", &Some("/"));
|
||||
} else {
|
||||
// return to status menu
|
||||
context.insert("back", &Some("/status"));
|
||||
}
|
||||
|
||||
Template::render("status/scuttlebutt", &context.into_json())
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue