Make Project Management a native feature
- Move the storage and model of the plugin into src/lib/features/pm/ as pure TypeScript, so the skill can still bundle them. - Move the DOM interface onto the host menus, the shared tooltip, and the host icons. - A ribbon button opens Project Management. Board tabs keep the owner runestone.pm and the board-<hex> view IDs through view patterns. - Read only .runestone/pm/. Offer the plugin migration, with backups, for legacy notes. - A save, move, or delete reads only that card again. Watcher paths reach the feature. - Add Settings → Project Management and the projectManagement section. View states move to localStorage. - Background reads the boards from workspace.json. Remove api.backgrounds and the boards service. - Add yaml 2.9.1. Use the host markdown-it. - Move 18 plugin test files to tests/unit/features/pm/ and add native tests.
This commit is contained in:
@@ -0,0 +1,76 @@
|
||||
import { defaultBoard, type BoardDocument, type BoardList } from "../storage/board.ts";
|
||||
import type { Task } from "./model.ts";
|
||||
|
||||
export interface TaskColumn {
|
||||
list?: BoardList;
|
||||
tasks: Task[];
|
||||
allowCreate?: boolean;
|
||||
}
|
||||
|
||||
/** Merge equal list names without changing the cards' board placements. */
|
||||
export function allTaskColumns(boards: BoardDocument[], tasks: Task[]): TaskColumn[] {
|
||||
const active = boards.filter(board => !board.archived);
|
||||
const columns = new Map<string, TaskColumn>();
|
||||
const assigned = new Set<string>();
|
||||
const append = (list: BoardList | undefined, members: Task[], allowCreate = false) => {
|
||||
const key = list ? `list:${list.name.trim().toLowerCase()}` : "unlisted";
|
||||
let column = columns.get(key);
|
||||
if (!column) {
|
||||
column = { list: list ? { id: allowCreate ? list.id : key, name: list.name, status: list.status, collapsed: false } : undefined, tasks: [], allowCreate };
|
||||
columns.set(key, column);
|
||||
}
|
||||
const included = new Set(column.tasks.map(task => task.id));
|
||||
for (const task of members) if (!included.has(task.id)) {
|
||||
column.tasks.push(task);
|
||||
included.add(task.id);
|
||||
}
|
||||
};
|
||||
for (const board of active) {
|
||||
const members = tasks.filter(task => Object.hasOwn(task.placements ?? {}, board.id));
|
||||
for (const task of members) assigned.add(task.id);
|
||||
for (const list of board.value.lists)
|
||||
append(list, members.filter(task => task.placements![board.id].listId === list.id));
|
||||
const unlisted = members.filter(task => !board.value.lists.some(list => list.id === task.placements![board.id].listId));
|
||||
if (unlisted.length) append(undefined, unlisted);
|
||||
}
|
||||
const standalone = tasks.filter(task => !assigned.has(task.id));
|
||||
if (standalone.length || !active.length) {
|
||||
for (const list of defaultBoard("all-tasks").lists)
|
||||
append(list, standalone.filter(task => task.status === list.status), true);
|
||||
}
|
||||
return [...columns.values()];
|
||||
}
|
||||
|
||||
export interface TaskBoardGroup {
|
||||
boardIds: string[];
|
||||
name: string;
|
||||
tasks: Task[];
|
||||
}
|
||||
|
||||
/** Keep shared cards once and name every board represented in this column. */
|
||||
export function allTaskGroups(boards: BoardDocument[], column: TaskColumn): TaskBoardGroup[] {
|
||||
const active = boards.filter(board => !board.archived);
|
||||
const groups = new Map<string, TaskBoardGroup>();
|
||||
for (const task of column.tasks) {
|
||||
const owners = active.filter(board => {
|
||||
const placement = task.placements?.[board.id];
|
||||
if (!placement) return false;
|
||||
const list = board.value.lists.find(list => list.id === placement.listId);
|
||||
return column.list
|
||||
? list?.name.trim().toLowerCase() === column.list.name.trim().toLowerCase()
|
||||
: !list;
|
||||
});
|
||||
const boardIds = owners.map(board => board.id);
|
||||
const key = JSON.stringify(boardIds);
|
||||
let group = groups.get(key);
|
||||
if (!group) {
|
||||
group = { boardIds, name: owners.length ? owners.map(board => board.name).join(" · ") : "No active board", tasks: [] };
|
||||
groups.set(key, group);
|
||||
}
|
||||
group.tasks.push(task);
|
||||
}
|
||||
return [...groups.values()].sort((a, b) => {
|
||||
const order = (group: TaskBoardGroup) => group.boardIds.length ? active.findIndex(board => board.id === group.boardIds[0]) : active.length;
|
||||
return order(a) - order(b);
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user