Extract label generation page action dropdown
This commit is contained in:
parent
7defae7931
commit
693fe68797
|
@ -13,7 +13,6 @@ use uuid::Uuid;
|
||||||
|
|
||||||
use super::templates::helpers::{Colour, ItemName, PageAction, PageActionGroup, PageActionMethod};
|
use super::templates::helpers::{Colour, ItemName, PageAction, PageActionGroup, PageActionMethod};
|
||||||
use super::templates::{self, datalist, forms, TemplateConfig};
|
use super::templates::{self, datalist, forms, TemplateConfig};
|
||||||
use crate::label::LabelPreset;
|
|
||||||
use crate::manage;
|
use crate::manage;
|
||||||
use crate::models::*;
|
use crate::models::*;
|
||||||
|
|
||||||
|
@ -84,21 +83,7 @@ async fn show(
|
||||||
},
|
},
|
||||||
colour: Colour::Success,
|
colour: Colour::Success,
|
||||||
}),
|
}),
|
||||||
(PageActionGroup::Dropdown {
|
PageActionGroup::generate_labels(&[&item]),
|
||||||
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 {
|
(PageActionGroup::Button {
|
||||||
action: PageAction {
|
action: PageAction {
|
||||||
method: PageActionMethod::Get,
|
method: PageActionMethod::Get,
|
||||||
|
|
|
@ -11,7 +11,6 @@ use uuid::Uuid;
|
||||||
|
|
||||||
use super::templates::helpers::{Colour, ItemName, PageAction, PageActionGroup, PageActionMethod};
|
use super::templates::helpers::{Colour, ItemName, PageAction, PageActionGroup, PageActionMethod};
|
||||||
use super::templates::{self, datalist, forms, TemplateConfig};
|
use super::templates::{self, datalist, forms, TemplateConfig};
|
||||||
use crate::label::LabelPreset;
|
|
||||||
use crate::manage;
|
use crate::manage;
|
||||||
use crate::models::*;
|
use crate::models::*;
|
||||||
|
|
||||||
|
@ -143,21 +142,9 @@ async fn show(
|
||||||
h3 { "Items" }
|
h3 { "Items" }
|
||||||
}
|
}
|
||||||
div {
|
div {
|
||||||
(PageActionGroup::Dropdown {
|
(PageActionGroup::generate_labels(
|
||||||
name: "Generate Labels".to_string(),
|
&items.iter().collect::<Vec<&Item>>(),
|
||||||
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,
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::fmt::{self, Display};
|
use std::fmt::{self, Display};
|
||||||
|
|
||||||
|
use crate::label::LabelPreset;
|
||||||
use crate::models::*;
|
use crate::models::*;
|
||||||
use maud::{html, Markup, PreEscaped, Render};
|
use maud::{html, Markup, PreEscaped, Render};
|
||||||
use uuid::Uuid;
|
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(
|
pub fn parents_breadcrumb(
|
||||||
item: &Item,
|
item: &Item,
|
||||||
item_class: &ItemClass,
|
item_class: &ItemClass,
|
||||||
|
|
Loading…
Reference in a new issue