@qrvey/filters 0.0.45 → 0.1.1
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/README.md +63 -1
- package/dist/cjs/classes/FilterAdapter.js +1 -80
- package/dist/cjs/classes/FilterBuilder.js +32 -251
- package/dist/cjs/classes/FilterManager.js +7 -64
- package/dist/cjs/classes/FilterResources.js +3 -116
- package/dist/cjs/classes/FilterSearcher.js +0 -77
- package/dist/cjs/classes/FilterValidation.js +0 -93
- package/dist/cjs/classes/FilterValues.js +0 -24
- package/dist/cjs/classes/index.js +8 -21
- package/dist/cjs/helpers/filter-adapt.helpers.js +3 -46
- package/dist/cjs/helpers/filter-adapt.legacy.helpers.js +6 -53
- package/dist/cjs/helpers/filter-adapt.logic.helpers.js +7 -128
- package/dist/cjs/helpers/filter-builder.helpers.js +1 -8
- package/dist/cjs/helpers/filter-settings.helpers.js +6 -41
- package/dist/cjs/helpers/filter-validators.helpers.js +15 -9
- package/dist/cjs/helpers/filter-verbose.helpers.js +211 -0
- package/dist/cjs/helpers/getAggregateFilters.js +11 -0
- package/dist/cjs/helpers/getFilterId.js +1 -17
- package/dist/cjs/helpers/getFilterType.js +1 -8
- package/dist/cjs/helpers/index.js +12 -20
- package/dist/cjs/helpers/isDateDistinctGrouping.js +15 -0
- package/dist/cjs/helpers/isRankingFilter.js +10 -0
- package/dist/cjs/helpers/resolveFilterConditions.js +2 -10
- package/dist/cjs/helpers/utils.helpers.js +2 -19
- package/dist/cjs/index.js +5 -18
- package/dist/cjs/models/index.js +4 -17
- package/dist/cjs/resources/filter-grouping.resources.js +0 -18
- package/dist/cjs/resources/filter-logic.resources.js +0 -3
- package/dist/cjs/resources/filter-scopes.resources.js +10 -27
- package/dist/cjs/resources/filter-validators.resources.js +0 -3
- package/dist/cjs/resources/filter-verbose.resources.js +13 -0
- package/dist/cjs/resources/filters.resources.js +0 -12
- package/dist/cjs/resources/index.js +12 -24
- package/dist/classes/FilterAdapter.d.ts +0 -80
- package/dist/classes/FilterAdapter.js +1 -80
- package/dist/classes/FilterBuilder.d.ts +2 -177
- package/dist/classes/FilterBuilder.js +32 -251
- package/dist/classes/FilterManager.d.ts +7 -62
- package/dist/classes/FilterManager.js +7 -64
- package/dist/classes/FilterResources.d.ts +1 -115
- package/dist/classes/FilterResources.js +3 -116
- package/dist/classes/FilterSearcher.d.ts +2 -77
- package/dist/classes/FilterSearcher.js +0 -77
- package/dist/classes/FilterValidation.d.ts +1 -47
- package/dist/classes/FilterValidation.js +0 -93
- package/dist/classes/FilterValues.d.ts +0 -25
- package/dist/classes/FilterValues.js +0 -24
- package/dist/classes/index.d.ts +0 -1
- package/dist/helpers/filter-adapt.helpers.d.ts +0 -15
- package/dist/helpers/filter-adapt.helpers.js +1 -43
- package/dist/helpers/filter-adapt.legacy.helpers.d.ts +0 -20
- package/dist/helpers/filter-adapt.legacy.helpers.js +3 -49
- package/dist/helpers/filter-adapt.logic.helpers.d.ts +0 -22
- package/dist/helpers/filter-adapt.logic.helpers.js +3 -123
- package/dist/helpers/filter-builder.helpers.d.ts +0 -7
- package/dist/helpers/filter-builder.helpers.js +0 -6
- package/dist/helpers/filter-settings.helpers.d.ts +0 -35
- package/dist/helpers/filter-settings.helpers.js +0 -34
- package/dist/helpers/filter-validators.helpers.d.ts +3 -6
- package/dist/helpers/filter-validators.helpers.js +11 -7
- package/dist/helpers/filter-verbose.helpers.d.ts +6 -0
- package/dist/helpers/filter-verbose.helpers.js +206 -0
- package/dist/helpers/getAggregateFilters.d.ts +3 -0
- package/dist/helpers/getAggregateFilters.js +7 -0
- package/dist/helpers/getFilterId.d.ts +0 -16
- package/dist/helpers/getFilterId.js +0 -15
- package/dist/helpers/getFilterType.d.ts +0 -7
- package/dist/helpers/getFilterType.js +0 -6
- package/dist/helpers/index.d.ts +5 -1
- package/dist/helpers/index.js +5 -0
- package/dist/helpers/isDateDistinctGrouping.d.ts +2 -0
- package/dist/helpers/isDateDistinctGrouping.js +12 -0
- package/dist/helpers/isRankingFilter.d.ts +2 -0
- package/dist/helpers/isRankingFilter.js +7 -0
- package/dist/helpers/resolveFilterConditions.d.ts +0 -8
- package/dist/helpers/resolveFilterConditions.js +1 -8
- package/dist/helpers/utils.helpers.d.ts +0 -17
- package/dist/helpers/utils.helpers.js +0 -16
- package/dist/index.d.ts +0 -1
- package/dist/models/filter-builder.models.d.ts +0 -156
- package/dist/models/filter-resources.models.d.ts +0 -53
- package/dist/models/filter-searcher.models.d.ts +5 -34
- package/dist/models/filter-validation.models.d.ts +0 -40
- package/dist/models/index.d.ts +0 -1
- package/dist/resources/filter-functions.resources.d.ts +0 -49
- package/dist/resources/filter-grouping.resources.d.ts +0 -7
- package/dist/resources/filter-grouping.resources.js +0 -18
- package/dist/resources/filter-logic.resources.d.ts +0 -79
- package/dist/resources/filter-logic.resources.js +0 -3
- package/dist/resources/filter-operators.resources.d.ts +0 -1
- package/dist/resources/filter-panel.interfaces.d.ts +0 -49
- package/dist/resources/filter-scopes.resources.d.ts +2 -25
- package/dist/resources/filter-scopes.resources.js +10 -27
- package/dist/resources/filter-validation.resources.d.ts +0 -1
- package/dist/resources/filter-validators.resources.d.ts +0 -1
- package/dist/resources/filter-validators.resources.js +0 -3
- package/dist/resources/filter-values.resources.d.ts +0 -13
- package/dist/resources/filter-verbose.resources.d.ts +23 -0
- package/dist/resources/filter-verbose.resources.js +10 -0
- package/dist/resources/filter-visual.resources.d.ts +0 -50
- package/dist/resources/filters.resources.d.ts +1 -102
- package/dist/resources/filters.resources.js +0 -12
- package/dist/resources/index.d.ts +1 -1
- package/dist/resources/index.js +1 -0
- package/package.json +59 -44
- package/.eslintignore +0 -6
- package/.eslintrc.json +0 -122
- package/.husky/pre-commit +0 -4
- package/.lintstagedrc +0 -7
- package/.prettierignore +0 -6
- package/.prettierrc.json +0 -1
- package/CHANGELOG.md +0 -274
- package/CODE_OF_CONDUCT.md +0 -132
- package/bitbucket-pipelines.yml +0 -92
- package/dist/cjs/classes/FilterAdapter.d.ts +0 -107
- package/dist/cjs/classes/FilterAdapter.d.ts.map +0 -1
- package/dist/cjs/classes/FilterBuilder.d.ts +0 -206
- package/dist/cjs/classes/FilterBuilder.d.ts.map +0 -1
- package/dist/cjs/classes/FilterManager.d.ts +0 -84
- package/dist/cjs/classes/FilterManager.d.ts.map +0 -1
- package/dist/cjs/classes/FilterResources.d.ts +0 -139
- package/dist/cjs/classes/FilterResources.d.ts.map +0 -1
- package/dist/cjs/classes/FilterSearcher.d.ts +0 -90
- package/dist/cjs/classes/FilterSearcher.d.ts.map +0 -1
- package/dist/cjs/classes/FilterValidation.d.ts +0 -58
- package/dist/cjs/classes/FilterValidation.d.ts.map +0 -1
- package/dist/cjs/classes/FilterValues.d.ts +0 -33
- package/dist/cjs/classes/FilterValues.d.ts.map +0 -1
- package/dist/cjs/classes/index.d.ts +0 -8
- package/dist/cjs/classes/index.d.ts.map +0 -1
- package/dist/cjs/helpers/filter-adapt.helpers.d.ts +0 -21
- package/dist/cjs/helpers/filter-adapt.helpers.d.ts.map +0 -1
- package/dist/cjs/helpers/filter-adapt.legacy.helpers.d.ts +0 -26
- package/dist/cjs/helpers/filter-adapt.legacy.helpers.d.ts.map +0 -1
- package/dist/cjs/helpers/filter-adapt.logic.helpers.d.ts +0 -29
- package/dist/cjs/helpers/filter-adapt.logic.helpers.d.ts.map +0 -1
- package/dist/cjs/helpers/filter-builder.helpers.d.ts +0 -11
- package/dist/cjs/helpers/filter-builder.helpers.d.ts.map +0 -1
- package/dist/cjs/helpers/filter-settings.helpers.d.ts +0 -42
- package/dist/cjs/helpers/filter-settings.helpers.d.ts.map +0 -1
- package/dist/cjs/helpers/filter-validators.helpers.d.ts +0 -8
- package/dist/cjs/helpers/filter-validators.helpers.d.ts.map +0 -1
- package/dist/cjs/helpers/getFilterId.d.ts +0 -18
- package/dist/cjs/helpers/getFilterId.d.ts.map +0 -1
- package/dist/cjs/helpers/getFilterType.d.ts +0 -11
- package/dist/cjs/helpers/getFilterType.d.ts.map +0 -1
- package/dist/cjs/helpers/index.d.ts +0 -7
- package/dist/cjs/helpers/index.d.ts.map +0 -1
- package/dist/cjs/helpers/resolveFilterConditions.d.ts +0 -11
- package/dist/cjs/helpers/resolveFilterConditions.d.ts.map +0 -1
- package/dist/cjs/helpers/utils.helpers.d.ts +0 -26
- package/dist/cjs/helpers/utils.helpers.d.ts.map +0 -1
- package/dist/cjs/index.d.ts +0 -5
- package/dist/cjs/index.d.ts.map +0 -1
- package/dist/cjs/models/filter-builder.models.d.ts +0 -203
- package/dist/cjs/models/filter-builder.models.d.ts.map +0 -1
- package/dist/cjs/models/filter-resources.models.d.ts +0 -71
- package/dist/cjs/models/filter-resources.models.d.ts.map +0 -1
- package/dist/cjs/models/filter-searcher.models.d.ts +0 -42
- package/dist/cjs/models/filter-searcher.models.d.ts.map +0 -1
- package/dist/cjs/models/filter-validation.models.d.ts +0 -59
- package/dist/cjs/models/filter-validation.models.d.ts.map +0 -1
- package/dist/cjs/models/index.d.ts +0 -4
- package/dist/cjs/models/index.d.ts.map +0 -1
- package/dist/cjs/resources/filter-functions.resources.d.ts +0 -94
- package/dist/cjs/resources/filter-functions.resources.d.ts.map +0 -1
- package/dist/cjs/resources/filter-grouping.resources.d.ts +0 -103
- package/dist/cjs/resources/filter-grouping.resources.d.ts.map +0 -1
- package/dist/cjs/resources/filter-logic.resources.d.ts +0 -135
- package/dist/cjs/resources/filter-logic.resources.d.ts.map +0 -1
- package/dist/cjs/resources/filter-operators.resources.d.ts +0 -16
- package/dist/cjs/resources/filter-operators.resources.d.ts.map +0 -1
- package/dist/cjs/resources/filter-panel.interfaces.d.ts +0 -80
- package/dist/cjs/resources/filter-panel.interfaces.d.ts.map +0 -1
- package/dist/cjs/resources/filter-scopes.resources.d.ts +0 -62
- package/dist/cjs/resources/filter-scopes.resources.d.ts.map +0 -1
- package/dist/cjs/resources/filter-validation.resources.d.ts +0 -20
- package/dist/cjs/resources/filter-validation.resources.d.ts.map +0 -1
- package/dist/cjs/resources/filter-validators.resources.d.ts +0 -80
- package/dist/cjs/resources/filter-validators.resources.d.ts.map +0 -1
- package/dist/cjs/resources/filter-values.resources.d.ts +0 -40
- package/dist/cjs/resources/filter-values.resources.d.ts.map +0 -1
- package/dist/cjs/resources/filter-visual.resources.d.ts +0 -77
- package/dist/cjs/resources/filter-visual.resources.d.ts.map +0 -1
- package/dist/cjs/resources/filters.resources.d.ts +0 -168
- package/dist/cjs/resources/filters.resources.d.ts.map +0 -1
- package/dist/cjs/resources/index.d.ts +0 -11
- package/dist/cjs/resources/index.d.ts.map +0 -1
- package/dist/classes/FilterAdapter.d.ts.map +0 -1
- package/dist/classes/FilterBuilder.d.ts.map +0 -1
- package/dist/classes/FilterManager.d.ts.map +0 -1
- package/dist/classes/FilterResources.d.ts.map +0 -1
- package/dist/classes/FilterSearcher.d.ts.map +0 -1
- package/dist/classes/FilterValidation.d.ts.map +0 -1
- package/dist/classes/FilterValues.d.ts.map +0 -1
- package/dist/classes/index.d.ts.map +0 -1
- package/dist/helpers/filter-adapt.helpers.d.ts.map +0 -1
- package/dist/helpers/filter-adapt.legacy.helpers.d.ts.map +0 -1
- package/dist/helpers/filter-adapt.logic.helpers.d.ts.map +0 -1
- package/dist/helpers/filter-builder.helpers.d.ts.map +0 -1
- package/dist/helpers/filter-settings.helpers.d.ts.map +0 -1
- package/dist/helpers/filter-validators.helpers.d.ts.map +0 -1
- package/dist/helpers/getFilterId.d.ts.map +0 -1
- package/dist/helpers/getFilterType.d.ts.map +0 -1
- package/dist/helpers/index.d.ts.map +0 -1
- package/dist/helpers/resolveFilterConditions.d.ts.map +0 -1
- package/dist/helpers/utils.helpers.d.ts.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/models/filter-builder.models.d.ts.map +0 -1
- package/dist/models/filter-resources.models.d.ts.map +0 -1
- package/dist/models/filter-searcher.models.d.ts.map +0 -1
- package/dist/models/filter-validation.models.d.ts.map +0 -1
- package/dist/models/index.d.ts.map +0 -1
- package/dist/resources/filter-functions.resources.d.ts.map +0 -1
- package/dist/resources/filter-grouping.resources.d.ts.map +0 -1
- package/dist/resources/filter-logic.resources.d.ts.map +0 -1
- package/dist/resources/filter-operators.resources.d.ts.map +0 -1
- package/dist/resources/filter-panel.interfaces.d.ts.map +0 -1
- package/dist/resources/filter-scopes.resources.d.ts.map +0 -1
- package/dist/resources/filter-validation.resources.d.ts.map +0 -1
- package/dist/resources/filter-validators.resources.d.ts.map +0 -1
- package/dist/resources/filter-values.resources.d.ts.map +0 -1
- package/dist/resources/filter-visual.resources.d.ts.map +0 -1
- package/dist/resources/filters.resources.d.ts.map +0 -1
- package/dist/resources/index.d.ts.map +0 -1
- package/jest.config.js +0 -10
- package/jsdoc.config.json +0 -14
- package/scripts/clean-build/index.js +0 -62
- package/sonar-project.properties +0 -2
- package/src/classes/FilterAdapter.ts +0 -208
- package/src/classes/FilterBuilder.ts +0 -822
- package/src/classes/FilterManager.ts +0 -126
- package/src/classes/FilterResources.ts +0 -411
- package/src/classes/FilterSearcher.ts +0 -243
- package/src/classes/FilterValidation.ts +0 -221
- package/src/classes/FilterValues.ts +0 -89
- package/src/classes/index.ts +0 -7
- package/src/helpers/filter-adapt.helpers.ts +0 -204
- package/src/helpers/filter-adapt.legacy.helpers.ts +0 -298
- package/src/helpers/filter-adapt.logic.helpers.ts +0 -631
- package/src/helpers/filter-builder.helpers.ts +0 -28
- package/src/helpers/filter-settings.helpers.ts +0 -133
- package/src/helpers/filter-validators.helpers.ts +0 -15
- package/src/helpers/getFilterId.ts +0 -35
- package/src/helpers/getFilterType.ts +0 -23
- package/src/helpers/index.ts +0 -6
- package/src/helpers/resolveFilterConditions.ts +0 -29
- package/src/helpers/utils.helpers.ts +0 -37
- package/src/index.ts +0 -4
- package/src/models/filter-builder.models.ts +0 -256
- package/src/models/filter-resources.models.ts +0 -89
- package/src/models/filter-searcher.models.ts +0 -61
- package/src/models/filter-validation.models.ts +0 -71
- package/src/models/index.ts +0 -3
- package/src/resources/filter-functions.resources.ts +0 -132
- package/src/resources/filter-grouping.resources.ts +0 -531
- package/src/resources/filter-logic.resources.ts +0 -148
- package/src/resources/filter-operators.resources.ts +0 -40
- package/src/resources/filter-panel.interfaces.ts +0 -86
- package/src/resources/filter-scopes.resources.ts +0 -152
- package/src/resources/filter-validation.resources.ts +0 -90
- package/src/resources/filter-validators.resources.ts +0 -411
- package/src/resources/filter-values.resources.ts +0 -57
- package/src/resources/filter-visual.resources.ts +0 -86
- package/src/resources/filters.resources.ts +0 -232
- package/src/resources/index.ts +0 -10
- package/tests/classes/FilterAdapter.test.ts +0 -124
- package/tests/classes/FilterBuilder.test.ts +0 -903
- package/tests/classes/FilterResources.test.ts +0 -267
- package/tests/classes/FilterSearcher.test.ts +0 -188
- package/tests/classes/FilterValidation.test.ts +0 -54
- package/tests/helpers/getFilterId.test.ts +0 -121
- package/tests/mock/datasets.mock.ts +0 -61
- package/tests/mock/filters-adapter.mock.ts +0 -646
- package/tests/mock/filters-interactive-table.mock.ts +0 -59
- package/tests/mock/filters.mock.ts +0 -277
- package/tsconfig.doc.json +0 -4
- package/tsconfig.eslint.json +0 -4
- package/tsconfig.json +0 -113
package/README.md
CHANGED
|
@@ -1 +1,63 @@
|
|
|
1
|
-
# qrvey_filters
|
|
1
|
+
# [@qrvey/filters](https://bitbucket.org/qrvey/qrvey_filters/wiki/Home) *0.1.1*
|
|
2
|
+
|
|
3
|
+
> Helpers and logic for Filtering Data in Qrvey app
|
|
4
|
+
|
|
5
|
+
## Release pipelines
|
|
6
|
+
|
|
7
|
+
- Guide to run manual releases in Bitbucket: [RELEASE_PIPELINES.md](./RELEASE_PIPELINES.md)
|
|
8
|
+
|
|
9
|
+
## Recommended consumption guide
|
|
10
|
+
|
|
11
|
+
This package exposes **ESM + CommonJS**:
|
|
12
|
+
|
|
13
|
+
- `import` (ESM) for modern bundlers and better tree shaking.
|
|
14
|
+
- `require` (CommonJS) for legacy implementations.
|
|
15
|
+
|
|
16
|
+
### 1) Recommended (ESM with tree shaking)
|
|
17
|
+
|
|
18
|
+
Use named imports from the entrypoint or specific subpaths.
|
|
19
|
+
|
|
20
|
+
```ts
|
|
21
|
+
// Good: allows bundlers to remove unused exports
|
|
22
|
+
import { FilterManager, FilterBuilder } from "@qrvey/filters";
|
|
23
|
+
|
|
24
|
+
// Better for critical bundles: import only the module you need
|
|
25
|
+
import { FilterManager } from "@qrvey/filters/classes/index";
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
### 2) Avoid for optimized bundles
|
|
29
|
+
|
|
30
|
+
```ts
|
|
31
|
+
// Avoid in frontend apps: can pull more code into the bundle
|
|
32
|
+
import * as QrveyFilters from "@qrvey/filters";
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
### 3) CommonJS compatibility
|
|
36
|
+
|
|
37
|
+
For Node projects or integrations that require CommonJS:
|
|
38
|
+
|
|
39
|
+
```js
|
|
40
|
+
const { FilterManager } = require("@qrvey/filters");
|
|
41
|
+
const { FilterManager } = require("@qrvey/filters/classes/index");
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
### 4) Recommendations for consumer apps
|
|
45
|
+
|
|
46
|
+
- Prefer `import` over `require` in frontend code.
|
|
47
|
+
- Use subpaths (`@qrvey/filters/<module>`) on performance-critical paths.
|
|
48
|
+
- Keep tree shaking enabled in your bundler (Webpack/Rollup/Vite in production mode).
|
|
49
|
+
|
|
50
|
+
---
|
|
51
|
+
|
|
52
|
+
<!-- MODULES_START -->
|
|
53
|
+
|
|
54
|
+
## Modules
|
|
55
|
+
|
|
56
|
+
| Module | Description | Subpath import | API docs |
|
|
57
|
+
| ------ | ----------- | -------------- | -------- |
|
|
58
|
+
| `classes` | Core classes: FilterBuilder, FilterManager, FilterAdapter, FilterSearcher, FilterValidation, FilterValues and FilterResources. | `@qrvey/filters/classes/index` | [docs](docs/classes/index.md) |
|
|
59
|
+
| `helpers` | Stateless utility functions for filter adaptation, settings, ID generation, type resolution and condition handling. | `@qrvey/filters/helpers/index` | [docs](docs/helpers/index.md) |
|
|
60
|
+
| `models` | TypeScript interfaces and types for FilterBuilder, FilterResources and FilterSearcher internals. | `@qrvey/filters/models/index` | [docs](docs/models/index.md) |
|
|
61
|
+
| `resources` | Enums, constants and panel interfaces for filter functions, grouping, logic, operators, scopes, validators, values, visual options and the DEFAULT_FILTER. | `@qrvey/filters/resources/index` | [docs](docs/resources/index.md) |
|
|
62
|
+
|
|
63
|
+
<!-- MODULES_END -->
|
|
@@ -5,72 +5,33 @@ const filter_adapt_helpers_1 = require("../helpers/filter-adapt.helpers");
|
|
|
5
5
|
const filter_adapt_legacy_helpers_1 = require("../helpers/filter-adapt.legacy.helpers");
|
|
6
6
|
const filter_adapt_logic_helpers_1 = require("../helpers/filter-adapt.logic.helpers");
|
|
7
7
|
const filters_resources_1 = require("../resources/filters.resources");
|
|
8
|
-
/**
|
|
9
|
-
* Class to adapt the filters
|
|
10
|
-
*/
|
|
11
8
|
class FilterAdapter {
|
|
12
9
|
_filters;
|
|
13
10
|
datasets;
|
|
14
11
|
interactiveTable;
|
|
15
|
-
/**
|
|
16
|
-
* The Logic filters
|
|
17
|
-
*/
|
|
18
12
|
_logic;
|
|
19
|
-
/**
|
|
20
|
-
* The visual filters
|
|
21
|
-
*/
|
|
22
13
|
_visual;
|
|
23
|
-
/**
|
|
24
|
-
* The old Filter Data structure
|
|
25
|
-
*/
|
|
26
14
|
_legacyVisual;
|
|
27
|
-
/**
|
|
28
|
-
* Constructor
|
|
29
|
-
* @param _filters the collection of filters
|
|
30
|
-
* @param datasets the collection of datasets info
|
|
31
|
-
* @param interactiveTable table of interaction properties for each section
|
|
32
|
-
*/
|
|
33
15
|
constructor(_filters = [], datasets = [], interactiveTable) {
|
|
34
16
|
this._filters = _filters;
|
|
35
17
|
this.datasets = datasets;
|
|
36
18
|
this.interactiveTable = interactiveTable;
|
|
37
19
|
this.setFilters(Array.isArray(_filters) ? _filters : []);
|
|
38
20
|
}
|
|
39
|
-
/**
|
|
40
|
-
*
|
|
41
|
-
*/
|
|
42
21
|
sync() {
|
|
43
22
|
this.setVisual(this.filterToVisual());
|
|
44
23
|
this.setLegacyVisual(this.filterToLegacyVisual());
|
|
45
24
|
this.setLogic(this.filterToLogic());
|
|
46
25
|
}
|
|
47
|
-
/**
|
|
48
|
-
* Generates a visual filter structure from the filter collection.
|
|
49
|
-
* @returns a visual Filter structure
|
|
50
|
-
*/
|
|
51
26
|
filterToLegacyVisual() {
|
|
52
27
|
return (0, filter_adapt_legacy_helpers_1.filterToLegacyVisual)(this._filters, this.datasets, this.interactiveTable);
|
|
53
28
|
}
|
|
54
|
-
/**
|
|
55
|
-
* Generates a logic filters structure from the filter collection.
|
|
56
|
-
* @returns the Logic Filters
|
|
57
|
-
*/
|
|
58
29
|
filterToLogic() {
|
|
59
30
|
return (0, filter_adapt_logic_helpers_1.filterToLogic)(this._filters);
|
|
60
31
|
}
|
|
61
|
-
/**
|
|
62
|
-
* Generates a visual filter structure from the filter collection.
|
|
63
|
-
* @returns a visual Filter structure
|
|
64
|
-
*/
|
|
65
32
|
filterToVisual() {
|
|
66
33
|
return (0, filter_adapt_helpers_1.filterToVisual)(this._filters, this.datasets, this.interactiveTable);
|
|
67
34
|
}
|
|
68
|
-
/**
|
|
69
|
-
* Generates the filter collection from the legacy filter
|
|
70
|
-
* @param legacyVisual the legacy filter
|
|
71
|
-
* @param interactiveTable the interactive table object
|
|
72
|
-
* @returns the filter collection
|
|
73
|
-
*/
|
|
74
35
|
static legacyVisualToFilter(legacyVisual, interactiveTable) {
|
|
75
36
|
const filters = (0, filter_adapt_legacy_helpers_1.legacyVisualToFilter)(legacyVisual);
|
|
76
37
|
const newInteractiveTable = (0, filter_adapt_legacy_helpers_1.legacyVisualToInteractiveTable)(legacyVisual, interactiveTable);
|
|
@@ -79,88 +40,48 @@ class FilterAdapter {
|
|
|
79
40
|
interactiveTable: newInteractiveTable,
|
|
80
41
|
};
|
|
81
42
|
}
|
|
82
|
-
/**
|
|
83
|
-
* Gets the legacy filter version attribute
|
|
84
|
-
* @returns the legacy filter version
|
|
85
|
-
*/
|
|
86
43
|
get legacyVisual() {
|
|
87
44
|
return {
|
|
88
45
|
filters: this._legacyVisual,
|
|
89
46
|
version: filters_resources_1.FILTER_VERSION_TYPE.UI_2,
|
|
90
47
|
};
|
|
91
48
|
}
|
|
92
|
-
/**
|
|
93
|
-
* Gets the filter logic version
|
|
94
|
-
* @returns the filter logic version
|
|
95
|
-
*/
|
|
96
49
|
get logic() {
|
|
97
50
|
return {
|
|
98
51
|
filters: this._logic,
|
|
99
52
|
version: filters_resources_1.FILTER_VERSION_TYPE.LOGIC,
|
|
100
53
|
};
|
|
101
54
|
}
|
|
102
|
-
/**
|
|
103
|
-
* Gets the visual filter version
|
|
104
|
-
* @returns the visual filter version
|
|
105
|
-
*/
|
|
106
55
|
get visual() {
|
|
107
56
|
return {
|
|
108
57
|
filters: this._visual,
|
|
109
58
|
version: filters_resources_1.FILTER_VERSION_TYPE.UI_3,
|
|
110
59
|
};
|
|
111
60
|
}
|
|
112
|
-
/**
|
|
113
|
-
* Gets the filter version 3
|
|
114
|
-
* @returns the filter version 3
|
|
115
|
-
*/
|
|
116
61
|
get filters() {
|
|
117
62
|
return {
|
|
118
|
-
filters: this._filters
|
|
63
|
+
filters: this._filters,
|
|
119
64
|
version: filters_resources_1.FILTER_VERSION_TYPE.V3,
|
|
120
65
|
};
|
|
121
66
|
}
|
|
122
|
-
/**
|
|
123
|
-
* Sets the datasets atribute
|
|
124
|
-
* @param datasets the collection of dataset info
|
|
125
|
-
*/
|
|
126
67
|
setDatasets(datasets = []) {
|
|
127
68
|
this.datasets = datasets;
|
|
128
69
|
this.sync();
|
|
129
70
|
}
|
|
130
|
-
/**
|
|
131
|
-
* Sets the collection of filters atribute
|
|
132
|
-
* @param filters the filters
|
|
133
|
-
*/
|
|
134
71
|
setFilters(filters) {
|
|
135
72
|
this._filters = filters;
|
|
136
73
|
this.sync();
|
|
137
74
|
}
|
|
138
|
-
/**
|
|
139
|
-
* Sets the table of interactive table attribute
|
|
140
|
-
* @param interactiveTable table of interaction properties for each section
|
|
141
|
-
*/
|
|
142
75
|
setInteractiveTable(interactiveTable) {
|
|
143
76
|
this.interactiveTable = interactiveTable;
|
|
144
77
|
this.sync();
|
|
145
78
|
}
|
|
146
|
-
/**
|
|
147
|
-
* Sets the filter legacy visual attribute
|
|
148
|
-
* @param legacyVisual the legacy visual filters
|
|
149
|
-
*/
|
|
150
79
|
setLegacyVisual(legacyVisual) {
|
|
151
80
|
this._legacyVisual = legacyVisual;
|
|
152
81
|
}
|
|
153
|
-
/**
|
|
154
|
-
* Sets the filter logic attribute
|
|
155
|
-
* @param logic the logic filters
|
|
156
|
-
*/
|
|
157
82
|
setLogic(logic) {
|
|
158
83
|
this._logic = logic;
|
|
159
84
|
}
|
|
160
|
-
/**
|
|
161
|
-
* Sets the filter visual attribute
|
|
162
|
-
* @param visual the visual filters
|
|
163
|
-
*/
|
|
164
85
|
setVisual(visual) {
|
|
165
86
|
this._visual = visual;
|
|
166
87
|
}
|
|
@@ -5,58 +5,30 @@ const utils_1 = require("@qrvey/utils");
|
|
|
5
5
|
const FilterSearcher_1 = require("./FilterSearcher");
|
|
6
6
|
const FilterValidation_1 = require("./FilterValidation");
|
|
7
7
|
const FilterValues_1 = require("./FilterValues");
|
|
8
|
+
const filter_builder_helpers_1 = require("../helpers/filter-builder.helpers");
|
|
8
9
|
const filter_settings_helpers_1 = require("../helpers/filter-settings.helpers");
|
|
9
10
|
const getFilterId_1 = require("../helpers/getFilterId");
|
|
10
11
|
const getFilterType_1 = require("../helpers/getFilterType");
|
|
11
12
|
const filter_operators_resources_1 = require("../resources/filter-operators.resources");
|
|
12
13
|
const filters_resources_1 = require("../resources/filters.resources");
|
|
13
|
-
const filter_builder_helpers_1 = require("../helpers/filter-builder.helpers");
|
|
14
|
-
/**
|
|
15
|
-
* Class to build new filters and manipulate ones.
|
|
16
|
-
*/
|
|
17
14
|
class FilterBuilder {
|
|
18
15
|
filters;
|
|
19
|
-
/**
|
|
20
|
-
* Instance to search filters
|
|
21
|
-
*/
|
|
22
16
|
searchEngine;
|
|
23
|
-
|
|
24
|
-
* Constructor
|
|
25
|
-
* @param filters the collection of filters
|
|
26
|
-
*/
|
|
27
|
-
constructor(filters = []) {
|
|
17
|
+
constructor(filters = [], searchEngine) {
|
|
28
18
|
this.filters = filters;
|
|
29
|
-
this.searchEngine = new FilterSearcher_1.FilterSearcher(filters);
|
|
19
|
+
this.searchEngine = searchEngine ?? new FilterSearcher_1.FilterSearcher(filters);
|
|
30
20
|
this.filters = (0, utils_1.objectCopy)(Array.isArray(filters) ? filters : []);
|
|
21
|
+
this.searchEngine.setFilters(this.filters);
|
|
31
22
|
}
|
|
32
|
-
/**
|
|
33
|
-
* **************************************************************************************************
|
|
34
|
-
****************************************** Adding **************************************************
|
|
35
|
-
****************************************************************************************************
|
|
36
|
-
*/
|
|
37
|
-
/**
|
|
38
|
-
* Adds various filter into the collection.
|
|
39
|
-
* Inserts them next to the last similar filter
|
|
40
|
-
* @param newFilters the filter to add
|
|
41
|
-
* @param inIndexes collection of indexes to add the new filters
|
|
42
|
-
* @param settings the settings object to setup this function
|
|
43
|
-
* @returns the new collection of filters
|
|
44
|
-
*/
|
|
45
23
|
addMultiple(newFilters, inIndexes, settings) {
|
|
46
24
|
if ((0, utils_1.isEmpty)(newFilters))
|
|
47
25
|
return { resulting: this.filters };
|
|
48
26
|
const filters = (0, utils_1.objectCopy)(this.filters);
|
|
49
27
|
const affected = [];
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
});
|
|
55
|
-
}
|
|
56
|
-
catch (_error) {
|
|
57
|
-
this.filters = filters;
|
|
58
|
-
return { resulting: filters };
|
|
59
|
-
}
|
|
28
|
+
newFilters.forEach((newFilter, index) => {
|
|
29
|
+
const affectedFilter = this.addSingle(newFilter, inIndexes?.[index], settings);
|
|
30
|
+
affected.push(affectedFilter.affected);
|
|
31
|
+
});
|
|
60
32
|
this.sync();
|
|
61
33
|
return {
|
|
62
34
|
resulting: this.filters,
|
|
@@ -64,17 +36,6 @@ class FilterBuilder {
|
|
|
64
36
|
original: filters,
|
|
65
37
|
};
|
|
66
38
|
}
|
|
67
|
-
/**
|
|
68
|
-
* Adds one filter into the collection.
|
|
69
|
-
* - Inserts it next to the last similar filter
|
|
70
|
-
* - If the new one is match with the last similar filter, the operator will change to OR
|
|
71
|
-
* - If the id is not provided, a new one is created.
|
|
72
|
-
* - If the inIndex nunber is provided, this will be the index where the filter is inserted
|
|
73
|
-
* @param filter the filter to add
|
|
74
|
-
* @param inIndex the index to add the new filter
|
|
75
|
-
* @param settings settings object to setup this function
|
|
76
|
-
* @returns the new collection of filters
|
|
77
|
-
*/
|
|
78
39
|
addSingle(filter, inIndex, settings) {
|
|
79
40
|
if ((0, utils_1.isEmpty)(filter))
|
|
80
41
|
return { resulting: this.filters };
|
|
@@ -117,12 +78,6 @@ class FilterBuilder {
|
|
|
117
78
|
original,
|
|
118
79
|
};
|
|
119
80
|
}
|
|
120
|
-
/**
|
|
121
|
-
* Adds one value from filter
|
|
122
|
-
* @param id the ID to search the filter to add value
|
|
123
|
-
* @param value the value to add
|
|
124
|
-
* @returns the new filter collection
|
|
125
|
-
*/
|
|
126
81
|
addValue(id, value) {
|
|
127
82
|
const index = this.searchEngine.findIndexByParams({ id });
|
|
128
83
|
if (index < 0)
|
|
@@ -138,28 +93,15 @@ class FilterBuilder {
|
|
|
138
93
|
original,
|
|
139
94
|
};
|
|
140
95
|
}
|
|
141
|
-
/**
|
|
142
|
-
* Adds various values on filter
|
|
143
|
-
* @param id the ID to search the filter to add value
|
|
144
|
-
* @param values the collection of value to add
|
|
145
|
-
* @returns the new filter collection
|
|
146
|
-
*/
|
|
147
96
|
addValues(id, values) {
|
|
148
97
|
const index = this.searchEngine.findIndexByParams({ id });
|
|
149
98
|
if ((0, utils_1.isEmpty)(values) || index < 0)
|
|
150
99
|
return { resulting: this.filters };
|
|
151
|
-
const filters = (0, utils_1.objectCopy)(this.filters);
|
|
152
100
|
const original = (0, utils_1.objectCopy)(this.filters[index]);
|
|
153
101
|
let affected;
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
});
|
|
158
|
-
}
|
|
159
|
-
catch (_error) {
|
|
160
|
-
this.filters = filters;
|
|
161
|
-
return { resulting: filters };
|
|
162
|
-
}
|
|
102
|
+
values.forEach((value) => {
|
|
103
|
+
affected = this.addValue(id, value).affected;
|
|
104
|
+
});
|
|
163
105
|
this.sync();
|
|
164
106
|
return {
|
|
165
107
|
resulting: this.filters,
|
|
@@ -167,17 +109,6 @@ class FilterBuilder {
|
|
|
167
109
|
original,
|
|
168
110
|
};
|
|
169
111
|
}
|
|
170
|
-
/**
|
|
171
|
-
* **************************************************************************************************
|
|
172
|
-
**************************************** Deleting **************************************************
|
|
173
|
-
****************************************************************************************************
|
|
174
|
-
*/
|
|
175
|
-
/**
|
|
176
|
-
* Removes various filters by params
|
|
177
|
-
* @param params params to search the filters to delete
|
|
178
|
-
* @param settings settings for this function
|
|
179
|
-
* @returns the new collection of filters
|
|
180
|
-
*/
|
|
181
112
|
deleteByParams(params, settings) {
|
|
182
113
|
const original = (0, utils_1.objectCopy)(this.filters);
|
|
183
114
|
const affected = this.searchEngine.filterByParams(params, settings);
|
|
@@ -189,26 +120,15 @@ class FilterBuilder {
|
|
|
189
120
|
original,
|
|
190
121
|
};
|
|
191
122
|
}
|
|
192
|
-
/**
|
|
193
|
-
* Removes various filters from the collection
|
|
194
|
-
* @param ids a collection of ID to search filters to remove
|
|
195
|
-
* @returns the new filter collection
|
|
196
|
-
*/
|
|
197
123
|
deleteMultiple(ids) {
|
|
198
124
|
if (!Array.isArray(ids))
|
|
199
125
|
return { resulting: this.filters };
|
|
200
126
|
const filters = (0, utils_1.objectCopy)(this.filters);
|
|
201
127
|
const affected = [];
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
});
|
|
207
|
-
}
|
|
208
|
-
catch (_error) {
|
|
209
|
-
this.filters = filters;
|
|
210
|
-
return { resulting: filters };
|
|
211
|
-
}
|
|
128
|
+
ids.forEach((id) => {
|
|
129
|
+
const deleted = this.deleteSingle(id);
|
|
130
|
+
affected.push(deleted.affected);
|
|
131
|
+
});
|
|
212
132
|
this.sync();
|
|
213
133
|
return {
|
|
214
134
|
resulting: this.filters,
|
|
@@ -216,11 +136,6 @@ class FilterBuilder {
|
|
|
216
136
|
original: filters,
|
|
217
137
|
};
|
|
218
138
|
}
|
|
219
|
-
/**
|
|
220
|
-
* Removes one filter from the collection
|
|
221
|
-
* @param id the ID to search the filter to remove
|
|
222
|
-
* @returns the new filter collection
|
|
223
|
-
*/
|
|
224
139
|
deleteSingle(id) {
|
|
225
140
|
const index = this.searchEngine.findIndexByParams({ id });
|
|
226
141
|
const original = { ...this.filters[index] };
|
|
@@ -235,12 +150,6 @@ class FilterBuilder {
|
|
|
235
150
|
original,
|
|
236
151
|
};
|
|
237
152
|
}
|
|
238
|
-
/**
|
|
239
|
-
* Removes one value from filter
|
|
240
|
-
* @param id the ID to search the filter to remove value
|
|
241
|
-
* @param index the index to search the value to remove
|
|
242
|
-
* @returns the new filter collection
|
|
243
|
-
*/
|
|
244
153
|
deleteValue(id, index) {
|
|
245
154
|
if (!Number.isInteger(index))
|
|
246
155
|
return { resulting: this.filters };
|
|
@@ -259,30 +168,16 @@ class FilterBuilder {
|
|
|
259
168
|
original,
|
|
260
169
|
};
|
|
261
170
|
}
|
|
262
|
-
/**
|
|
263
|
-
* Removes various values from filter
|
|
264
|
-
* @param id the ID to search the filter to remove value
|
|
265
|
-
* @param indexes the index collection to search the value to remove
|
|
266
|
-
* @returns the new filter collection
|
|
267
|
-
*/
|
|
268
171
|
deleteValues(id, indexes) {
|
|
269
172
|
if (!Array.isArray(indexes))
|
|
270
173
|
return { resulting: this.filters };
|
|
271
|
-
|
|
272
|
-
sortedIndex = indexes.reverse();
|
|
273
|
-
const filters = (0, utils_1.objectCopy)(this.filters);
|
|
174
|
+
const sortedIndex = indexes.sort().reverse();
|
|
274
175
|
const original = this.searchEngine.findByParams({
|
|
275
176
|
id,
|
|
276
177
|
});
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
});
|
|
281
|
-
}
|
|
282
|
-
catch (_error) {
|
|
283
|
-
this.filters = filters;
|
|
284
|
-
return { resulting: filters };
|
|
285
|
-
}
|
|
178
|
+
sortedIndex.forEach((index) => {
|
|
179
|
+
this.deleteValue(id, index);
|
|
180
|
+
});
|
|
286
181
|
this.sync();
|
|
287
182
|
const affected = this.searchEngine.findByParams({ id });
|
|
288
183
|
return {
|
|
@@ -291,18 +186,6 @@ class FilterBuilder {
|
|
|
291
186
|
original,
|
|
292
187
|
};
|
|
293
188
|
}
|
|
294
|
-
/**
|
|
295
|
-
* **************************************************************************************************
|
|
296
|
-
****************************************** Editing *************************************************
|
|
297
|
-
****************************************************************************************************
|
|
298
|
-
*/
|
|
299
|
-
/**
|
|
300
|
-
* Edits various filters from the collection
|
|
301
|
-
* @param ids the collection of IDs to search filters to edit
|
|
302
|
-
* @param filters a collection of object with properties to edit
|
|
303
|
-
* @param settings settings object for the function
|
|
304
|
-
* @returns the new filter collection
|
|
305
|
-
*/
|
|
306
189
|
editMultiple(ids, filters, settings) {
|
|
307
190
|
if (!Array.isArray(ids) ||
|
|
308
191
|
!Array.isArray(filters) ||
|
|
@@ -310,16 +193,10 @@ class FilterBuilder {
|
|
|
310
193
|
return { resulting: this.filters };
|
|
311
194
|
const originalFilters = (0, utils_1.objectCopy)(this.filters);
|
|
312
195
|
const editedFilters = [];
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
});
|
|
318
|
-
}
|
|
319
|
-
catch (_error) {
|
|
320
|
-
this.filters = originalFilters;
|
|
321
|
-
return { resulting: originalFilters };
|
|
322
|
-
}
|
|
196
|
+
ids.forEach((id, index) => {
|
|
197
|
+
const editedFilter = this.editSingle(id, filters[index], settings);
|
|
198
|
+
editedFilters.push(editedFilter.affected);
|
|
199
|
+
});
|
|
323
200
|
this.sync();
|
|
324
201
|
return {
|
|
325
202
|
resulting: this.filters,
|
|
@@ -327,13 +204,6 @@ class FilterBuilder {
|
|
|
327
204
|
original: originalFilters,
|
|
328
205
|
};
|
|
329
206
|
}
|
|
330
|
-
/**
|
|
331
|
-
* Edits one filter from the collection
|
|
332
|
-
* @param id the ID to search the filter to edit
|
|
333
|
-
* @param filter an object with properties to edit
|
|
334
|
-
* @param settings settings object for the function
|
|
335
|
-
* @returns the new filter collection
|
|
336
|
-
*/
|
|
337
207
|
editSingle(id, filter, settings) {
|
|
338
208
|
if ((0, utils_1.isEmpty)(filter))
|
|
339
209
|
return { resulting: this.filters };
|
|
@@ -356,13 +226,6 @@ class FilterBuilder {
|
|
|
356
226
|
original,
|
|
357
227
|
};
|
|
358
228
|
}
|
|
359
|
-
/**
|
|
360
|
-
* Edits one value from filter
|
|
361
|
-
* @param id the ID to search the filter to edit value
|
|
362
|
-
* @param value the value to edit
|
|
363
|
-
* @param index the value index to edit
|
|
364
|
-
* @returns the new filter collection
|
|
365
|
-
*/
|
|
366
229
|
editValue(id, value, index) {
|
|
367
230
|
const filterIndex = this.searchEngine.findIndexByParams({ id });
|
|
368
231
|
if ((0, utils_1.isEmpty)(value) ||
|
|
@@ -380,29 +243,16 @@ class FilterBuilder {
|
|
|
380
243
|
original,
|
|
381
244
|
};
|
|
382
245
|
}
|
|
383
|
-
/**
|
|
384
|
-
* Edits various values from filter
|
|
385
|
-
* @param id the ID to search the filter to edit value
|
|
386
|
-
* @param values the value collection to edit
|
|
387
|
-
* @param indexes the index collection to edit
|
|
388
|
-
* @returns the new filter collection
|
|
389
|
-
*/
|
|
390
246
|
editValues(id, values, indexes) {
|
|
391
247
|
const filterIndex = this.searchEngine.findIndexByParams({ id });
|
|
392
248
|
if ((0, utils_1.isEmpty)(values) || filterIndex < 0 || !Array.isArray(indexes))
|
|
393
249
|
return { resulting: this.filters };
|
|
394
250
|
const original = (0, utils_1.objectCopy)(this.filters);
|
|
395
251
|
let finalAffectedFilter;
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
});
|
|
401
|
-
}
|
|
402
|
-
catch (_error) {
|
|
403
|
-
this.filters = original;
|
|
404
|
-
return { resulting: original };
|
|
405
|
-
}
|
|
252
|
+
values.forEach((value, index) => {
|
|
253
|
+
const affectedFilter = this.editValue(id, value, indexes[index]);
|
|
254
|
+
finalAffectedFilter = affectedFilter.affected;
|
|
255
|
+
});
|
|
406
256
|
this.sync();
|
|
407
257
|
return {
|
|
408
258
|
resulting: this.filters,
|
|
@@ -410,17 +260,6 @@ class FilterBuilder {
|
|
|
410
260
|
original: original[filterIndex],
|
|
411
261
|
};
|
|
412
262
|
}
|
|
413
|
-
/**
|
|
414
|
-
* **************************************************************************************************
|
|
415
|
-
****************************************** Merging *************************************************
|
|
416
|
-
****************************************************************************************************
|
|
417
|
-
*/
|
|
418
|
-
/**
|
|
419
|
-
* Merge the filter into the collection by some filter parameters
|
|
420
|
-
* @param filter the filter to merge
|
|
421
|
-
* @param settings the settings object to setup this function
|
|
422
|
-
* @returns the new filter collection
|
|
423
|
-
*/
|
|
424
263
|
mergeSingle(filter, settings) {
|
|
425
264
|
if ((0, utils_1.isEmpty)(filter))
|
|
426
265
|
return { resulting: this.filters };
|
|
@@ -433,7 +272,7 @@ class FilterBuilder {
|
|
|
433
272
|
validator: filter.validator,
|
|
434
273
|
});
|
|
435
274
|
let original = filter;
|
|
436
|
-
let affected
|
|
275
|
+
let affected;
|
|
437
276
|
if (filterIndex > -1) {
|
|
438
277
|
original = (0, utils_1.objectCopy)(this.filters[filterIndex]);
|
|
439
278
|
const { affected: affectedMergeFilter } = this.mergeValues(this.filters[filterIndex].id, filter.values);
|
|
@@ -449,27 +288,15 @@ class FilterBuilder {
|
|
|
449
288
|
original,
|
|
450
289
|
};
|
|
451
290
|
}
|
|
452
|
-
/**
|
|
453
|
-
* Merge the filters into the collection by some filter parameters
|
|
454
|
-
* @param filters the filter collection to merge
|
|
455
|
-
* @param settings the settings object to setup this function
|
|
456
|
-
* @returns the new filter collection
|
|
457
|
-
*/
|
|
458
291
|
mergeMultiple(filters, settings) {
|
|
459
292
|
if (!Array.isArray(filters) || (0, utils_1.isEmpty)(filters))
|
|
460
293
|
return { resulting: this.filters };
|
|
461
294
|
const originalFilters = (0, utils_1.objectCopy)(this.filters);
|
|
462
295
|
const mergedFilters = [];
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
});
|
|
468
|
-
}
|
|
469
|
-
catch (_error) {
|
|
470
|
-
this.filters = originalFilters;
|
|
471
|
-
return { resulting: originalFilters };
|
|
472
|
-
}
|
|
296
|
+
filters.forEach((filter) => {
|
|
297
|
+
const mergedFilter = this.mergeSingle(filter, settings);
|
|
298
|
+
mergedFilters.push(mergedFilter.affected);
|
|
299
|
+
});
|
|
473
300
|
this.sync();
|
|
474
301
|
return {
|
|
475
302
|
resulting: this.filters,
|
|
@@ -477,12 +304,6 @@ class FilterBuilder {
|
|
|
477
304
|
original: originalFilters,
|
|
478
305
|
};
|
|
479
306
|
}
|
|
480
|
-
/**
|
|
481
|
-
* Merge values from filter
|
|
482
|
-
* @param id the ID to search the filter to merge values
|
|
483
|
-
* @param values the value collection to merge
|
|
484
|
-
* @returns the new filter collection
|
|
485
|
-
*/
|
|
486
307
|
mergeValues(id, values) {
|
|
487
308
|
const filterIndex = this.searchEngine.findIndexByParams({ id });
|
|
488
309
|
if ((0, utils_1.isEmpty)(values) || filterIndex < 0)
|
|
@@ -521,17 +342,6 @@ class FilterBuilder {
|
|
|
521
342
|
original,
|
|
522
343
|
};
|
|
523
344
|
}
|
|
524
|
-
/**
|
|
525
|
-
* **************************************************************************************************
|
|
526
|
-
****************************************** Others **************************************************
|
|
527
|
-
****************************************************************************************************
|
|
528
|
-
*/
|
|
529
|
-
/**
|
|
530
|
-
* Builds an filter structure based on given params
|
|
531
|
-
* @param filter the partial filter params
|
|
532
|
-
* @param settings the settings object to setup this function
|
|
533
|
-
* @returns the complete filter structure
|
|
534
|
-
*/
|
|
535
345
|
static createFilter(filter, settings) {
|
|
536
346
|
const newSettings = (0, filter_settings_helpers_1.getFilterCreateSettings)(settings);
|
|
537
347
|
const newFilter = {
|
|
@@ -565,14 +375,6 @@ class FilterBuilder {
|
|
|
565
375
|
}
|
|
566
376
|
return newFilter;
|
|
567
377
|
}
|
|
568
|
-
/**
|
|
569
|
-
* Sets the given filters by param
|
|
570
|
-
* - Remove the filters by the sucesfull conditions and replace the given ones
|
|
571
|
-
* @param filters the filters to set
|
|
572
|
-
* @param params params to search the filters
|
|
573
|
-
* @param settings settings for this function
|
|
574
|
-
* @returns the new collection of filters
|
|
575
|
-
*/
|
|
576
378
|
replaceByParams(filters, params, settings) {
|
|
577
379
|
const original = (0, utils_1.objectCopy)(this.filters);
|
|
578
380
|
const newSettings = (0, filter_settings_helpers_1.getReplaceByParamsSettings)(settings);
|
|
@@ -592,33 +394,12 @@ class FilterBuilder {
|
|
|
592
394
|
original,
|
|
593
395
|
};
|
|
594
396
|
}
|
|
595
|
-
/**
|
|
596
|
-
* Method to sync the Filter instances
|
|
597
|
-
*/
|
|
598
397
|
sync() {
|
|
599
398
|
this.searchEngine.setFilters(this.filters);
|
|
600
399
|
}
|
|
601
|
-
/**
|
|
602
|
-
* **************************************************************************************************
|
|
603
|
-
****************************************** Getters *************************************************
|
|
604
|
-
****************************************************************************************************
|
|
605
|
-
*/
|
|
606
|
-
/**
|
|
607
|
-
* Gets the filter collection
|
|
608
|
-
* @returns the collection of filters of the context
|
|
609
|
-
*/
|
|
610
400
|
getFilters() {
|
|
611
401
|
return this.filters;
|
|
612
402
|
}
|
|
613
|
-
/**
|
|
614
|
-
* **************************************************************************************************
|
|
615
|
-
****************************************** Setters *************************************************
|
|
616
|
-
****************************************************************************************************
|
|
617
|
-
*/
|
|
618
|
-
/**
|
|
619
|
-
* Sets the filters
|
|
620
|
-
* @param filters the new collection of filters to set
|
|
621
|
-
*/
|
|
622
403
|
setFilters(filters) {
|
|
623
404
|
this.filters = (0, utils_1.objectCopy)(filters);
|
|
624
405
|
this.sync();
|