2025-06-25 13:06:38 +03:00
|
|
|
import { createGrid, AllCommunityModule, ModuleRegistry, columnDropStyleBordered, GridOptions } from "ag-grid-community";
|
|
|
|
|
import { buildData, type TableData } from "./data.js";
|
2025-06-25 11:03:43 +03:00
|
|
|
import FNote from "../../../entities/fnote.js";
|
2025-06-25 13:06:38 +03:00
|
|
|
import getPromotedAttributeInformation, { PromotedAttributeInformation } from "./parser.js";
|
|
|
|
|
import { setLabel } from "../../../services/attributes.js";
|
2025-06-25 10:49:33 +03:00
|
|
|
|
|
|
|
|
ModuleRegistry.registerModules([ AllCommunityModule ]);
|
|
|
|
|
|
2025-06-25 11:23:34 +03:00
|
|
|
export default function renderTable(el: HTMLElement, parentNote: FNote, notes: FNote[]) {
|
2025-06-25 13:06:38 +03:00
|
|
|
const info = getPromotedAttributeInformation(parentNote);
|
|
|
|
|
|
2025-06-25 10:49:33 +03:00
|
|
|
createGrid(el, {
|
2025-06-25 13:06:38 +03:00
|
|
|
...buildData(info, notes),
|
|
|
|
|
...setupEditing(info)
|
2025-06-25 10:49:33 +03:00
|
|
|
});
|
|
|
|
|
}
|
2025-06-25 13:06:38 +03:00
|
|
|
|
|
|
|
|
function setupEditing(info: PromotedAttributeInformation[]): GridOptions<TableData> {
|
|
|
|
|
return {
|
|
|
|
|
onCellValueChanged(event) {
|
|
|
|
|
if (event.type !== "cellValueChanged") {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const noteId = event.data.noteId;
|
|
|
|
|
const name = event.colDef.field;
|
|
|
|
|
if (!name) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const { newValue } = event;
|
|
|
|
|
setLabel(noteId, name, newValue);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|