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

View file

@ -14,14 +14,14 @@ SPDX-License-Identifier: AGPL-3.0-or-later
<thead> <thead>
<tr> <tr>
<th>Name</th> <th>Name</th>
<th>Type</th> <th>Parent</th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
{% for item_class in item_classes -%} {% for item_class in item_classes.values() -%}
<tr> <tr>
<td><a href="/item-class/{{ item_class.id }}">{{ item_class.name }}</a></td> <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> </tr>
{% endfor -%} {% endfor -%}
</tbody> </tbody>