From 07c18ea64dda81872d980475fdaf088a9856d21e Mon Sep 17 00:00:00 2001 From: glyph Date: Fri, 11 Mar 2022 14:28:31 +0200 Subject: [PATCH] create settings menu route and move home route --- peach-web/src/{templates => routes}/home.rs | 0 peach-web/src/routes/mod.rs | 5 +- peach-web/src/routes/settings/menu.rs | 55 ++++++++++----------- peach-web/src/routes/settings/mod.rs | 10 ++-- peach-web/src/templates/mod.rs | 3 +- 5 files changed, 34 insertions(+), 39 deletions(-) rename peach-web/src/{templates => routes}/home.rs (100%) diff --git a/peach-web/src/templates/home.rs b/peach-web/src/routes/home.rs similarity index 100% rename from peach-web/src/templates/home.rs rename to peach-web/src/routes/home.rs diff --git a/peach-web/src/routes/mod.rs b/peach-web/src/routes/mod.rs index d7078c2..1c94673 100644 --- a/peach-web/src/routes/mod.rs +++ b/peach-web/src/routes/mod.rs @@ -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; diff --git a/peach-web/src/routes/settings/menu.rs b/peach-web/src/routes/settings/menu.rs index b93c645..d7f520c 100644 --- a/peach-web/src/routes/settings/menu.rs +++ b/peach-web/src/routes/settings/menu.rs @@ -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, - config: &State, -) -> 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 { + let menu_template = html! { + (PreEscaped("")) + div class="card center" { + (PreEscaped("")) + 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) } diff --git a/peach-web/src/routes/settings/mod.rs b/peach-web/src/routes/settings/mod.rs index 0356538..b9a9b54 100644 --- a/peach-web/src/routes/settings/mod.rs +++ b/peach-web/src/routes/settings/mod.rs @@ -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; diff --git a/peach-web/src/templates/mod.rs b/peach-web/src/templates/mod.rs index 7bfc9fc..137668d 100644 --- a/peach-web/src/templates/mod.rs +++ b/peach-web/src/templates/mod.rs @@ -1,3 +1,2 @@ -mod base; -pub mod home; +pub mod base; pub mod nav;