mirror of
https://github.com/TriliumNext/Notes.git
synced 2025-09-18 17:31:53 +08:00
feat(client/tasks): display tasks
This commit is contained in:
parent
1024733252
commit
7cba5a7c7d
31
src/public/app/entities/ftask.ts
Normal file
31
src/public/app/entities/ftask.ts
Normal file
@ -0,0 +1,31 @@
|
||||
import type { Froca } from "../services/froca-interface.js";
|
||||
|
||||
export interface FTaskRow {
|
||||
taskId: string;
|
||||
parentNoteId: string;
|
||||
title: string;
|
||||
dueDate?: string;
|
||||
isDone?: boolean;
|
||||
}
|
||||
|
||||
export default class FTask {
|
||||
private froca: Froca;
|
||||
taskId!: string;
|
||||
parentNoteId!: string;
|
||||
title!: string;
|
||||
dueDate?: string;
|
||||
isDone!: boolean;
|
||||
|
||||
constructor(froca: Froca, row: FTaskRow) {
|
||||
this.froca = froca;
|
||||
this.update(row);
|
||||
}
|
||||
|
||||
update(row: FTaskRow) {
|
||||
this.taskId = row.taskId;
|
||||
this.parentNoteId = row.parentNoteId;
|
||||
this.title = row.title;
|
||||
this.dueDate = row.dueDate;
|
||||
this.isDone = !!row.isDone;
|
||||
}
|
||||
}
|
@ -6,6 +6,8 @@ import appContext from "../components/app_context.js";
|
||||
import FBlob, { type FBlobRow } from "../entities/fblob.js";
|
||||
import FAttachment, { type FAttachmentRow } from "../entities/fattachment.js";
|
||||
import type { Froca } from "./froca-interface.js";
|
||||
import FTask from "../entities/ftask.js";
|
||||
import type { FTaskRow } from "../entities/ftask.js";
|
||||
|
||||
interface SubtreeResponse {
|
||||
notes: FNoteRow[];
|
||||
@ -37,6 +39,7 @@ class FrocaImpl implements Froca {
|
||||
attributes!: Record<string, FAttribute>;
|
||||
attachments!: Record<string, FAttachment>;
|
||||
blobPromises!: Record<string, Promise<void | FBlob> | null>;
|
||||
tasks!: Record<string, FTask>;
|
||||
|
||||
constructor() {
|
||||
this.initializedPromise = this.loadInitialTree();
|
||||
@ -52,6 +55,7 @@ class FrocaImpl implements Froca {
|
||||
this.attributes = {};
|
||||
this.attachments = {};
|
||||
this.blobPromises = {};
|
||||
this.tasks = {};
|
||||
|
||||
this.addResp(resp);
|
||||
}
|
||||
@ -368,6 +372,20 @@ class FrocaImpl implements Froca {
|
||||
});
|
||||
}
|
||||
|
||||
async getTasks() {
|
||||
const taskRows = await server.get<FTaskRow[]>(`tasks`);
|
||||
return this.processTaskRow(taskRows);
|
||||
}
|
||||
|
||||
processTaskRow(taskRows: FTaskRow[]): FTask[] {
|
||||
return taskRows.map((taskRow) => {
|
||||
const task = new FTask(this, taskRow);
|
||||
this.tasks[task.taskId] = task;
|
||||
|
||||
return task;
|
||||
});
|
||||
}
|
||||
|
||||
async getBlob(entityType: string, entityId: string) {
|
||||
// I'm not sure why we're not using blobIds directly, it would save us this composite key ...
|
||||
// perhaps one benefit is that we're always requesting the latest blob, not relying on perhaps faulty/slow
|
||||
|
@ -1,18 +1,28 @@
|
||||
import type FNote from "../../entities/fnote.js";
|
||||
import type FTask from "../../entities/ftask.js";
|
||||
import froca from "../../services/froca.js";
|
||||
import TypeWidget from "./type_widget.js";
|
||||
|
||||
const TPL = `
|
||||
<div class="note-detail-task-list note-detail-printable">
|
||||
Task list goes here.
|
||||
<div class="task-container">
|
||||
</div>
|
||||
</div>
|
||||
`;
|
||||
|
||||
function buildTask(task: FTask) {
|
||||
return `<div class="task">${task.title}</div>`;
|
||||
}
|
||||
|
||||
export default class TaskListWidget extends TypeWidget {
|
||||
|
||||
private $taskContainer!: JQuery<HTMLElement>;
|
||||
|
||||
static getType() { return "taskList" }
|
||||
|
||||
doRender() {
|
||||
this.$widget = $(TPL);
|
||||
this.$taskContainer = this.$widget.find(".task-container");
|
||||
}
|
||||
|
||||
async doRefresh(note: FNote) {
|
||||
@ -21,6 +31,13 @@ export default class TaskListWidget extends TypeWidget {
|
||||
if (!this.note) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.$taskContainer.clearQueue();
|
||||
|
||||
const tasks = await froca.getTasks();
|
||||
for (const task of tasks) {
|
||||
this.$taskContainer.append($(buildTask(task)));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user