Allow generating label from item (class) page

This commit is contained in:
Simon Bruder 2024-07-14 16:37:23 +02:00
parent b15a2e2885
commit c33733c614
Signed by: simon
GPG key ID: 347FF8699CDA0776
2 changed files with 39 additions and 1 deletions

View file

@ -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::<LabelPreset>()
.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,

View file

@ -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::<LabelPreset>()
.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::<Vec<String>>().join(",")
),
name: preset.to_string(),
})
.collect(),
colour: Colour::Primary,
})
}
}
ul {
@for item in items {