From b5322364faf108fc8c61bd6e11ca096b1e099612 Mon Sep 17 00:00:00 2001 From: Raphael Sobik Date: Sun, 2 Oct 2022 02:51:35 +0200 Subject: [PATCH] feat: :sparkles: add preference to include/exclude on-hold templates closes #31 --- README.md | 4 ++++ Templates.omnifocusjs/Resources/createFromTemplate.js | 7 ++++++- Templates.omnifocusjs/Resources/preferences.js | 3 +++ 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index ce84e58..8dac746 100644 --- a/README.md +++ b/README.md @@ -64,6 +64,8 @@ This action can be run at any time on macOS. It can optionally only be run when The user is prompted to select a template (from the projects included in the templates folder). If a template project is already selected, the prompt is not shown and the selected template is used. ![Prompt to choose template](https://user-images.githubusercontent.com/16893787/142519500-f0c0e1f3-8c89-4825-9dde-413660b19e6b.png) +Optionally, on-hold templates can be excluded from this list; this setting is located in Preferences. + ### 2. Select a destination _(if applicable)_ The `getDestination` function is used to determine where the new project should be created. (This skips the below dialogue if a folder is specified in the note, as in our example template above.) @@ -106,6 +108,8 @@ This action allows the user to set the preferences for the plug-in. Currently, t * **Sort folder/project list alphabetically (instead of in OmniFocus order)** _Please note that this setting is device-specific and does not sync between devices._ +* **Include On-Hold template projects** Determines whether on-hold template projects are included in the dropdown list when the 'Create From Template' action is run. (Defaults to included.) + # Functions This plug-in contains the following functions within the `templateLibrary` library: diff --git a/Templates.omnifocusjs/Resources/createFromTemplate.js b/Templates.omnifocusjs/Resources/createFromTemplate.js index feefdbb..be52dff 100644 --- a/Templates.omnifocusjs/Resources/createFromTemplate.js +++ b/Templates.omnifocusjs/Resources/createFromTemplate.js @@ -20,7 +20,12 @@ async function generateTemplateForm () { // select template to use and destination - show form const templateFolder = await templateLibrary.getTemplateFolder() - const templateProjects = templateFolder.flattenedProjects.filter(project => project.status === Project.Status.Active) + const templateProjects = templateFolder.flattenedProjects.filter(project => { + let isOnHold = preferences.readBoolean('includeOnHoldProjects') && project.status === Project.Status.OnHold + let isActive = project.status === Project.Status.Active + + return isActive || isOnHold + }) const templateForm = new Form() templateForm.addField( diff --git a/Templates.omnifocusjs/Resources/preferences.js b/Templates.omnifocusjs/Resources/preferences.js index a7c1eb1..4160ad2 100644 --- a/Templates.omnifocusjs/Resources/preferences.js +++ b/Templates.omnifocusjs/Resources/preferences.js @@ -8,6 +8,7 @@ // get current preferences or set defaults if they don't yet exist const alwaysGoTo = (preferences.read('alwaysGoTo') !== null) ? preferences.readBoolean('alwaysGoTo') : false + const includeOnHoldProjects = (preferences.read('includeOnHoldProjects') !== null) ? preferences.readBoolean('includeOnHoldProjects') : true const sortLocationsAlphabetically = (preferences.read('sortLocationsAlphabetically') !== null) ? preferences.readBoolean('sortLocationsAlphabetically') : false const templateFolderID = syncedPrefs.read('templateFolderID') const templateFolder = templateFolderID ? Folder.byIdentifier(templateFolderID) : null @@ -15,12 +16,14 @@ // create and show form const prefForm = new Form() prefForm.addField(new Form.Field.Checkbox('alwaysGoTo', 'Auto-select \'Go to created project\' when creating from template', alwaysGoTo)) + prefForm.addField(new Form.Field.Checkbox('includeOnHoldProjects', 'Include On-Hold template projects', includeOnHoldProjects)) prefForm.addField(new Form.Field.Checkbox('sortLocationsAlphabetically', 'Sort folder/project list alphabetically (instead of in OmniFocus order)', sortLocationsAlphabetically)) prefForm.addField(new Form.Field.Option('templateFolder', 'Template Folder', flattenedFolders, flattenedFolders.map(folder => folder.name), templateFolder, 'Please select')) await prefForm.show('Preferences: Templates', 'OK') // save preferences preferences.write('alwaysGoTo', prefForm.values.alwaysGoTo) + preferences.write('includeOnHoldProjects', prefForm.values.includeOnHoldProjects) preferences.write('sortLocationsAlphabetically', prefForm.values.sortLocationsAlphabetically) syncedPrefs.write('templateFolderID', prefForm.values.templateFolder.id.primaryKey) })