From b574bded1c628ad01b8506c5960d212734dbe2c2 Mon Sep 17 00:00:00 2001 From: Simon Bruder Date: Tue, 6 Aug 2024 16:48:48 +0200 Subject: [PATCH] Generalize parents_breadcrumb --- src/frontend/item/list.rs | 10 ++++++++-- src/frontend/item/show.rs | 10 ++++++++-- src/frontend/templates/helpers.rs | 9 ++++----- 3 files changed, 20 insertions(+), 9 deletions(-) diff --git a/src/frontend/item/list.rs b/src/frontend/item/list.rs index aa4afc2..a274c9d 100644 --- a/src/frontend/item/list.rs +++ b/src/frontend/item/list.rs @@ -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 + )) + } } } } diff --git a/src/frontend/item/show.rs b/src/frontend/item/show.rs index 49ab444..0a02c24 100644 --- a/src/frontend/item/show.rs +++ b/src/frontend/item/show.rs @@ -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" } diff --git a/src/frontend/templates/helpers.rs b/src/frontend/templates/helpers.rs index 2a0f649..18d1429 100644 --- a/src/frontend/templates/helpers.rs +++ b/src/frontend/templates/helpers.rs @@ -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> = if full { - Box::new(parents.iter()) + @let parents: Box> = 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 {