mirror of
https://github.com/zadam/trilium.git
synced 2025-11-06 13:26:01 +01:00
72 lines
2.3 KiB
TypeScript
72 lines
2.3 KiB
TypeScript
|
|
import FNote from "../../../entities/fnote.js";
|
||
|
|
import type { LabelType } from "../../../services/promoted_attribute_definition_parser.js";
|
||
|
|
import type { PromotedAttributeInformation } from "./columns.js";
|
||
|
|
|
||
|
|
export type TableData = {
|
||
|
|
iconClass: string;
|
||
|
|
noteId: string;
|
||
|
|
title: string;
|
||
|
|
labels: Record<string, boolean | string | null>;
|
||
|
|
relations: Record<string, boolean | string | null>;
|
||
|
|
branchId: string;
|
||
|
|
};
|
||
|
|
|
||
|
|
export async function buildRowDefinitions(parentNote: FNote, notes: FNote[], infos: PromotedAttributeInformation[]) {
|
||
|
|
const definitions: TableData[] = [];
|
||
|
|
for (const branch of parentNote.getChildBranches()) {
|
||
|
|
const note = await branch.getNote();
|
||
|
|
if (!note) {
|
||
|
|
continue; // Skip if the note is not found
|
||
|
|
}
|
||
|
|
|
||
|
|
const labels: typeof definitions[0]["labels"] = {};
|
||
|
|
const relations: typeof definitions[0]["relations"] = {};
|
||
|
|
for (const { name, type } of infos) {
|
||
|
|
if (type === "relation") {
|
||
|
|
relations[name] = note.getRelationValue(name);
|
||
|
|
} else {
|
||
|
|
labels[name] = note.getLabelValue(name);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
definitions.push({
|
||
|
|
iconClass: note.getIcon(),
|
||
|
|
noteId: note.noteId,
|
||
|
|
title: note.title,
|
||
|
|
labels,
|
||
|
|
relations,
|
||
|
|
branchId: branch.branchId
|
||
|
|
});
|
||
|
|
}
|
||
|
|
|
||
|
|
return definitions;
|
||
|
|
}
|
||
|
|
|
||
|
|
export default function getPromotedAttributeInformation(parentNote: FNote) {
|
||
|
|
const info: PromotedAttributeInformation[] = [];
|
||
|
|
for (const promotedAttribute of parentNote.getPromotedDefinitionAttributes()) {
|
||
|
|
const def = promotedAttribute.getDefinition();
|
||
|
|
if (def.multiplicity !== "single") {
|
||
|
|
console.warn("Multiple values are not supported for now");
|
||
|
|
continue;
|
||
|
|
}
|
||
|
|
|
||
|
|
const [ labelType, name ] = promotedAttribute.name.split(":", 2);
|
||
|
|
if (promotedAttribute.type !== "label") {
|
||
|
|
console.warn("Relations are not supported for now");
|
||
|
|
continue;
|
||
|
|
}
|
||
|
|
|
||
|
|
let type: LabelType | "relation" = def.labelType || "text";
|
||
|
|
if (labelType === "relation") {
|
||
|
|
type = "relation";
|
||
|
|
}
|
||
|
|
|
||
|
|
info.push({
|
||
|
|
name,
|
||
|
|
title: def.promotedAlias,
|
||
|
|
type
|
||
|
|
});
|
||
|
|
}
|
||
|
|
return info;
|
||
|
|
}
|