feat: add wirings - view and ui
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
import * as vscode from "vscode";
|
||||
import { Task, TaskStatus } from "@/model/task";
|
||||
import { IConfigProvider, ITaskRepository } from "@/ports";
|
||||
import * as vscode from "vscode";
|
||||
|
||||
const STATUS_ORDER: TaskStatus[] = ["todo", "in-progress", "done", "cancelled"];
|
||||
import { TASK_STATUS_LABELS, TASK_STATUS_ORDER } from "@/ui/taskLabels";
|
||||
import { TaskTreeItem } from "./taskTreeItem";
|
||||
|
||||
const STATUS_ICONS: Record<TaskStatus, vscode.ThemeIcon> = {
|
||||
todo: new vscode.ThemeIcon("circle-outline"),
|
||||
@@ -14,11 +14,16 @@ const STATUS_ICONS: Record<TaskStatus, vscode.ThemeIcon> = {
|
||||
class TaskGroupTreeItem extends vscode.TreeItem {
|
||||
readonly tasks: Task[];
|
||||
|
||||
constructor(label: string, tasks: Task[], icon: vscode.ThemeIcon) {
|
||||
super(label, vscode.TreeItemCollapsibleState.Collapsed);
|
||||
this.iconPath = icon;
|
||||
constructor(status: TaskStatus, tasks: Task[]) {
|
||||
super(
|
||||
TASK_STATUS_LABELS[status],
|
||||
vscode.TreeItemCollapsibleState.Collapsed,
|
||||
);
|
||||
this.iconPath = STATUS_ICONS[status];
|
||||
this.tasks = tasks;
|
||||
this.description = `(${tasks.length})`;
|
||||
this.id = `group-${status}`;
|
||||
this.contextValue = "taskGroup";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -48,7 +53,10 @@ export class TaskTreeProvider implements vscode.TreeDataProvider<vscode.TreeItem
|
||||
if (!element) {
|
||||
return this.getRootChildren();
|
||||
}
|
||||
return this.getTaskChildren(element as TaskGroupTreeItem);
|
||||
if (element instanceof TaskGroupTreeItem) {
|
||||
return element.tasks.map((task) => new TaskTreeItem(task));
|
||||
}
|
||||
return [];
|
||||
}
|
||||
|
||||
private async getRootChildren(): Promise<vscode.TreeItem[]> {
|
||||
@@ -59,37 +67,9 @@ export class TaskTreeProvider implements vscode.TreeDataProvider<vscode.TreeItem
|
||||
|
||||
const tasks = await this.#taskStore.list(projectPath);
|
||||
|
||||
return STATUS_ORDER.map((status) => {
|
||||
return TASK_STATUS_ORDER.map((status) => {
|
||||
const groupTasks = tasks.filter((t) => t.status === status);
|
||||
const label =
|
||||
status === "todo"
|
||||
? "To Do"
|
||||
: status === "in-progress"
|
||||
? "In Progress"
|
||||
: status === "done"
|
||||
? "Done"
|
||||
: "Cancelled";
|
||||
const item = new TaskGroupTreeItem(
|
||||
label,
|
||||
groupTasks,
|
||||
STATUS_ICONS[status],
|
||||
);
|
||||
item.id = `group-${status}`;
|
||||
item.contextValue = "taskGroup";
|
||||
return item;
|
||||
});
|
||||
}
|
||||
|
||||
private getTaskChildren(group: TaskGroupTreeItem): vscode.TreeItem[] {
|
||||
return group.tasks.map((task) => {
|
||||
const item = new vscode.TreeItem(task.title);
|
||||
item.id = task.id;
|
||||
item.description = task.priority;
|
||||
item.tooltip = new vscode.MarkdownString(
|
||||
`**${task.title}**\n\nPriority: ${task.priority}\nStatus: ${task.status}${task.assignee ? `\nAssignee: ${task.assignee}` : ""}`,
|
||||
);
|
||||
item.contextValue = "task";
|
||||
return item;
|
||||
return new TaskGroupTreeItem(status, groupTasks);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user