mirror of
				https://github.com/zadam/trilium.git
				synced 2025-11-04 05:28:59 +01:00 
			
		
		
		
	feat(views/board): insert above/below
This commit is contained in:
		
							parent
							
								
									1763d80d5f
								
							
						
					
					
						commit
						26ee0ff48f
					
				@ -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"
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -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);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -17,6 +17,7 @@ export function showNoteContextMenu({ $container, api }: ShowNoteContextMenuArgs
 | 
			
		||||
        const $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",
 | 
			
		||||
 | 
			
		||||
@ -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
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user