Generalize parents_breadcrumb
This commit is contained in:
parent
bb309f5cd9
commit
06f9d3f3ad
|
@ -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
|
||||
))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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" }
|
||||
|
|
|
@ -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 {
|
||||
|
|
Loading…
Reference in a new issue