Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
feat(views/board): insert above/below
Elian Doran26ee0ff48fdd
diff --git a/apps/client/src/translations/en/translation.json b/apps/client/src/translations/en/translation.jsonindex d436cc078c..6a9f5a4134 100644--- a/apps/client/src/translations/en/translation.json+++ b/apps/client/src/translations/en/translation.json@@ -1971,6 +1971,8 @@},"board_view": {"delete-note": "Delete Note",- "move-to": "Move to"+ "move-to": "Move to",+ "insert-above": "Insert above",+ "insert-below": "Insert below"}}diff --git a/apps/client/src/widgets/view_widgets/board_view/api.ts b/apps/client/src/widgets/view_widgets/board_view/api.tsindex af87668aea..436e881521 100644--- a/apps/client/src/widgets/view_widgets/board_view/api.ts+++ b/apps/client/src/widgets/view_widgets/board_view/api.ts@@ -1,12 +1,45 @@+import appContext from "../../../components/app_context";import attributes from "../../../services/attributes";+import note_create from "../../../services/note_create";export default class BoardApi {- constructor(public columns: string[]) {+ constructor(+ private _columns: string[],+ private _parentNoteId: string) {}++ get columns() {+ return this._columns;}async changeColumn(noteId: string, newColumn: string) {await attributes.setLabel(noteId, "status", newColumn);}+ openNote(noteId: string) {+ appContext.triggerCommand("openInPopup", { noteIdOrPath: noteId });+ }++ async insertRowAtPosition(+ column: string,+ relativeToBranchId: string,+ direction: "before" | "after",+ open: boolean = true) {+ const { note } = await note_create.createNote(this._parentNoteId, {+ activate: false,+ targetBranchId: relativeToBranchId,+ target: direction+ });++ if (!note) {+ throw new Error("Failed to create note");+ }++ const { noteId } = note;+ await this.changeColumn(noteId, column);+ if (open) {+ this.openNote(noteId);+ }+ }+}diff --git a/apps/client/src/widgets/view_widgets/board_view/context_menu.ts b/apps/client/src/widgets/view_widgets/board_view/context_menu.tsindex 03d8099ddf..fb7291922d 100644--- a/apps/client/src/widgets/view_widgets/board_view/context_menu.ts+++ b/apps/client/src/widgets/view_widgets/board_view/context_menu.ts@@ -17,6 +17,7 @@ export function showNoteContextMenu({ $container, api }: ShowNoteContextMenuArgsconst $el = $(event.currentTarget);const noteId = $el.data("note-id");const branchId = $el.data("branch-id");+ const column = $el.closest(".board-column").data("column");if (!noteId) return;contextMenu.show({@@ -34,6 +35,15 @@ export function showNoteContextMenu({ $container, api }: ShowNoteContextMenuArgs}))},{ title: "----" },+ {+ title: t("board_view.insert-above"),+ handler: () => api.insertRowAtPosition(column, branchId, "before")+ },+ {+ title: t("board_view.insert-below"),+ handler: () => api.insertRowAtPosition(column, branchId, "after")+ },+ { title: "----" },{title: t("board_view.delete-note"),uiIcon: "bx bx-trash",diff --git a/apps/client/src/widgets/view_widgets/board_view/index.ts b/apps/client/src/widgets/view_widgets/board_view/index.tsindex d1f8a81087..7ca6d97384 100644--- a/apps/client/src/widgets/view_widgets/board_view/index.ts+++ b/apps/client/src/widgets/view_widgets/board_view/index.ts@@ -157,7 +157,10 @@ export default class BoardView extends ViewMode<BoardData> {const data = await getBoardData(this.parentNote, "status", persistedData);const columns = Array.from(data.byColumn.keys()) || [];- this.api = new BoardApi(columns);+ this.api = new BoardApi(+ columns,+ this.parentNote.noteId+ );showNoteContextMenu({$container: this.$container,api: this.api