Skip to content

Commit

Permalink
add option to cancel instead of delete fixes lumoe#128
Browse files Browse the repository at this point in the history
  • Loading branch information
lzilioli committed Mar 21, 2024
1 parent 9d50486 commit f45bba6
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 6 deletions.
23 changes: 22 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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);
}
Expand Down
30 changes: 25 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 Down

0 comments on commit f45bba6

Please sign in to comment.