From a6461723c5b36ae51cdf2d8df1ae16471c347abf Mon Sep 17 00:00:00 2001 From: Simon Bruder Date: Thu, 11 Jul 2024 23:20:22 +0200 Subject: [PATCH] Add useful page actions --- src/frontend/item.rs | 4 ++++ src/frontend/item_class.rs | 24 ++++++++++++++++++------ 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/src/frontend/item.rs b/src/frontend/item.rs index 6473731..96878e9 100644 --- a/src/frontend/item.rs +++ b/src/frontend/item.rs @@ -57,6 +57,10 @@ async fn show_item( title: Some(&title), page_title: Some(Box::new(item_name.clone())), page_actions: vec![ + (templates::helpers::PageAction { + href: format!("/items/add?parent={}", item.id), + name: "Add Child".to_string(), + }), (templates::helpers::PageAction { href: format!("/item/{}/edit", item.id), name: "Edit".to_string(), diff --git a/src/frontend/item_class.rs b/src/frontend/item_class.rs index 8506db6..9593b55 100644 --- a/src/frontend/item_class.rs +++ b/src/frontend/item_class.rs @@ -47,17 +47,29 @@ async fn show_item_class( let mut title = item_class.name.clone(); title.push_str(" – Item Details"); + let mut page_actions = vec![ + (templates::helpers::PageAction { + href: format!("/items/add?class={}", item_class.id), + name: "Add Item".to_string(), + }), + ]; + if item_class.parent.is_none() { + page_actions.push(templates::helpers::PageAction { + href: format!("/item-classes/add?parent={}", item_class.id), + name: "Add Child".to_string(), + }); + } + page_actions.push(templates::helpers::PageAction { + href: format!("/item-class/{}/edit", item_class.id), + name: "Edit".to_string(), + }); + Ok(templates::base( TemplateConfig { path: &format!("/item-class/{}", item_class.id), title: Some(&title), page_title: Some(Box::new(item_class.name.clone())), - page_actions: vec![ - (templates::helpers::PageAction { - href: format!("/item-class/{}/edit", item_class.id), - name: "Edit".to_string(), - }), - ], + page_actions, ..Default::default() }, html! {