Skip to content

Commit

Permalink
feat: ✨ add preference to include/exclude on-hold templates
Browse files Browse the repository at this point in the history
closes #31
  • Loading branch information
rsobik authored Oct 2, 2022
1 parent 54ad958 commit b532236
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.)
Expand Down Expand Up @@ -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:
Expand Down
7 changes: 6 additions & 1 deletion Templates.omnifocusjs/Resources/createFromTemplate.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
3 changes: 3 additions & 0 deletions Templates.omnifocusjs/Resources/preferences.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,22 @@

// 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

// 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)
})
Expand Down

0 comments on commit b532236

Please sign in to comment.