@aneuhold/core-ts-db-lib 1.0.36 → 1.0.38
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/services/dashboard/Task/TaskService.d.ts +7 -1
- package/lib/services/dashboard/Task/TaskService.d.ts.map +1 -1
- package/lib/services/dashboard/Task/TaskService.js +8 -0
- package/lib/services/dashboard/Task/TaskService.spec.js +59 -0
- package/lib/services/dashboard/Task/TaskSortService.d.ts +12 -1
- package/lib/services/dashboard/Task/TaskSortService.d.ts.map +1 -1
- package/lib/services/dashboard/Task/TaskSortService.js +61 -11
- package/package.json +1 -1
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { ObjectId } from 'bson';
|
|
2
2
|
import DashboardTask, { DashboardTaskMap } from '../../../documents/dashboard/Task';
|
|
3
|
-
import { RecurrenceFrequency } from '../../../embedded-types/dashboard/task/RecurrenceInfo';
|
|
4
3
|
import { DashboardTaskListFilterSettings } from '../../../embedded-types/dashboard/task/FilterSettings';
|
|
5
4
|
import { DashboardTaskListSortSettings } from '../../../embedded-types/dashboard/task/SortSettings';
|
|
6
5
|
import { DashboardTagSettings } from '../../../embedded-types/dashboard/userConfig/Tags';
|
|
6
|
+
import { RecurrenceFrequency } from '../../../embedded-types/dashboard/task/RecurrenceInfo';
|
|
7
7
|
/**
|
|
8
8
|
* A type for the task filter settings for a particular task.
|
|
9
9
|
*/
|
|
@@ -40,6 +40,12 @@ export default class DashboardTaskService {
|
|
|
40
40
|
* the user does not have filter settings, then it will use the default.
|
|
41
41
|
*/
|
|
42
42
|
static getFilteredAndSortedTaskIds(taskMap: DashboardTaskMap, category: string, filterSettings: DashboardTaskListFilterSettings, sortSettings: DashboardTaskListSortSettings, tagSettings: DashboardTagSettings, taskInfo?: DashboardTaskFilterTaskInfo): string[];
|
|
43
|
+
/**
|
|
44
|
+
* Gets a map of task IDs to tag header names. Used only for when sorting by
|
|
45
|
+
* tags. If the first task in the list has no high-priority tags, then
|
|
46
|
+
* noPriorityTagsIndicator will be used as the header name.
|
|
47
|
+
*/
|
|
48
|
+
static getTagHeaderMap(taskMap: DashboardTaskMap, taskIds: string[], userId: string, tagSettings: DashboardTagSettings, noPriorityTagsIndicator: string): Record<string, string>;
|
|
43
49
|
private static getChildrenTaskIds;
|
|
44
50
|
}
|
|
45
51
|
//# sourceMappingURL=TaskService.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TaskService.d.ts","sourceRoot":"","sources":["../../../../src/services/dashboard/Task/TaskService.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,MAAM,CAAC;AAChC,OAAO,aAAa,EAAE,EACpB,gBAAgB,EACjB,MAAM,mCAAmC,CAAC;
|
|
1
|
+
{"version":3,"file":"TaskService.d.ts","sourceRoot":"","sources":["../../../../src/services/dashboard/Task/TaskService.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,MAAM,CAAC;AAChC,OAAO,aAAa,EAAE,EACpB,gBAAgB,EACjB,MAAM,mCAAmC,CAAC;AAE3C,OAAO,EAAE,+BAA+B,EAAE,MAAM,uDAAuD,CAAC;AACxG,OAAO,EAAE,6BAA6B,EAAE,MAAM,qDAAqD,CAAC;AAGpG,OAAO,EAAE,oBAAoB,EAAE,MAAM,mDAAmD,CAAC;AACzF,OAAO,EAAE,mBAAmB,EAAE,MAAM,uDAAuD,CAAC;AAE5F;;GAEG;AACH,MAAM,MAAM,2BAA2B,GAAG;IACxC,MAAM,EAAE,MAAM,CAAC;IACf,cAAc,EAAE,MAAM,EAAE,CAAC;CAC1B,CAAC;AAEF,MAAM,CAAC,OAAO,OAAO,oBAAoB;IACvC;;OAEG;IACH,MAAM,CAAC,cAAc,iBACL,aAAa,EAAE,iBACd,QAAQ,EAAE,KACxB,QAAQ,EAAE,CA2BX;IAEF;;;OAGG;IACH,MAAM,CAAC,oBAAoB,CAAC,SAAS,EAAE,IAAI,EAAE,SAAS,EAAE,mBAAmB;IAO3E;;;;;;;;OAQG;IACH,MAAM,CAAC,wBAAwB,CAAC,IAAI,EAAE,aAAa;IAInD;;;;;;;OAOG;IACH,MAAM,CAAC,2BAA2B,CAChC,OAAO,EAAE,gBAAgB,EACzB,QAAQ,EAAE,MAAM,EAChB,cAAc,EAAE,+BAA+B,EAC/C,YAAY,EAAE,6BAA6B,EAC3C,WAAW,EAAE,oBAAoB,EACjC,QAAQ,CAAC,EAAE,2BAA2B,GACrC,MAAM,EAAE;IA2BX;;;;OAIG;IACH,MAAM,CAAC,eAAe,CACpB,OAAO,EAAE,gBAAgB,EACzB,OAAO,EAAE,MAAM,EAAE,EACjB,MAAM,EAAE,MAAM,EACd,WAAW,EAAE,oBAAoB,EACjC,uBAAuB,EAAE,MAAM;IAWjC,OAAO,CAAC,MAAM,CAAC,kBAAkB;CAsBlC"}
|
|
@@ -70,6 +70,14 @@ class DashboardTaskService {
|
|
|
70
70
|
}
|
|
71
71
|
return TaskSortService_1.default.sort(taskMap, filterResult, sortSettings, tagSettings);
|
|
72
72
|
}
|
|
73
|
+
/**
|
|
74
|
+
* Gets a map of task IDs to tag header names. Used only for when sorting by
|
|
75
|
+
* tags. If the first task in the list has no high-priority tags, then
|
|
76
|
+
* noPriorityTagsIndicator will be used as the header name.
|
|
77
|
+
*/
|
|
78
|
+
static getTagHeaderMap(taskMap, taskIds, userId, tagSettings, noPriorityTagsIndicator) {
|
|
79
|
+
return TaskSortService_1.default.getTagHeaderMap(taskMap, taskIds, userId, tagSettings, noPriorityTagsIndicator);
|
|
80
|
+
}
|
|
73
81
|
static getChildrenTaskIds(taskIdToTaskDict, parentToTaskIdsDict, taskId) {
|
|
74
82
|
const childrenIds = parentToTaskIdsDict[taskId];
|
|
75
83
|
if (!childrenIds) {
|
|
@@ -273,6 +273,65 @@ describe('DashboardTaskService', () => {
|
|
|
273
273
|
]);
|
|
274
274
|
expect(taskMap[result[2]].tags[sortSettings.userId]).toEqual(['tag1']);
|
|
275
275
|
});
|
|
276
|
+
it('should return a correct tag header map when sorting tags descending', () => {
|
|
277
|
+
const { tasksList, taskMap, filterSettings, sortSettings, tagSettings } = setupSortAndFilterTest(10);
|
|
278
|
+
sortSettings.sortList.push({
|
|
279
|
+
sortBy: SortSettings_1.DashboardTaskSortBy.tags,
|
|
280
|
+
sortDirection: SortSettings_1.DashboardTaskSortDirection.descending
|
|
281
|
+
});
|
|
282
|
+
sortSettings.sortList.push({
|
|
283
|
+
sortBy: SortSettings_1.DashboardTaskSortBy.title,
|
|
284
|
+
sortDirection: SortSettings_1.DashboardTaskSortDirection.ascending
|
|
285
|
+
});
|
|
286
|
+
tagSettings.tag1 = {
|
|
287
|
+
priority: 1
|
|
288
|
+
};
|
|
289
|
+
tagSettings.tag2 = {
|
|
290
|
+
priority: 2
|
|
291
|
+
};
|
|
292
|
+
tagSettings.tag3 = {
|
|
293
|
+
priority: 3
|
|
294
|
+
};
|
|
295
|
+
const task1 = tasksList[4];
|
|
296
|
+
const task2 = tasksList[0];
|
|
297
|
+
const task3 = tasksList[1];
|
|
298
|
+
const task4 = tasksList[2];
|
|
299
|
+
const task5 = tasksList[3];
|
|
300
|
+
const task6 = tasksList[5];
|
|
301
|
+
task1.tags = {
|
|
302
|
+
[sortSettings.userId]: ['tag1', 'tag3']
|
|
303
|
+
};
|
|
304
|
+
task1.title = 'a';
|
|
305
|
+
task2.tags = {
|
|
306
|
+
[sortSettings.userId]: ['tag3']
|
|
307
|
+
};
|
|
308
|
+
task2.title = 'b';
|
|
309
|
+
task3.tags = {
|
|
310
|
+
[sortSettings.userId]: ['tag2', 'tag1']
|
|
311
|
+
};
|
|
312
|
+
task4.tags = {
|
|
313
|
+
[sortSettings.userId]: ['tag1']
|
|
314
|
+
};
|
|
315
|
+
task5.tags = {
|
|
316
|
+
[sortSettings.userId]: ['tagWithoutPriority']
|
|
317
|
+
};
|
|
318
|
+
task6.tags = {
|
|
319
|
+
[sortSettings.userId]: ['tagWithoutPriority']
|
|
320
|
+
};
|
|
321
|
+
const sortedTaskIds = TaskService_1.default.getFilteredAndSortedTaskIds(taskMap, 'default', filterSettings, sortSettings, tagSettings);
|
|
322
|
+
expect(sortedTaskIds.length).toBe(10);
|
|
323
|
+
expect(sortedTaskIds[0]).toBe(task1._id.toString());
|
|
324
|
+
expect(sortedTaskIds[1]).toBe(task2._id.toString());
|
|
325
|
+
expect(sortedTaskIds[2]).toBe(task3._id.toString());
|
|
326
|
+
expect(sortedTaskIds[3]).toBe(task4._id.toString());
|
|
327
|
+
expect(sortedTaskIds[4]).toBe(task5._id.toString());
|
|
328
|
+
const result = TaskService_1.default.getTagHeaderMap(taskMap, sortedTaskIds, sortSettings.userId, tagSettings, 'No Priority');
|
|
329
|
+
expect(Object.keys(result).length).toBe(4);
|
|
330
|
+
expect(result[task1._id.toString()]).toBe('tag3');
|
|
331
|
+
expect(result[task3._id.toString()]).toBe('tag2');
|
|
332
|
+
expect(result[task4._id.toString()]).toBe('tag1');
|
|
333
|
+
expect(result[task5._id.toString()]).toBe('No Priority');
|
|
334
|
+
});
|
|
276
335
|
it('should return a sorted list of tasks by tags, start date, and title', () => {
|
|
277
336
|
const { tasksList, taskMap, filterSettings, sortSettings, tagSettings } = setupSortAndFilterTest(10);
|
|
278
337
|
sortSettings.sortList.push({
|
|
@@ -9,10 +9,21 @@ export default class DashboardTaskSortService {
|
|
|
9
9
|
* Sorts the provided task IDs based on the provided sort settings.
|
|
10
10
|
*/
|
|
11
11
|
static sort(taskMap: DashboardTaskMap, taskIds: string[], sortSettings: DashboardTaskListSortSettings, tagSettings: DashboardTagSettings): string[];
|
|
12
|
+
/**
|
|
13
|
+
* Gets a map of task IDs to tag header names. Used only for when sorting by
|
|
14
|
+
* tags. If the first task in the list has no high-priority tags, then
|
|
15
|
+
* noPriorityTagsIndicator will be used as the header name.
|
|
16
|
+
*/
|
|
17
|
+
static getTagHeaderMap(taskMap: DashboardTaskMap, taskIds: string[], userId: string, tagSettings: DashboardTagSettings, noPriorityTagsIndicator: string): Record<string, string>;
|
|
18
|
+
private static getTaskSortFunction;
|
|
19
|
+
/**
|
|
20
|
+
* Gets the highest priority tag for the provided task. If there are no tags,
|
|
21
|
+
* or if there are no tags with a priority, then this will return null.
|
|
22
|
+
*/
|
|
23
|
+
private static getHighestPriorityTag;
|
|
12
24
|
/**
|
|
13
25
|
* Gets the highest priority tag value for the provided task.
|
|
14
26
|
*/
|
|
15
27
|
static getHighestPriorityTagValue(task: DashboardTask, userId: string, tagSettings: DashboardTagSettings): number;
|
|
16
|
-
private static getTaskSortFunction;
|
|
17
28
|
}
|
|
18
29
|
//# sourceMappingURL=TaskSortService.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TaskSortService.d.ts","sourceRoot":"","sources":["../../../../src/services/dashboard/Task/TaskSortService.ts"],"names":[],"mappings":"AAAA,OAAO,aAAa,EAAE,EACpB,gBAAgB,EACjB,MAAM,mCAAmC,CAAC;AAC3C,OAAO,EACL,6BAA6B,EAG9B,MAAM,qDAAqD,CAAC;AAC7D,OAAO,EAAE,oBAAoB,EAAE,MAAM,mDAAmD,CAAC;AAEzF;;GAEG;AACH,MAAM,CAAC,OAAO,OAAO,wBAAwB;IAC3C;;OAEG;IACH,MAAM,CAAC,IAAI,CACT,OAAO,EAAE,gBAAgB,EACzB,OAAO,EAAE,MAAM,EAAE,EACjB,YAAY,EAAE,6BAA6B,EAC3C,WAAW,EAAE,oBAAoB;IA0BnC
|
|
1
|
+
{"version":3,"file":"TaskSortService.d.ts","sourceRoot":"","sources":["../../../../src/services/dashboard/Task/TaskSortService.ts"],"names":[],"mappings":"AAAA,OAAO,aAAa,EAAE,EACpB,gBAAgB,EACjB,MAAM,mCAAmC,CAAC;AAC3C,OAAO,EACL,6BAA6B,EAG9B,MAAM,qDAAqD,CAAC;AAC7D,OAAO,EAAE,oBAAoB,EAAE,MAAM,mDAAmD,CAAC;AAEzF;;GAEG;AACH,MAAM,CAAC,OAAO,OAAO,wBAAwB;IAC3C;;OAEG;IACH,MAAM,CAAC,IAAI,CACT,OAAO,EAAE,gBAAgB,EACzB,OAAO,EAAE,MAAM,EAAE,EACjB,YAAY,EAAE,6BAA6B,EAC3C,WAAW,EAAE,oBAAoB;IA0BnC;;;;OAIG;IACH,MAAM,CAAC,eAAe,CACpB,OAAO,EAAE,gBAAgB,EACzB,OAAO,EAAE,MAAM,EAAE,EACjB,MAAM,EAAE,MAAM,EACd,WAAW,EAAE,oBAAoB,EACjC,uBAAuB,EAAE,MAAM,GAC9B,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC;IAwBzB,OAAO,CAAC,MAAM,CAAC,mBAAmB;IAgElC;;;OAGG;IACH,OAAO,CAAC,MAAM,CAAC,qBAAqB;IAoBpC;;OAEG;IACH,MAAM,CAAC,0BAA0B,CAC/B,IAAI,EAAE,aAAa,EACnB,MAAM,EAAE,MAAM,EACd,WAAW,EAAE,oBAAoB;CAapC"}
|
|
@@ -26,19 +26,35 @@ class DashboardTaskSortService {
|
|
|
26
26
|
});
|
|
27
27
|
}
|
|
28
28
|
/**
|
|
29
|
-
* Gets
|
|
29
|
+
* Gets a map of task IDs to tag header names. Used only for when sorting by
|
|
30
|
+
* tags. If the first task in the list has no high-priority tags, then
|
|
31
|
+
* noPriorityTagsIndicator will be used as the header name.
|
|
30
32
|
*/
|
|
31
|
-
static
|
|
32
|
-
const
|
|
33
|
-
if (
|
|
34
|
-
return
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
33
|
+
static getTagHeaderMap(taskMap, taskIds, userId, tagSettings, noPriorityTagsIndicator) {
|
|
34
|
+
const tagHeaderMap = {};
|
|
35
|
+
if (taskIds.length === 0 || taskIds.length === 1)
|
|
36
|
+
return tagHeaderMap;
|
|
37
|
+
const firstTask = taskMap[taskIds[0]];
|
|
38
|
+
if (!firstTask)
|
|
39
|
+
return tagHeaderMap;
|
|
40
|
+
let tag = this.getHighestPriorityTag(firstTask, userId, tagSettings);
|
|
41
|
+
if (!tag) {
|
|
42
|
+
tagHeaderMap[taskIds[0]] = noPriorityTagsIndicator;
|
|
43
|
+
}
|
|
44
|
+
else {
|
|
45
|
+
tagHeaderMap[taskIds[0]] = tag;
|
|
46
|
+
}
|
|
47
|
+
for (let i = 1; i < taskIds.length; i += 1) {
|
|
48
|
+
const task = taskMap[taskIds[i]];
|
|
49
|
+
if (task) {
|
|
50
|
+
const taskTag = this.getHighestPriorityTag(task, userId, tagSettings);
|
|
51
|
+
if (taskTag !== tag && tag !== noPriorityTagsIndicator) {
|
|
52
|
+
tag = taskTag || noPriorityTagsIndicator;
|
|
53
|
+
tagHeaderMap[taskIds[i]] = tag;
|
|
54
|
+
}
|
|
39
55
|
}
|
|
40
|
-
|
|
41
|
-
|
|
56
|
+
}
|
|
57
|
+
return tagHeaderMap;
|
|
42
58
|
}
|
|
43
59
|
static getTaskSortFunction(sortBy, sortDirection, tagSettings, userId) {
|
|
44
60
|
switch (sortBy) {
|
|
@@ -93,5 +109,39 @@ class DashboardTaskSortService {
|
|
|
93
109
|
};
|
|
94
110
|
}
|
|
95
111
|
}
|
|
112
|
+
/**
|
|
113
|
+
* Gets the highest priority tag for the provided task. If there are no tags,
|
|
114
|
+
* or if there are no tags with a priority, then this will return null.
|
|
115
|
+
*/
|
|
116
|
+
static getHighestPriorityTag(task, userId, tagSettings) {
|
|
117
|
+
const tags = task.tags[userId];
|
|
118
|
+
if (!tags || tags.length === 0)
|
|
119
|
+
return null;
|
|
120
|
+
let highestPriorityTag = null;
|
|
121
|
+
let highestPriority = 0;
|
|
122
|
+
tags.forEach((tag) => {
|
|
123
|
+
const priority = tagSettings[tag]?.priority;
|
|
124
|
+
if (priority && priority > highestPriority) {
|
|
125
|
+
highestPriorityTag = tag;
|
|
126
|
+
highestPriority = priority;
|
|
127
|
+
}
|
|
128
|
+
});
|
|
129
|
+
return highestPriorityTag;
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Gets the highest priority tag value for the provided task.
|
|
133
|
+
*/
|
|
134
|
+
static getHighestPriorityTagValue(task, userId, tagSettings) {
|
|
135
|
+
const tags = task.tags[userId];
|
|
136
|
+
if (!tags || tags.length === 0)
|
|
137
|
+
return 0;
|
|
138
|
+
return tags.reduce((highestPriority, tag) => {
|
|
139
|
+
const priority = tagSettings[tag]?.priority;
|
|
140
|
+
if (priority && priority > highestPriority) {
|
|
141
|
+
return priority;
|
|
142
|
+
}
|
|
143
|
+
return highestPriority;
|
|
144
|
+
}, 0);
|
|
145
|
+
}
|
|
96
146
|
}
|
|
97
147
|
exports.default = DashboardTaskSortService;
|