peach-workspace/peach-web/src/routes/settings/menu.rs

36 lines
1.1 KiB
Rust
Raw Normal View History

use rocket::{get, request::FlashMessage, State};
2022-01-13 11:16:38 +00:00
use rocket_dyn_templates::{tera::Context, Template};
2021-11-15 15:32:00 +00:00
use crate::routes::authentication::Authenticated;
use crate::utils;
use crate::RocketConfig;
2021-11-15 15:32:00 +00:00
// HELPERS AND ROUTES FOR /settings
/// View and delete currently configured admin.
#[get("/settings")]
pub fn settings_menu(
_auth: Authenticated,
flash: Option<FlashMessage>,
config: &State<RocketConfig>,
) -> Template {
// retrieve current ui theme
let theme = utils::get_theme();
2022-01-13 11:16:38 +00:00
let mut context = Context::new();
context.insert("theme", &theme);
2022-01-13 11:16:38 +00:00
context.insert("back", &Some("/".to_string()));
context.insert("title", &Some("Settings".to_string()));
// pass in mode from managed state so we can conditionally render html elements
context.insert("standalone_mode", &config.standalone_mode);
2021-11-15 15:32:00 +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-11-15 15:32:00 +00:00
};
2022-01-13 11:16:38 +00:00
Template::render("settings/menu", &context.into_json())
2021-11-15 15:32:00 +00:00
}