forked from rhydlewis/alfred-search-omnifocus
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathresult_factory.js
126 lines (107 loc) · 3.57 KB
/
result_factory.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
import path from 'path'
import {OF_ICON_ROOT} from "./omnifocus.js"
import {parseISO} from "date-fns";
const DROPPED_ICON = path.join(OF_ICON_ROOT, '[email protected]')
const FLAGGED_ICON = path.join(OF_ICON_ROOT, '[email protected]')
const ON_HOLD_ICON = path.join(OF_ICON_ROOT, '[email protected]')
const ACTIVE_ICON = path.join(OF_ICON_ROOT, '[email protected]')
const COMPLETED_ICON = path.join(OF_ICON_ROOT, '[email protected]')
const INBOX_ICON = path.join(OF_ICON_ROOT, '[email protected]')
const DEFERRED_ICON = path.join("./", 'deferred.png')
const FOLDER_ICON = path.join(OF_ICON_ROOT, '[email protected]')
const TAG_ICON = path.join(OF_ICON_ROOT, '[email protected]')
const STATUS_ACTIVE = 'active'
// const DATETIME_FORMAT = 'yyyy-MM-dd[T]HH:mm:ss.ttt'
const DATETIME_OFFSET = 978307200
export function createTask(result) {
let iconPath = ACTIVE_ICON
let dateCompleted = result["date_completed"]
let projectName = result["project_name"]
let blockedByFutureDate = result["blocked_by_future_start_date"] === 1
let blocked = result["blocked"] === 1
let childCount = result["child_count"]
let parentStatus = result["status"]
let inboxTask = (result["in_inbox"] === 1 || result["effective_in_inbox"] === 1)
// let effectiveStartDate = result["effective_date_to_start"]
// let startDate = result["date_to_start"]
// let actualStartDate = effectiveStartDate === 0 ? startDate : effectiveStartDate
if (dateCompleted) iconPath = COMPLETED_ICON
else if (inboxTask) {
iconPath = INBOX_ICON
projectName = "Inbox"
}
else if (blockedByFutureDate || (blocked && !childCount) || parentStatus !== STATUS_ACTIVE) iconPath = ON_HOLD_ICON
// else if (isDeferred(actualStartDate)) iconPath = DEFERRED_ICON
return {
icon: {
path: iconPath
},
title: result["name"],
subtitle: projectName,
arg: result["id"]
}
}
export function createProject(result) {
let status = result["status"]
let folderName = result["folder_name"]
let startDate = result['start_date']
let iconPath = ACTIVE_ICON
switch (status) {
case 'done':
iconPath = COMPLETED_ICON;
break;
case 'dropped':
iconPath = DROPPED_ICON;
break;
case 'inactive':
iconPath = ON_HOLD_ICON;
break;
}
if (status === 'active' && startDate !== null && isDeferred(startDate)) iconPath = DEFERRED_ICON
return {
icon: {
path: iconPath
},
title: result["name"],
subtitle: folderName,
arg: result["id"]
}
}
export function createFolder(result) {
let iconPath = FOLDER_ICON
return {
icon: {
path: iconPath
},
title: result["name"],
subtitle: '',
arg: result["id"]
}
}
export function createTag(result) {
let iconPath = ACTIVE_ICON
let allowsNextAction = result["allows_next_action"]
let availableTasks = result["available_task_count"]
let subtitle = availableTasks === 1 ? "1 task available" : `${availableTasks} tasks available`
if (allowsNextAction === 0) iconPath = ON_HOLD_ICON
return {
icon: {
path: iconPath
},
title: result["name"],
subtitle: subtitle,
arg: result["id"]
}
}
function isDeferred(actualStartDate) {
let pdt = parseDatetime(actualStartDate)
return (pdt !== null && pdt > Date.now())
}
function parseDatetime(dt) {
try {
return parseISO(dt)
}
catch (error) {
return null
}
}