Extract label generation page action dropdown

This commit is contained in:
Simon Bruder 2024-07-16 12:46:30 +02:00
parent 7defae7931
commit 693fe68797
Signed by: simon
GPG key ID: 347FF8699CDA0776
3 changed files with 29 additions and 32 deletions

View file

@ -13,7 +13,6 @@ 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::*;
@ -84,21 +83,7 @@ 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::generate_labels(&[&item]),
(PageActionGroup::Button {
action: PageAction {
method: PageActionMethod::Get,

View file

@ -11,7 +11,6 @@ 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::*;
@ -143,21 +142,9 @@ async fn show(
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,
})
(PageActionGroup::generate_labels(
&items.iter().collect::<Vec<&Item>>(),
))
}
}

View file

@ -5,6 +5,7 @@
use std::collections::HashMap;
use std::fmt::{self, Display};
use crate::label::LabelPreset;
use crate::models::*;
use maud::{html, Markup, PreEscaped, Render};
use uuid::Uuid;
@ -190,6 +191,30 @@ impl Render for PageActionGroup {
}
}
impl PageActionGroup {
pub fn generate_labels(items: &[&Item]) -> PageActionGroup {
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(),
items
.iter()
.map(|item| item.id.to_string())
.collect::<Vec<String>>()
.join(",")
),
name: preset.to_string(),
})
.collect(),
colour: Colour::Primary,
}
}
}
pub fn parents_breadcrumb(
item: &Item,
item_class: &ItemClass,