From 037323460a46d48ebfbfcbd964202384ebd26e7b Mon Sep 17 00:00:00 2001 From: Luke Zilioli Date: Wed, 6 Dec 2023 13:09:55 -0500 Subject: [PATCH] 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(