@esfaenza/preferences 11.2.19 → 11.2.20
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/bundles/esfaenza-preferences.umd.js +316 -237
- package/bundles/esfaenza-preferences.umd.js.map +1 -1
- package/bundles/esfaenza-preferences.umd.min.js +2 -2
- package/bundles/esfaenza-preferences.umd.min.js.map +1 -1
- package/esfaenza-preferences.d.ts +5 -2
- package/esfaenza-preferences.metadata.json +1 -1
- package/esm2015/esfaenza-preferences.js +5 -3
- package/esm2015/lib/models/PreferencesModuleConfig.js +1 -1
- package/esm2015/lib/persistor/base/CachePersistor.js +31 -0
- package/esm2015/lib/persistor/base/IBasePersistor.js +2 -0
- package/esm2015/lib/persistor/base/PreferencesPersistor.js +33 -0
- package/esm2015/lib/persistor/implementation/LocalStorageCachePersistor.js +52 -0
- package/esm2015/lib/persistor/implementation/LocalStoragePreferencesPersistor.js +52 -0
- package/esm2015/lib/preferences.module.js +10 -5
- package/esm2015/lib/services/base/IBaseStorage.js +2 -0
- package/esm2015/lib/services/base/base.service.js +114 -0
- package/esm2015/lib/services/cache.service.js +21 -0
- package/esm2015/lib/services/preferences.service.js +21 -0
- package/esm2015/public-api.js +5 -3
- package/fesm2015/esfaenza-preferences.js +190 -115
- package/fesm2015/esfaenza-preferences.js.map +1 -1
- package/lib/models/PreferencesModuleConfig.d.ts +8 -2
- package/lib/persistor/base/CachePersistor.d.ts +57 -0
- package/lib/persistor/base/IBasePersistor.d.ts +17 -0
- package/lib/persistor/base/{BasePreferencesPersistor.d.ts → PreferencesPersistor.d.ts} +7 -10
- package/lib/persistor/implementation/{LocalStoragePersistor.d.ts → LocalStorageCachePersistor.d.ts} +3 -4
- package/lib/persistor/implementation/LocalStoragePreferencesPersistor.d.ts +19 -0
- package/lib/services/base/IBaseStorage.d.ts +9 -0
- package/lib/{preferences.service.d.ts → services/base/base.service.d.ts} +11 -19
- package/lib/services/cache.service.d.ts +7 -0
- package/lib/services/preferences.service.d.ts +7 -0
- package/package.json +1 -1
- package/public-api.d.ts +4 -2
- package/esm2015/lib/persistor/base/BasePreferencesPersistor.js +0 -34
- package/esm2015/lib/persistor/implementation/LocalStoragePersistor.js +0 -52
- package/esm2015/lib/preferences.service.js +0 -147
|
@@ -4,202 +4,6 @@
|
|
|
4
4
|
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory((global.esfaenza = global.esfaenza || {}, global.esfaenza.preferences = {}), global.ng.core, global.rxjs, global.rxjs.operators));
|
|
5
5
|
})(this, (function (exports, core, rxjs, operators) { 'use strict';
|
|
6
6
|
|
|
7
|
-
/**
|
|
8
|
-
* Classe astratta che rappresenta lo stato di persistenza fra la libreria e uno storage
|
|
9
|
-
*/
|
|
10
|
-
var BasePreferencesPersistor = /** @class */ (function () {
|
|
11
|
-
/** @ignore Costruttore */
|
|
12
|
-
function BasePreferencesPersistor(session) {
|
|
13
|
-
this.session = session;
|
|
14
|
-
}
|
|
15
|
-
/**
|
|
16
|
-
* Effettua il **persist** massivo di una lista di Chiave - Valore
|
|
17
|
-
*
|
|
18
|
-
* @param {{ [key: string]: string }} dictionary Dizionario (lista di Chiave - Valore) da persistere
|
|
19
|
-
* @param {'cache' | 'preference'} storeLevel Livello a cui storicizzare l'oggetto. Utilizzare **cache** per cose salvate dall'applicazione, utilizzare **preference** per cose salvate dall'utente
|
|
20
|
-
*/
|
|
21
|
-
BasePreferencesPersistor.prototype.persistAll = function (dictionary, storeLevel) {
|
|
22
|
-
var observables = [];
|
|
23
|
-
for (var key in dictionary)
|
|
24
|
-
observables.push(this.persist(key, dictionary[key], storeLevel));
|
|
25
|
-
return rxjs.forkJoin(observables).pipe(operators.map(function (res) { return res.reduce(function (acc, val) { return acc && val; }, true); }));
|
|
26
|
-
};
|
|
27
|
-
/**
|
|
28
|
-
* Ottiene la chiave "Reale" da utilizzare per la persistenza di una chiave generica
|
|
29
|
-
*
|
|
30
|
-
* @param {string} key Chiave da storicizzare
|
|
31
|
-
*
|
|
32
|
-
* @returns {string} Unione fra l'identificativo della sessione e la chiave specificata
|
|
33
|
-
*/
|
|
34
|
-
BasePreferencesPersistor.prototype.getKey = function (key) {
|
|
35
|
-
return this.session.getSessionKey() + "§" + key + "§";
|
|
36
|
-
};
|
|
37
|
-
return BasePreferencesPersistor;
|
|
38
|
-
}());
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
* Indica se recuperare autonomamente tutte le configurazioni salvate al bootstrap della libreria o se aspettare le richieste specifiche.
|
|
42
|
-
*
|
|
43
|
-
* Utile se non vengono salvate tante cose, potrebbe creare un momento di irresponsività se le info da recuperare sono molte
|
|
44
|
-
*/
|
|
45
|
-
var PREF_FULL_RETRIEVE_AT_START = new core.InjectionToken('PREF_FULL_RETRIEVE_AT_START');
|
|
46
|
-
|
|
47
|
-
// Angular
|
|
48
|
-
/**
|
|
49
|
-
* Service che si occupa di salvare e recuperare le preferenze utente rispetto alle chiavi salvate
|
|
50
|
-
*/
|
|
51
|
-
var PreferencesService = /** @class */ (function () {
|
|
52
|
-
/**
|
|
53
|
-
* Costruttore
|
|
54
|
-
*
|
|
55
|
-
* @ignore
|
|
56
|
-
*/
|
|
57
|
-
function PreferencesService(persistor, PREF_FULL_RETRIEVE_AT_START) {
|
|
58
|
-
var _this = this;
|
|
59
|
-
this.persistor = persistor;
|
|
60
|
-
this.PREF_FULL_RETRIEVE_AT_START = PREF_FULL_RETRIEVE_AT_START;
|
|
61
|
-
/**
|
|
62
|
-
* Store in memoria delle preferenze locali che sarà persistito per mezzo della classe che fa le veci del **BasePreferencesPersistor**
|
|
63
|
-
*/
|
|
64
|
-
this.LocalPreferences = {};
|
|
65
|
-
/**
|
|
66
|
-
* Indica le chiavi contenute in **LocalPreferences** di che tipo sono in modo da ripulire correttamente sulla clear
|
|
67
|
-
*/
|
|
68
|
-
this.LocalPreferenceType = {};
|
|
69
|
-
if (this.PREF_FULL_RETRIEVE_AT_START) {
|
|
70
|
-
// Recupero tutti gli oggetti differenziando anche lato locale fra cache e preferences
|
|
71
|
-
rxjs.forkJoin([
|
|
72
|
-
this.persistor.recoverAll('cache').pipe(operators.take(1)),
|
|
73
|
-
this.persistor.recoverAll('preference').pipe(operators.take(1))
|
|
74
|
-
]).subscribe(function (res) {
|
|
75
|
-
for (var cProp in res[0]) {
|
|
76
|
-
_this.LocalPreferences[cProp] = res[0][cProp];
|
|
77
|
-
_this.LocalPreferenceType[cProp] = 'cache';
|
|
78
|
-
}
|
|
79
|
-
for (var pProp in res[1]) {
|
|
80
|
-
_this.LocalPreferences[pProp] = res[0][pProp];
|
|
81
|
-
_this.LocalPreferenceType[pProp] = 'preference';
|
|
82
|
-
}
|
|
83
|
-
});
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
/**
|
|
87
|
-
* Salva un oggetto sia nella cache locale che nel persistor
|
|
88
|
-
*
|
|
89
|
-
* @param {string} key Chiave di persistenza
|
|
90
|
-
* @param {T} item Oggetto da salvare
|
|
91
|
-
* @param {'cache' | 'preference'} storeLevel Livello a cui storicizzare l'oggetto. Utilizzare **cache** per cose salvate dall'applicazione, utilizzare **preference** per cose salvate dall'utente
|
|
92
|
-
*/
|
|
93
|
-
PreferencesService.prototype.setItem = function (key, item, storeLevel) {
|
|
94
|
-
if (storeLevel === void 0) { storeLevel = 'cache'; }
|
|
95
|
-
this.setLocalItem(key, item, storeLevel);
|
|
96
|
-
return this.persist(key, item, storeLevel);
|
|
97
|
-
};
|
|
98
|
-
/**
|
|
99
|
-
* Salva un oggetto solo nella cache locale. Dovrà essere persistito manualmente o andrà perso al riavvio dell'applicazione
|
|
100
|
-
*
|
|
101
|
-
* @param {string} key Chiave di persistenza
|
|
102
|
-
* @param {T} item Oggetto da salvare
|
|
103
|
-
* @param {'cache' | 'preference'} storeLevel Livello a cui storicizzare l'oggetto. Utilizzare **cache** per cose salvate dall'applicazione, utilizzare **preference** per cose salvate dall'utente
|
|
104
|
-
*/
|
|
105
|
-
PreferencesService.prototype.setLocalItem = function (key, item, storeLevel) {
|
|
106
|
-
if (storeLevel === void 0) { storeLevel = 'cache'; }
|
|
107
|
-
this.LocalPreferences[key] = item;
|
|
108
|
-
this.LocalPreferenceType[key] = storeLevel;
|
|
109
|
-
return true;
|
|
110
|
-
};
|
|
111
|
-
/**
|
|
112
|
-
* Salva, per una sessione, una chiave con un valore, viene chiamato automaticamente dal metodo **store** ma dev'essere chiamato manualmente
|
|
113
|
-
* nel caso si utilizzi il metodo **storeLocal**
|
|
114
|
-
*
|
|
115
|
-
* @param {string} key Chiave da storicizzare
|
|
116
|
-
* @param {'cache' | 'preference'} storeLevel Livello a cui storicizzare l'oggetto. Utilizzare **cache** per cose salvate dall'applicazione, utilizzare **preference** per cose salvate dall'utente
|
|
117
|
-
*/
|
|
118
|
-
PreferencesService.prototype.persist = function (key, item, storeLevel) {
|
|
119
|
-
return this.persistor.persist(key, item, storeLevel);
|
|
120
|
-
};
|
|
121
|
-
/**
|
|
122
|
-
* Recupera un oggetto in base a una chiave. Permette di accedere alla copia locale o alla copia persistita.
|
|
123
|
-
*
|
|
124
|
-
* @param {string} key Chiave del valore da recuperare
|
|
125
|
-
* @param {boolean} cacheBust Indica se ignorare il valore della cache locale e recuperare l'oggetto dallo store persistito,
|
|
126
|
-
* in caso fosse stato modificato fuori sistema o da un altro sistema
|
|
127
|
-
*
|
|
128
|
-
* @returns {T} Oggetto richiesto
|
|
129
|
-
*/
|
|
130
|
-
PreferencesService.prototype.getItem = function (key, cacheBust) {
|
|
131
|
-
var _this = this;
|
|
132
|
-
if (cacheBust === void 0) { cacheBust = false; }
|
|
133
|
-
if (this.LocalPreferences[key] && !cacheBust)
|
|
134
|
-
return rxjs.of(this.LocalPreferences[key]);
|
|
135
|
-
else {
|
|
136
|
-
var obj = this.persistor.recover(key);
|
|
137
|
-
if (!obj)
|
|
138
|
-
return rxjs.of(null);
|
|
139
|
-
obj.pipe(operators.tap(function (item) { _this.LocalPreferences[key] = item; }));
|
|
140
|
-
return obj;
|
|
141
|
-
}
|
|
142
|
-
};
|
|
143
|
-
/**
|
|
144
|
-
* Recupera un oggetto in base a una chiave. Permette di accedere solo alla copia locale
|
|
145
|
-
*
|
|
146
|
-
* @param {string} key Chiave del valore da recuperare
|
|
147
|
-
*
|
|
148
|
-
* @returns {T} Oggetto richiesto
|
|
149
|
-
*/
|
|
150
|
-
PreferencesService.prototype.getLocalItem = function (key) {
|
|
151
|
-
if (this.LocalPreferences[key])
|
|
152
|
-
return this.LocalPreferences[key];
|
|
153
|
-
else
|
|
154
|
-
return null;
|
|
155
|
-
};
|
|
156
|
-
/**
|
|
157
|
-
* Elimina un oggetto dalla cache sia locale che persistita
|
|
158
|
-
*
|
|
159
|
-
* @param {string} key Chiave da rimuovere
|
|
160
|
-
*/
|
|
161
|
-
PreferencesService.prototype.removeItem = function (key) {
|
|
162
|
-
if (this.LocalPreferences[key]) {
|
|
163
|
-
delete this.LocalPreferences[key];
|
|
164
|
-
delete this.LocalPreferenceType[key];
|
|
165
|
-
}
|
|
166
|
-
return this.persistor.remove(key);
|
|
167
|
-
};
|
|
168
|
-
/**
|
|
169
|
-
* Ripulisce le impostazioni locali e le impostazioni salvate dal persistor
|
|
170
|
-
*
|
|
171
|
-
* @param {'cache' | 'preference'} storeLevel Livello a cui ripulire la cache. Utilizzare **cache** per cancellare cose salvate dall'applicazione, utilizzare **preference** per cancellare cose salvate dall'utente
|
|
172
|
-
*/
|
|
173
|
-
PreferencesService.prototype.clear = function (storeLevel) {
|
|
174
|
-
// Pulisco la cache locale
|
|
175
|
-
for (var prop in this.LocalPreferenceType) {
|
|
176
|
-
if (this.LocalPreferenceType[prop] == storeLevel) {
|
|
177
|
-
delete this.LocalPreferenceType[prop];
|
|
178
|
-
delete this.LocalPreferences[prop];
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
// "Committo" le modifiche
|
|
182
|
-
return this.persistor.clear(storeLevel);
|
|
183
|
-
};
|
|
184
|
-
return PreferencesService;
|
|
185
|
-
}());
|
|
186
|
-
PreferencesService.decorators = [
|
|
187
|
-
{ type: core.Injectable }
|
|
188
|
-
];
|
|
189
|
-
PreferencesService.ctorParameters = function () { return [
|
|
190
|
-
{ type: BasePreferencesPersistor },
|
|
191
|
-
{ type: Boolean, decorators: [{ type: core.Optional }, { type: core.Inject, args: [PREF_FULL_RETRIEVE_AT_START,] }] }
|
|
192
|
-
]; };
|
|
193
|
-
|
|
194
|
-
/**
|
|
195
|
-
* Classe di Configurazione per la libreria
|
|
196
|
-
*/
|
|
197
|
-
var PreferencesModuleConfig = /** @class */ (function () {
|
|
198
|
-
function PreferencesModuleConfig() {
|
|
199
|
-
}
|
|
200
|
-
return PreferencesModuleConfig;
|
|
201
|
-
}());
|
|
202
|
-
|
|
203
7
|
/*! *****************************************************************************
|
|
204
8
|
Copyright (c) Microsoft Corporation.
|
|
205
9
|
|
|
@@ -512,6 +316,231 @@
|
|
|
512
316
|
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
513
317
|
}
|
|
514
318
|
|
|
319
|
+
/**
|
|
320
|
+
* Indica se recuperare autonomamente tutte le configurazioni salvate al bootstrap della libreria o se aspettare le richieste specifiche.
|
|
321
|
+
*
|
|
322
|
+
* Utile se non vengono salvate tante cose, potrebbe creare un momento di irresponsività se le info da recuperare sono molte
|
|
323
|
+
*/
|
|
324
|
+
var PREF_FULL_RETRIEVE_AT_START = new core.InjectionToken('PREF_FULL_RETRIEVE_AT_START');
|
|
325
|
+
|
|
326
|
+
// Angular
|
|
327
|
+
/**
|
|
328
|
+
* Service che si occupa di salvare e recuperare le preferenze utente rispetto alle chiavi salvate
|
|
329
|
+
*/
|
|
330
|
+
var BaseService = /** @class */ (function () {
|
|
331
|
+
/**
|
|
332
|
+
* Costruttore
|
|
333
|
+
*
|
|
334
|
+
* @ignore
|
|
335
|
+
*/
|
|
336
|
+
function BaseService(persistor, PREF_FULL_RETRIEVE_AT_START) {
|
|
337
|
+
var _this = this;
|
|
338
|
+
this.persistor = persistor;
|
|
339
|
+
this.PREF_FULL_RETRIEVE_AT_START = PREF_FULL_RETRIEVE_AT_START;
|
|
340
|
+
/** Store in memoria delle preferenze locali che sarà persistito per mezzo della classe che fa le veci del **BasePreferencesPersistor** */
|
|
341
|
+
this.LocalStore = {};
|
|
342
|
+
if (this.PREF_FULL_RETRIEVE_AT_START) {
|
|
343
|
+
this.persistor.recoverAll().pipe(operators.take(1)).subscribe(function (t) {
|
|
344
|
+
for (var cProp in t)
|
|
345
|
+
_this.LocalStore[cProp] = t[cProp];
|
|
346
|
+
});
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
/**
|
|
350
|
+
* Salva un oggetto sia nella cache locale che nel persistor
|
|
351
|
+
*
|
|
352
|
+
* @param {string} key Chiave di persistenza
|
|
353
|
+
* @param {T} item Oggetto da salvare
|
|
354
|
+
*/
|
|
355
|
+
BaseService.prototype.setItem = function (key, item) {
|
|
356
|
+
this.setLocalItem(key, item);
|
|
357
|
+
return this.persist(key, item);
|
|
358
|
+
};
|
|
359
|
+
/**
|
|
360
|
+
* Salva un oggetto solo nella cache locale. Dovrà essere persistito manualmente o andrà perso al riavvio dell'applicazione
|
|
361
|
+
*
|
|
362
|
+
* @param {string} key Chiave di persistenza
|
|
363
|
+
* @param {T} item Oggetto da salvare
|
|
364
|
+
*/
|
|
365
|
+
BaseService.prototype.setLocalItem = function (key, item) {
|
|
366
|
+
this.LocalStore[key] = item;
|
|
367
|
+
return true;
|
|
368
|
+
};
|
|
369
|
+
/**
|
|
370
|
+
* Salva, per una sessione, una chiave con un valore, viene chiamato automaticamente dal metodo **store** ma dev'essere chiamato manualmente
|
|
371
|
+
* nel caso si utilizzi il metodo **storeLocal**
|
|
372
|
+
*
|
|
373
|
+
* @param {string} key Chiave da storicizzare
|
|
374
|
+
*/
|
|
375
|
+
BaseService.prototype.persist = function (key, item) {
|
|
376
|
+
return this.persistor.persist(key, item);
|
|
377
|
+
};
|
|
378
|
+
/**
|
|
379
|
+
* Recupera un oggetto in base a una chiave. Permette di accedere alla copia locale o alla copia persistita.
|
|
380
|
+
*
|
|
381
|
+
* @param {string} key Chiave del valore da recuperare
|
|
382
|
+
* @param {boolean} cacheBust Indica se ignorare il valore della cache locale e recuperare l'oggetto dallo store persistito,
|
|
383
|
+
* in caso fosse stato modificato fuori sistema o da un altro sistema
|
|
384
|
+
*
|
|
385
|
+
* @returns {T} Oggetto richiesto
|
|
386
|
+
*/
|
|
387
|
+
BaseService.prototype.getItem = function (key, cacheBust) {
|
|
388
|
+
var _this = this;
|
|
389
|
+
if (cacheBust === void 0) { cacheBust = false; }
|
|
390
|
+
if (this.LocalStore[key] && !cacheBust)
|
|
391
|
+
return rxjs.of(this.LocalStore[key]);
|
|
392
|
+
else {
|
|
393
|
+
var obj = this.persistor.recover(key);
|
|
394
|
+
if (!obj)
|
|
395
|
+
return rxjs.of(null);
|
|
396
|
+
obj.pipe(operators.tap(function (item) { _this.LocalStore[key] = item; }));
|
|
397
|
+
return obj;
|
|
398
|
+
}
|
|
399
|
+
};
|
|
400
|
+
/**
|
|
401
|
+
* Recupera un oggetto in base a una chiave. Permette di accedere solo alla copia locale
|
|
402
|
+
*
|
|
403
|
+
* @param {string} key Chiave del valore da recuperare
|
|
404
|
+
*
|
|
405
|
+
* @returns {T} Oggetto richiesto
|
|
406
|
+
*/
|
|
407
|
+
BaseService.prototype.getLocalItem = function (key) {
|
|
408
|
+
if (this.LocalStore[key])
|
|
409
|
+
return this.LocalStore[key];
|
|
410
|
+
else
|
|
411
|
+
return null;
|
|
412
|
+
};
|
|
413
|
+
/**
|
|
414
|
+
* Elimina un oggetto dalla cache sia locale che persistita
|
|
415
|
+
*
|
|
416
|
+
* @param {string} key Chiave da rimuovere
|
|
417
|
+
*/
|
|
418
|
+
BaseService.prototype.removeItem = function (key) {
|
|
419
|
+
if (this.LocalStore[key])
|
|
420
|
+
delete this.LocalStore[key];
|
|
421
|
+
return this.persistor.remove(key);
|
|
422
|
+
};
|
|
423
|
+
/**
|
|
424
|
+
* Ripulisce le impostazioni locali e le impostazioni salvate dal persistor
|
|
425
|
+
*/
|
|
426
|
+
BaseService.prototype.clear = function () {
|
|
427
|
+
// Pulisco la cache locale
|
|
428
|
+
this.LocalStore = {};
|
|
429
|
+
// "Committo" le modifiche
|
|
430
|
+
return this.persistor.clear();
|
|
431
|
+
};
|
|
432
|
+
return BaseService;
|
|
433
|
+
}());
|
|
434
|
+
BaseService.ctorParameters = function () { return [
|
|
435
|
+
{ type: undefined },
|
|
436
|
+
{ type: Boolean, decorators: [{ type: core.Optional }, { type: core.Inject, args: [PREF_FULL_RETRIEVE_AT_START,] }] }
|
|
437
|
+
]; };
|
|
438
|
+
|
|
439
|
+
/** Classe astratta che rappresenta lo stato di persistenza fra la libreria e uno storage */
|
|
440
|
+
var CachePersistor = /** @class */ (function () {
|
|
441
|
+
/** @ignore Costruttore */
|
|
442
|
+
function CachePersistor(session) {
|
|
443
|
+
this.session = session;
|
|
444
|
+
}
|
|
445
|
+
/**
|
|
446
|
+
* Effettua il **persist** massivo di una lista di Chiave - Valore
|
|
447
|
+
*
|
|
448
|
+
* @param {{ [key: string]: string }} dictionary Dizionario (lista di Chiave - Valore) da persistere
|
|
449
|
+
*/
|
|
450
|
+
CachePersistor.prototype.persistAll = function (dictionary) {
|
|
451
|
+
var observables = [];
|
|
452
|
+
for (var key in dictionary)
|
|
453
|
+
observables.push(this.persist(key, dictionary[key]));
|
|
454
|
+
return rxjs.forkJoin(observables).pipe(operators.map(function (res) { return res.reduce(function (acc, val) { return acc && val; }, true); }));
|
|
455
|
+
};
|
|
456
|
+
/**
|
|
457
|
+
* Ottiene la chiave "Reale" da utilizzare per la persistenza di una chiave generica
|
|
458
|
+
*
|
|
459
|
+
* @param {string} key Chiave da storicizzare
|
|
460
|
+
*
|
|
461
|
+
* @returns {string} Unione fra l'identificativo della sessione e la chiave specificata
|
|
462
|
+
*/
|
|
463
|
+
CachePersistor.prototype.getKey = function (key) {
|
|
464
|
+
return this.session.getSessionKey() + "§" + key + "§";
|
|
465
|
+
};
|
|
466
|
+
return CachePersistor;
|
|
467
|
+
}());
|
|
468
|
+
|
|
469
|
+
/** Service che si occupa di salvare e recuperare le preferenze utente rispetto alle chiavi salvate */
|
|
470
|
+
var CacheService = /** @class */ (function (_super) {
|
|
471
|
+
__extends(CacheService, _super);
|
|
472
|
+
/** @ignore Costruttore */
|
|
473
|
+
function CacheService(persistor, PREF_FULL_RETRIEVE_AT_START) {
|
|
474
|
+
return _super.call(this, persistor, PREF_FULL_RETRIEVE_AT_START) || this;
|
|
475
|
+
}
|
|
476
|
+
return CacheService;
|
|
477
|
+
}(BaseService));
|
|
478
|
+
CacheService.decorators = [
|
|
479
|
+
{ type: core.Injectable }
|
|
480
|
+
];
|
|
481
|
+
CacheService.ctorParameters = function () { return [
|
|
482
|
+
{ type: CachePersistor },
|
|
483
|
+
{ type: Boolean, decorators: [{ type: core.Optional }, { type: core.Inject, args: [PREF_FULL_RETRIEVE_AT_START,] }] }
|
|
484
|
+
]; };
|
|
485
|
+
|
|
486
|
+
/**
|
|
487
|
+
* Classe astratta che rappresenta lo stato di persistenza fra la libreria e uno storage
|
|
488
|
+
*/
|
|
489
|
+
var PreferencesPersistor = /** @class */ (function () {
|
|
490
|
+
/** @ignore Costruttore */
|
|
491
|
+
function PreferencesPersistor(session) {
|
|
492
|
+
this.session = session;
|
|
493
|
+
}
|
|
494
|
+
/**
|
|
495
|
+
* Effettua il **persist** massivo di una lista di Chiave - Valore
|
|
496
|
+
*
|
|
497
|
+
* @param {{ [key: string]: string }} dictionary Dizionario (lista di Chiave - Valore) da persistere
|
|
498
|
+
*/
|
|
499
|
+
PreferencesPersistor.prototype.persistAll = function (dictionary) {
|
|
500
|
+
var observables = [];
|
|
501
|
+
for (var key in dictionary)
|
|
502
|
+
observables.push(this.persist(key, dictionary[key]));
|
|
503
|
+
return rxjs.forkJoin(observables).pipe(operators.map(function (res) { return res.reduce(function (acc, val) { return acc && val; }, true); }));
|
|
504
|
+
};
|
|
505
|
+
/**
|
|
506
|
+
* Ottiene la chiave "Reale" da utilizzare per la persistenza di una chiave generica
|
|
507
|
+
*
|
|
508
|
+
* @param {string} key Chiave da storicizzare
|
|
509
|
+
*
|
|
510
|
+
* @returns {string} Unione fra l'identificativo della sessione e la chiave specificata
|
|
511
|
+
*/
|
|
512
|
+
PreferencesPersistor.prototype.getKey = function (key) {
|
|
513
|
+
return this.session.getSessionKey() + "§" + key + "§";
|
|
514
|
+
};
|
|
515
|
+
return PreferencesPersistor;
|
|
516
|
+
}());
|
|
517
|
+
|
|
518
|
+
/** Service che si occupa di salvare e recuperare le preferenze utente rispetto alle chiavi salvate */
|
|
519
|
+
var PreferencesService = /** @class */ (function (_super) {
|
|
520
|
+
__extends(PreferencesService, _super);
|
|
521
|
+
/** @ignore Costruttore */
|
|
522
|
+
function PreferencesService(persistor, PREF_FULL_RETRIEVE_AT_START) {
|
|
523
|
+
return _super.call(this, persistor, PREF_FULL_RETRIEVE_AT_START) || this;
|
|
524
|
+
}
|
|
525
|
+
return PreferencesService;
|
|
526
|
+
}(BaseService));
|
|
527
|
+
PreferencesService.decorators = [
|
|
528
|
+
{ type: core.Injectable }
|
|
529
|
+
];
|
|
530
|
+
PreferencesService.ctorParameters = function () { return [
|
|
531
|
+
{ type: PreferencesPersistor },
|
|
532
|
+
{ type: Boolean, decorators: [{ type: core.Optional }, { type: core.Inject, args: [PREF_FULL_RETRIEVE_AT_START,] }] }
|
|
533
|
+
]; };
|
|
534
|
+
|
|
535
|
+
/**
|
|
536
|
+
* Classe di Configurazione per la libreria
|
|
537
|
+
*/
|
|
538
|
+
var PreferencesModuleConfig = /** @class */ (function () {
|
|
539
|
+
function PreferencesModuleConfig() {
|
|
540
|
+
}
|
|
541
|
+
return PreferencesModuleConfig;
|
|
542
|
+
}());
|
|
543
|
+
|
|
515
544
|
/**
|
|
516
545
|
* Classe astratta che si occupa di recuperare l'Id sessione univoco per applicazione ed utente collegato
|
|
517
546
|
*/
|
|
@@ -521,30 +550,56 @@
|
|
|
521
550
|
return BaseSessionRetriever;
|
|
522
551
|
}());
|
|
523
552
|
|
|
524
|
-
/**
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
553
|
+
/**
|
|
554
|
+
* Implementazione di default per la classe **BaseSessionRetriever**
|
|
555
|
+
*/
|
|
556
|
+
var DefaultSessionRetriever = /** @class */ (function (_super) {
|
|
557
|
+
__extends(DefaultSessionRetriever, _super);
|
|
558
|
+
/**
|
|
559
|
+
* Costruttore
|
|
560
|
+
*
|
|
561
|
+
* @ignore
|
|
562
|
+
*/
|
|
563
|
+
function DefaultSessionRetriever() {
|
|
564
|
+
return _super.call(this) || this;
|
|
565
|
+
}
|
|
566
|
+
/**
|
|
567
|
+
* Ottiene un ID sessione
|
|
568
|
+
*
|
|
569
|
+
* @returns {string} ID sessione
|
|
570
|
+
*/
|
|
571
|
+
DefaultSessionRetriever.prototype.getSessionKey = function () {
|
|
572
|
+
return "DUMMY_SESSION";
|
|
573
|
+
};
|
|
574
|
+
return DefaultSessionRetriever;
|
|
575
|
+
}(BaseSessionRetriever));
|
|
576
|
+
DefaultSessionRetriever.decorators = [
|
|
577
|
+
{ type: core.Injectable }
|
|
578
|
+
];
|
|
579
|
+
DefaultSessionRetriever.ctorParameters = function () { return []; };
|
|
580
|
+
|
|
581
|
+
var LocalStorageCachePersistor = /** @class */ (function (_super) {
|
|
582
|
+
__extends(LocalStorageCachePersistor, _super);
|
|
583
|
+
function LocalStorageCachePersistor(session) {
|
|
529
584
|
return _super.call(this, session) || this;
|
|
530
585
|
}
|
|
531
586
|
/** @ignore Vedi classe base */
|
|
532
|
-
|
|
587
|
+
LocalStorageCachePersistor.prototype.persist = function (key, item) {
|
|
533
588
|
localStorage.setItem(this.getKey(key), JSON.stringify(item));
|
|
534
589
|
return rxjs.of(true).pipe(operators.first());
|
|
535
590
|
};
|
|
536
591
|
/** @ignore Vedi classe base */
|
|
537
|
-
|
|
592
|
+
LocalStorageCachePersistor.prototype.recover = function (key) {
|
|
538
593
|
var ret = JSON.parse(localStorage.getItem(this.getKey(key)));
|
|
539
594
|
return rxjs.of(ret).pipe(operators.first());
|
|
540
595
|
};
|
|
541
596
|
/** @ignore Vedi classe base */
|
|
542
|
-
|
|
597
|
+
LocalStorageCachePersistor.prototype.remove = function (key) {
|
|
543
598
|
var ret = localStorage.removeItem(this.getKey(key));
|
|
544
599
|
return rxjs.of(true).pipe(operators.first());
|
|
545
600
|
};
|
|
546
601
|
/** @ignore Vedi classe base */
|
|
547
|
-
|
|
602
|
+
LocalStorageCachePersistor.prototype.recoverAll = function () {
|
|
548
603
|
var ret = {};
|
|
549
604
|
for (var k in localStorage) {
|
|
550
605
|
if (k.includes("§") && k.startsWith(this.session.getSessionKey()))
|
|
@@ -553,49 +608,67 @@
|
|
|
553
608
|
return rxjs.of(ret).pipe(operators.first());
|
|
554
609
|
};
|
|
555
610
|
/** @ignore Vedi classe base */
|
|
556
|
-
|
|
611
|
+
LocalStorageCachePersistor.prototype.clear = function () {
|
|
557
612
|
for (var k in localStorage) {
|
|
558
613
|
if (k.includes("§") && k.startsWith(this.session.getSessionKey()))
|
|
559
614
|
localStorage.removeItem(k);
|
|
560
615
|
}
|
|
561
616
|
return rxjs.of(true).pipe(operators.first());
|
|
562
617
|
};
|
|
563
|
-
return
|
|
564
|
-
}(
|
|
565
|
-
|
|
618
|
+
return LocalStorageCachePersistor;
|
|
619
|
+
}(CachePersistor));
|
|
620
|
+
LocalStorageCachePersistor.decorators = [
|
|
566
621
|
{ type: core.Injectable }
|
|
567
622
|
];
|
|
568
|
-
|
|
623
|
+
LocalStorageCachePersistor.ctorParameters = function () { return [
|
|
569
624
|
{ type: BaseSessionRetriever }
|
|
570
625
|
]; };
|
|
571
626
|
|
|
572
|
-
/**
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
__extends(DefaultSessionRetriever, _super);
|
|
577
|
-
/**
|
|
578
|
-
* Costruttore
|
|
579
|
-
*
|
|
580
|
-
* @ignore
|
|
581
|
-
*/
|
|
582
|
-
function DefaultSessionRetriever() {
|
|
583
|
-
return _super.call(this) || this;
|
|
627
|
+
var LocalStoragePreferencesPersistor = /** @class */ (function (_super) {
|
|
628
|
+
__extends(LocalStoragePreferencesPersistor, _super);
|
|
629
|
+
function LocalStoragePreferencesPersistor(session) {
|
|
630
|
+
return _super.call(this, session) || this;
|
|
584
631
|
}
|
|
585
|
-
/**
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
*/
|
|
590
|
-
DefaultSessionRetriever.prototype.getSessionKey = function () {
|
|
591
|
-
return "DUMMY_SESSION";
|
|
632
|
+
/** @ignore Vedi classe base */
|
|
633
|
+
LocalStoragePreferencesPersistor.prototype.persist = function (key, item) {
|
|
634
|
+
localStorage.setItem(this.getKey(key), JSON.stringify(item));
|
|
635
|
+
return rxjs.of(true).pipe(operators.first());
|
|
592
636
|
};
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
637
|
+
/** @ignore Vedi classe base */
|
|
638
|
+
LocalStoragePreferencesPersistor.prototype.recover = function (key) {
|
|
639
|
+
var ret = JSON.parse(localStorage.getItem(this.getKey(key)));
|
|
640
|
+
return rxjs.of(ret).pipe(operators.first());
|
|
641
|
+
};
|
|
642
|
+
/** @ignore Vedi classe base */
|
|
643
|
+
LocalStoragePreferencesPersistor.prototype.remove = function (key) {
|
|
644
|
+
var ret = localStorage.removeItem(this.getKey(key));
|
|
645
|
+
return rxjs.of(true).pipe(operators.first());
|
|
646
|
+
};
|
|
647
|
+
/** @ignore Vedi classe base */
|
|
648
|
+
LocalStoragePreferencesPersistor.prototype.recoverAll = function () {
|
|
649
|
+
var ret = {};
|
|
650
|
+
for (var k in localStorage) {
|
|
651
|
+
if (k.includes("§") && k.startsWith(this.session.getSessionKey()))
|
|
652
|
+
ret[k.match(/§(.*)§/)[1]] = JSON.parse(localStorage.getItem(k));
|
|
653
|
+
}
|
|
654
|
+
return rxjs.of(ret).pipe(operators.first());
|
|
655
|
+
};
|
|
656
|
+
/** @ignore Vedi classe base */
|
|
657
|
+
LocalStoragePreferencesPersistor.prototype.clear = function () {
|
|
658
|
+
for (var k in localStorage) {
|
|
659
|
+
if (k.includes("§") && k.startsWith(this.session.getSessionKey()))
|
|
660
|
+
localStorage.removeItem(k);
|
|
661
|
+
}
|
|
662
|
+
return rxjs.of(true).pipe(operators.first());
|
|
663
|
+
};
|
|
664
|
+
return LocalStoragePreferencesPersistor;
|
|
665
|
+
}(PreferencesPersistor));
|
|
666
|
+
LocalStoragePreferencesPersistor.decorators = [
|
|
596
667
|
{ type: core.Injectable }
|
|
597
668
|
];
|
|
598
|
-
|
|
669
|
+
LocalStoragePreferencesPersistor.ctorParameters = function () { return [
|
|
670
|
+
{ type: BaseSessionRetriever }
|
|
671
|
+
]; };
|
|
599
672
|
|
|
600
673
|
var PreferencesModule = /** @class */ (function () {
|
|
601
674
|
function PreferencesModule() {
|
|
@@ -604,8 +677,10 @@
|
|
|
604
677
|
return {
|
|
605
678
|
ngModule: PreferencesModule,
|
|
606
679
|
providers: [
|
|
680
|
+
CacheService,
|
|
607
681
|
PreferencesService,
|
|
608
|
-
{ provide:
|
|
682
|
+
{ provide: PreferencesPersistor, useClass: (config === null || config === void 0 ? void 0 : config.preferencePersistor) || LocalStoragePreferencesPersistor },
|
|
683
|
+
{ provide: CachePersistor, useClass: (config === null || config === void 0 ? void 0 : config.cachePersistor) || LocalStorageCachePersistor },
|
|
609
684
|
{ provide: BaseSessionRetriever, useClass: (config === null || config === void 0 ? void 0 : config.sessionRetriever) || DefaultSessionRetriever },
|
|
610
685
|
{ provide: PREF_FULL_RETRIEVE_AT_START, useValue: (config === null || config === void 0 ? void 0 : config.retrieveAllAtStart) || true }
|
|
611
686
|
]
|
|
@@ -621,14 +696,18 @@
|
|
|
621
696
|
* Generated bundle index. Do not edit.
|
|
622
697
|
*/
|
|
623
698
|
|
|
624
|
-
exports.BasePreferencesPersistor = BasePreferencesPersistor;
|
|
625
699
|
exports.BaseSessionRetriever = BaseSessionRetriever;
|
|
700
|
+
exports.CachePersistor = CachePersistor;
|
|
701
|
+
exports.CacheService = CacheService;
|
|
626
702
|
exports.PREF_FULL_RETRIEVE_AT_START = PREF_FULL_RETRIEVE_AT_START;
|
|
627
703
|
exports.PreferencesModule = PreferencesModule;
|
|
628
704
|
exports.PreferencesModuleConfig = PreferencesModuleConfig;
|
|
705
|
+
exports.PreferencesPersistor = PreferencesPersistor;
|
|
629
706
|
exports.PreferencesService = PreferencesService;
|
|
630
|
-
exports["ɵa"] =
|
|
631
|
-
exports["
|
|
707
|
+
exports["ɵa"] = BaseService;
|
|
708
|
+
exports["ɵc"] = LocalStoragePreferencesPersistor;
|
|
709
|
+
exports["ɵd"] = LocalStorageCachePersistor;
|
|
710
|
+
exports["ɵe"] = DefaultSessionRetriever;
|
|
632
711
|
|
|
633
712
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
634
713
|
|