2022-02-01 08:06:45 +00:00
|
|
|
use peach_lib::sbot::SbotStatus;
|
2022-01-18 15:00:53 +00:00
|
|
|
use rocket::{get, request::FlashMessage, State};
|
2022-01-13 11:16:38 +00:00
|
|
|
use rocket_dyn_templates::{tera::Context, Template};
|
2021-10-28 08:01:31 +00:00
|
|
|
|
2021-11-08 15:38:10 +00:00
|
|
|
use crate::routes::authentication::Authenticated;
|
2022-02-03 14:29:20 +00:00
|
|
|
use crate::utils;
|
2022-01-18 15:00:53 +00:00
|
|
|
use crate::RocketConfig;
|
2021-11-08 15:38:10 +00:00
|
|
|
|
2021-11-03 09:52:02 +00:00
|
|
|
// HELPERS AND ROUTES FOR / (HOME PAGE)
|
2021-10-28 08:01:31 +00:00
|
|
|
|
|
|
|
#[get("/")]
|
2022-01-18 15:00:53 +00:00
|
|
|
pub fn home(_auth: Authenticated, config: &State<RocketConfig>) -> Template {
|
2022-02-03 14:29:20 +00:00
|
|
|
// retrieve current ui theme
|
|
|
|
let theme = utils::get_theme();
|
|
|
|
|
2022-02-01 08:06:45 +00:00
|
|
|
// retrieve go-sbot systemd process status
|
|
|
|
let sbot_status = SbotStatus::read().ok();
|
2022-01-27 08:55:44 +00:00
|
|
|
|
2022-01-13 11:16:38 +00:00
|
|
|
let mut context = Context::new();
|
2022-02-03 14:29:20 +00:00
|
|
|
context.insert("theme", &theme);
|
2022-02-01 08:06:45 +00:00
|
|
|
context.insert("sbot_status", &sbot_status);
|
2022-01-13 11:16:38 +00:00
|
|
|
context.insert("flash_name", &None::<()>);
|
|
|
|
context.insert("flash_msg", &None::<()>);
|
|
|
|
context.insert("title", &None::<()>);
|
2022-01-18 15:00:53 +00:00
|
|
|
|
|
|
|
// pass in mode from managed state so we can define appropriate urls in template
|
|
|
|
context.insert("standalone_mode", &config.standalone_mode);
|
2021-10-28 08:01:31 +00:00
|
|
|
|
2022-01-13 11:16:38 +00:00
|
|
|
Template::render("home", &context.into_json())
|
2021-10-28 08:01:31 +00:00
|
|
|
}
|
|
|
|
|
2022-03-07 09:35:19 +00:00
|
|
|
// HELPERS AND ROUTES FOR /guide
|
2021-10-28 08:01:31 +00:00
|
|
|
|
2022-03-07 09:35:19 +00:00
|
|
|
#[get("/guide")]
|
|
|
|
pub fn guide(flash: Option<FlashMessage>) -> Template {
|
2022-02-03 14:29:20 +00:00
|
|
|
// retrieve current ui theme
|
|
|
|
let theme = utils::get_theme();
|
|
|
|
|
2022-01-13 11:16:38 +00:00
|
|
|
let mut context = Context::new();
|
2022-02-03 14:29:20 +00:00
|
|
|
context.insert("theme", &theme);
|
2022-01-13 11:16:38 +00:00
|
|
|
context.insert("back", &Some("/".to_string()));
|
2022-03-07 09:35:19 +00:00
|
|
|
context.insert("title", &Some("Guide".to_string()));
|
2022-01-13 11:16:38 +00:00
|
|
|
|
2021-10-28 08:01:31 +00:00
|
|
|
// check to see if there is a flash message to display
|
|
|
|
if let Some(flash) = flash {
|
2022-01-13 11:16:38 +00:00
|
|
|
context.insert("flash_name", &Some(flash.kind().to_string()));
|
|
|
|
context.insert("flash_msg", &Some(flash.message().to_string()));
|
2021-10-28 08:01:31 +00:00
|
|
|
};
|
2022-01-13 11:16:38 +00:00
|
|
|
|
2022-03-07 09:35:19 +00:00
|
|
|
Template::render("guide", &context.into_json())
|
2021-10-28 08:01:31 +00:00
|
|
|
}
|