@geosdi/ngx-utility-service 2.0.0 → 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.
|
|
@@ -86,10 +86,10 @@ class NgxFiltersCacheService {
|
|
|
86
86
|
}
|
|
87
87
|
return { name: item, value: item };
|
|
88
88
|
}
|
|
89
|
-
/** @nocollapse */ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "
|
|
90
|
-
/** @nocollapse */ static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "
|
|
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" }); }
|
|
91
91
|
}
|
|
92
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "
|
|
92
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.9", ngImport: i0, type: NgxFiltersCacheService, decorators: [{
|
|
93
93
|
type: Injectable,
|
|
94
94
|
args: [{
|
|
95
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 _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,EAAE,OAA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AK,EAAE;QAC/D;QACA,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE;IACtC;
|
|
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,EAAE,OAAgB,KAAK,EAAA;AACrD,QAAA,IAAI,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,EAAE;YACd;QACJ;AACA,QAAA,MAAM,KAAK,GAAU,CAAC,CAAC,OAAO,CAAC,KAAK;AAChC,cAAE;AACF,cAAE,CAAC,CAAC,KAAK,CAAC,KAAK;AACb,kBAAE;AACF,kBAAE,CAAC,KAAK,CAAC;AACf,QAAA,MAAM,OAAO,GAAU,KAAK,CAAC,MAAM,CAC/B,CAAC,IAAS,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,IAAI,EAAE,OAAO,CAAC,GAAG,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,CACpE;AACD,QAAA,IAAI,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AAA,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": "2.0.
|
|
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
|
}
|
|
File without changes
|