@qrvey/filters 0.0.1 → 0.0.2

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.
Files changed (85) hide show
  1. package/CHANGELOG.md +11 -0
  2. package/dist/classes/FilterAdapter.d.ts +97 -0
  3. package/dist/classes/FilterAdapter.d.ts.map +1 -0
  4. package/dist/classes/FilterAdapter.js +113 -0
  5. package/dist/classes/FilterBuilder.d.ts +37 -4
  6. package/dist/classes/FilterBuilder.d.ts.map +1 -1
  7. package/dist/classes/FilterBuilder.js +55 -3
  8. package/dist/classes/FilterManager.d.ts +55 -11
  9. package/dist/classes/FilterManager.d.ts.map +1 -1
  10. package/dist/classes/FilterManager.js +64 -14
  11. package/dist/classes/FilterResources.d.ts +14 -14
  12. package/dist/classes/FilterResources.d.ts.map +1 -1
  13. package/dist/classes/FilterResources.js +17 -17
  14. package/dist/classes/{FilterSearch.d.ts → FilterSearcher.d.ts} +23 -4
  15. package/dist/classes/FilterSearcher.d.ts.map +1 -0
  16. package/dist/classes/{FilterSearch.js → FilterSearcher.js} +37 -7
  17. package/dist/classes/index.d.ts +1 -1
  18. package/dist/classes/index.d.ts.map +1 -1
  19. package/dist/classes/index.js +1 -1
  20. package/dist/helpers/filter-adapt.helpers.d.ts +21 -0
  21. package/dist/helpers/filter-adapt.helpers.d.ts.map +1 -0
  22. package/dist/helpers/filter-adapt.helpers.js +230 -0
  23. package/dist/helpers/filter-settings.helpers.d.ts +2 -2
  24. package/dist/helpers/filter-settings.helpers.d.ts.map +1 -1
  25. package/dist/helpers/filter-settings.helpers.js +6 -6
  26. package/dist/helpers/getFilterId.d.ts.map +1 -1
  27. package/dist/helpers/getFilterId.js +6 -4
  28. package/dist/helpers/getFilterType.d.ts +6 -3
  29. package/dist/helpers/getFilterType.d.ts.map +1 -1
  30. package/dist/helpers/getFilterType.js +5 -4
  31. package/dist/helpers/utils.helpers.d.ts +26 -0
  32. package/dist/helpers/utils.helpers.d.ts.map +1 -0
  33. package/dist/helpers/utils.helpers.js +26 -0
  34. package/dist/models/filter-builder.models.d.ts +15 -1
  35. package/dist/models/filter-builder.models.d.ts.map +1 -1
  36. package/dist/models/filter-resources.models.d.ts +11 -11
  37. package/dist/models/filter-resources.models.d.ts.map +1 -1
  38. package/dist/resources/filter-functions.resources.d.ts +2 -2
  39. package/dist/resources/filter-functions.resources.d.ts.map +1 -1
  40. package/dist/resources/filter-functions.resources.js +1 -1
  41. package/dist/resources/filter-grouping.resources.d.ts +7 -7
  42. package/dist/resources/filter-logic.resources.d.ts +136 -0
  43. package/dist/resources/filter-logic.resources.d.ts.map +1 -0
  44. package/dist/resources/filter-logic.resources.js +25 -0
  45. package/dist/resources/filter-panel.interfaces.d.ts +6 -0
  46. package/dist/resources/filter-panel.interfaces.d.ts.map +1 -1
  47. package/dist/resources/filter-scopes.resources.d.ts +36 -11
  48. package/dist/resources/filter-scopes.resources.d.ts.map +1 -1
  49. package/dist/resources/filter-scopes.resources.js +17 -3
  50. package/dist/resources/filter-validators.resources.d.ts +5 -5
  51. package/dist/resources/filter-values.resources.d.ts +0 -8
  52. package/dist/resources/filter-values.resources.d.ts.map +1 -1
  53. package/dist/resources/filter-values.resources.js +13 -0
  54. package/dist/resources/filter-visual.resources.d.ts +93 -0
  55. package/dist/resources/filter-visual.resources.d.ts.map +1 -0
  56. package/dist/resources/filter-visual.resources.js +2 -0
  57. package/dist/resources/filters.resources.d.ts +65 -13
  58. package/dist/resources/filters.resources.d.ts.map +1 -1
  59. package/dist/resources/filters.resources.js +1 -27
  60. package/jest.config.js +4 -1
  61. package/package.json +15 -11
  62. package/src/classes/FilterAdapter.ts +158 -0
  63. package/src/classes/FilterBuilder.ts +97 -7
  64. package/src/classes/FilterManager.ts +83 -15
  65. package/src/classes/FilterResources.ts +39 -38
  66. package/src/classes/{FilterSearch.ts → FilterSearcher.ts} +63 -12
  67. package/src/classes/index.ts +1 -1
  68. package/src/helpers/filter-adapt.helpers.ts +379 -0
  69. package/src/helpers/filter-settings.helpers.ts +9 -9
  70. package/src/helpers/getFilterId.ts +7 -3
  71. package/src/helpers/getFilterType.ts +10 -6
  72. package/src/helpers/utils.helpers.ts +37 -0
  73. package/src/models/filter-builder.models.ts +23 -1
  74. package/src/models/filter-resources.models.ts +13 -13
  75. package/src/resources/filter-functions.resources.ts +2 -2
  76. package/src/resources/filter-grouping.resources.ts +7 -7
  77. package/src/resources/filter-logic.resources.ts +149 -0
  78. package/src/resources/filter-panel.interfaces.ts +8 -0
  79. package/src/resources/filter-scopes.resources.ts +36 -12
  80. package/src/resources/filter-validators.resources.ts +5 -5
  81. package/src/resources/filter-values.resources.ts +14 -14
  82. package/src/resources/filter-visual.resources.ts +102 -0
  83. package/src/resources/filters.resources.ts +65 -47
  84. package/tests/helpers/getFilterId.test.ts +123 -0
  85. package/dist/classes/FilterSearch.d.ts.map +0 -1
@@ -1,6 +1,6 @@
1
1
  import { getLastIndexFromArray, isEmpty, objectCopy } from "@qrvey/utils";
2
2
 
3
- import { FilterSearch } from "./FilterSearch";
3
+ import { FilterSearcher } from "./FilterSearcher";
4
4
 
5
5
  import { getEditFiltersSettings } from "../helpers/filter-settings.helpers";
6
6
  import { getFilterId } from "../helpers/getFilterId";
@@ -12,11 +12,15 @@ import {
12
12
  IFilterBuilderEdit,
13
13
  IFilterBuilderEditValue,
14
14
  IFilterBuilderMultipleReturn,
15
+ IFilterBuilderSet,
15
16
  IFilterBuilderSingleReturn,
16
17
  } from "../models/filter-builder.models";
17
- import { IFilterBuilderEditSettings } from "../resources/filter-functions.resources";
18
+ import {
19
+ IFilterBuilderEditSettings,
20
+ IFilterParamSettings,
21
+ } from "../resources/filter-functions.resources";
18
22
  import { IFilterValue } from "../resources/filter-values.resources";
19
- import { IFilter } from "../resources/filters.resources";
23
+ import { DEFAULT_FILTER, IFilter } from "../resources/filters.resources";
20
24
 
21
25
  /**
22
26
  * Class to build new filters and manipulate ones.
@@ -28,19 +32,20 @@ export class FilterBuilder
28
32
  IFilterBuilderDelete,
29
33
  IFilterBuilderDeleteValue,
30
34
  IFilterBuilderEdit,
31
- IFilterBuilderEditValue
35
+ IFilterBuilderEditValue,
36
+ IFilterBuilderSet
32
37
  {
33
38
  /**
34
39
  * Instance to search filters
35
40
  */
36
- private searchEngine: FilterSearch;
41
+ private searchEngine: FilterSearcher;
37
42
 
38
43
  /**
39
44
  * Constructor
40
45
  * @param filters the collection of filters
41
46
  */
42
- constructor(protected filters: IFilter[]) {
43
- this.searchEngine = new FilterSearch(filters);
47
+ constructor(protected filters: IFilter[] = []) {
48
+ this.searchEngine = new FilterSearcher(filters);
44
49
  }
45
50
 
46
51
  /**
@@ -150,6 +155,40 @@ export class FilterBuilder
150
155
  return { resulting: this.filters, affected: affectedFilters };
151
156
  }
152
157
 
158
+ /**
159
+ * Builds an filter structure based on given params
160
+ * @param filter the partial filter params
161
+ * @param automaticId flag to generate a new filter ID based on the filter info
162
+ * @returns the complete filter structure
163
+ */
164
+ createFilter(filter: Partial<IFilter>, automaticId = true): IFilter {
165
+ const newFilter: IFilter = {
166
+ ...DEFAULT_FILTER,
167
+ aggregateType: filter.aggregateType ?? DEFAULT_FILTER.aggregateType,
168
+ collapsed: filter.collapsed ?? DEFAULT_FILTER.collapsed,
169
+ columnId: filter.columnId ?? DEFAULT_FILTER.columnId,
170
+ columnType: filter.columnType ?? DEFAULT_FILTER.columnType,
171
+ datasetId: filter.datasetId ?? DEFAULT_FILTER.datasetId,
172
+ deletable: filter.deletable ?? DEFAULT_FILTER.deletable,
173
+ displayed: filter.displayed ?? DEFAULT_FILTER.displayed,
174
+ editable: filter.editable ?? DEFAULT_FILTER.editable,
175
+ enableable: filter.enableable ?? DEFAULT_FILTER.enableable,
176
+ enabled: filter.enabled ?? DEFAULT_FILTER.enabled,
177
+ id: "",
178
+ operator: filter.operator || DEFAULT_FILTER.operator,
179
+ scope: filter.scope || DEFAULT_FILTER.scope,
180
+ scopeId: filter.scopeId || DEFAULT_FILTER.scopeId,
181
+ validator: filter.validator || DEFAULT_FILTER.validator,
182
+ grouping: filter.grouping || DEFAULT_FILTER.grouping,
183
+ section: filter.section || DEFAULT_FILTER.section,
184
+ selectAll: filter.selectAll ?? DEFAULT_FILTER.selectAll,
185
+ values: filter.values || DEFAULT_FILTER.values,
186
+ };
187
+ if (automaticId) newFilter.id = getFilterId(newFilter);
188
+
189
+ return newFilter;
190
+ }
191
+
153
192
  /**
154
193
  * Removes one filter from the collection
155
194
  * @param id the ID to search the filter to remove
@@ -190,6 +229,23 @@ export class FilterBuilder
190
229
  return { resulting: this.filters, affected: deletedFilters };
191
230
  }
192
231
 
232
+ /**
233
+ * Removes various filters by params
234
+ * @param params params to search the filters to delete
235
+ * @param settings settings for this function
236
+ * @returns the new collection of filters
237
+ */
238
+ public deleteByParams(
239
+ params: Partial<IFilter>,
240
+ settings?: IFilterParamSettings,
241
+ ): IFilterBuilderMultipleReturn {
242
+ const affected = this.searchEngine.filterByParams(params, settings);
243
+ this.filters = this.searchEngine.excludeByParams(params, settings);
244
+
245
+ this.sync();
246
+ return { resulting: this.filters, affected };
247
+ }
248
+
193
249
  /**
194
250
  * Removes one value from filter
195
251
  * @param id the ID to search the filter to remove value
@@ -369,10 +425,44 @@ export class FilterBuilder
369
425
  return { resulting: this.filters, affected: affectedFilters };
370
426
  }
371
427
 
428
+ /**
429
+ * **************************************************************************************************
430
+ ****************************************** Setters *************************************************
431
+ ****************************************************************************************************
432
+ */
433
+
434
+ /**
435
+ * Sets the given filters by param
436
+ * - Remove the filters by the sucesfull conditions and replace the given ones
437
+ * @param filters the filters to set
438
+ * @param params params to search the filters
439
+ * @param settings settings for this function
440
+ * @returns the new collection of filters
441
+ */
442
+ replaceByParams(
443
+ filters: IFilter[],
444
+ params: Partial<IFilter>,
445
+ settings?: IFilterParamSettings,
446
+ ): IFilterBuilderMultipleReturn {
447
+ this.filters = this.searchEngine.excludeByParams(params, settings);
448
+ const resulting = this.addMutiple(filters);
449
+
450
+ this.sync();
451
+ return { resulting: this.filters, affected: resulting.affected };
452
+ }
453
+
372
454
  /**
373
455
  * Method to sync the Filter instances
374
456
  */
375
457
  private sync(): void {
376
458
  this.searchEngine.setFilters(this.filters);
377
459
  }
460
+
461
+ /**
462
+ * Sets the filters
463
+ * @param filters the new collection of filters to set
464
+ */
465
+ public setFilters(filters: IFilter[]): void {
466
+ this.filters = filters;
467
+ }
378
468
  }
@@ -1,40 +1,108 @@
1
+ import { IDataset } from "@qrvey/utils";
2
+
3
+ import { FilterAdapter } from "./FilterAdapter";
1
4
  import { FilterBuilder } from "./FilterBuilder";
2
- import { FilterSearch } from "./FilterSearch";
5
+ import { FilterSearcher } from "./FilterSearcher";
3
6
 
7
+ import { IFilterPanelInteractiveTable } from "../resources";
4
8
  import { IFilter } from "../resources/filters.resources";
5
9
 
6
10
  /**
7
- *
11
+ * Class to manage the filters
8
12
  */
9
13
  export class FilterManager {
10
14
  /**
11
- * Instance to search filters
15
+ * Instance to adapt filters
12
16
  */
13
- private searchEngine: FilterSearch;
17
+ private _adapt: FilterAdapter;
14
18
 
15
19
  /**
16
20
  * Instance to build filters
17
21
  */
18
- private builder: FilterBuilder;
22
+ private _builder: FilterBuilder;
19
23
 
20
24
  /**
21
- * Class to get static resources
25
+ * Instance to search filters
22
26
  */
23
- // private resources: FilterResources;
27
+ private _searchEngine: FilterSearcher;
24
28
 
25
29
  /**
26
30
  * Constructor
27
31
  * @param filters the collection of filters
32
+ * @param datasets the collection of datasets info
33
+ * @param interactiveTable table of interaction properties for each section
34
+ */
35
+ constructor(
36
+ protected filters: IFilter[] = [],
37
+ protected datasets: IDataset[] = [],
38
+ protected interactiveTable?: IFilterPanelInteractiveTable,
39
+ ) {
40
+ this._searchEngine = new FilterSearcher(filters);
41
+ this._builder = new FilterBuilder(filters);
42
+ this._adapt = new FilterAdapter(filters, datasets, interactiveTable);
43
+ }
44
+
45
+ /**
46
+ * **************************************************************************************************
47
+ ****************************************** Getters *************************************************
48
+ ****************************************************************************************************
49
+ */
50
+
51
+ /**
52
+ * Gets the builder methods
53
+ * @returns the builder methods
54
+ */
55
+ public get builder(): FilterBuilder {
56
+ return this._builder;
57
+ }
58
+
59
+ /**
60
+ * Gets the adapt methods
61
+ * @returns the adapt methods
28
62
  */
29
- constructor(protected filters: IFilter[]) {
30
- this.searchEngine = new FilterSearch(filters);
31
- this.builder = new FilterBuilder(filters);
63
+ public get adapt(): FilterAdapter {
64
+ return this._adapt;
32
65
  }
33
66
 
34
- manager() {
35
- return {
36
- searchEngine: this.searchEngine,
37
- buider: this.builder,
38
- };
67
+ /**
68
+ * Gets the search methods
69
+ * @returns the search methods
70
+ */
71
+ public get search(): FilterSearcher {
72
+ return this._searchEngine;
73
+ }
74
+
75
+ /**
76
+ * **************************************************************************************************
77
+ ****************************************** Setters *************************************************
78
+ ****************************************************************************************************
79
+ */
80
+
81
+ /**
82
+ * Sets the datasets
83
+ * @param datasets the collection of dataset info
84
+ */
85
+ public setDatasets(datasets: IDataset[]): void {
86
+ this._adapt.setDatasets(datasets);
87
+ }
88
+
89
+ /**
90
+ * Sets the filters
91
+ * @param filters the new collection of filters to set
92
+ */
93
+ public setFilters(filters: IFilter[] = []): void {
94
+ this._builder.setFilters(filters);
95
+ this._searchEngine.setFilters(filters);
96
+ this._adapt.setFilters(filters);
97
+ }
98
+
99
+ /**
100
+ * Sets the table of interactive table
101
+ * @param interactiveTable table of interaction properties for each section
102
+ */
103
+ public setInteractiveTable(
104
+ interactiveTable: IFilterPanelInteractiveTable,
105
+ ): void {
106
+ this.interactiveTable = interactiveTable;
39
107
  }
40
108
  }
@@ -1,7 +1,7 @@
1
1
  import { COLUMN, IColumnType, intersectObjectArrays } from "@qrvey/utils";
2
2
 
3
3
  import { getInfoGroupingsByColumnTypeSettings } from "../helpers/filter-settings.helpers";
4
- import { IFilterInfoGroupingsByColumnSettings } from "../resources/filter-functions.resources";
4
+ import { IFilterGroupingInfoListByColumnSettings } from "../resources/filter-functions.resources";
5
5
  import {
6
6
  FILTER_GROUPING,
7
7
  FILTER_GROUPING_INFO,
@@ -13,15 +13,15 @@ import {
13
13
  FILTER_GROUPINGS,
14
14
  IColumnTypeWithGrouping,
15
15
  IFilterGrouping,
16
- IFilterInfoGrouping,
16
+ IFilterGroupingInfo,
17
17
  } from "../resources/filter-grouping.resources";
18
18
  import {
19
19
  FILTER_VALIDATOR_INFO,
20
20
  FILTER_VALIDATOR_INFO_LIST,
21
21
  FILTER_VALIDATORS,
22
22
  FILTER_VALIDATORS_INFO_BY_COLUMN_TYPE,
23
- IFilterInfoValidator,
24
23
  IFilterValidator,
24
+ IFilterValidatorInfo,
25
25
  } from "../resources/filter-validators.resources";
26
26
 
27
27
  /**
@@ -40,7 +40,7 @@ export class FilterResources {
40
40
  * Gets the complete collection of validator info
41
41
  * @returns the collection of validator info
42
42
  */
43
- static getInfoValidators(): IFilterInfoValidator[] {
43
+ static getValidatorInfoList(): IFilterValidatorInfo[] {
44
44
  return FILTER_VALIDATOR_INFO_LIST;
45
45
  }
46
46
 
@@ -49,7 +49,7 @@ export class FilterResources {
49
49
  * @param validator the validator type
50
50
  * @returns a single validator info
51
51
  */
52
- static getInfoByValidator(validator: IFilterValidator): IFilterInfoValidator {
52
+ static getValidatorInfo(validator: IFilterValidator): IFilterValidatorInfo {
53
53
  return FILTER_VALIDATOR_INFO[validator];
54
54
  }
55
55
 
@@ -58,9 +58,9 @@ export class FilterResources {
58
58
  * @param type the column type
59
59
  * @returns a collection of validator info
60
60
  */
61
- static getInfoValidatorsByColumnType(
61
+ static getValidatorInfoListByColumnType(
62
62
  type: IColumnType,
63
- ): IFilterInfoValidator[] {
63
+ ): IFilterValidatorInfo[] {
64
64
  return FILTER_VALIDATORS_INFO_BY_COLUMN_TYPE[type];
65
65
  }
66
66
 
@@ -70,13 +70,13 @@ export class FilterResources {
70
70
  * @param types a collection of column types
71
71
  * @returns a collection of validator info
72
72
  */
73
- static getInfoValidatorsByColumnTypes(
73
+ static getValidatorInfoListByColumnTypes(
74
74
  types: IColumnType[],
75
- ): IFilterInfoValidator[] {
75
+ ): IFilterValidatorInfo[] {
76
76
  if (!Array.isArray(types)) return [];
77
77
 
78
78
  const infoValidators = types.map((type) =>
79
- FilterResources.getInfoValidatorsByColumnType(type),
79
+ FilterResources.getValidatorInfoListByColumnType(type),
80
80
  );
81
81
  return intersectObjectArrays(infoValidators, "value");
82
82
  }
@@ -93,7 +93,7 @@ export class FilterResources {
93
93
  * Gets the complete collection of validator info
94
94
  * @returns the collection of validator info
95
95
  */
96
- static getInfoGroupings(): IFilterInfoGrouping[] {
96
+ static getGroupingsInfoList(): IFilterGroupingInfo[] {
97
97
  return FILTER_GROUPING_INFO_LIST;
98
98
  }
99
99
 
@@ -102,7 +102,7 @@ export class FilterResources {
102
102
  * @param grouping the grouping type
103
103
  * @returns a single grouping info
104
104
  */
105
- static getInfoByGrouping(grouping: IFilterGrouping): IFilterInfoGrouping {
105
+ static getGroupingInfo(grouping: IFilterGrouping): IFilterGroupingInfo {
106
106
  return FILTER_GROUPING_INFO[grouping];
107
107
  }
108
108
 
@@ -112,25 +112,26 @@ export class FilterResources {
112
112
  * @param settings settings for the function
113
113
  * @returns a collection of grouping info
114
114
  */
115
- static getInfoGroupingsByColumnType(
116
- type: IColumnTypeWithGrouping,
117
- settings?: IFilterInfoGroupingsByColumnSettings,
118
- ): IFilterInfoGrouping[] {
115
+ static getGroupingInfoListByColumnType(
116
+ type: IColumnType,
117
+ settings?: IFilterGroupingInfoListByColumnSettings,
118
+ ): IFilterGroupingInfo[] {
119
119
  const completeSettings = getInfoGroupingsByColumnTypeSettings(settings);
120
- let groupinInfoList = FILTER_GROUPING_INFO_BY_COLUMN_TYPE[type];
120
+ let groupinInfoList =
121
+ FILTER_GROUPING_INFO_BY_COLUMN_TYPE[type as IColumnTypeWithGrouping];
121
122
 
122
123
  if (type === COLUMN.EXPRESSION)
123
- groupinInfoList = this.getInfoGroupingOnExpressions(
124
+ groupinInfoList = this.getGroupingInfoListOnExpressions(
124
125
  groupinInfoList,
125
126
  completeSettings,
126
127
  );
127
128
  if (type === COLUMN.IMAGEUPLOAD)
128
- groupinInfoList = this.getInfoGroupingOnImageUploads(
129
+ groupinInfoList = this.getGroupingInfoListOnImageUploads(
129
130
  groupinInfoList,
130
131
  completeSettings,
131
132
  );
132
- if ([COLUMN.DATE, COLUMN.DATE_FORMULA].includes(type))
133
- groupinInfoList = this.getInfoGroupingOnDates(
133
+ if (type === COLUMN.DATE || type === COLUMN.DATE_FORMULA)
134
+ groupinInfoList = this.getGroupingInfoListOnDates(
134
135
  groupinInfoList,
135
136
  completeSettings,
136
137
  );
@@ -144,10 +145,10 @@ export class FilterResources {
144
145
  * @param settings settings for the function
145
146
  * @returns the new grouping info list
146
147
  */
147
- static getInfoGroupingOnExpressions(
148
- groupinInfoList: IFilterInfoGrouping[],
149
- settings: IFilterInfoGroupingsByColumnSettings,
150
- ): IFilterInfoGrouping[] {
148
+ static getGroupingInfoListOnExpressions(
149
+ groupinInfoList: IFilterGroupingInfo[],
150
+ settings: IFilterGroupingInfoListByColumnSettings,
151
+ ): IFilterGroupingInfo[] {
151
152
  if (!settings.isExpressionCategorizable) return [];
152
153
 
153
154
  return groupinInfoList;
@@ -159,10 +160,10 @@ export class FilterResources {
159
160
  * @param settings settings for the function
160
161
  * @returns the new grouping info list
161
162
  */
162
- static getInfoGroupingOnImageUploads(
163
- groupinInfoList: IFilterInfoGrouping[],
164
- settings: IFilterInfoGroupingsByColumnSettings,
165
- ): IFilterInfoGrouping[] {
163
+ static getGroupingInfoListOnImageUploads(
164
+ groupinInfoList: IFilterGroupingInfo[],
165
+ settings: IFilterGroupingInfoListByColumnSettings,
166
+ ): IFilterGroupingInfo[] {
166
167
  if (settings.hasImageUploadAnalysis) return groupinInfoList;
167
168
 
168
169
  return groupinInfoList.filter(
@@ -177,10 +178,10 @@ export class FilterResources {
177
178
  * @param settings settings for the function
178
179
  * @returns the new grouping info list
179
180
  */
180
- static getInfoGroupingOnDates(
181
- groupinInfoList: IFilterInfoGrouping[],
182
- settings: IFilterInfoGroupingsByColumnSettings,
183
- ): IFilterInfoGrouping[] {
181
+ static getGroupingInfoListOnDates(
182
+ groupinInfoList: IFilterGroupingInfo[],
183
+ settings: IFilterGroupingInfoListByColumnSettings,
184
+ ): IFilterGroupingInfo[] {
184
185
  let newGroupInfoList = groupinInfoList;
185
186
  if (settings.hasDateTime) {
186
187
  newGroupInfoList = [
@@ -211,14 +212,14 @@ export class FilterResources {
211
212
  * @param settings settings for the function
212
213
  * @returns a collection of grouping info
213
214
  */
214
- static getInfoGroupingsByColumnTypes(
215
- types: IColumnTypeWithGrouping[],
216
- settings?: IFilterInfoGroupingsByColumnSettings[],
217
- ): IFilterInfoGrouping[] {
215
+ static getGroupingInfoListByColumnTypes(
216
+ types: IColumnType[],
217
+ settings?: IFilterGroupingInfoListByColumnSettings[],
218
+ ): IFilterGroupingInfo[] {
218
219
  if (!Array.isArray(types)) return [];
219
220
 
220
221
  const infoGroupings = types.map((type, index) =>
221
- FilterResources.getInfoGroupingsByColumnType(type, settings?.[index]),
222
+ FilterResources.getGroupingInfoListByColumnType(type, settings?.[index]),
222
223
  );
223
224
  return intersectObjectArrays(infoGroupings, "value");
224
225
  }
@@ -8,13 +8,34 @@ import { IFilter } from "../resources/filters.resources";
8
8
  /**
9
9
  * Class to search filters.
10
10
  */
11
- export class FilterSearch {
11
+ export class FilterSearcher {
12
12
  /**
13
13
  * Constructor
14
14
  * @param filters the collection of filters
15
15
  */
16
16
  constructor(protected filters: IFilter[] = []) {}
17
17
 
18
+ /**
19
+ * Searchs and excludes filters by the given params
20
+ * @param params params to exclude the filters
21
+ * @param settings settings for this function
22
+ * @returns the new collection of filters
23
+ */
24
+ public excludeByParams(
25
+ params: Partial<IFilter>,
26
+ settings?: IFilterParamSettings,
27
+ ): IFilter[] {
28
+ if (isEmpty(this.filters) || isEmpty(params)) return this.filters;
29
+
30
+ const completeSettings: IFilterParamSettings =
31
+ getParamFiltersSettings(settings);
32
+
33
+ return this.filters.filter(
34
+ (filter: IFilter) =>
35
+ !resolveFilterConditions(filter, params, completeSettings),
36
+ );
37
+ }
38
+
18
39
  /**
19
40
  * Searchs filters by the given params
20
41
  * @param params params to search the filters
@@ -30,21 +51,45 @@ export class FilterSearch {
30
51
  const completeSettings: IFilterParamSettings =
31
52
  getParamFiltersSettings(settings);
32
53
 
33
- return this.filters.reduce((filters: IFilter[], filter: IFilter) => {
34
- const condition = resolveFilterConditions(
35
- filter,
36
- params,
37
- completeSettings,
38
- );
54
+ return this.filters.filter((filter: IFilter) =>
55
+ resolveFilterConditions(filter, params, completeSettings),
56
+ );
57
+ }
39
58
 
40
- if (condition) filters.push(filter);
41
- return filters;
42
- }, []);
59
+ /**
60
+ * Searchs filters by the given params and returns the inexes
61
+ * @param params params to search the filters
62
+ * @param settings settings for this function
63
+ * @returns the new collection of filters
64
+ */
65
+ public filterIndexesByParams(
66
+ params: Partial<IFilter>,
67
+ settings?: IFilterParamSettings,
68
+ ): number[] {
69
+ if (isEmpty(this.filters) || isEmpty(params)) return [];
70
+
71
+ const completeSettings: IFilterParamSettings =
72
+ getParamFiltersSettings(settings);
73
+
74
+ return this.filters.reduce(
75
+ (indexes: number[], filter: IFilter, index: number) => {
76
+ const condition = resolveFilterConditions(
77
+ filter,
78
+ params,
79
+ completeSettings,
80
+ );
81
+ if (condition) {
82
+ indexes.push(index);
83
+ }
84
+ return indexes;
85
+ },
86
+ [],
87
+ );
43
88
  }
44
89
 
45
90
  /**
46
91
  * Searchs filters by the given params.
47
- * Get the first match of the searching
92
+ * Gets the first match of the searching
48
93
  * @param params params to search the filters
49
94
  * @param settings settings for this function
50
95
  * @returns the new collection of filters
@@ -66,7 +111,7 @@ export class FilterSearch {
66
111
 
67
112
  /**
68
113
  * Searchs filters by the given params.
69
- * Get the first match of the searching and return the related index
114
+ * Gets the first match of the searching and returns the related index
70
115
  * @param params params to search the filters
71
116
  * @param settings settings for this function
72
117
  * @returns the new collection of filters
@@ -86,6 +131,12 @@ export class FilterSearch {
86
131
  );
87
132
  }
88
133
 
134
+ /**
135
+ * **************************************************************************************************
136
+ ****************************************** Setters *************************************************
137
+ ****************************************************************************************************
138
+ */
139
+
89
140
  /**
90
141
  * Sets the filters
91
142
  * @param filters the new collection of filters to set
@@ -1,4 +1,4 @@
1
1
  export * from "./FilterBuilder";
2
2
  export * from "./FilterManager";
3
3
  export * from "./FilterResources";
4
- export * from "./FilterSearch";
4
+ export * from "./FilterSearcher";