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
127
128
129
130
131
132
133
134
|
#import "ThingsTagHandler.h"
NS_ASSUME_NONNULL_BEGIN
@implementation ThingsTagHandler
- (BOOL)objectHasChildren:(QSObject *)object {
return YES;
}
- (void)setQuickIconForObject:(QSObject *)object {
NSImage *baseImage = [QSResourceManager imageNamed:@"com.culturedcode.ThingsMac"];
NSColor *color = [NSColor colorWithRed:0.263 green:0.502 blue:0.376 alpha:1.0];
NSImage *imageWithBadge = [baseImage imageOfSize:NSMakeSize(512, 512) withSystemBadge:@"tag.circle" ofColor:color];
if (imageWithBadge) {
[object setIcon:imageWithBadge];
} else {
[object setIcon:baseImage];
}
}
- (BOOL)loadChildrenForObject:(QSObject *)object {
NSDictionary *contents = [object objectForType:kTagType];
if (!contents) {
NSLog(@"Malformed Things Task: No content.");
return NO;
}
NSString *path = [contents objectForKey:@"path"];
if (!path) {
NSLog(@"Malformed Things Task: No path.");
return NO;
}
NSString *uuid = [contents objectForKey:@"uuid"];
if (!uuid) {
NSLog(@"Malformed Things Task: No uuid.");
return NO;
}
NSMutableArray *children = [NSMutableArray array];
[children addObjectsFromArray:[self areasForTagIdentifiedBy:uuid usingDatabaseAt:path ]];
[children addObjectsFromArray:[self projectsForTagIdentifiedBy:uuid usingDatabaseAt:path ]];
[children addObjectsFromArray:[self tasksForTagIdentifiedBy:uuid usingDatabaseAt:path ]];
[object setChildren:children];
return YES;
}
- (NSArray *)projectsForTagIdentifiedBy:(NSString *)uuid usingDatabaseAt:(NSString *)path {
NSString *query = [NSString stringWithFormat: @"SELECT "
"project.uuid as uuid, "
"project.creationDate as creationDate, "
"project.status as status, "
"project.title as title, "
"project.notes as notes, "
"project.area as area "
"FROM TMTag AS tag "
"LEFT JOIN TMTaskTag as junction "
"ON junction.tags = tag.uuid "
"LEFT JOIN TMTask as project "
"ON junction.tasks = project.uuid "
"WHERE tag.uuid = '%@' "
"AND project.uuid IS NOT NULL "
"AND project.type = 1 "
"AND project.status = 0 "
"AND project.trashed = 0 "
"ORDER BY project.title;", uuid];
NSArray *results = [SQLHelper executeSql:query onFile:path];
NSMutableArray *objects = [NSMutableArray array];
[results enumerateObjectsUsingBlock:^(NSDictionary *dictionary, NSUInteger i, BOOL *stop) {
[objects addObject:[ObjectHelper projectFromSQLResult:dictionary usingPath:path ]];
}];
return objects;
}
- (NSArray *)tasksForTagIdentifiedBy:(NSString *)uuid usingDatabaseAt:(NSString *)path {
NSString *query = [NSString stringWithFormat: @"SELECT "
"task.uuid as uuid, "
"task.creationDate as creationDate, "
"task.status as status, "
"task.title as title, "
"task.notes as notes, "
"task.area as area "
"FROM TMTag AS tag "
"LEFT JOIN TMTaskTag as junction "
"ON junction.tags = tag.uuid "
"LEFT JOIN TMTask as task "
"ON junction.tasks = task.uuid "
"WHERE tag.uuid = '%@' "
"AND task.uuid IS NOT NULL "
"AND task.type = 0 "
"AND task.status = 0 "
"AND task.trashed = 0 "
"ORDER BY task.title;", uuid];
NSArray *results = [SQLHelper executeSql:query onFile:path];
NSMutableArray *objects = [NSMutableArray array];
[results enumerateObjectsUsingBlock:^(NSDictionary *dictionary, NSUInteger i, BOOL *stop) {
[objects addObject:[ObjectHelper taskFromSQLResult:dictionary usingPath:path ]];
}];
return objects;
}
- (NSArray *)areasForTagIdentifiedBy:(NSString *)uuid usingDatabaseAt:(NSString *)path {
NSString *query = [NSString stringWithFormat: @"SELECT "
"area.uuid as uuid, "
"area.title as title "
"FROM TMTag AS tag "
"LEFT JOIN TMAreaTag as junction "
"ON junction.tags = tag.uuid "
"LEFT JOIN TMArea as area "
"ON junction.areas = area.uuid "
"WHERE tag.uuid = '%@' "
"AND area.uuid IS NOT NULL "
"ORDER BY area.title;", uuid];
NSArray *results = [SQLHelper executeSql:query onFile:path];
NSMutableArray *objects = [NSMutableArray array];
[results enumerateObjectsUsingBlock:^(NSDictionary *dictionary, NSUInteger i, BOOL *stop) {
[objects addObject:[ObjectHelper areaFromSQLResult:dictionary usingPath:path ]];
}];
return objects;
}
@end
NS_ASSUME_NONNULL_END
|