@geosdi/ngx-utility-service 1.2.8 → 2.0.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
CHANGED
|
@@ -1,24 +1,64 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @geosdi/ngx-utility-service
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
`NgxFiltersCacheService`: where an application keeps the values of the filters the user has applied,
|
|
4
|
+
by key. A filter with a value is "live"; a filter without one does not exist.
|
|
4
5
|
|
|
5
|
-
##
|
|
6
|
+
## Installation
|
|
6
7
|
|
|
7
|
-
|
|
8
|
-
> Note: Don't forget to add `--project ngx-utility-service` or else it will be added to the default project in your `angular.json` file.
|
|
8
|
+
`npm i @geosdi/ngx-utility-service --save`
|
|
9
9
|
|
|
10
|
-
|
|
10
|
+
Peer dependencies:
|
|
11
11
|
|
|
12
|
-
|
|
12
|
+
"@angular/common": ">=20.0.0",
|
|
13
|
+
"@angular/core": ">=20.0.0",
|
|
14
|
+
"lodash": ">=4.17.21",
|
|
15
|
+
"typescript": ">=5.0.0"
|
|
13
16
|
|
|
14
|
-
##
|
|
17
|
+
## Usage
|
|
15
18
|
|
|
16
|
-
|
|
19
|
+
```typescript
|
|
20
|
+
import { NgxFiltersCacheService } from "@geosdi/ngx-utility-service";
|
|
17
21
|
|
|
18
|
-
|
|
22
|
+
const filters = inject(NgxFiltersCacheService);
|
|
19
23
|
|
|
20
|
-
|
|
24
|
+
filters.saveFilter("region", "Basilicata"); // stored as ["Basilicata"]
|
|
25
|
+
filters.saveFilter("year", [2025, 2026]); // stored as [2025, 2026]
|
|
26
|
+
filters.getFilter("region"); // ["Basilicata"]
|
|
21
27
|
|
|
22
|
-
|
|
28
|
+
filters.saveFilter("region", null); // the key is removed
|
|
29
|
+
filters.hasFilter("region"); // false
|
|
30
|
+
```
|
|
23
31
|
|
|
24
|
-
|
|
32
|
+
## Methods
|
|
33
|
+
|
|
34
|
+
| Method | Meaning |
|
|
35
|
+
| ------------------------ | ------------------------------------------------------------ |
|
|
36
|
+
| `saveFilter(key, value)` | stores the value of a filter; see below how it is normalized |
|
|
37
|
+
| `getFilter(key)` | the stored array, or `null` for a key that is not there |
|
|
38
|
+
| `hasFilter(key)` | whether the filter has a value |
|
|
39
|
+
| `removeFilter(key)` | removes a filter |
|
|
40
|
+
| `filtersSize()` | how many filters have a value |
|
|
41
|
+
| `clearFilters()` | removes them all |
|
|
42
|
+
| `filtersValuesMap` | the underlying `Map`, by key |
|
|
43
|
+
|
|
44
|
+
## How a value is stored
|
|
45
|
+
|
|
46
|
+
`saveFilter` always stores an **array**:
|
|
47
|
+
|
|
48
|
+
- a single value is wrapped: `"Basilicata"` becomes `["Basilicata"]`;
|
|
49
|
+
- `null` and `undefined` items are dropped, and so are items shaped `{ name, value }` whose
|
|
50
|
+
`value` is `null` or `undefined`;
|
|
51
|
+
- **if nothing is left, the key is deleted** rather than stored as an empty array.
|
|
52
|
+
|
|
53
|
+
So a key is present only while the filter has a value, and `hasFilter` / `filtersSize` tell which
|
|
54
|
+
filters are live. A `null` or `undefined` key is ignored.
|
|
55
|
+
|
|
56
|
+
The service is a singleton (`providedIn: "root"`): the values are shared by the whole application
|
|
57
|
+
and live as long as the page.
|
|
58
|
+
|
|
59
|
+
## Changes in 2.0.1
|
|
60
|
+
|
|
61
|
+
- The peer dependencies match the code: `lodash`, which the service imports, is declared;
|
|
62
|
+
`@ngx-translate/core` and `@ngx-translate/http-loader`, left over from a service removed in 2025,
|
|
63
|
+
are not.
|
|
64
|
+
- This README, which replaces the one generated by Angular CLI. The code is unchanged.
|
|
@@ -8,44 +8,14 @@ import _ from 'lodash';
|
|
|
8
8
|
*/
|
|
9
9
|
class NgxFiltersCacheService {
|
|
10
10
|
constructor() {
|
|
11
|
-
this._bindingValuesMap = new Map();
|
|
12
11
|
this._filtersValuesMap = new Map();
|
|
13
12
|
}
|
|
14
|
-
/**
|
|
15
|
-
*
|
|
16
|
-
*/
|
|
17
|
-
get bindingValuesMap() {
|
|
18
|
-
return this._bindingValuesMap;
|
|
19
|
-
}
|
|
20
13
|
/**
|
|
21
14
|
*
|
|
22
15
|
*/
|
|
23
16
|
get filtersValuesMap() {
|
|
24
17
|
return this._filtersValuesMap;
|
|
25
18
|
}
|
|
26
|
-
/**
|
|
27
|
-
*
|
|
28
|
-
* @param key
|
|
29
|
-
*/
|
|
30
|
-
bindValue(key) {
|
|
31
|
-
return this._bindingValuesMap.get(key);
|
|
32
|
-
}
|
|
33
|
-
/**
|
|
34
|
-
*
|
|
35
|
-
* @param key
|
|
36
|
-
*/
|
|
37
|
-
addValue(key, value) {
|
|
38
|
-
this._bindingValuesMap.set(key, value);
|
|
39
|
-
}
|
|
40
|
-
/**
|
|
41
|
-
*
|
|
42
|
-
* @param key
|
|
43
|
-
*/
|
|
44
|
-
getValue(key) {
|
|
45
|
-
return this._bindingValuesMap.has(key)
|
|
46
|
-
? this._bindingValuesMap.get(key)
|
|
47
|
-
: null;
|
|
48
|
-
}
|
|
49
19
|
/**
|
|
50
20
|
*
|
|
51
21
|
* @param key
|
|
@@ -59,21 +29,30 @@ class NgxFiltersCacheService {
|
|
|
59
29
|
*
|
|
60
30
|
* @param key
|
|
61
31
|
*/
|
|
62
|
-
|
|
63
|
-
return this.
|
|
32
|
+
hasFilter(key) {
|
|
33
|
+
return this._filtersValuesMap.has(key);
|
|
64
34
|
}
|
|
65
35
|
/**
|
|
66
36
|
*
|
|
67
37
|
* @param key
|
|
68
38
|
* @param value
|
|
39
|
+
* @param type
|
|
69
40
|
*/
|
|
70
|
-
saveFilter(key, value) {
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
41
|
+
saveFilter(key, value, type = false) {
|
|
42
|
+
if (_.isNil(key)) {
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
const items = _.isArray(value)
|
|
46
|
+
? value
|
|
47
|
+
: _.isNil(value)
|
|
48
|
+
? []
|
|
49
|
+
: [value];
|
|
50
|
+
const cleaned = items.filter((item) => !_.isNil(_.has(item, "value") ? item.value : item));
|
|
51
|
+
if (cleaned.length === 0) {
|
|
52
|
+
this._filtersValuesMap.delete(key);
|
|
53
|
+
return;
|
|
76
54
|
}
|
|
55
|
+
this._filtersValuesMap.set(key, cleaned);
|
|
77
56
|
}
|
|
78
57
|
/**
|
|
79
58
|
*
|
|
@@ -83,9 +62,6 @@ class NgxFiltersCacheService {
|
|
|
83
62
|
if (this._filtersValuesMap.has(key)) {
|
|
84
63
|
this._filtersValuesMap.delete(key);
|
|
85
64
|
}
|
|
86
|
-
if (this._bindingValuesMap.has(key)) {
|
|
87
|
-
this._bindingValuesMap.delete(key);
|
|
88
|
-
}
|
|
89
65
|
}
|
|
90
66
|
/**
|
|
91
67
|
*
|
|
@@ -98,12 +74,22 @@ class NgxFiltersCacheService {
|
|
|
98
74
|
*/
|
|
99
75
|
clearFilters() {
|
|
100
76
|
this._filtersValuesMap.clear();
|
|
101
|
-
this._bindingValuesMap.clear();
|
|
102
77
|
}
|
|
103
|
-
/**
|
|
104
|
-
|
|
78
|
+
/**
|
|
79
|
+
*
|
|
80
|
+
* @param item
|
|
81
|
+
* @private
|
|
82
|
+
*/
|
|
83
|
+
toCanonical(item) {
|
|
84
|
+
if (_.has(item, "value")) {
|
|
85
|
+
return { name: item.name ?? item.value, value: item.value };
|
|
86
|
+
}
|
|
87
|
+
return { name: item, value: item };
|
|
88
|
+
}
|
|
89
|
+
/** @nocollapse */ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.9", ngImport: i0, type: NgxFiltersCacheService, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
|
|
90
|
+
/** @nocollapse */ static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "21.2.9", ngImport: i0, type: NgxFiltersCacheService, providedIn: "root" }); }
|
|
105
91
|
}
|
|
106
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "
|
|
92
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.9", ngImport: i0, type: NgxFiltersCacheService, decorators: [{
|
|
107
93
|
type: Injectable,
|
|
108
94
|
args: [{
|
|
109
95
|
providedIn: "root",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"geosdi-ngx-utility-service.mjs","sources":["../../../../projects/geosdi/support/ngx-utility-service/src/lib/ngx-filters-cache.service.ts","../../../../projects/geosdi/support/ngx-utility-service/src/index.ts","../../../../projects/geosdi/support/ngx-utility-service/src/geosdi-ngx-utility-service.ts"],"sourcesContent":["import { Injectable } from \"@angular/core\";\nimport _ from \"lodash\";\n\n/**\n * @author Vito Salvia - CNR IMAA geoSDI Group\n * @email vito.salvia@gmail.com\n */\n@Injectable({\n providedIn: \"root\",\n})\nexport class NgxFiltersCacheService {\n private
|
|
1
|
+
{"version":3,"file":"geosdi-ngx-utility-service.mjs","sources":["../../../../projects/geosdi/support/ngx-utility-service/src/lib/ngx-filters-cache.service.ts","../../../../projects/geosdi/support/ngx-utility-service/src/index.ts","../../../../projects/geosdi/support/ngx-utility-service/src/geosdi-ngx-utility-service.ts"],"sourcesContent":["import { Injectable } from \"@angular/core\";\nimport _ from \"lodash\";\n\n/**\n * @author Vito Salvia - CNR IMAA geoSDI Group\n * @email vito.salvia@gmail.com\n */\n@Injectable({\n providedIn: \"root\",\n})\nexport class NgxFiltersCacheService {\n private _filtersValuesMap: Map<string, any> = new Map<string, any>();\n\n /**\n *\n */\n get filtersValuesMap(): Map<string, any> {\n return this._filtersValuesMap;\n }\n\n /**\n *\n * @param key\n */\n getFilter(key: string): any {\n return this._filtersValuesMap.has(key)\n ? this._filtersValuesMap.get(key)\n : null;\n }\n\n /**\n *\n * @param key\n */\n hasFilter(key: string): boolean {\n return this._filtersValuesMap.has(key);\n }\n\n /**\n *\n * @param key\n * @param value\n * @param type\n */\n saveFilter(key: string, value: any, type: boolean = false) {\n if (_.isNil(key)) {\n return;\n }\n const items: any[] = _.isArray(value)\n ? value\n : _.isNil(value)\n ? []\n : [value];\n const cleaned: any[] = items.filter(\n (item: any) => !_.isNil(_.has(item, \"value\") ? item.value : item),\n );\n if (cleaned.length === 0) {\n this._filtersValuesMap.delete(key);\n return;\n }\n this._filtersValuesMap.set(key, cleaned);\n }\n\n /**\n *\n * @param key\n */\n removeFilter(key: string) {\n if (this._filtersValuesMap.has(key)) {\n this._filtersValuesMap.delete(key);\n }\n }\n\n /**\n *\n */\n filtersSize(): number {\n return this._filtersValuesMap.size;\n }\n\n /**\n *\n */\n clearFilters() {\n this._filtersValuesMap.clear();\n }\n\n /**\n *\n * @param item\n * @private\n */\n private toCanonical(item: any): { name: any; value: any } {\n if (_.has(item, \"value\")) {\n return { name: item.name ?? item.value, value: item.value };\n }\n return { name: item, value: item };\n }\n}\n","/*\n * Public API Surface of ngx-utility-service\n */\nexport * from \"./lib/ngx-filters-cache.service\";\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './index';\n"],"names":[],"mappings":";;;;AAGA;;;AAGG;MAIU,sBAAsB,CAAA;AAHnC,IAAA,WAAA,GAAA;AAIY,QAAA,IAAA,CAAA,iBAAiB,GAAqB,IAAI,GAAG,EAAe;AAuFvE,IAAA;AArFG;;AAEG;AACH,IAAA,IAAI,gBAAgB,GAAA;QAChB,OAAO,IAAI,CAAC,iBAAiB;IACjC;AAEA;;;AAGG;AACH,IAAA,SAAS,CAAC,GAAW,EAAA;AACjB,QAAA,OAAO,IAAI,CAAC,iBAAiB,CAAC,GAAG,CAAC,GAAG;cAC/B,IAAI,CAAC,iBAAiB,CAAC,GAAG,CAAC,GAAG;cAC9B,IAAI;IACd;AAEA;;;AAGG;AACH,IAAA,SAAS,CAAC,GAAW,EAAA;QACjB,OAAO,IAAI,CAAC,iBAAiB,CAAC,GAAG,CAAC,GAAG,CAAC;IAC1C;AAEA;;;;;AAKG;AACH,IAAA,UAAU,CAAC,GAAW,EAAE,KAAU,EA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AAC,KAAK,EAAE;QAC/D;QACA,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE;IACtC;iIAvFS,sBAAsB,EAAA,IAAA,EAAA,EAAA,EAAA,MAAA,EAAA,EAAA,CAAA,eAAA,CAAA,UAAA,EAAA,CAAA,CAAA;AAAtB,uBAAA,SAAA,IAAA,CAAA,KAAA,GAAA,EAAA,CAAA,qBAAA,CAAA,EAAA,UAAA,EAAA,QAAA,EAAA,OAAA,EAAA,QAAA,EAAA,QAAA,EAAA,EAAA,EAAA,IAAA,EAAA,sBAAsB,cAFnB,MAAM,EAAA,CAAA,CAAA;;2FAET,sBAAsB,EAAA,UAAA,EAAA,CAAA;kBAHlC,UAAU;AAAC,YAAA,IAAA,EAAA,CAAA;AACR,oBAAA,UAAU,EAAE,MAAM;AACrB,iBAAA;;;ACTD;;AAEG;;ACFH;;AAEG;;;;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@geosdi/ngx-utility-service",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.1",
|
|
4
4
|
"description": "Utility sercvice",
|
|
5
5
|
"author": "Salvia Vito (vito.salvia@gmail.com)",
|
|
6
6
|
"keywords": [
|
|
@@ -14,22 +14,22 @@
|
|
|
14
14
|
"peerDependencies": {
|
|
15
15
|
"@angular/common": ">=20.0.0",
|
|
16
16
|
"@angular/core": ">=20.0.0",
|
|
17
|
-
"
|
|
18
|
-
"
|
|
19
|
-
"@ngx-translate/http-loader": ">=17.0.0"
|
|
17
|
+
"lodash": ">=4.17.21",
|
|
18
|
+
"typescript": ">=5.0.0"
|
|
20
19
|
},
|
|
21
20
|
"sideEffects": false,
|
|
22
21
|
"module": "fesm2022/geosdi-ngx-utility-service.mjs",
|
|
23
|
-
"typings": "
|
|
22
|
+
"typings": "types/geosdi-ngx-utility-service.d.ts",
|
|
24
23
|
"exports": {
|
|
25
24
|
"./package.json": {
|
|
26
25
|
"default": "./package.json"
|
|
27
26
|
},
|
|
28
27
|
".": {
|
|
29
|
-
"types": "./
|
|
28
|
+
"types": "./types/geosdi-ngx-utility-service.d.ts",
|
|
30
29
|
"default": "./fesm2022/geosdi-ngx-utility-service.mjs"
|
|
31
30
|
}
|
|
32
31
|
},
|
|
32
|
+
"type": "module",
|
|
33
33
|
"dependencies": {
|
|
34
34
|
"tslib": "^2.3.0"
|
|
35
35
|
}
|
|
@@ -5,31 +5,11 @@ import * as i0 from '@angular/core';
|
|
|
5
5
|
* @email vito.salvia@gmail.com
|
|
6
6
|
*/
|
|
7
7
|
declare class NgxFiltersCacheService {
|
|
8
|
-
private _bindingValuesMap;
|
|
9
|
-
/**
|
|
10
|
-
*
|
|
11
|
-
*/
|
|
12
|
-
get bindingValuesMap(): Map<string, any>;
|
|
13
8
|
private _filtersValuesMap;
|
|
14
9
|
/**
|
|
15
10
|
*
|
|
16
11
|
*/
|
|
17
12
|
get filtersValuesMap(): Map<string, any>;
|
|
18
|
-
/**
|
|
19
|
-
*
|
|
20
|
-
* @param key
|
|
21
|
-
*/
|
|
22
|
-
bindValue(key: string): any;
|
|
23
|
-
/**
|
|
24
|
-
*
|
|
25
|
-
* @param key
|
|
26
|
-
*/
|
|
27
|
-
addValue(key: string, value: any): void;
|
|
28
|
-
/**
|
|
29
|
-
*
|
|
30
|
-
* @param key
|
|
31
|
-
*/
|
|
32
|
-
getValue(key: string): any;
|
|
33
13
|
/**
|
|
34
14
|
*
|
|
35
15
|
* @param key
|
|
@@ -39,13 +19,14 @@ declare class NgxFiltersCacheService {
|
|
|
39
19
|
*
|
|
40
20
|
* @param key
|
|
41
21
|
*/
|
|
42
|
-
|
|
22
|
+
hasFilter(key: string): boolean;
|
|
43
23
|
/**
|
|
44
24
|
*
|
|
45
25
|
* @param key
|
|
46
26
|
* @param value
|
|
27
|
+
* @param type
|
|
47
28
|
*/
|
|
48
|
-
saveFilter(key: string, value: any): void;
|
|
29
|
+
saveFilter(key: string, value: any, type?: boolean): void;
|
|
49
30
|
/**
|
|
50
31
|
*
|
|
51
32
|
* @param key
|
|
@@ -59,6 +40,12 @@ declare class NgxFiltersCacheService {
|
|
|
59
40
|
*
|
|
60
41
|
*/
|
|
61
42
|
clearFilters(): void;
|
|
43
|
+
/**
|
|
44
|
+
*
|
|
45
|
+
* @param item
|
|
46
|
+
* @private
|
|
47
|
+
*/
|
|
48
|
+
private toCanonical;
|
|
62
49
|
static ɵfac: i0.ɵɵFactoryDeclaration<NgxFiltersCacheService, never>;
|
|
63
50
|
static ɵprov: i0.ɵɵInjectableDeclaration<NgxFiltersCacheService>;
|
|
64
51
|
}
|