mirror of
https://github.com/zadam/trilium.git
synced 2025-10-21 23:59:02 +02:00
refactor(views/table): clean up
This commit is contained in:
parent
e703ce92a8
commit
cd338085fb
@ -1,6 +1,5 @@
|
|||||||
import { RelationEditor } from "./relation_editor.js";
|
import { RelationEditor } from "./relation_editor.js";
|
||||||
import { NoteFormatter, NoteTitleFormatter, RowNumberFormatter } from "./formatters.js";
|
import { NoteFormatter, NoteTitleFormatter, RowNumberFormatter } from "./formatters.js";
|
||||||
import { applyHeaderMenu } from "./header-menu.js";
|
|
||||||
import type { ColumnDefinition, Tabulator } from "tabulator-tables";
|
import type { ColumnDefinition, Tabulator } from "tabulator-tables";
|
||||||
import { LabelType } from "../../../services/promoted_attribute_definition_parser.js";
|
import { LabelType } from "../../../services/promoted_attribute_definition_parser.js";
|
||||||
|
|
||||||
@ -86,7 +85,6 @@ export function buildColumnDefinitions(info: AttributeDefinitionInformation[], m
|
|||||||
seenFields.add(field);
|
seenFields.add(field);
|
||||||
}
|
}
|
||||||
|
|
||||||
applyHeaderMenu(columnDefs);
|
|
||||||
if (existingColumnData) {
|
if (existingColumnData) {
|
||||||
restoreExistingData(columnDefs, existingColumnData);
|
restoreExistingData(columnDefs, existingColumnData);
|
||||||
}
|
}
|
||||||
|
@ -1,53 +0,0 @@
|
|||||||
import type { ColumnComponent, ColumnDefinition, MenuObject, Tabulator } from "tabulator-tables";
|
|
||||||
|
|
||||||
export function applyHeaderMenu(columns: ColumnDefinition[]) {
|
|
||||||
for (let column of columns) {
|
|
||||||
if (column.headerSort !== false) {
|
|
||||||
column.headerMenu = headerMenu;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function headerMenu(this: Tabulator) {
|
|
||||||
const menu: MenuObject<ColumnComponent>[] = [];
|
|
||||||
const columns = this.getColumns();
|
|
||||||
|
|
||||||
for (let column of columns) {
|
|
||||||
//create checkbox element using font awesome icons
|
|
||||||
let icon = document.createElement("i");
|
|
||||||
icon.classList.add("bx");
|
|
||||||
icon.classList.add(column.isVisible() ? "bx-check" : "bx-empty");
|
|
||||||
|
|
||||||
//build label
|
|
||||||
let label = document.createElement("span");
|
|
||||||
let title = document.createElement("span");
|
|
||||||
|
|
||||||
title.textContent = " " + column.getDefinition().title;
|
|
||||||
|
|
||||||
label.appendChild(icon);
|
|
||||||
label.appendChild(title);
|
|
||||||
|
|
||||||
//create menu item
|
|
||||||
menu.push({
|
|
||||||
label: label,
|
|
||||||
action: function (e) {
|
|
||||||
//prevent menu closing
|
|
||||||
e.stopPropagation();
|
|
||||||
|
|
||||||
//toggle current column visibility
|
|
||||||
column.toggle();
|
|
||||||
|
|
||||||
//change menu item icon
|
|
||||||
if (column.isVisible()) {
|
|
||||||
icon.classList.remove("bx-empty");
|
|
||||||
icon.classList.add("bx-check");
|
|
||||||
} else {
|
|
||||||
icon.classList.remove("bx-check");
|
|
||||||
icon.classList.add("bx-empty");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
return menu;
|
|
||||||
};
|
|
@ -106,8 +106,6 @@ export default class TableView extends ViewMode<StateInfo> {
|
|||||||
private api?: Tabulator;
|
private api?: Tabulator;
|
||||||
private newAttribute?: Attribute;
|
private newAttribute?: Attribute;
|
||||||
private persistentData: StateInfo["tableData"];
|
private persistentData: StateInfo["tableData"];
|
||||||
/** If set to a note ID, whenever the rows will be updated, the title of the note will be automatically focused for editing. */
|
|
||||||
private branchIdToEdit?: string;
|
|
||||||
|
|
||||||
constructor(args: ViewModeArgs) {
|
constructor(args: ViewModeArgs) {
|
||||||
super(args, "table");
|
super(args, "table");
|
||||||
|
Loading…
x
Reference in New Issue
Block a user