@aneuhold/core-ts-db-lib 1.0.37 → 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.
@@ -1,10 +1,9 @@
1
1
  import { ObjectId } from 'bson';
2
2
  import DashboardTask, { DashboardTaskMap } from '../../../documents/dashboard/Task';
3
- import DashboardTaskRecurrenceService from './TaskRecurrenceService';
4
3
  import { DashboardTaskListFilterSettings } from '../../../embedded-types/dashboard/task/FilterSettings';
5
4
  import { DashboardTaskListSortSettings } from '../../../embedded-types/dashboard/task/SortSettings';
6
- import DashboardTaskSortService from './TaskSortService';
7
5
  import { DashboardTagSettings } from '../../../embedded-types/dashboard/userConfig/Tags';
6
+ import { RecurrenceFrequency } from '../../../embedded-types/dashboard/task/RecurrenceInfo';
8
7
  /**
9
8
  * A type for the task filter settings for a particular task.
10
9
  */
@@ -21,7 +20,7 @@ export default class DashboardTaskService {
21
20
  * Gets the next frequency date from the provided basis date. Returns null
22
21
  * if the provided frequency is in an invalid state.
23
22
  */
24
- static getNextFrequencyDate: typeof DashboardTaskRecurrenceService.getNextFrequencyDate;
23
+ static getNextFrequencyDate(basisDate: Date, frequency: RecurrenceFrequency): Date | null;
25
24
  /**
26
25
  * Moves the start and due date forward by one frequency.
27
26
  *
@@ -31,7 +30,7 @@ export default class DashboardTaskService {
31
30
  * Makes no changes if the state of the task is invalid for recurrence or
32
31
  * there isn't recurrence info.
33
32
  */
34
- static updateDatesForRecurrence: typeof DashboardTaskRecurrenceService.updateDatesForRecurrence;
33
+ static updateDatesForRecurrence(task: DashboardTask): void;
35
34
  /**
36
35
  * Gets the filtered and sorted set of task ids for a particular category.
37
36
  *
@@ -42,9 +41,11 @@ export default class DashboardTaskService {
42
41
  */
43
42
  static getFilteredAndSortedTaskIds(taskMap: DashboardTaskMap, category: string, filterSettings: DashboardTaskListFilterSettings, sortSettings: DashboardTaskListSortSettings, tagSettings: DashboardTagSettings, taskInfo?: DashboardTaskFilterTaskInfo): string[];
44
43
  /**
45
- * Gets the highest priority tag value for the provided task.
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.
46
47
  */
47
- static getHighestPriorityTagValue: typeof DashboardTaskSortService.getHighestPriorityTagValue;
48
+ static getTagHeaderMap(taskMap: DashboardTaskMap, taskIds: string[], userId: string, tagSettings: DashboardTagSettings, noPriorityTagsIndicator: string): Record<string, string>;
48
49
  private static getChildrenTaskIds;
49
50
  }
50
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;AAC3C,OAAO,8BAA8B,MAAM,yBAAyB,CAAC;AACrE,OAAO,EAAE,+BAA+B,EAAE,MAAM,uDAAuD,CAAC;AACxG,OAAO,EAAE,6BAA6B,EAAE,MAAM,qDAAqD,CAAC;AAEpG,OAAO,wBAAwB,MAAM,mBAAmB,CAAC;AACzD,OAAO,EAAE,oBAAoB,EAAE,MAAM,mDAAmD,CAAC;AAEzF;;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,6DAC2B;IAEtD;;;;;;;;OAQG;IACH,MAAM,CAAC,wBAAwB,iEAC2B;IAE1D;;;;;;;OAOG;IACH,MAAM,CAAC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B,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"}
@@ -37,7 +37,9 @@ class DashboardTaskService {
37
37
  * Gets the next frequency date from the provided basis date. Returns null
38
38
  * if the provided frequency is in an invalid state.
39
39
  */
40
- static getNextFrequencyDate = TaskRecurrenceService_1.default.getNextFrequencyDate;
40
+ static getNextFrequencyDate(basisDate, frequency) {
41
+ return TaskRecurrenceService_1.default.getNextFrequencyDate(basisDate, frequency);
42
+ }
41
43
  /**
42
44
  * Moves the start and due date forward by one frequency.
43
45
  *
@@ -47,7 +49,9 @@ class DashboardTaskService {
47
49
  * Makes no changes if the state of the task is invalid for recurrence or
48
50
  * there isn't recurrence info.
49
51
  */
50
- static updateDatesForRecurrence = TaskRecurrenceService_1.default.updateDatesForRecurrence;
52
+ static updateDatesForRecurrence(task) {
53
+ return TaskRecurrenceService_1.default.updateDatesForRecurrence(task);
54
+ }
51
55
  /**
52
56
  * Gets the filtered and sorted set of task ids for a particular category.
53
57
  *
@@ -67,9 +71,13 @@ class DashboardTaskService {
67
71
  return TaskSortService_1.default.sort(taskMap, filterResult, sortSettings, tagSettings);
68
72
  }
69
73
  /**
70
- * Gets the highest priority tag value for the provided task.
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.
71
77
  */
72
- static getHighestPriorityTagValue = TaskSortService_1.default.getHighestPriorityTagValue;
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;;OAEG;IACH,MAAM,CAAC,0BAA0B,CAC/B,IAAI,EAAE,aAAa,EACnB,MAAM,EAAE,MAAM,EACd,WAAW,EAAE,oBAAoB;IAcnC,OAAO,CAAC,MAAM,CAAC,mBAAmB;CA+DnC"}
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 the highest priority tag value for the provided task.
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 getHighestPriorityTagValue(task, userId, tagSettings) {
32
- const tags = task.tags[userId];
33
- if (!tags || tags.length === 0)
34
- return 0;
35
- return tags.reduce((highestPriority, tag) => {
36
- const priority = tagSettings[tag]?.priority;
37
- if (priority && priority > highestPriority) {
38
- return priority;
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
- return highestPriority;
41
- }, 0);
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;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aneuhold/core-ts-db-lib",
3
- "version": "1.0.37",
3
+ "version": "1.0.38",
4
4
  "description": "A core database library used for personal projects",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",