From 5a49940b89ca16dfb9caa91a835186a43db2248f Mon Sep 17 00:00:00 2001 From: realaravinth Date: Sat, 18 Dec 2021 16:00:09 +0530 Subject: [PATCH] Get sitekey routes using methods on `pages::panel::sitekey::routes::Sitekey` for consistency purposes --- src/pages/mod.rs | 7 +-- src/pages/panel/sitekey/mod.rs | 54 ++++++++++++++++--- .../panel/header/taskbar/new-sitekey-btn.html | 2 +- 3 files changed, 53 insertions(+), 10 deletions(-) diff --git a/src/pages/mod.rs b/src/pages/mod.rs index e460bbdf..ba0150e2 100644 --- a/src/pages/mod.rs +++ b/src/pages/mod.rs @@ -58,11 +58,12 @@ mod tests { let app = get_app!(data).await; - let edit_sitekey_url = format!("/sitekey/{}/edit", &token_key.key); - let delete_sitekey_url = format!("/sitekey/{}/delete", &token_key.key); + let edit_sitekey_url = PAGES.panel.sitekey.get_edit_advance(&token_key.key); + let delete_sitekey_url = PAGES.panel.sitekey.get_delete(&token_key.key); let urls = vec![ PAGES.home, - PAGES.panel.sitekey.add, + PAGES.panel.sitekey.add_advance, + PAGES.panel.sitekey.add_easy, PAGES.panel.sitekey.list, PAGES.panel.notifications, PAGES.panel.settings.home, diff --git a/src/pages/panel/sitekey/mod.rs b/src/pages/panel/sitekey/mod.rs index 9043251f..c57421ec 100644 --- a/src/pages/panel/sitekey/mod.rs +++ b/src/pages/panel/sitekey/mod.rs @@ -24,9 +24,11 @@ mod view; pub mod routes { pub struct Sitekey { pub list: &'static str, - pub add: &'static str, + pub add_easy: &'static str, + pub add_advance: &'static str, pub view: &'static str, - pub edit: &'static str, + pub edit_easy: &'static str, + pub edit_advance: &'static str, pub delete: &'static str, } @@ -34,23 +36,63 @@ pub mod routes { pub const fn new() -> Self { Sitekey { list: "/sitekeys", - add: "/sitekeys/add", + add_advance: "/sitekeys/advance/add", + add_easy: "/sitekeys/easy/add", view: "/sitekey/{key}", - edit: "/sitekey/{key}/edit", + edit_advance: "/sitekey/{key}/advance/edit", + edit_easy: "/sitekey/{key}/easy/edit", delete: "/sitekey/{key}/delete", } } pub const fn get_sitemap() -> [&'static str; 2] { const S: Sitekey = Sitekey::new(); - [S.list, S.add] + [S.list, S.add_advance] + } + + pub fn get_edit_easy(&self, key: &str) -> String { + self.edit_easy.replace("{key}", key) + } + + pub fn get_edit_advance(&self, key: &str) -> String { + self.edit_advance.replace("{key}", key) + } + + pub fn get_view(&self, key: &str) -> String { + self.view.replace("{key}", key) + } + + pub fn get_delete(&self, key: &str) -> String { + self.delete.replace("{key}", key) } } } pub fn services(cfg: &mut actix_web::web::ServiceConfig) { - cfg.service(add::add_sitekey); + cfg.service(add::advance); + cfg.service(add::easy); cfg.service(list::list_sitekeys); cfg.service(view::view_sitekey); cfg.service(edit::edit_sitekey); cfg.service(delete::delete_sitekey); } + +#[cfg(test)] +mod tests { + use super::routes::Sitekey; + + #[test] + fn get_sitekey_routes_work() { + const ROUTES: Sitekey = Sitekey::new(); + const KEY: &str = "foo"; + let tests = [ + (ROUTES.get_edit_easy(KEY), "/sitekey/foo/easy/edit"), + (ROUTES.get_edit_advance(KEY), "/sitekey/foo/advance/edit"), + (ROUTES.get_view(KEY), "/sitekey/foo"), + (ROUTES.get_delete(KEY), "/sitekey/foo/delete"), + ]; + + for (r, l) in tests.iter() { + assert_eq!(r, l); + } + } +} diff --git a/templates/panel/header/taskbar/new-sitekey-btn.html b/templates/panel/header/taskbar/new-sitekey-btn.html index 3f708166..45412bd2 100644 --- a/templates/panel/header/taskbar/new-sitekey-btn.html +++ b/templates/panel/header/taskbar/new-sitekey-btn.html @@ -1,4 +1,4 @@ - +