Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add cancel option fixes #128, don't roll over duplicates fixes #130 #131

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 31 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,10 @@ export default class RolloverTodosPlugin extends Plugin {
const DEFAULT_SETTINGS = {
templateHeading: "none",
deleteOnComplete: false,
// only relevant if !deleteOnComplete
cancelOnComplete: false,
removeEmptyTodos: false,
skipExistingTodos: false,
rolloverChildren: false,
rolloverOnFileCreate: true,
};
Expand Down Expand Up @@ -195,7 +198,7 @@ export default class RolloverTodosPlugin extends Plugin {
10000
);
} else {
const { templateHeading, deleteOnComplete, removeEmptyTodos } =
const { templateHeading, deleteOnComplete, cancelOnComplete, removeEmptyTodos, skipExistingTodos } =
this.settings;

// check if there is a daily note from yesterday
Expand Down Expand Up @@ -256,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
Expand Down Expand Up @@ -297,6 +308,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);
}
Expand Down
44 changes: 39 additions & 5 deletions src/ui/RolloverSettingTab.js
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -80,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(
Expand Down