Show item class parent in listing

This commit is contained in:
Simon Bruder 2024-07-08 20:54:57 +02:00
parent 02c1ac1e9d
commit 089657d5da
Signed by: simon
GPG key ID: 347FF8699CDA0776
2 changed files with 7 additions and 5 deletions

View file

@ -2,6 +2,8 @@
//
// SPDX-License-Identifier: AGPL-3.0-or-later
use std::collections::HashMap;
use actix_web::{error, get, post, web, HttpRequest, Responder};
use askama_actix::Template;
use uuid::Uuid;
@ -59,7 +61,7 @@ async fn show_item_class(
#[template(path = "item_class_list.html")]
struct ItemClassList {
req: HttpRequest,
item_classes: Vec<ItemClass>,
item_classes: HashMap<Uuid, ItemClass>,
}
#[get("/item-classes")]
@ -67,7 +69,7 @@ async fn list_item_classes(
req: HttpRequest,
pool: web::Data<DbPool>,
) -> actix_web::Result<impl Responder> {
let item_classes = manage::item_class::get_all(&mut pool.get().await.unwrap())
let item_classes = manage::item_class::get_all_as_map(&mut pool.get().await.unwrap())
.await
.map_err(error::ErrorInternalServerError)?;

View file

@ -14,14 +14,14 @@ SPDX-License-Identifier: AGPL-3.0-or-later
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th>Parent</th>
</tr>
</thead>
<tbody>
{% for item_class in item_classes -%}
{% for item_class in item_classes.values() -%}
<tr>
<td><a href="/item-class/{{ item_class.id }}">{{ item_class.name }}</a></td>
<td>{{ item_class.type }}</td>
<td>{% if let Some(parent) = item_class.parent %}<a href="/item-class/{{ parent }}">{{ item_classes.get(parent).unwrap().name }}</a>{% else %}-{% endif %}</td>
</tr>
{% endfor -%}
</tbody>