Generalize parents_breadcrumb
This commit is contained in:
parent
413a02cdaa
commit
61f356269c
|
@ -4,7 +4,7 @@
|
||||||
|
|
||||||
use actix_identity::Identity;
|
use actix_identity::Identity;
|
||||||
use actix_web::{error, get, web, Responder};
|
use actix_web::{error, get, web, Responder};
|
||||||
use maud::html;
|
use maud::{html, Render};
|
||||||
|
|
||||||
use crate::database::{items::ItemPreview, ItemRepository};
|
use crate::database::{items::ItemPreview, ItemRepository};
|
||||||
use crate::frontend::templates::{
|
use crate::frontend::templates::{
|
||||||
|
@ -61,7 +61,13 @@ async fn get(
|
||||||
td { (ItemPreview::new(item.id, item.name.clone().terse())) }
|
td { (ItemPreview::new(item.id, item.name.clone().terse())) }
|
||||||
td { (item.state) }
|
td { (item.state) }
|
||||||
td { a href={ "/item-class/" (item.class) } { (item.class_name) } }
|
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_identity::Identity;
|
||||||
use actix_web::{error, get, web, Responder};
|
use actix_web::{error, get, web, Responder};
|
||||||
use maud::html;
|
use maud::{html, Render};
|
||||||
use serde_variant::to_variant_name;
|
use serde_variant::to_variant_name;
|
||||||
use time::OffsetDateTime;
|
use time::OffsetDateTime;
|
||||||
use uuid::Uuid;
|
use uuid::Uuid;
|
||||||
|
@ -121,7 +121,13 @@ async fn get(
|
||||||
}
|
}
|
||||||
tr {
|
tr {
|
||||||
th { "Parents" }
|
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 {
|
tr {
|
||||||
th { "Original Packaging" }
|
th { "Original Packaging" }
|
||||||
|
|
|
@ -7,7 +7,6 @@ use std::fmt;
|
||||||
use maud::{html, Markup, PreEscaped, Render};
|
use maud::{html, Markup, PreEscaped, Render};
|
||||||
use uuid::Uuid;
|
use uuid::Uuid;
|
||||||
|
|
||||||
use crate::database::items::{ItemName, ItemPreview};
|
|
||||||
use crate::label::LabelPreset;
|
use crate::label::LabelPreset;
|
||||||
|
|
||||||
pub enum Css<'a> {
|
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;
|
const LIMIT: usize = 3;
|
||||||
|
|
||||||
html! {
|
html! {
|
||||||
|
@ -178,10 +177,10 @@ pub fn parents_breadcrumb(name: ItemName, parents: &[ItemPreview], full: bool) -
|
||||||
@if !full && parents.len() > LIMIT {
|
@if !full && parents.len() > LIMIT {
|
||||||
li .breadcrumb-item { "…" }
|
li .breadcrumb-item { "…" }
|
||||||
}
|
}
|
||||||
@let parents: Box<dyn Iterator<Item = &ItemPreview>> = if full {
|
@let parents: Box<dyn Iterator<Item = &dyn Render>> = if full {
|
||||||
Box::new(parents.iter())
|
Box::new(parents.into_iter())
|
||||||
} else {
|
} else {
|
||||||
Box::new(parents.iter().rev().take(LIMIT).rev())
|
Box::new(parents.into_iter().rev().take(LIMIT).rev())
|
||||||
};
|
};
|
||||||
@for parent in parents {
|
@for parent in parents {
|
||||||
li .breadcrumb-item {
|
li .breadcrumb-item {
|
||||||
|
|
Loading…
Reference in a new issue