mirror of
https://github.com/zadam/trilium.git
synced 2025-11-03 11:56:01 +01:00
feat(views/board): insert above/below
This commit is contained in:
@@ -1971,6 +1971,8 @@
|
|||||||
},
|
},
|
||||||
"board_view": {
|
"board_view": {
|
||||||
"delete-note": "Delete Note",
|
"delete-note": "Delete Note",
|
||||||
"move-to": "Move to"
|
"move-to": "Move to",
|
||||||
|
"insert-above": "Insert above",
|
||||||
|
"insert-below": "Insert below"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,12 +1,45 @@
|
|||||||
|
import appContext from "../../../components/app_context";
|
||||||
import attributes from "../../../services/attributes";
|
import attributes from "../../../services/attributes";
|
||||||
|
import note_create from "../../../services/note_create";
|
||||||
|
|
||||||
export default class BoardApi {
|
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) {
|
async changeColumn(noteId: string, newColumn: string) {
|
||||||
await attributes.setLabel(noteId, "status", newColumn);
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ export function showNoteContextMenu({ $container, api }: ShowNoteContextMenuArgs
|
|||||||
const $el = $(event.currentTarget);
|
const $el = $(event.currentTarget);
|
||||||
const noteId = $el.data("note-id");
|
const noteId = $el.data("note-id");
|
||||||
const branchId = $el.data("branch-id");
|
const branchId = $el.data("branch-id");
|
||||||
|
const column = $el.closest(".board-column").data("column");
|
||||||
if (!noteId) return;
|
if (!noteId) return;
|
||||||
|
|
||||||
contextMenu.show({
|
contextMenu.show({
|
||||||
@@ -34,6 +35,15 @@ export function showNoteContextMenu({ $container, api }: ShowNoteContextMenuArgs
|
|||||||
}))
|
}))
|
||||||
},
|
},
|
||||||
{ title: "----" },
|
{ 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"),
|
title: t("board_view.delete-note"),
|
||||||
uiIcon: "bx bx-trash",
|
uiIcon: "bx bx-trash",
|
||||||
|
|||||||
@@ -157,7 +157,10 @@ export default class BoardView extends ViewMode<BoardData> {
|
|||||||
|
|
||||||
const data = await getBoardData(this.parentNote, "status", persistedData);
|
const data = await getBoardData(this.parentNote, "status", persistedData);
|
||||||
const columns = Array.from(data.byColumn.keys()) || [];
|
const columns = Array.from(data.byColumn.keys()) || [];
|
||||||
this.api = new BoardApi(columns);
|
this.api = new BoardApi(
|
||||||
|
columns,
|
||||||
|
this.parentNote.noteId
|
||||||
|
);
|
||||||
showNoteContextMenu({
|
showNoteContextMenu({
|
||||||
$container: this.$container,
|
$container: this.$container,
|
||||||
api: this.api
|
api: this.api
|
||||||
|
|||||||
Reference in New Issue
Block a user