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

36 lines
1.1 KiB
Rust

use rocket::{get, request::FlashMessage, State};
use rocket_dyn_templates::{tera::Context, Template};
use crate::routes::authentication::Authenticated;
use crate::utils;
use crate::RocketConfig;
// 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();
let mut context = Context::new();
context.insert("theme", &theme);
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);
// check to see if there is a flash message to display
if let Some(flash) = flash {
context.insert("flash_name", &Some(flash.kind().to_string()));
context.insert("flash_msg", &Some(flash.message().to_string()));
};
Template::render("settings/menu", &context.into_json())
}