Skip to content

Commit

Permalink
feat: ✨ add getTaskPathWithFolders function
Browse files Browse the repository at this point in the history
  • Loading branch information
ksalzke committed Jun 12, 2024
1 parent 42bc3b7 commit aaf5604
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 2 deletions.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,10 @@ The following functions are contained within the `fuzzySearchLib` library:

## `getTaskPath: (task: Task) => string`

Returns the full path of a task, from the project level. Nested action groups are also included
Returns the full path of a task, from the project level. Nested action groups are also included.

## `getTaskPathWithFolders: (task: Task) => string`
Returns the full path of a task, from the root level including all folders. Nested action groups are also included.

## `searchForm: (allItems: any, itemTitles: string[], firstSelected: any, matchingFunction: Function | null) => FuzzySearchForm`

Expand Down
20 changes: 20 additions & 0 deletions fuzzySearchLib.omnifocusjs/Resources/fuzzySearchLib.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,26 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
};
return getPath(task);
};
lib.getTaskPathWithFolders = function (task) {
var getFolderPath = function (task) {
var folders = __spreadArray([], flattenedFolders, true).filter(function (folder) { return __spreadArray([], folder.flattenedProjects, true).includes(task.containingProject); });
var folderNames = __spreadArray([], folders, true).map(function (folder) { return folder.name; });
return folderNames.join(' > ');
};
var getPath = function (task) {
if (task.inInbox)
return task.name; // task in inbox
if (!task.parent)
return getFolderPath(task) + " > " + task.name; // is a project
if (task.containingProject && task.parent === task.containingProject.task) {
// task is at root of project
return getFolderPath(task) + " > " + task.containingProject.name + " > " + task.name;
}
else
return getPath(task.parent) + " > " + task.name;
};
return getPath(task);
};
lib.truncateString = function (str, length) {
if (str.length <= length)
return str;
Expand Down
21 changes: 21 additions & 0 deletions src/fuzzySearchLib.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
interface FuzzySearchLibrary extends PlugIn.Library {
getTaskPath?: (task: Task) => string
getTaskPathWithFolders?: (task: Task) => string
searchForm?: (allItems: any, itemTitles: string[], firstSelected: any, matchingFunction: Function | null) => FuzzySearchForm
allTasksFuzzySearchForm?: () => FuzzySearchForm
remainingTasksFuzzySearchForm?: () => FuzzySearchForm
Expand Down Expand Up @@ -29,6 +30,26 @@ interface FuzzySearchForm extends Form {
return getPath(task)
}

lib.getTaskPathWithFolders = (task: Task) => {

const getFolderPath = (task: Task) => {
const folders = [...flattenedFolders].filter(folder => [...folder.flattenedProjects].includes(task.containingProject))
const folderNames = [...folders].map(folder => folder.name)
return folderNames.join(' > ')
}

const getPath = (task: Task) => {
if (task.inInbox) return task.name // task in inbox
if (!task.parent) return `${getFolderPath(task)} > ${task.name}` // is a project
if (task.containingProject && task.parent === task.containingProject.task) {
// task is at root of project
return `${getFolderPath(task)} > ${task.containingProject.name} > ${task.name}`
}
else return `${getPath(task.parent)} > ${task.name}`
}
return getPath(task)
}

lib.truncateString = (str: string, length: number) => {
if (str.length <= length) return str
return str.slice(0, length) + '...'
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"compilerOptions": {
"lib": [
"ES2019"
"ES2021"
],
"outDir": "fuzzySearchLib.omnifocusjs/Resources"
},
Expand Down

0 comments on commit aaf5604

Please sign in to comment.