create settings menu route and move home route

This commit is contained in:
glyph 2022-03-11 14:28:31 +02:00
parent ec288658f3
commit 07c18ea64d
5 changed files with 34 additions and 39 deletions

View File

@ -1,6 +1,7 @@
//pub mod authentication;
//pub mod catchers;
pub mod index;
//pub mod index;
pub mod home;
//pub mod scuttlebutt;
//pub mod settings;
pub mod settings;
//pub mod status;

View File

@ -1,35 +1,30 @@
use rocket::{get, request::FlashMessage, State};
use rocket_dyn_templates::{tera::Context, Template};
use maud::{html, PreEscaped};
use crate::routes::authentication::Authenticated;
use crate::utils;
use crate::RocketConfig;
use crate::{templates, CONFIG};
// 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()));
// TODO: flash message implementation for rouille
//
/// Main settings menu template builder.
pub fn build() -> PreEscaped<String> {
let menu_template = html! {
(PreEscaped("<!-- SETTINGS MENU -->"))
div class="card center" {
(PreEscaped("<!-- BUTTONS -->"))
div id="settingsButtons" {
// render the network settings button if we're not in standalone mode
@if !CONFIG.standalone_mode {
a id="network" class="button button-primary center" href="/settings/network" title="Network Settings" { "Network" }
}
a id="scuttlebutt" class="button button-primary center" href="/settings/scuttlebutt" title="Scuttlebutt Settings" { "Scuttlebutt" }
a id="admin" class="button button-primary center" href="/settings/admin" title="Administrator Settings" { "Administration" }
}
}
};
Template::render("settings/menu", &context.into_json())
// wrap the nav bars around the settings menu template content
// parameters are template, title and back url
let body = templates::nav::build(menu_template, "Settings", Some("/"));
// render the base template with the provided body
templates::base::build(body)
}

View File

@ -1,6 +1,6 @@
pub mod admin;
pub mod dns;
//pub mod admin;
//pub mod dns;
pub mod menu;
pub mod network;
pub mod scuttlebutt;
pub mod theme;
//pub mod network;
//pub mod scuttlebutt;
//pub mod theme;

View File

@ -1,3 +1,2 @@
mod base;
pub mod home;
pub mod base;
pub mod nav;