@aneuhold/core-ts-db-lib 1.0.42 → 1.0.44
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 +2 -2
- package/lib/services/dashboard/Task/TaskService.d.ts.map +1 -1
- package/lib/services/dashboard/Task/TaskService.js +2 -2
- package/lib/services/dashboard/Task/TaskService.spec.js +54 -1
- package/lib/services/dashboard/Task/TaskSortService.d.ts +5 -4
- package/lib/services/dashboard/Task/TaskSortService.d.ts.map +1 -1
- package/lib/services/dashboard/Task/TaskSortService.js +33 -27
- package/package.json +1 -1
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { ObjectId } from 'bson';
|
|
2
2
|
import DashboardTask, { DashboardTaskMap } from '../../../documents/dashboard/Task';
|
|
3
3
|
import { DashboardTaskListFilterSettings } from '../../../embedded-types/dashboard/task/FilterSettings';
|
|
4
|
-
import { DashboardTaskListSortSettings } from '../../../embedded-types/dashboard/task/SortSettings';
|
|
4
|
+
import { DashboardTaskListSortSettings, DashboardTaskSortDirection } from '../../../embedded-types/dashboard/task/SortSettings';
|
|
5
5
|
import { DashboardTagSettings } from '../../../embedded-types/dashboard/userConfig/Tags';
|
|
6
6
|
import { RecurrenceFrequency } from '../../../embedded-types/dashboard/task/RecurrenceInfo';
|
|
7
7
|
/**
|
|
@@ -54,7 +54,7 @@ export default class DashboardTaskService {
|
|
|
54
54
|
* tags. If the first task in the list has no high-priority tags, then
|
|
55
55
|
* noPriorityTagsIndicator will be used as the header name.
|
|
56
56
|
*/
|
|
57
|
-
static getTagHeaderMap(taskMap: DashboardTaskMap, taskIds: string[], userId: string, tagSettings: DashboardTagSettings, noPriorityTagsIndicator: string): Record<string, string>;
|
|
57
|
+
static getTagHeaderMap(taskMap: DashboardTaskMap, taskIds: string[], userId: string, tagSettings: DashboardTagSettings, noPriorityTagsIndicator: string, sortDirection: DashboardTaskSortDirection): Record<string, string>;
|
|
58
58
|
private static getChildrenTaskIds;
|
|
59
59
|
}
|
|
60
60
|
//# 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;AAE3C,OAAO,EAAE,+BAA+B,EAAE,MAAM,uDAAuD,CAAC;AACxG,OAAO,
|
|
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,EACL,6BAA6B,EAC7B,0BAA0B,EAC3B,MAAM,qDAAqD,CAAC;AAK7D,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,MAAM,gCAAgC,GAAG;IAC7C,oBAAoB,EAAE,MAAM,EAAE,CAAC;IAC/B;;;;OAIG;IACH,UAAU,EAAE,MAAM,EAAE,CAAC;CACtB,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,gCAAgC;IA8BnC;;;;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,EAC/B,aAAa,EAAE,0BAA0B;IAY3C,OAAO,CAAC,MAAM,CAAC,kBAAkB;CAsBlC"}
|
|
@@ -78,8 +78,8 @@ class DashboardTaskService {
|
|
|
78
78
|
* tags. If the first task in the list has no high-priority tags, then
|
|
79
79
|
* noPriorityTagsIndicator will be used as the header name.
|
|
80
80
|
*/
|
|
81
|
-
static getTagHeaderMap(taskMap, taskIds, userId, tagSettings, noPriorityTagsIndicator) {
|
|
82
|
-
return TaskSortService_1.default.getTagHeaderMap(taskMap, taskIds, userId, tagSettings, noPriorityTagsIndicator);
|
|
81
|
+
static getTagHeaderMap(taskMap, taskIds, userId, tagSettings, noPriorityTagsIndicator, sortDirection) {
|
|
82
|
+
return TaskSortService_1.default.getTagHeaderMap(taskMap, taskIds, userId, tagSettings, noPriorityTagsIndicator, sortDirection);
|
|
83
83
|
}
|
|
84
84
|
static getChildrenTaskIds(taskIdToTaskDict, parentToTaskIdsDict, taskId) {
|
|
85
85
|
const childrenIds = parentToTaskIdsDict[taskId];
|
|
@@ -325,13 +325,66 @@ describe('DashboardTaskService', () => {
|
|
|
325
325
|
expect(sortedTaskIds[2]).toBe(task3._id.toString());
|
|
326
326
|
expect(sortedTaskIds[3]).toBe(task4._id.toString());
|
|
327
327
|
expect(sortedTaskIds[4]).toBe(task5._id.toString());
|
|
328
|
-
const result = TaskService_1.default.getTagHeaderMap(taskMap, sortedTaskIds, sortSettings.userId, tagSettings, 'No Priority');
|
|
328
|
+
const result = TaskService_1.default.getTagHeaderMap(taskMap, sortedTaskIds, sortSettings.userId, tagSettings, 'No Priority', SortSettings_1.DashboardTaskSortDirection.descending);
|
|
329
329
|
expect(Object.keys(result).length).toBe(4);
|
|
330
330
|
expect(result[task1._id.toString()]).toBe('tag3');
|
|
331
331
|
expect(result[task3._id.toString()]).toBe('tag2');
|
|
332
332
|
expect(result[task4._id.toString()]).toBe('tag1');
|
|
333
333
|
expect(result[task5._id.toString()]).toBe('No Priority');
|
|
334
334
|
});
|
|
335
|
+
it('should return a correct tag header map when sorting tags ascending', () => {
|
|
336
|
+
const { tasksList, taskMap, filterSettings, sortSettings, tagSettings } = setupSortAndFilterTest();
|
|
337
|
+
sortSettings.sortList.push({
|
|
338
|
+
sortBy: SortSettings_1.DashboardTaskSortBy.tags,
|
|
339
|
+
sortDirection: SortSettings_1.DashboardTaskSortDirection.ascending
|
|
340
|
+
});
|
|
341
|
+
tagSettings.tag1 = {
|
|
342
|
+
priority: 1
|
|
343
|
+
};
|
|
344
|
+
tagSettings.tag2 = {
|
|
345
|
+
priority: 2
|
|
346
|
+
};
|
|
347
|
+
tagSettings.tag3 = {
|
|
348
|
+
priority: 3
|
|
349
|
+
};
|
|
350
|
+
tagSettings.tag4 = {
|
|
351
|
+
priority: 4
|
|
352
|
+
};
|
|
353
|
+
const task1 = tasksList[4];
|
|
354
|
+
const task2 = tasksList[0];
|
|
355
|
+
const task3 = tasksList[1];
|
|
356
|
+
const task4 = tasksList[2];
|
|
357
|
+
const task5 = tasksList[3];
|
|
358
|
+
task1.tags = {
|
|
359
|
+
[sortSettings.userId]: ['tagWithoutPriority', 'tag3']
|
|
360
|
+
};
|
|
361
|
+
task2.tags = {
|
|
362
|
+
[sortSettings.userId]: ['tag3', 'tag4', 'tag1']
|
|
363
|
+
};
|
|
364
|
+
task3.tags = {
|
|
365
|
+
[sortSettings.userId]: ['tag2']
|
|
366
|
+
};
|
|
367
|
+
task4.tags = {
|
|
368
|
+
[sortSettings.userId]: ['tag3', 'tag4']
|
|
369
|
+
};
|
|
370
|
+
task5.tags = {
|
|
371
|
+
[sortSettings.userId]: ['tag4']
|
|
372
|
+
};
|
|
373
|
+
const { filteredAndSortedIds: sortedTaskIds } = TaskService_1.default.getFilteredAndSortedTaskIds(taskMap, 'default', filterSettings, sortSettings, tagSettings);
|
|
374
|
+
expect(sortedTaskIds.length).toBe(5);
|
|
375
|
+
expect(sortedTaskIds[0]).toBe(task1._id.toString());
|
|
376
|
+
expect(sortedTaskIds[1]).toBe(task2._id.toString());
|
|
377
|
+
expect(sortedTaskIds[2]).toBe(task3._id.toString());
|
|
378
|
+
expect(sortedTaskIds[3]).toBe(task4._id.toString());
|
|
379
|
+
expect(sortedTaskIds[4]).toBe(task5._id.toString());
|
|
380
|
+
const result = TaskService_1.default.getTagHeaderMap(taskMap, sortedTaskIds, sortSettings.userId, tagSettings, 'No Priority', SortSettings_1.DashboardTaskSortDirection.ascending);
|
|
381
|
+
expect(Object.keys(result).length).toBe(5);
|
|
382
|
+
expect(result[task1._id.toString()]).toBe('No Priority');
|
|
383
|
+
expect(result[task2._id.toString()]).toBe('tag1');
|
|
384
|
+
expect(result[task3._id.toString()]).toBe('tag2');
|
|
385
|
+
expect(result[task4._id.toString()]).toBe('tag3');
|
|
386
|
+
expect(result[task5._id.toString()]).toBe('tag4');
|
|
387
|
+
});
|
|
335
388
|
it('should return a sorted list of tasks by tags, start date, and title', () => {
|
|
336
389
|
const { tasksList, taskMap, filterSettings, sortSettings, tagSettings } = setupSortAndFilterTest(10);
|
|
337
390
|
sortSettings.sortList.push({
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { DashboardTaskListSortSettings } from '../../../embedded-types/dashboard/task/SortSettings';
|
|
1
|
+
import { DashboardTaskMap } from '../../../documents/dashboard/Task';
|
|
2
|
+
import { DashboardTaskListSortSettings, DashboardTaskSortDirection } from '../../../embedded-types/dashboard/task/SortSettings';
|
|
3
3
|
import { DashboardTagSettings } from '../../../embedded-types/dashboard/userConfig/Tags';
|
|
4
4
|
/**
|
|
5
5
|
* A service for sorting tasks.
|
|
@@ -14,7 +14,7 @@ export default class DashboardTaskSortService {
|
|
|
14
14
|
* tags. If the first task in the list has no high-priority tags, then
|
|
15
15
|
* noPriorityTagsIndicator will be used as the header name.
|
|
16
16
|
*/
|
|
17
|
-
static getTagHeaderMap(taskMap: DashboardTaskMap, taskIds: string[], userId: string, tagSettings: DashboardTagSettings, noPriorityTagsIndicator: string): Record<string, string>;
|
|
17
|
+
static getTagHeaderMap(taskMap: DashboardTaskMap, taskIds: string[], userId: string, tagSettings: DashboardTagSettings, noPriorityTagsIndicator: string, sortDirection: DashboardTaskSortDirection): Record<string, string>;
|
|
18
18
|
private static getTaskSortFunction;
|
|
19
19
|
/**
|
|
20
20
|
* Gets the highest priority tag for the provided task. If there are no tags,
|
|
@@ -24,6 +24,7 @@ export default class DashboardTaskSortService {
|
|
|
24
24
|
/**
|
|
25
25
|
* Gets the highest priority tag value for the provided task.
|
|
26
26
|
*/
|
|
27
|
-
static getHighestPriorityTagValue
|
|
27
|
+
private static getHighestPriorityTagValue;
|
|
28
|
+
private static getPriorityTagForTask;
|
|
28
29
|
}
|
|
29
30
|
//# 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,
|
|
1
|
+
{"version":3,"file":"TaskSortService.d.ts","sourceRoot":"","sources":["../../../../src/services/dashboard/Task/TaskSortService.ts"],"names":[],"mappings":"AAAA,OAAsB,EACpB,gBAAgB,EACjB,MAAM,mCAAmC,CAAC;AAC3C,OAAO,EACL,6BAA6B,EAE7B,0BAA0B,EAC3B,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,EAC/B,aAAa,EAAE,0BAA0B,GACxC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC;IAkCzB,OAAO,CAAC,MAAM,CAAC,mBAAmB;IAkElC;;;OAGG;IACH,OAAO,CAAC,MAAM,CAAC,qBAAqB;IAepC;;OAEG;IACH,OAAO,CAAC,MAAM,CAAC,0BAA0B;IAezC,OAAO,CAAC,MAAM,CAAC,qBAAqB;CAgCrC"}
|
|
@@ -30,14 +30,14 @@ class DashboardTaskSortService {
|
|
|
30
30
|
* tags. If the first task in the list has no high-priority tags, then
|
|
31
31
|
* noPriorityTagsIndicator will be used as the header name.
|
|
32
32
|
*/
|
|
33
|
-
static getTagHeaderMap(taskMap, taskIds, userId, tagSettings, noPriorityTagsIndicator) {
|
|
33
|
+
static getTagHeaderMap(taskMap, taskIds, userId, tagSettings, noPriorityTagsIndicator, sortDirection) {
|
|
34
34
|
const tagHeaderMap = {};
|
|
35
35
|
if (taskIds.length === 0 || taskIds.length === 1)
|
|
36
36
|
return tagHeaderMap;
|
|
37
37
|
const firstTask = taskMap[taskIds[0]];
|
|
38
38
|
if (!firstTask)
|
|
39
39
|
return tagHeaderMap;
|
|
40
|
-
let tag = this.getHighestPriorityTag(firstTask, userId, tagSettings);
|
|
40
|
+
let tag = this.getHighestPriorityTag(firstTask, userId, tagSettings, sortDirection);
|
|
41
41
|
if (!tag) {
|
|
42
42
|
tagHeaderMap[taskIds[0]] = noPriorityTagsIndicator;
|
|
43
43
|
}
|
|
@@ -47,7 +47,7 @@ class DashboardTaskSortService {
|
|
|
47
47
|
for (let i = 1; i < taskIds.length; i += 1) {
|
|
48
48
|
const task = taskMap[taskIds[i]];
|
|
49
49
|
if (task) {
|
|
50
|
-
const taskTag = this.getHighestPriorityTag(task, userId, tagSettings);
|
|
50
|
+
const taskTag = this.getHighestPriorityTag(task, userId, tagSettings, sortDirection);
|
|
51
51
|
if (taskTag !== tag && tag !== noPriorityTagsIndicator) {
|
|
52
52
|
tag = taskTag || noPriorityTagsIndicator;
|
|
53
53
|
tagHeaderMap[taskIds[i]] = tag;
|
|
@@ -60,8 +60,8 @@ class DashboardTaskSortService {
|
|
|
60
60
|
switch (sortBy) {
|
|
61
61
|
case SortSettings_1.DashboardTaskSortBy.tags:
|
|
62
62
|
return (taskA, taskB) => {
|
|
63
|
-
const highestPriorityTagA = this.getHighestPriorityTagValue(taskA, userId, tagSettings);
|
|
64
|
-
const highestPriorityTagB = this.getHighestPriorityTagValue(taskB, userId, tagSettings);
|
|
63
|
+
const highestPriorityTagA = this.getHighestPriorityTagValue(taskA, userId, tagSettings, sortDirection);
|
|
64
|
+
const highestPriorityTagB = this.getHighestPriorityTagValue(taskB, userId, tagSettings, sortDirection);
|
|
65
65
|
if (highestPriorityTagA === highestPriorityTagB) {
|
|
66
66
|
return 0;
|
|
67
67
|
}
|
|
@@ -113,35 +113,41 @@ class DashboardTaskSortService {
|
|
|
113
113
|
* Gets the highest priority tag for the provided task. If there are no tags,
|
|
114
114
|
* or if there are no tags with a priority, then this will return null.
|
|
115
115
|
*/
|
|
116
|
-
static getHighestPriorityTag(task, userId, tagSettings) {
|
|
117
|
-
const
|
|
118
|
-
|
|
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;
|
|
116
|
+
static getHighestPriorityTag(task, userId, tagSettings, sortDirection) {
|
|
117
|
+
const priorityTag = this.getPriorityTagForTask(task, userId, tagSettings, sortDirection);
|
|
118
|
+
return priorityTag ? priorityTag.tag : null;
|
|
130
119
|
}
|
|
131
120
|
/**
|
|
132
121
|
* Gets the highest priority tag value for the provided task.
|
|
133
122
|
*/
|
|
134
|
-
static getHighestPriorityTagValue(task, userId, tagSettings) {
|
|
123
|
+
static getHighestPriorityTagValue(task, userId, tagSettings, sortDirection) {
|
|
124
|
+
const priorityTag = this.getPriorityTagForTask(task, userId, tagSettings, sortDirection);
|
|
125
|
+
return priorityTag ? priorityTag.priority : 0;
|
|
126
|
+
}
|
|
127
|
+
static getPriorityTagForTask(task, userId, tagSettings, sortDirection) {
|
|
128
|
+
let priorityTag = null;
|
|
135
129
|
const tags = task.tags[userId];
|
|
136
130
|
if (!tags || tags.length === 0)
|
|
137
|
-
return
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
131
|
+
return priorityTag;
|
|
132
|
+
let highestPriority = 0;
|
|
133
|
+
const isAscending = sortDirection === SortSettings_1.DashboardTaskSortDirection.ascending;
|
|
134
|
+
// If the sort direction is descending, then we want to start with the
|
|
135
|
+
// lowest priority number.
|
|
136
|
+
if (isAscending) {
|
|
137
|
+
highestPriority = Number.MAX_SAFE_INTEGER;
|
|
138
|
+
}
|
|
139
|
+
tags.forEach((tag) => {
|
|
140
|
+
const priority = tagSettings[tag]?.priority ?? 0;
|
|
141
|
+
if ((isAscending && priority < highestPriority) ||
|
|
142
|
+
(!isAscending && priority > highestPriority)) {
|
|
143
|
+
highestPriority = priority;
|
|
144
|
+
priorityTag = { tag, priority };
|
|
142
145
|
}
|
|
143
|
-
|
|
144
|
-
|
|
146
|
+
});
|
|
147
|
+
if (highestPriority === 0) {
|
|
148
|
+
return null;
|
|
149
|
+
}
|
|
150
|
+
return priorityTag;
|
|
145
151
|
}
|
|
146
152
|
}
|
|
147
153
|
exports.default = DashboardTaskSortService;
|