-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
331 additions
and
30 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# Task Management Action | ||
Manage the rollover of tasks given the next properties: | ||
|
||
* **Regex**: The regex to find the tasks in the notes. | ||
* **Folder**: The folder where the notes will be searched. | ||
* **Prefix**: The prefix to add to the task when it's rollovered. | ||
* **Suffix**: The suffix to add to the task when it's rollovered. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
import { CustomZettelAction, ExecuteInfo } from "architecture/api"; | ||
import { FileService } from "architecture/plugin"; | ||
import { Notice, TFile } from "obsidian"; | ||
import { taskManagementSettings } from "./TaskManagementSettings"; | ||
import { TaskManagementElement } from "./typing"; | ||
import { t } from "architecture/lang"; | ||
import { log } from "architecture"; | ||
|
||
export class TaskManagementAction extends CustomZettelAction { | ||
private static ICON = "list-checks"; | ||
id = "task-management"; | ||
defaultAction = { | ||
type: this.id, | ||
description: "Task Management", | ||
hasUI: false, | ||
id: this.id, | ||
}; | ||
|
||
settings = taskManagementSettings; | ||
|
||
getIcon(): string { | ||
return TaskManagementAction.ICON; | ||
} | ||
|
||
async execute(info: ExecuteInfo): Promise<void> { | ||
const { content } = info; | ||
const { | ||
initialFolder, | ||
regex, | ||
rollupHeader, | ||
prefix = "", | ||
suffix = "", | ||
} = info.element as TaskManagementElement; | ||
const initFilesToSearch = FileService.getTfilesFromFolder( | ||
initialFolder || "/", | ||
["md"] | ||
); | ||
|
||
log.debug(`Initial files to search: ${initFilesToSearch.length}`); | ||
// Filter by regex | ||
const compiledRegex = new RegExp(regex); | ||
const filesToSearch = initFilesToSearch.filter((file) => | ||
file.basename.match(compiledRegex) | ||
); | ||
log.debug(`Files to search after regex: ${filesToSearch.length}`); | ||
|
||
// Get all unfinished todos | ||
const unfinishedTodos = []; | ||
for (const file of filesToSearch) { | ||
const todos = await getAllUnfinishedTodos(file, rollupHeader); | ||
unfinishedTodos.push(...todos); | ||
} | ||
const normalizedTodos = unfinishedTodos | ||
.map((task) => `${prefix}${task}${suffix}`) | ||
.join("\n"); | ||
|
||
if (normalizedTodos.length !== 0) { | ||
content.add(`${rollupHeader}\n${normalizedTodos}`); | ||
} | ||
} | ||
|
||
getLabel(): string { | ||
return t("type_option_task_management"); | ||
} | ||
} | ||
|
||
const getAllUnfinishedTodos = async (file: TFile, tasksHeader: string) => { | ||
const contents = await FileService.getContent(file); | ||
const contentsForDailyTasks = contents.split(tasksHeader)[1] || contents; | ||
const unfinishedTodosRegex = /\t*- \[ \].*/g; | ||
const unfinishedTodos = Array.from( | ||
contentsForDailyTasks.matchAll(unfinishedTodosRegex) | ||
).map(([todo]) => todo); | ||
const fileWithoutTasks = contents.split(/.*\t*- \[ \].*\n?/g).join(""); | ||
await FileService.modify(file, fileWithoutTasks); | ||
new Notice( | ||
`Rollover ${unfinishedTodos.length} unfinished task/s from ${file.basename}` | ||
); | ||
return unfinishedTodos; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
import { ActionSetting } from "architecture/api"; | ||
import { t } from "architecture/lang"; | ||
import { Setting } from "obsidian"; | ||
import { TaskManagementElement } from "./typing"; | ||
import { FolderSuggest } from "architecture/settings"; | ||
|
||
export const taskManagementSettings: ActionSetting = (contentEl, _, action) => { | ||
const { initialFolder, regex, rollupHeader, prefix, suffix } = | ||
action as TaskManagementElement; | ||
|
||
new Setting(contentEl) | ||
.setName(t("step_builder_element_type_task_management_target_folder_title")) | ||
.setDesc( | ||
t("step_builder_element_type_task_management_target_folder_description") | ||
) | ||
.addSearch((cb) => { | ||
new FolderSuggest(cb.inputEl); | ||
cb.setPlaceholder("Example: path/to/folder") | ||
.setValue(initialFolder || "") | ||
.onChange((value: string) => { | ||
if (value) { | ||
action.initialFolder = value; | ||
} else { | ||
delete action.initialFolder; | ||
} | ||
}); | ||
}); | ||
|
||
new Setting(contentEl) | ||
.setName(t("step_builder_element_type_task_management_regex_title")) | ||
.setDesc(t("step_builder_element_type_task_management_regex_description")) | ||
.addText((text) => { | ||
text | ||
.setPlaceholder( | ||
t("step_builder_element_type_task_management_regex_placeholder") | ||
) | ||
.setValue(regex || "") | ||
.onChange(async (value) => { | ||
action.regex = value; | ||
}); | ||
}); | ||
|
||
new Setting(contentEl) | ||
.setName(t("step_builder_element_type_task_management_rollup_header_title")) | ||
.setDesc( | ||
t("step_builder_element_type_task_management_rollup_header_description") | ||
) | ||
.addText((text) => { | ||
text | ||
.setPlaceholder( | ||
t( | ||
"step_builder_element_type_task_management_rollup_header_placeholder" | ||
) | ||
) | ||
.setValue(rollupHeader) | ||
.onChange(async (value) => { | ||
if (value) { | ||
action.rollupHeader = value; | ||
} else { | ||
delete action.rollupHeader; | ||
} | ||
}); | ||
}); | ||
|
||
new Setting(contentEl) | ||
.setName(t("step_builder_element_type_task_management_prefix_title")) | ||
.setDesc(t("step_builder_element_type_task_management_prefix_description")) | ||
.addText((text) => { | ||
text.setValue(prefix || "").onChange(async (value) => { | ||
action.prefix = value; | ||
}); | ||
}); | ||
|
||
new Setting(contentEl) | ||
.setName(t("step_builder_element_type_task_management_suffix_title")) | ||
.setDesc(t("step_builder_element_type_task_management_suffix_description")) | ||
.addText((text) => { | ||
text | ||
.setPlaceholder( | ||
t("step_builder_element_type_task_management_suffix_placeholder") | ||
) | ||
.setValue(suffix || "!") | ||
.onChange(async (value) => { | ||
action.suffix = value; | ||
}); | ||
}); | ||
if (action.suffix === undefined) { | ||
action.suffix = "!"; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { FinalElement } from "application/notes"; | ||
|
||
export type TaskManagementElement = { | ||
rollupHeader: string; | ||
regex: string; | ||
initialFolder?: string; | ||
prefix?: string; | ||
suffix?: string; | ||
} & FinalElement; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.