mirror of
https://github.com/zadam/trilium.git
synced 2025-11-03 03:46:37 +01:00
feat(views/board): add move to in context menu
This commit is contained in:
@@ -1970,6 +1970,7 @@
|
||||
"delete_row": "Delete row"
|
||||
},
|
||||
"board_view": {
|
||||
"delete-note": "Delete Note"
|
||||
"delete-note": "Delete Note",
|
||||
"move-to": "Move to"
|
||||
}
|
||||
}
|
||||
|
||||
12
apps/client/src/widgets/view_widgets/board_view/api.ts
Normal file
12
apps/client/src/widgets/view_widgets/board_view/api.ts
Normal file
@@ -0,0 +1,12 @@
|
||||
import attributes from "../../../services/attributes";
|
||||
|
||||
export default class BoardApi {
|
||||
|
||||
constructor(public columns: string[]) {
|
||||
}
|
||||
|
||||
async changeColumn(noteId: string, newColumn: string) {
|
||||
await attributes.setLabel(noteId, "status", newColumn);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
interface BoardColumnData {
|
||||
export interface BoardColumnData {
|
||||
value: string;
|
||||
}
|
||||
|
||||
|
||||
@@ -2,8 +2,14 @@ import contextMenu from "../../../menus/context_menu.js";
|
||||
import link_context_menu from "../../../menus/link_context_menu.js";
|
||||
import branches from "../../../services/branches.js";
|
||||
import { t } from "../../../services/i18n.js";
|
||||
import BoardApi from "./api.js";
|
||||
|
||||
export function showNoteContextMenu($container: JQuery<HTMLElement>) {
|
||||
interface ShowNoteContextMenuArgs {
|
||||
$container: JQuery<HTMLElement>;
|
||||
api: BoardApi;
|
||||
}
|
||||
|
||||
export function showNoteContextMenu({ $container, api }: ShowNoteContextMenuArgs) {
|
||||
$container.on("contextmenu", ".board-note", (event) => {
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
@@ -19,6 +25,15 @@ export function showNoteContextMenu($container: JQuery<HTMLElement>) {
|
||||
items: [
|
||||
...link_context_menu.getItems(),
|
||||
{ title: "----" },
|
||||
{
|
||||
title: t("board_view.move-to"),
|
||||
uiIcon: "bx bx-transfer",
|
||||
items: api.columns.map(column => ({
|
||||
title: column,
|
||||
handler: () => api.changeColumn(noteId, column)
|
||||
}))
|
||||
},
|
||||
{ title: "----" },
|
||||
{
|
||||
title: t("board_view.delete-note"),
|
||||
uiIcon: "bx bx-trash",
|
||||
|
||||
@@ -8,6 +8,7 @@ import appContext, { EventData } from "../../../components/app_context";
|
||||
import { BoardData } from "./config";
|
||||
import SpacedUpdate from "../../../services/spaced_update";
|
||||
import { showNoteContextMenu } from "./context_menu";
|
||||
import BoardApi from "./api";
|
||||
|
||||
const TPL = /*html*/`
|
||||
<div class="board-view">
|
||||
@@ -127,6 +128,7 @@ export default class BoardView extends ViewMode<BoardData> {
|
||||
private draggedBranch: any = null;
|
||||
private draggedNoteElement: JQuery<HTMLElement> | null = null;
|
||||
private persistentData: BoardData;
|
||||
private api?: BoardApi;
|
||||
|
||||
constructor(args: ViewModeArgs) {
|
||||
super(args, "board");
|
||||
@@ -134,7 +136,6 @@ export default class BoardView extends ViewMode<BoardData> {
|
||||
this.$root = $(TPL);
|
||||
setupHorizontalScrollViaWheel(this.$root);
|
||||
this.$container = this.$root.find(".board-view-container");
|
||||
showNoteContextMenu(this.$container);
|
||||
this.spacedUpdate = new SpacedUpdate(() => this.onSave(), 5_000);
|
||||
this.persistentData = {
|
||||
columns: []
|
||||
@@ -155,6 +156,12 @@ export default class BoardView extends ViewMode<BoardData> {
|
||||
this.persistentData = persistedData;
|
||||
|
||||
const data = await getBoardData(this.parentNote, "status", persistedData);
|
||||
const columns = Array.from(data.byColumn.keys()) || [];
|
||||
this.api = new BoardApi(columns);
|
||||
showNoteContextMenu({
|
||||
$container: this.$container,
|
||||
api: this.api
|
||||
});
|
||||
|
||||
if (data.newPersistedData) {
|
||||
this.persistentData = data.newPersistedData;
|
||||
@@ -317,7 +324,7 @@ export default class BoardView extends ViewMode<BoardData> {
|
||||
try {
|
||||
// Handle column change
|
||||
if (currentColumn !== column) {
|
||||
await attributeService.setLabel(draggedNote.noteId, "status", column);
|
||||
await this.api?.changeColumn(draggedNote.noteId, column);
|
||||
}
|
||||
|
||||
// Handle position change (works for both same column and different column moves)
|
||||
|
||||
Reference in New Issue
Block a user