mirror of
https://github.com/zadam/trilium.git
synced 2025-10-21 23:59:02 +02:00
feat(views/table): merge open note and icon into title
This commit is contained in:
parent
e5b10ab16a
commit
08cf95aa38
@ -1,8 +1,8 @@
|
|||||||
import FNote from "../../../entities/fnote.js";
|
import FNote from "../../../entities/fnote.js";
|
||||||
import type { LabelType } from "../../../services/promoted_attribute_definition_parser.js";
|
import type { LabelType } from "../../../services/promoted_attribute_definition_parser.js";
|
||||||
import type { ColumnDefinition } from "tabulator-tables";
|
import type { ColumnDefinition } from "tabulator-tables";
|
||||||
import link from "../../../services/link.js";
|
import { RelationEditor } from "./relation_editor.js";
|
||||||
import { RelationEditor, RelationFormatter } from "./relation_editor.js";
|
import { NoteFormatter, NoteTitleFormatter } from "./formatters.js";
|
||||||
|
|
||||||
export type TableData = {
|
export type TableData = {
|
||||||
iconClass: string;
|
iconClass: string;
|
||||||
@ -47,7 +47,7 @@ const labelTypeMappings: Record<ColumnType, Partial<ColumnDefinition>> = {
|
|||||||
},
|
},
|
||||||
relation: {
|
relation: {
|
||||||
editor: RelationEditor,
|
editor: RelationEditor,
|
||||||
formatter: RelationFormatter
|
formatter: NoteFormatter
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -74,18 +74,6 @@ export function buildColumnDefinitions(info: PromotedAttributeInformation[]) {
|
|||||||
resizable: false,
|
resizable: false,
|
||||||
frozen: true
|
frozen: true
|
||||||
},
|
},
|
||||||
{
|
|
||||||
field: "iconClass",
|
|
||||||
title: "Note icon",
|
|
||||||
titleFormatter: emptyTitleFormatter,
|
|
||||||
width: 40,
|
|
||||||
headerSort: false,
|
|
||||||
hozAlign: "center",
|
|
||||||
formatter(cell) {
|
|
||||||
const iconClass = cell.getValue();
|
|
||||||
return `<span class="bx ${iconClass}"></span>`;
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
field: "noteId",
|
field: "noteId",
|
||||||
title: "Note ID",
|
title: "Note ID",
|
||||||
@ -95,6 +83,7 @@ export function buildColumnDefinitions(info: PromotedAttributeInformation[]) {
|
|||||||
field: "title",
|
field: "title",
|
||||||
title: "Title",
|
title: "Title",
|
||||||
editor: "input",
|
editor: "input",
|
||||||
|
formatter: NoteTitleFormatter,
|
||||||
width: 400
|
width: 400
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
@ -110,22 +99,6 @@ export function buildColumnDefinitions(info: PromotedAttributeInformation[]) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// End actions
|
|
||||||
columnDefs.push({
|
|
||||||
title: "Open note button",
|
|
||||||
width: 40,
|
|
||||||
hozAlign: "center",
|
|
||||||
headerSort: false,
|
|
||||||
formatter: () => `<span class="bx bx-window-open"></span>`,
|
|
||||||
titleFormatter: emptyTitleFormatter,
|
|
||||||
cellClick: (e, cell) => {
|
|
||||||
const noteId = cell.getRow().getCell("noteId").getValue();
|
|
||||||
if (noteId) {
|
|
||||||
link.goToLinkExt(e as MouseEvent, `#root/${noteId}`);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
return columnDefs;
|
return columnDefs;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -0,0 +1,41 @@
|
|||||||
|
import { CellComponent } from "tabulator-tables";
|
||||||
|
import { loadReferenceLinkTitle } from "../../../services/link.js";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Custom formatter to represent a note, with the icon and note title being rendered.
|
||||||
|
*
|
||||||
|
* The value of the cell must be the note ID.
|
||||||
|
*/
|
||||||
|
export function NoteFormatter(cell: CellComponent, formatterParams, onRendered) {
|
||||||
|
let noteId = cell.getValue();
|
||||||
|
if (!noteId) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
onRendered(async () => {
|
||||||
|
const $noteRef = $("<span>");
|
||||||
|
const href = `#root/${noteId}`;
|
||||||
|
$noteRef.addClass("reference-link");
|
||||||
|
$noteRef.attr("data-href", href);
|
||||||
|
|
||||||
|
await loadReferenceLinkTitle($noteRef, href);
|
||||||
|
cell.getElement().appendChild($noteRef[0]);
|
||||||
|
});
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
export function NoteTitleFormatter(cell: CellComponent, formatterParams, onRendered) {
|
||||||
|
const { noteId, iconClass } = cell.getRow().getData();
|
||||||
|
if (!noteId) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
const $noteRef = $("<span>");
|
||||||
|
const href = `#root/${noteId}`;
|
||||||
|
$noteRef.addClass("reference-link");
|
||||||
|
$noteRef.attr("data-href", href);
|
||||||
|
$noteRef.text(cell.getValue());
|
||||||
|
$noteRef.prepend($("<span>").addClass(iconClass));
|
||||||
|
|
||||||
|
return $noteRef[0].outerHTML;
|
||||||
|
}
|
@ -1,6 +1,5 @@
|
|||||||
import { CellComponent } from "tabulator-tables";
|
import { CellComponent } from "tabulator-tables";
|
||||||
import note_autocomplete from "../../../services/note_autocomplete";
|
import note_autocomplete from "../../../services/note_autocomplete";
|
||||||
import { loadReferenceLinkTitle } from "../../../services/link";
|
|
||||||
import froca from "../../../services/froca";
|
import froca from "../../../services/froca";
|
||||||
|
|
||||||
export function RelationEditor(cell: CellComponent, onRendered, success, cancel, editorParams){
|
export function RelationEditor(cell: CellComponent, onRendered, success, cancel, editorParams){
|
||||||
@ -50,21 +49,3 @@ export function RelationEditor(cell: CellComponent, onRendered, success, cancel,
|
|||||||
container.appendChild(editor);
|
container.appendChild(editor);
|
||||||
return container;
|
return container;
|
||||||
};
|
};
|
||||||
|
|
||||||
export function RelationFormatter(cell: CellComponent, formatterParams, onRendered) {
|
|
||||||
const noteId = cell.getValue();
|
|
||||||
if (!noteId) {
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
|
|
||||||
onRendered(async () => {
|
|
||||||
const $noteRef = $("<span>");
|
|
||||||
const href = `#root/${noteId}`;
|
|
||||||
$noteRef.addClass("reference-link");
|
|
||||||
$noteRef.attr("data-href", href);
|
|
||||||
|
|
||||||
await loadReferenceLinkTitle($noteRef, href);
|
|
||||||
cell.getElement().appendChild($noteRef[0]);
|
|
||||||
});
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user