From f45bba66d404e3a63c8f6e2eb3be06e3c3852cb0 Mon Sep 17 00:00:00 2001 From: Luke Zilioli Date: Wed, 6 Dec 2023 13:09:37 -0500 Subject: [PATCH 1/2] add option to cancel instead of delete fixes #128 --- src/index.js | 23 ++++++++++++++++++++++- src/ui/RolloverSettingTab.js | 30 +++++++++++++++++++++++++----- 2 files changed, 47 insertions(+), 6 deletions(-) diff --git a/src/index.js b/src/index.js index 49f3766..babad50 100644 --- a/src/index.js +++ b/src/index.js @@ -43,6 +43,8 @@ export default class RolloverTodosPlugin extends Plugin { const DEFAULT_SETTINGS = { templateHeading: "none", deleteOnComplete: false, + // only relevant if !deleteOnComplete + cancelOnComplete: false, removeEmptyTodos: false, rolloverChildren: false, rolloverOnFileCreate: true, @@ -195,7 +197,7 @@ export default class RolloverTodosPlugin extends Plugin { 10000 ); } else { - const { templateHeading, deleteOnComplete, removeEmptyTodos } = + const { templateHeading, deleteOnComplete, cancelOnComplete, removeEmptyTodos } = this.settings; // check if there is a daily note from yesterday @@ -297,6 +299,25 @@ export default class RolloverTodosPlugin extends Plugin { } } + const modifiedContent = lines.join("\n"); + await this.app.vault.modify(lastDailyNote, modifiedContent); + } else if (cancelOnComplete) { + // if deleteOnComplete, get yesterday's content and modify it to mark tasks as completed + let lastDailyNoteContent = await this.app.vault.read(lastDailyNote); + undoHistoryInstance.previousDay = { + file: lastDailyNote, + oldContent: `${lastDailyNoteContent}`, + }; + let lines = lastDailyNoteContent.split("\n"); + + // Update the status of todos from yesterday + for (let i = 0; i < lines.length; i++) { + if (todos_yesterday.includes(lines[i])) { + // Change the task status to '- [-]' + lines[i] = lines[i].replace("- [ ]", "- [-]"); + } + } + const modifiedContent = lines.join("\n"); await this.app.vault.modify(lastDailyNote, modifiedContent); } diff --git a/src/ui/RolloverSettingTab.js b/src/ui/RolloverSettingTab.js index ac85220..ca049ae 100644 --- a/src/ui/RolloverSettingTab.js +++ b/src/ui/RolloverSettingTab.js @@ -52,19 +52,39 @@ export default class RolloverSettingTab extends PluginSettingTab { }) ); - new Setting(this.containerEl) - .setName("Delete todos from previous day") + if (!this.plugin.settings.cancelOnComplete) { + new Setting(this.containerEl) + .setName("Delete todos from previous day") + .setDesc( + `Once todos are found, they are added to Today's Daily Note. If successful, they are deleted from Yesterday's Daily note. Enabling this is destructive and may result in lost data. Keeping this disabled will simply duplicate them from yesterday's note and place them in the appropriate section. Note that currently, duplicate todos will be deleted regardless of what heading they are in, and which heading you choose from above.` + ) + .addToggle((toggle) => + toggle + .setValue(this.plugin.settings.deleteOnComplete || false) + .onChange((value) => { + this.plugin.settings.deleteOnComplete = value; + this.plugin.saveSettings(); + this.display() + }) + ); + } + + if (!this.plugin.settings.deleteOnComplete) { + new Setting(this.containerEl) + .setName("Cancel todos from previous day") .setDesc( - `Once todos are found, they are added to Today's Daily Note. If successful, they are deleted from Yesterday's Daily note. Enabling this is destructive and may result in lost data. Keeping this disabled will simply duplicate them from yesterday's note and place them in the appropriate section. Note that currently, duplicate todos will be deleted regardless of what heading they are in, and which heading you choose from above.` + `Once todos are found, they are added to Today's Daily Note. If successful, they are cancelled from Yesterday's Daily note (status changed to [-]. Enabling this is destructive and may result in lost data. Keeping this disabled will simply duplicate them from yesterday's note and place them in the appropriate section. Note that currently, duplicate todos will be deleted regardless of what heading they are in, and which heading you choose from above.` ) .addToggle((toggle) => toggle - .setValue(this.plugin.settings.deleteOnComplete || false) + .setValue(this.plugin.settings.cancelOnComplete || false) .onChange((value) => { - this.plugin.settings.deleteOnComplete = value; + this.plugin.settings.cancelOnComplete = value; this.plugin.saveSettings(); + this.display(); }) ); + } new Setting(this.containerEl) .setName("Remove empty todos in rollover") From 037323460a46d48ebfbfcbd964202384ebd26e7b Mon Sep 17 00:00:00 2001 From: Luke Zilioli Date: Wed, 6 Dec 2023 13:09:55 -0500 Subject: [PATCH 2/2] do not rollover duplicate notes fixes #130 --- src/index.js | 11 ++++++++++- src/ui/RolloverSettingTab.js | 14 ++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/src/index.js b/src/index.js index babad50..ed210fc 100644 --- a/src/index.js +++ b/src/index.js @@ -46,6 +46,7 @@ export default class RolloverTodosPlugin extends Plugin { // only relevant if !deleteOnComplete cancelOnComplete: false, removeEmptyTodos: false, + skipExistingTodos: false, rolloverChildren: false, rolloverOnFileCreate: true, }; @@ -197,7 +198,7 @@ export default class RolloverTodosPlugin extends Plugin { 10000 ); } else { - const { templateHeading, deleteOnComplete, cancelOnComplete, removeEmptyTodos } = + const { templateHeading, deleteOnComplete, cancelOnComplete, removeEmptyTodos, skipExistingTodos } = this.settings; // check if there is a daily note from yesterday @@ -258,6 +259,14 @@ export default class RolloverTodosPlugin extends Plugin { file: file, oldContent: `${dailyNoteContent}`, }; + // find todos that already exist in todays note + // and do not add them to today + if (skipExistingTodos) { + let existing_todos = await this.getAllUnfinishedTodos(file); + console.log(`rollover-daily-todos: filtering ${todos_today.length} tasks for tasks that already exist`); + todos_today = todos_today.filter(todo => !existing_todos.includes(todo)); + console.log(`rollover-daily-todos: new count: ${todos_today.length}`); + } const todos_todayString = `\n${todos_today.join("\n")}`; // If template heading is selected, try to rollover to template heading diff --git a/src/ui/RolloverSettingTab.js b/src/ui/RolloverSettingTab.js index ca049ae..30d3026 100644 --- a/src/ui/RolloverSettingTab.js +++ b/src/ui/RolloverSettingTab.js @@ -100,6 +100,20 @@ export default class RolloverSettingTab extends PluginSettingTab { }) ); + new Setting(this.containerEl) + .setName("Skip existing todos in rollover") + .setDesc( + `If a todo from yesterday already exists in todays note, do not roll it over.` + ) + .addToggle((toggle) => + toggle + .setValue(this.plugin.settings.skipExistingTodos || false) + .onChange((value) => { + this.plugin.settings.skipExistingTodos = value; + this.plugin.saveSettings(); + }) + ); + new Setting(this.containerEl) .setName("Roll over children of todos") .setDesc(