Skip to content

Commit

Permalink
cleaning up ModelTask for update
Browse files Browse the repository at this point in the history
because otherwise it overwrites stuff, we currently not implemented.
  • Loading branch information
Heiss committed Aug 10, 2024
1 parent 9acacdf commit 7f3063b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/processing/processor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ class Processor {

private async createTaskAndUpdateToVault(task: PluginTask) {
if (this.plugin.settings.debugging) console.log("Step CreateTask: Pushing task to vikunja", task);
task.task = await this.plugin.tasksApi.createTask(task.task);
task.task = await this.plugin.tasksApi.createTask(task);
if (this.plugin.settings.debugging) console.log("Step CreateTask: Update task in Vault ", task);

try {
Expand Down
29 changes: 19 additions & 10 deletions src/vikunja/tasks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,13 @@ class Tasks implements VikunjaAPI {
throw new Error("TasksApi: Task id is not defined");
}
if (this.plugin.settings.debugging) console.log("TasksApi: Updating task", task.task.id, task);
if (task.task.done) {
task.task.bucketId = this.plugin.settings.selectBucketForDoneTasks;
}
task = this.generateDescriptionLink(task);

await this.addLabelToTask(task.task);
const param: TasksIdPostRequest = {id: id, task: task.task};
const param: TasksIdPostRequest = {
id: id,
task: this.getCleanedModelTask(task.task)
};
const vikunjaTask = await this.tasksApi.tasksIdPost(param);
task.task = vikunjaTask;
this.plugin.cache.update(task);
Expand All @@ -73,12 +73,6 @@ class Tasks implements VikunjaAPI {
const id = task.task.projectId;
if (id === undefined) throw new Error("TasksApi: Project id is not defined");

// TODO add link to vault file in Vikunja task
// let url = encodeURI(`obsidian://open?vault=${this.app.vault.getName()}&file=${filepath}`)
// description =`[${filepath}](${url})`;
// filepath could be an issue, because this information is dropped right before calling this method right now
// Another problem is, that it cannot track moved tasks in the vault

if (task.task.done) {
task.task.bucketId = this.plugin.settings.selectBucketForDoneTasks;
}
Expand Down Expand Up @@ -190,6 +184,21 @@ class Tasks implements VikunjaAPI {
newTask.task.description += restLines;
return newTask
}

private getCleanedModelTask(task: ModelsTask): ModelsTask {
// This needs to be updated, when we have more fields managed in obsidian!
let bucketId = undefined;
if (task.done) {
bucketId = this.plugin.settings.selectBucketForDoneTasks;
}
return {
projectId: task.projectId,
title: task.title,
description: task.description,
done: task.done,
bucketId: bucketId,
};
}
}

export {Tasks};

0 comments on commit 7f3063b

Please sign in to comment.