mirror of
https://github.com/zadam/trilium.git
synced 2025-10-26 07:46:30 +01:00
refactor(views/board): use branches instead of notes
This commit is contained in:
@@ -1,11 +1,23 @@
|
||||
import FBranch from "../../../entities/fbranch";
|
||||
import FNote from "../../../entities/fnote";
|
||||
import froca from "../../../services/froca";
|
||||
|
||||
export async function getBoardData(noteIds: string[], groupByColumn: string) {
|
||||
const notes = await froca.getNotes(noteIds);
|
||||
const byColumn: Map<string, FNote[]> = new Map();
|
||||
export async function getBoardData(parentNote: FNote, groupByColumn: string) {
|
||||
const byColumn: Map<string, FBranch[]> = new Map();
|
||||
|
||||
await recursiveGroupBy(parentNote.getChildBranches(), byColumn, groupByColumn);
|
||||
|
||||
return {
|
||||
byColumn
|
||||
};
|
||||
}
|
||||
|
||||
async function recursiveGroupBy(branches: FBranch[], byColumn: Map<string, FBranch[]>, groupByColumn: string) {
|
||||
for (const branch of branches) {
|
||||
const note = await branch.getNote();
|
||||
if (!note) {
|
||||
continue;
|
||||
}
|
||||
|
||||
for (const note of notes) {
|
||||
const group = note.getLabelValue(groupByColumn);
|
||||
if (!group) {
|
||||
continue;
|
||||
@@ -14,10 +26,6 @@ export async function getBoardData(noteIds: string[], groupByColumn: string) {
|
||||
if (!byColumn.has(group)) {
|
||||
byColumn.set(group, []);
|
||||
}
|
||||
byColumn.get(group)!.push(note);
|
||||
byColumn.get(group)!.push(branch);
|
||||
}
|
||||
|
||||
return {
|
||||
byColumn
|
||||
};
|
||||
}
|
||||
|
||||
@@ -120,11 +120,11 @@ export default class BoardView extends ViewMode<StateInfo> {
|
||||
}
|
||||
|
||||
private async renderBoard(el: HTMLElement) {
|
||||
const data = await getBoardData(this.noteIds, "status");
|
||||
const data = await getBoardData(this.parentNote, "status");
|
||||
|
||||
for (const column of data.byColumn.keys()) {
|
||||
const columnNotes = data.byColumn.get(column);
|
||||
if (!columnNotes) {
|
||||
const columnBranches = data.byColumn.get(column);
|
||||
if (!columnBranches) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -145,7 +145,12 @@ export default class BoardView extends ViewMode<StateInfo> {
|
||||
// Setup drop zone for the column
|
||||
this.setupColumnDropZone($columnEl, column);
|
||||
|
||||
for (const note of columnNotes) {
|
||||
for (const branch of columnBranches) {
|
||||
const note = await branch.getNote();
|
||||
if (!note) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const $iconEl = $("<span>")
|
||||
.addClass("icon")
|
||||
.addClass(note.getIcon());
|
||||
|
||||
Reference in New Issue
Block a user