[ui] load attribute labels from db

This commit is contained in:
Tomáš Mládek 2022-03-02 22:39:20 +01:00
parent 376d929232
commit 52879cfe2c
No known key found for this signature in database
GPG key ID: 65E225C8B3E2ED8A

View file

@ -13,6 +13,7 @@
import { query } from "../../lib/entity"; import { query } from "../../lib/entity";
import { Readable, readable } from "svelte/store"; import { Readable, readable } from "svelte/store";
import { defaultEntitySort, entityValueSort } from "../../util/sort"; import { defaultEntitySort, entityValueSort } from "../../util/sort";
import { fetchAllAttributes } from "../../lib/api";
const dispatch = createEventDispatcher(); const dispatch = createEventDispatcher();
export let columns: string | undefined = undefined; export let columns: string | undefined = undefined;
@ -141,8 +142,7 @@
}); });
// Formatting & Display // Formatting & Display
// todo - grab from db let ATTRIBUTE_LABELS: { [key: string]: string } = {
const ATTRIBUTE_LABELS: { [key: string]: string } = {
FILE_MIME: "MIME type", FILE_MIME: "MIME type",
FILE_MTIME: "Last modified", FILE_MTIME: "Last modified",
FILE_SIZE: "File size", FILE_SIZE: "File size",
@ -152,16 +152,21 @@
IS: "Type", 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 } = { const COLUMN_LABELS: { [key: string]: string } = {
entity: "Entity", entity: "Entity",
attribute: "Attribute", attribute: "Attribute",
value: "Value", value: "Value",
}; };
function formatAttribute(attribute: string) {
return ATTRIBUTE_LABELS[attribute];
}
function formatValue(value: string | number, attribute: string): string { function formatValue(value: string | number, attribute: string): string {
switch (attribute) { switch (attribute) {
case "FILE_MTIME": case "FILE_MTIME":
@ -233,9 +238,13 @@
/> />
</td> </td>
{:else if column == ATTR_COL} {:else if column == ATTR_COL}
<td class:formatted={Boolean(formatAttribute(entry.attribute))}> <td
class:formatted={Boolean(
Object.keys(ATTRIBUTE_LABELS).includes(entry.attribute)
)}
>
<Ellipsis <Ellipsis
value={formatAttribute(entry.attribute) || entry.attribute} value={ATTRIBUTE_LABELS[entry.attribute] || entry.attribute}
title={entry.attribute} title={entry.attribute}
/> />
</td> </td>