Show direct children for item
This commit is contained in:
parent
b736eba0a0
commit
5147257e72
|
@ -28,6 +28,7 @@ struct ItemDetails {
|
|||
item: Item,
|
||||
item_class: ItemClass,
|
||||
parents: Vec<Item>,
|
||||
children: Vec<Item>,
|
||||
}
|
||||
|
||||
#[get("/item/{id}")]
|
||||
|
@ -50,11 +51,16 @@ async fn show_item(
|
|||
.await
|
||||
.map_err(error::ErrorInternalServerError)?;
|
||||
|
||||
let children = manage::item::get_children(&mut pool.get().await.unwrap(), item.id)
|
||||
.await
|
||||
.map_err(error::ErrorInternalServerError)?;
|
||||
|
||||
Ok(ItemDetails {
|
||||
req,
|
||||
item,
|
||||
item_class,
|
||||
parents,
|
||||
children,
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
@ -122,3 +122,14 @@ pub async fn get_parents_details(
|
|||
.load(conn)
|
||||
.await
|
||||
}
|
||||
|
||||
pub async fn get_children(
|
||||
conn: &mut AsyncPgConnection,
|
||||
id: Uuid,
|
||||
) -> Result<Vec<Item>, diesel::result::Error> {
|
||||
schema::items::table
|
||||
.filter(schema::items::parent.eq(id))
|
||||
.select(Item::as_select())
|
||||
.load(conn)
|
||||
.await
|
||||
}
|
||||
|
|
|
@ -49,4 +49,14 @@ SPDX-License-Identifier: AGPL-3.0-or-later
|
|||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
{% if children.len() != 0 %}
|
||||
<h3 class="mt-4">Direct Children</h3>
|
||||
|
||||
<ul>
|
||||
{% for child in children %}
|
||||
<li><a href="/item/{{ child.id }}">{{ child.name }}</a></li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
{% endif %}
|
||||
{% endblock %}
|
||||
|
|
Loading…
Reference in a new issue