Get sitekey routes using methods on pages::panel::sitekey::routes::Sitekey
for consistency purposes
This commit is contained in:
parent
f15df541c1
commit
5a49940b89
3 changed files with 53 additions and 10 deletions
|
@ -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,
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
<a class="taskbar__link" href="<.= crate::PAGES.panel.sitekey.add .>">
|
||||
<a class="taskbar__link" href="<.= crate::PAGES.panel.sitekey.add_easy .>">
|
||||
<button class="taskbar__add-site">
|
||||
+ New Site
|
||||
</button>
|
||||
|
|
Loading…
Reference in a new issue