2025-09-11 19:25:17 +03:00
|
|
|
import { BoardViewData } from ".";
|
2025-09-10 21:10:31 +03:00
|
|
|
import FNote from "../../../entities/fnote";
|
|
|
|
|
import attributes from "../../../services/attributes";
|
2025-09-11 19:25:17 +03:00
|
|
|
import { executeBulkActions } from "../../../services/bulk_action";
|
2025-09-10 21:10:31 +03:00
|
|
|
import note_create from "../../../services/note_create";
|
2025-09-11 20:02:58 +03:00
|
|
|
import server from "../../../services/server";
|
2025-09-11 19:25:17 +03:00
|
|
|
import { ColumnMap } from "./data";
|
2025-09-10 21:10:31 +03:00
|
|
|
|
2025-09-11 19:14:54 +03:00
|
|
|
export default class BoardApi {
|
|
|
|
|
|
|
|
|
|
constructor(
|
2025-09-11 19:25:17 +03:00
|
|
|
private byColumn: ColumnMap | undefined,
|
2025-09-11 19:35:46 +03:00
|
|
|
public columns: string[],
|
2025-09-11 19:14:54 +03:00
|
|
|
private parentNote: FNote,
|
2025-09-11 19:25:17 +03:00
|
|
|
private statusAttribute: string,
|
|
|
|
|
private viewConfig: BoardViewData,
|
2025-09-11 20:02:58 +03:00
|
|
|
private saveConfig: (newConfig: BoardViewData) => void,
|
|
|
|
|
private setBranchIdToEdit: (branchId: string | undefined) => void
|
2025-09-11 19:14:54 +03:00
|
|
|
) {};
|
|
|
|
|
|
|
|
|
|
async createNewItem(column: string) {
|
|
|
|
|
try {
|
|
|
|
|
// Get the parent note path
|
|
|
|
|
const parentNotePath = this.parentNote.noteId;
|
|
|
|
|
|
|
|
|
|
// Create a new note as a child of the parent note
|
2025-09-11 20:02:58 +03:00
|
|
|
const { note: newNote, branch: newBranch } = await note_create.createNote(parentNotePath, {
|
2025-09-11 19:14:54 +03:00
|
|
|
activate: false,
|
|
|
|
|
title: "New item"
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if (newNote) {
|
|
|
|
|
await this.changeColumn(newNote.noteId, column);
|
2025-09-11 20:02:58 +03:00
|
|
|
this.setBranchIdToEdit(newBranch?.branchId);
|
2025-09-11 19:14:54 +03:00
|
|
|
}
|
|
|
|
|
} catch (error) {
|
|
|
|
|
console.error("Failed to create new item:", error);
|
2025-09-10 21:10:31 +03:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-09-11 19:14:54 +03:00
|
|
|
async changeColumn(noteId: string, newColumn: string) {
|
|
|
|
|
await attributes.setLabel(noteId, this.statusAttribute, newColumn);
|
|
|
|
|
}
|
|
|
|
|
|
2025-09-11 19:25:17 +03:00
|
|
|
async removeColumn(column: string) {
|
|
|
|
|
// Remove the value from the notes.
|
|
|
|
|
const noteIds = this.byColumn?.get(column)?.map(item => item.note.noteId) || [];
|
|
|
|
|
await executeBulkActions(noteIds, [
|
|
|
|
|
{
|
|
|
|
|
name: "deleteLabel",
|
|
|
|
|
labelName: this.statusAttribute
|
|
|
|
|
}
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
this.viewConfig.columns = (this.viewConfig.columns ?? []).filter(col => col.value !== column);
|
|
|
|
|
this.saveConfig(this.viewConfig);
|
|
|
|
|
}
|
|
|
|
|
|
2025-09-11 20:02:58 +03:00
|
|
|
dismissEditingTitle() {
|
|
|
|
|
this.setBranchIdToEdit(undefined);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
renameCard(noteId: string, newTitle: string) {
|
|
|
|
|
return server.put(`notes/${noteId}/title`, { title: newTitle.trim() });
|
|
|
|
|
}
|
|
|
|
|
|
2025-09-10 21:10:31 +03:00
|
|
|
}
|
2025-09-11 19:14:54 +03:00
|
|
|
|