From ec559b9041b733477ef53c6a612e9c0d70f70ba6 Mon Sep 17 00:00:00 2001 From: Simon Bruder Date: Sun, 14 Jul 2024 16:37:23 +0200 Subject: [PATCH] Allow generating label from item (class) page --- src/frontend/item.rs | 16 ++++++++++++++++ src/frontend/item_class.rs | 24 +++++++++++++++++++++++- 2 files changed, 39 insertions(+), 1 deletion(-) diff --git a/src/frontend/item.rs b/src/frontend/item.rs index a10af3b..6cc2edf 100644 --- a/src/frontend/item.rs +++ b/src/frontend/item.rs @@ -12,6 +12,7 @@ use uuid::Uuid; use super::templates::helpers::{Colour, ItemName, PageAction, PageActionGroup, PageActionMethod}; use super::templates::{self, datalist, forms, TemplateConfig}; +use crate::label::LabelPreset; use crate::manage; use crate::models::*; @@ -82,6 +83,21 @@ async fn show( }, colour: Colour::Success, }), + (PageActionGroup::Dropdown { + name: "Generate Label".to_string(), + actions: enum_iterator::all::() + .map(|preset| PageAction { + method: PageActionMethod::Get, + target: format!( + "/labels/generate?preset={}&ids={}", + &serde_variant::to_variant_name(&preset).unwrap(), + item.id + ), + name: preset.to_string(), + }) + .collect(), + colour: Colour::Primary, + }), (PageActionGroup::Button { action: PageAction { method: PageActionMethod::Get, diff --git a/src/frontend/item_class.rs b/src/frontend/item_class.rs index 2e78069..7c5cc5b 100644 --- a/src/frontend/item_class.rs +++ b/src/frontend/item_class.rs @@ -10,6 +10,7 @@ use uuid::Uuid; use super::templates::helpers::{Colour, ItemName, PageAction, PageActionGroup, PageActionMethod}; use super::templates::{self, datalist, forms, TemplateConfig}; +use crate::label::LabelPreset; use crate::manage; use crate::models::*; @@ -136,7 +137,28 @@ async fn show( } @if !items.is_empty() { - h3 .mt-4 { "Items" } + div .d-flex.justify-content-between.mt-4 { + div { + h3 { "Items" } + } + div { + (PageActionGroup::Dropdown { + name: "Generate Labels".to_string(), + actions: enum_iterator::all::() + .map(|preset| PageAction { + method: PageActionMethod::Get, + target: format!( + "/labels/generate?preset={}&ids={}", + &serde_variant::to_variant_name(&preset).unwrap(), + items.iter().map(|i| i.id.to_string()).collect::>().join(",") + ), + name: preset.to_string(), + }) + .collect(), + colour: Colour::Primary, + }) + } + } ul { @for item in items {