From 52879cfe2c853c06911aec228fd4f88f9a9182ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Ml=C3=A1dek?= Date: Wed, 2 Mar 2022 22:39:20 +0100 Subject: [PATCH] [ui] load attribute labels from db --- webui/src/components/widgets/Table.svelte | 25 +++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/webui/src/components/widgets/Table.svelte b/webui/src/components/widgets/Table.svelte index e490cf1..84b8a51 100644 --- a/webui/src/components/widgets/Table.svelte +++ b/webui/src/components/widgets/Table.svelte @@ -13,6 +13,7 @@ import { query } from "../../lib/entity"; import { Readable, readable } from "svelte/store"; import { defaultEntitySort, entityValueSort } from "../../util/sort"; + import { fetchAllAttributes } from "../../lib/api"; const dispatch = createEventDispatcher(); export let columns: string | undefined = undefined; @@ -141,8 +142,7 @@ }); // Formatting & Display - // todo - grab from db - const ATTRIBUTE_LABELS: { [key: string]: string } = { + let ATTRIBUTE_LABELS: { [key: string]: string } = { FILE_MIME: "MIME type", FILE_MTIME: "Last modified", FILE_SIZE: "File size", @@ -152,16 +152,21 @@ IS: "Type", }; + fetchAllAttributes().then((attributes) => { + attributes.forEach((attribute) => { + if (attribute.labels.length) { + ATTRIBUTE_LABELS[attribute.name] = attribute.labels[0]; + } + }); + ATTRIBUTE_LABELS = ATTRIBUTE_LABELS; + }); + const COLUMN_LABELS: { [key: string]: string } = { entity: "Entity", attribute: "Attribute", value: "Value", }; - function formatAttribute(attribute: string) { - return ATTRIBUTE_LABELS[attribute]; - } - function formatValue(value: string | number, attribute: string): string { switch (attribute) { case "FILE_MTIME": @@ -233,9 +238,13 @@ /> {:else if column == ATTR_COL} - +