Skip to content

Commit

Permalink
Merge branch 'feature/content-rollover-options'
Browse files Browse the repository at this point in the history
  • Loading branch information
RafaelGB committed May 3, 2024
2 parents 69a3794 + a924d88 commit 561ef44
Show file tree
Hide file tree
Showing 7 changed files with 123 additions and 35 deletions.
8 changes: 4 additions & 4 deletions WorkFlow Test/Workflow of new notes.canvas

Large diffs are not rendered by default.

16 changes: 12 additions & 4 deletions src/actions/taskManagement/TaskManagementAction.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,17 @@ export class TaskManagementAction extends CustomZettelAction {
const {
initialFolder,
regex,
rollupHeader,
rolloverHeader,
prefix = "",
suffix = "",
key,
isContent,
recursiveFolders,
} = info.element as TaskManagementElement;
const initFilesToSearch = FileService.getTfilesFromFolder(
initialFolder || "/",
["md"]
["md"],
recursiveFolders
);

log.debug(`Initial files to search: ${initFilesToSearch.length}`);
Expand All @@ -47,15 +51,19 @@ export class TaskManagementAction extends CustomZettelAction {
// Get all unfinished todos
const unfinishedTodos = [];
for (const file of filesToSearch) {
const todos = await getAllUnfinishedTodos(file, rollupHeader);
const todos = await getAllUnfinishedTodos(file, rolloverHeader);
unfinishedTodos.push(...todos);
}
const normalizedTodos = unfinishedTodos
.map((task) => `${prefix}${task}${suffix}`)
.join("\n");

if (normalizedTodos.length !== 0) {
content.add(`${rollupHeader}\n${normalizedTodos}`);
if (isContent && key !== undefined) {
content.modify(key, normalizedTodos);
} else {
content.add(`${rolloverHeader}\n${normalizedTodos}`);
}
}
}

Expand Down
79 changes: 70 additions & 9 deletions src/actions/taskManagement/TaskManagementSettings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,21 @@ import { ActionSetting } from "architecture/api";
import { t } from "architecture/lang";
import { Setting } from "obsidian";
import { TaskManagementElement } from "./typing";
import { FolderSuggest } from "architecture/settings";
import { FolderSuggest, PropertySuggest } from "architecture/settings";
import { ObsidianConfig } from "architecture/plugin";
import { v4 as uuid4 } from "uuid";

export const taskManagementSettings: ActionSetting = (contentEl, _, action) => {
const { initialFolder, regex, rollupHeader, prefix, suffix } =
action as TaskManagementElement;
const {
initialFolder,
regex,
rolloverHeader,
prefix,
suffix,
isContent,
key,
recursiveFolders = true,
} = action as TaskManagementElement;

new Setting(contentEl)
.setName(t("step_builder_element_type_task_management_target_folder_title"))
Expand All @@ -26,6 +36,22 @@ export const taskManagementSettings: ActionSetting = (contentEl, _, action) => {
});
});

new Setting(contentEl)
.setName(
t("step_builder_element_type_task_management_allow_recursive_title")
)
.setDesc(
t("step_builder_element_type_task_management_allow_recursive_description")
)
.addToggle((toggle) => {
toggle.setValue(recursiveFolders).onChange((value) => {
action.recursiveFolders = value;
});
});
if (action.recursiveFolders === undefined) {
action.recursiveFolders = true;
}

new Setting(contentEl)
.setName(t("step_builder_element_type_task_management_regex_title"))
.setDesc(t("step_builder_element_type_task_management_regex_description"))
Expand All @@ -41,23 +67,25 @@ export const taskManagementSettings: ActionSetting = (contentEl, _, action) => {
});

new Setting(contentEl)
.setName(t("step_builder_element_type_task_management_rollup_header_title"))
.setName(
t("step_builder_element_type_task_management_rollover_header_title")
)
.setDesc(
t("step_builder_element_type_task_management_rollup_header_description")
t("step_builder_element_type_task_management_rollover_header_description")
)
.addText((text) => {
text
.setPlaceholder(
t(
"step_builder_element_type_task_management_rollup_header_placeholder"
"step_builder_element_type_task_management_rollover_header_placeholder"
)
)
.setValue(rollupHeader)
.setValue(rolloverHeader)
.onChange(async (value) => {
if (value) {
action.rollupHeader = value;
action.rolloverHeader = value;
} else {
delete action.rollupHeader;
delete action.rolloverHeader;
}
});
});
Expand All @@ -84,7 +112,40 @@ export const taskManagementSettings: ActionSetting = (contentEl, _, action) => {
action.suffix = value;
});
});

if (action.suffix === undefined) {
action.suffix = "!";
}

const keyElementId = uuid4();
new Setting(contentEl)
.setName(t("step_builder_element_type_task_management_is_content_title"))
.setDesc(
t("step_builder_element_type_task_management_is_content_description")
)
.addToggle((toggle) => {
toggle.setValue(isContent || false).onChange(async (value) => {
action.isContent = value;
const keyElement = document.getElementById(keyElementId);
if (keyElement) {
keyElement.style.display = value ? "block" : "none";
}
});
});

const keyElement = new Setting(contentEl)
.setName(t("step_builder_element_type_key_title"))
.setDesc(t("step_builder_element_type_key_description"))
.addSearch((search) => {
ObsidianConfig.getTypes().then((types) => {
new PropertySuggest(search.inputEl, types, ["text", "checkbox"]);
search.setValue(key || ``).onChange(async (value) => {
action.key = value;
});
});
});
keyElement.settingEl.id = keyElementId;
if (!isContent) {
keyElement.settingEl.style.display = "none";
}
};
5 changes: 4 additions & 1 deletion src/actions/taskManagement/typing.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import { FinalElement } from "application/notes";

export type TaskManagementElement = {
rollupHeader: string;
rolloverHeader: string;
regex: string;
initialFolder?: string;
recursiveFolders?: boolean;
prefix?: string;
suffix?: string;
isContent?: boolean;
key?: string;
} & FinalElement;
18 changes: 11 additions & 7 deletions src/architecture/lang/locale/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,18 +120,22 @@ export default {
step_builder_element_type_number_placeholder_title: 'Placeholder of number',
step_builder_element_type_number_placeholder_description: 'Helper text to display in the number',
step_builder_element_type_task_management_target_folder_title: 'Initial folder',
step_builder_element_type_task_management_target_folder_description: 'Choose the initial folder where the search will start to rollup the tasks',
step_builder_element_type_task_management_target_folder_description: 'Choose the initial folder where the search will start to rollover the tasks',
step_builder_element_type_task_management_regex_title: 'Regex',
step_builder_element_type_task_management_regex_description: 'Regex to search notes with the desired tasks to rollup',
step_builder_element_type_task_management_regex_description: 'Regex to search notes with the desired tasks to rollover',
step_builder_element_type_task_management_regex_placeholder: '^my-regex-to-search-files*$',
step_builder_element_type_task_management_rollup_header_title: 'Header title',
step_builder_element_type_task_management_rollup_header_description: 'It will search for the heading into all the filtered notes and rollup the unfinished tasks',
step_builder_element_type_task_management_rollup_header_placeholder: '## Tasks',
step_builder_element_type_task_management_rollover_header_title: 'Initial header',
step_builder_element_type_task_management_rollover_header_description: 'It will search for the heading into all the filtered notes and rollover the unfinished tasks',
step_builder_element_type_task_management_rollover_header_placeholder: '## Tasks',
step_builder_element_type_task_management_allow_recursive_title: 'Allow recursive',
step_builder_element_type_task_management_allow_recursive_description: 'Enable recursive search in the initial folder',
step_builder_element_type_task_management_prefix_title: 'Prefix title',
step_builder_element_type_task_management_prefix_description: 'Prefix to add to the task after the rollup',
step_builder_element_type_task_management_prefix_description: 'Prefix to add to the task after the rollover',
step_builder_element_type_task_management_suffix_title: 'Suffix title',
step_builder_element_type_task_management_suffix_description: 'Suffix to add to the task after the rollup',
step_builder_element_type_task_management_suffix_description: 'Suffix to add to the task after the rollover',
step_builder_element_type_task_management_suffix_placeholder: '!',
step_builder_element_type_task_management_is_content_title: 'Enable as content behaviour',
step_builder_element_type_task_management_is_content_description: 'When enabled, the unfinished tasks will be added where the "{{key}}" is placed in the note previously',
step_builder_actions_management_title: 'Actions management',
step_builder_actions_management_add_action_tooltip: 'Add action',
// MENUS
Expand Down
16 changes: 10 additions & 6 deletions src/architecture/lang/locale/es.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,18 +121,22 @@ export default {
step_builder_actions_management_title: 'Gestión de acciones',
step_builder_actions_management_add_action_tooltip: 'Añadir acción',
step_builder_element_type_task_management_target_folder_title: 'Carpeta inicial',
step_builder_element_type_task_management_target_folder_description: 'Carpeta inicial para buscar las notas con las tareas a rollup',
step_builder_element_type_task_management_target_folder_description: 'Carpeta inicial para buscar las notas con las tareas a rollover',
step_builder_element_type_task_management_allow_recursive_title: 'Permitir búsqueda recursiva',
step_builder_element_type_task_management_allow_recursive_description: 'Permitir la búsqueda recursiva en las subcarpetas de la carpeta inicial',
step_builder_element_type_task_management_regex_title: 'Regex para buscar tareas',
step_builder_element_type_task_management_regex_description: 'Regex para buscar las tareas en las notas',
step_builder_element_type_task_management_regex_placeholder: '^mi-filtro-regex-parabuscar-tareas*$',
step_builder_element_type_task_management_rollup_header_title: 'Encabezado a usar',
step_builder_element_type_task_management_rollup_header_description: 'Buscará el encabezado en todas las notas filtradas y agrupará las tareas no finalizadas',
step_builder_element_type_task_management_rollup_header_placeholder: '## Tareas',
step_builder_element_type_task_management_rollover_header_title: 'Encabezado a usar',
step_builder_element_type_task_management_rollover_header_description: 'Buscará el encabezado en todas las notas filtradas y agrupará las tareas no finalizadas',
step_builder_element_type_task_management_rollover_header_placeholder: '## Tareas',
step_builder_element_type_task_management_prefix_title: 'Prefijo para añadir a la tarea',
step_builder_element_type_task_management_prefix_description: 'Prefijo a añadir a la tarea tras del rollup',
step_builder_element_type_task_management_prefix_description: 'Prefijo a añadir a la tarea tras del rollover',
step_builder_element_type_task_management_suffix_title: 'Sufijo para añadir a la tarea',
step_builder_element_type_task_management_suffix_description: 'Sufijo a añadir a la tarea tras del rollup',
step_builder_element_type_task_management_suffix_description: 'Sufijo a añadir a la tarea tras del rollover',
step_builder_element_type_task_management_suffix_placeholder: '!',
step_builder_element_type_task_management_is_content_title: 'Activar el comportamiento como contenido',
step_builder_element_type_task_management_is_content_description: 'Cuando está activado, el rollover se añadirá donde se coloque la clave "{{key}}" en la nota previamente',
// MENUS
editor_menu_rigth_click_title: 'Opciones del editor de ZettelFlow',
// NOTIFICATIONS
Expand Down
16 changes: 12 additions & 4 deletions src/architecture/plugin/services/FileService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,20 +72,28 @@ export class FileService {

public static getTfilesFromFolder(
folder_str: string,
fileExtensions: string[] = FILE_EXTENSIONS.BASIC
fileExtensions: string[] = FILE_EXTENSIONS.BASIC,
allowRecursive = true
): Array<TFile> {
let folder;
let folder: TFolder;
try {
folder = FileService.getFolder(folder_str);
} catch (err) {
// Split the string into '/' and remove the last element
folder = FileService.getFolder(folder_str.split(FileService.PATH_SEPARATOR).slice(0, -1).join(FileService.PATH_SEPARATOR));
}
let files: Array<TFile> = [];
console.log(folder);
Vault.recurseChildren(folder, (file: TAbstractFile) => {
if (file instanceof TFile) {
files.push(file);

if (!(file instanceof TFile)) {
return;
}
const fileParent = file.parent;
if (fileParent !== null && !allowRecursive && fileParent.path !== folder.path) {
return;
}
files.push(file);
});

if (fileExtensions.length > 0) {
Expand Down

0 comments on commit 561ef44

Please sign in to comment.