Generalize parents_breadcrumb

This commit is contained in:
Simon Bruder 2024-08-06 16:48:48 +02:00
parent bb309f5cd9
commit 06f9d3f3ad
Signed by: simon
GPG key ID: 347FF8699CDA0776
3 changed files with 20 additions and 9 deletions

View file

@ -4,7 +4,7 @@
use actix_identity::Identity;
use actix_web::{error, get, web, Responder};
use maud::html;
use maud::{html, Render};
use crate::database::{items::ItemPreview, ItemRepository};
use crate::frontend::templates::{
@ -61,7 +61,13 @@ async fn get(
td { (ItemPreview::new(item.id, item.name.clone().terse())) }
td { (item.state) }
td { a href={ "/item-class/" (item.class) } { (item.class_name) } }
td { (templates::helpers::parents_breadcrumb(item.name, &item.parents, false)) }
td {
(templates::helpers::parents_breadcrumb(
&item.name,
item.parents.iter().map(|parent| parent as &dyn Render).collect(),
false
))
}
}
}
}

View file

@ -4,7 +4,7 @@
use actix_identity::Identity;
use actix_web::{error, get, web, Responder};
use maud::html;
use maud::{html, Render};
use serde_variant::to_variant_name;
use time::OffsetDateTime;
use uuid::Uuid;
@ -121,7 +121,13 @@ async fn get(
}
tr {
th { "Parents" }
td { (templates::helpers::parents_breadcrumb(item.name, &parents, true)) }
td {
(templates::helpers::parents_breadcrumb(
&item.name,
parents.iter().map(|parent| parent as &dyn Render).collect(),
true
))
}
}
tr {
th { "Original Packaging" }

View file

@ -7,7 +7,6 @@ use std::fmt;
use maud::{html, Markup, PreEscaped, Render};
use uuid::Uuid;
use crate::database::items::{ItemName, ItemPreview};
use crate::label::LabelPreset;
pub enum Css<'a> {
@ -170,7 +169,7 @@ impl PageActionGroup {
}
}
pub fn parents_breadcrumb(name: ItemName, parents: &[ItemPreview], full: bool) -> Markup {
pub fn parents_breadcrumb(name: &dyn Render, parents: Vec<&dyn Render>, full: bool) -> Markup {
const LIMIT: usize = 3;
html! {
@ -178,10 +177,10 @@ pub fn parents_breadcrumb(name: ItemName, parents: &[ItemPreview], full: bool) -
@if !full && parents.len() > LIMIT {
li .breadcrumb-item { "" }
}
@let parents: Box<dyn Iterator<Item = &ItemPreview>> = if full {
Box::new(parents.iter())
@let parents: Box<dyn Iterator<Item = &dyn Render>> = if full {
Box::new(parents.into_iter())
} else {
Box::new(parents.iter().rev().take(LIMIT).rev())
Box::new(parents.into_iter().rev().take(LIMIT).rev())
};
@for parent in parents {
li .breadcrumb-item {