@sumaris-net/ngx-components 1.4.3 → 1.5.0

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.
@@ -511,9 +511,7 @@
511
511
  return value.replace(/([a-z])([A-Z])/g, '$1_$2').toLowerCase();
512
512
  }
513
513
  function removeDiacritics(text) {
514
- return text.normalize('NFD')
515
- //
516
- .replace(/[\u0300-\u036f]/g, '');
514
+ return text.normalize('NFD').replace(/[\u0300-\u036f]/g, '');
517
515
  }
518
516
  function suggestFromArray(items, value, opts) {
519
517
  var _this = this;
@@ -1368,14 +1366,14 @@
1368
1366
  });
1369
1367
  Object.defineProperty(MatAutocompleteField.prototype, "disabled", {
1370
1368
  get: function () {
1371
- return this.readonly || this.formControl.disabled;
1369
+ return this._readonly || this.formControl.disabled;
1372
1370
  },
1373
1371
  enumerable: false,
1374
1372
  configurable: true
1375
1373
  });
1376
1374
  Object.defineProperty(MatAutocompleteField.prototype, "enabled", {
1377
1375
  get: function () {
1378
- return !this.readonly && this.formControl.enabled;
1376
+ return !this._readonly && this.formControl.enabled;
1379
1377
  },
1380
1378
  enumerable: false,
1381
1379
  configurable: true
@@ -1486,12 +1484,13 @@
1486
1484
  // Filter if not enough character
1487
1485
  operators.filter(function (value) { return value.length >= _this.suggestLengthThreshold; }),
1488
1486
  // Wait a debounce time
1489
- operators.debounceTime(this.debounceTime),
1487
+ operators.debounceTime(this.debounceTime)
1490
1488
  // DEBUG
1491
- operators.tap(function (value) { return console.debug(_this.logPrefix + ' Search text changes:', value); })),
1489
+ //tap((value) => console.debug(this.logPrefix + ' Search text changes:', value)),
1490
+ ),
1492
1491
  // Object set: use it (no distinctUntilChanged() pipe need)
1493
1492
  this.formControl.valueChanges
1494
- .pipe(operators.startWith(this.formControl.value), operators.filter(function (value) { return _this.searchable && (typeof value === 'object'); }), operators.tap(function (value) {
1493
+ .pipe(operators.startWith(this.formControl.value), operators.filter(function (value) { return (_this.searchable && isNotNil(value) && typeof value === 'object'); }), operators.tap(function (value) {
1495
1494
  // DEBUG
1496
1495
  //console.debug(this.logPrefix + ' object changes:', value)
1497
1496
  // Update the display value (if need)
@@ -1503,25 +1502,24 @@
1503
1502
  _this.matInputText.nativeElement.value = _this.displayValue;
1504
1503
  }
1505
1504
  }
1506
- }),
1505
+ })
1507
1506
  // DEBUG
1508
- operators.tap(function (value) { return console.debug(_this.logPrefix + ' Received an object value: ', value); })),
1507
+ //tap(value => console.debug(this.logPrefix + ' Received an object value: ', value))
1508
+ ),
1509
1509
  // Merge some observables, with a common distinctUntilChanged() pipe, and NO debounceTime
1510
1510
  rxjs.merge(
1511
1511
  // Focus or click => Load all
1512
1512
  rxjs.merge(this.onFocus, this.onClick)
1513
- .pipe(operators.filter(function (_) { return _this.searchable && _this.enabled; }), operators.map(function (_) { return _this.showAllOnFocus ? '*' : _this.formControl.value; })),
1513
+ .pipe(operators.filter(function (_) { return _this.enabled && _this.searchable; }), operators.map(function (_) { return _this.showAllOnFocus ? '*' : _this.formControl.value; })),
1514
1514
  // On dropdown button click
1515
1515
  this.onDropButtonClick
1516
- .pipe(operators.filter(function (event) { return _this.searchable && (!event || !event.defaultPrevented) && _this.formControl.enabled; }), operators.map(function (_) { return _this.showAllOnFocus ? '*' : _this.formControl.value; })), rxjs.merge(this.$inputItems, this._filter$)
1517
- .pipe(operators.map(function (_) { return _this.searchable && _this.formControl.value; })))
1516
+ .pipe(operators.filter(function (event) { return _this.enabled && _this.searchable && (!event || !event.defaultPrevented); }), operators.map(function (_) { return _this.showAllOnFocus ? '*' : _this.formControl.value; })), rxjs.merge(this.$inputItems, this._filter$)
1517
+ .pipe(operators.filter(function (event) { return _this.enabled && _this.searchable; }), operators.map(function (_) { return _this.formControl.value; })))
1518
1518
  .pipe(
1519
1519
  // If value is a string (and is not = '*'), filter if not enough character
1520
1520
  operators.filter(function (value) { return value === '*' || !(typeof value === 'string') || value.length >= _this.suggestLengthThreshold; }),
1521
1521
  // Distinguish changes
1522
- operators.distinctUntilChanged(),
1523
- // DEBUG
1524
- operators.tap(function (value) { return console.debug(_this.logPrefix + ' Received update event: ', value); })))
1522
+ operators.distinctUntilChanged()))
1525
1523
  .pipe(
1526
1524
  // Suggest values
1527
1525
  operators.mergeMap(function (value) { return _this.suggest(value, _this.filter); }),
@@ -1581,7 +1579,9 @@
1581
1579
  }));
1582
1580
  // Listen form control status change
1583
1581
  this._subscription.add(this.formControl.statusChanges
1584
- .pipe(operators.distinctUntilChanged())
1582
+ .pipe(
1583
+ //filter(() => this.enabled),
1584
+ operators.distinctUntilChanged())
1585
1585
  // Update component state
1586
1586
  .subscribe(function () { return _this.checkIfTouched(); }));
1587
1587
  this._subscription.add(this.onKeydownEscape.subscribe(function (event) {
@@ -1683,7 +1683,7 @@
1683
1683
  // If combo is empty, or if has content but should force to show panel on focus
1684
1684
  if (!hasContent || (this.showPanelOnFocus && this.showAllOnFocus)) {
1685
1685
  // DEBUG
1686
- console.debug(this.logPrefix + ' Emit focus event');
1686
+ //console.debug(this.logPrefix + ' Emit focus event');
1687
1687
  this.onFocus.emit(event);
1688
1688
  return true;
1689
1689
  }
@@ -10871,7 +10871,7 @@
10871
10871
  });
10872
10872
  };
10873
10873
  LocalSettingsService.prototype.setProperty = function (keyOrDef, value) {
10874
- if (!this._data)
10874
+ if (!this._data || !keyOrDef)
10875
10875
  return;
10876
10876
  if (typeof keyOrDef === 'object') {
10877
10877
  this.setProperty(keyOrDef.key, value);
@@ -10994,8 +10994,9 @@
10994
10994
  var feature = this._data.offlineFeatures.find(function (f) {
10995
10995
  if (typeof f === 'string')
10996
10996
  return f.toLowerCase().startsWith(featurePrefix);
10997
- if (typeof f === 'object' && f.name)
10997
+ if (f && typeof f === 'object' && f.name)
10998
10998
  return f.name === featureName;
10999
+ return false;
10999
11000
  });
11000
11001
  if (!feature)
11001
11002
  return; // Not found
@@ -11026,8 +11027,9 @@
11026
11027
  var existingIndex = this._data.offlineFeatures.findIndex(function (f) {
11027
11028
  if (typeof f === 'string')
11028
11029
  return f.toLowerCase().startsWith(featurePrefix);
11029
- if (typeof f === 'object' && f.name)
11030
+ if (f && typeof f === 'object' && f.name)
11030
11031
  return f.name === feature.name;
11032
+ return false;
11031
11033
  });
11032
11034
  if (existingIndex !== -1) {
11033
11035
  this._data.offlineFeatures[existingIndex] = feature;
@@ -12144,6 +12146,14 @@
12144
12146
  this._storageKey = ENTITIES_STORAGE_KEY_PREFIX + '#' + name;
12145
12147
  this._mapToLightEntity = this.createLightEntityMapFn(this.policy);
12146
12148
  }
12149
+ Object.defineProperty(EntityStore.prototype, "length", {
12150
+ get: function () {
12151
+ var _a;
12152
+ return ((_a = this._cache) === null || _a === void 0 ? void 0 : _a.length) || 0;
12153
+ },
12154
+ enumerable: false,
12155
+ configurable: true
12156
+ });
12147
12157
  Object.defineProperty(EntityStore.prototype, "cache", {
12148
12158
  get: function () {
12149
12159
  return this._cache;
@@ -12182,12 +12192,12 @@
12182
12192
  };
12183
12193
  EntityStore.prototype.load = function (id, opts) {
12184
12194
  return __awaiter(this, void 0, void 0, function () {
12185
- return __generator(this, function (_a) {
12186
- switch (_a.label) {
12195
+ return __generator(this, function (_b) {
12196
+ switch (_b.label) {
12187
12197
  case 0:
12188
12198
  if (!(this._mapToLightEntity && (!opts || opts.fullLoad !== false))) return [3 /*break*/, 2];
12189
12199
  return [4 /*yield*/, this.loadFullEntity(id, opts)];
12190
- case 1: return [2 /*return*/, _a.sent()];
12200
+ case 1: return [2 /*return*/, _b.sent()];
12191
12201
  case 2: return [2 /*return*/, this.loadCachedEntity(id, opts)];
12192
12202
  }
12193
12203
  });
@@ -12227,20 +12237,20 @@
12227
12237
  */
12228
12238
  EntityStore.prototype.loadAll = function (variables, opts) {
12229
12239
  return __awaiter(this, void 0, void 0, function () {
12230
- var res, _a;
12240
+ var res, _b;
12231
12241
  var _this = this;
12232
- return __generator(this, function (_b) {
12233
- switch (_b.label) {
12242
+ return __generator(this, function (_c) {
12243
+ switch (_c.label) {
12234
12244
  case 0:
12235
12245
  res = this.reduceAndSort(this._cache, variables);
12236
12246
  if (!(this._mapToLightEntity && isNotEmptyArray(res.data) && (opts && opts.fullLoad === true))) return [3 /*break*/, 2];
12237
12247
  // Load full entities, one by one
12238
- _a = res;
12248
+ _b = res;
12239
12249
  return [4 /*yield*/, chainPromises((res.data || []).map(function (e) { return function () { return _this.load(e.id); }; }))];
12240
12250
  case 1:
12241
12251
  // Load full entities, one by one
12242
- _a.data = _b.sent();
12243
- _b.label = 2;
12252
+ _b.data = _c.sent();
12253
+ _c.label = 2;
12244
12254
  case 2: return [2 /*return*/, res];
12245
12255
  }
12246
12256
  });
@@ -12357,8 +12367,8 @@
12357
12367
  return __awaiter(this, void 0, void 0, function () {
12358
12368
  var dirtyIndexes, entities;
12359
12369
  var _this = this;
12360
- return __generator(this, function (_a) {
12361
- switch (_a.label) {
12370
+ return __generator(this, function (_b) {
12371
+ switch (_b.label) {
12362
12372
  case 0:
12363
12373
  opts = Object.assign({ skipIfPristine: this.policy.skipNonLocalEntities }, opts);
12364
12374
  // Skip is not dirty
@@ -12382,7 +12392,7 @@
12382
12392
  return [4 /*yield*/, this.storage.remove(this._storageKey)];
12383
12393
  case 1:
12384
12394
  // Clean the local storage
12385
- _a.sent();
12395
+ _b.sent();
12386
12396
  return [3 /*break*/, 7];
12387
12397
  case 2:
12388
12398
  if (!this.isByIdMode) return [3 /*break*/, 5];
@@ -12390,7 +12400,7 @@
12390
12400
  return [4 /*yield*/, this.storage.set(this.storageKeyById, entities.filter(isNotNil).map(function (e) { return e.id; }))];
12391
12401
  case 3:
12392
12402
  // Save ids
12393
- _a.sent();
12403
+ _b.sent();
12394
12404
  // Saved dirty entities
12395
12405
  return [4 /*yield*/, Promise.all(dirtyIndexes
12396
12406
  .map(function (index) {
@@ -12400,15 +12410,15 @@
12400
12410
  }))];
12401
12411
  case 4:
12402
12412
  // Saved dirty entities
12403
- _a.sent();
12413
+ _b.sent();
12404
12414
  console.info("[entity-storage] Persisting " + dirtyIndexes.length + "/" + entities.length + " " + this.name + "(s)...");
12405
12415
  return [3 /*break*/, 7];
12406
12416
  case 5:
12407
12417
  console.info("[entity-storage] Persisting " + entities.length + " " + this.name + "(s)...");
12408
12418
  return [4 /*yield*/, this.storage.set(this._storageKey, entities)];
12409
12419
  case 6:
12410
- _a.sent();
12411
- _a.label = 7;
12420
+ _b.sent();
12421
+ _b.label = 7;
12412
12422
  case 7: return [2 /*return*/, entities.length];
12413
12423
  }
12414
12424
  });
@@ -12418,14 +12428,14 @@
12418
12428
  return __awaiter(this, void 0, void 0, function () {
12419
12429
  var entities, res, values, ids, migration, oldKeysToClean, storageKeys, storageKeys, err_1;
12420
12430
  var _this = this;
12421
- return __generator(this, function (_a) {
12422
- switch (_a.label) {
12431
+ return __generator(this, function (_b) {
12432
+ switch (_b.label) {
12423
12433
  case 0: return [4 /*yield*/, Promise.all([
12424
12434
  this.storage.get(this._storageKey),
12425
12435
  this.storage.get(this.storageKeyById)
12426
12436
  ])];
12427
12437
  case 1:
12428
- res = _a.sent();
12438
+ res = _b.sent();
12429
12439
  values = res[0] && Array.isArray(res[0]) ? res[0] : null;
12430
12440
  ids = res[1] && Array.isArray(res[1]) ? res[1] : null;
12431
12441
  migration = false;
@@ -12434,7 +12444,7 @@
12434
12444
  storageKeys = ids.map(function (id) { return _this._storageKey + '#' + id; });
12435
12445
  return [4 /*yield*/, chainPromises(storageKeys.map(function (key) { return function () { return _this.storage.get(key); }; }))];
12436
12446
  case 2:
12437
- entities = _a.sent();
12447
+ entities = _b.sent();
12438
12448
  return [3 /*break*/, 4];
12439
12449
  case 3:
12440
12450
  if (isNotNil(values)) {
@@ -12442,7 +12452,7 @@
12442
12452
  migration = true;
12443
12453
  oldKeysToClean = [this._storageKey];
12444
12454
  }
12445
- _a.label = 4;
12455
+ _b.label = 4;
12446
12456
  case 4: return [3 /*break*/, 8];
12447
12457
  case 5:
12448
12458
  if (!isNotNil(values)) return [3 /*break*/, 6];
@@ -12454,10 +12464,10 @@
12454
12464
  return [4 /*yield*/, chainPromises(storageKeys.map(function (key) { return function () { return _this.storage.get(key); }; }))];
12455
12465
  case 7:
12456
12466
  // Load entity by id (one by one)
12457
- entities = _a.sent();
12467
+ entities = _b.sent();
12458
12468
  migration = true;
12459
12469
  oldKeysToClean = __spread(storageKeys, [this.storageKeyById]);
12460
- _a.label = 8;
12470
+ _b.label = 8;
12461
12471
  case 8:
12462
12472
  // OK, there is something in storage...
12463
12473
  if (isNotEmptyArray(entities)) {
@@ -12472,23 +12482,23 @@
12472
12482
  this.setEntities(entities || [], Object.assign(Object.assign({}, opts), { emitEvent: false }));
12473
12483
  this._dirty = false;
12474
12484
  if (!migration) return [3 /*break*/, 14];
12475
- _a.label = 9;
12485
+ _b.label = 9;
12476
12486
  case 9:
12477
- _a.trys.push([9, 13, , 14]);
12487
+ _b.trys.push([9, 13, , 14]);
12478
12488
  console.warn("[entity-storage] - Migrate " + this.name + " into {mode: '" + this.policy.mode + "'}...");
12479
12489
  // Force to persist, using the new mode
12480
12490
  return [4 /*yield*/, this.persist({ skipIfPristine: false /* force persist using the new mode */ })];
12481
12491
  case 10:
12482
12492
  // Force to persist, using the new mode
12483
- _a.sent();
12493
+ _b.sent();
12484
12494
  if (!isNotEmptyArray(oldKeysToClean)) return [3 /*break*/, 12];
12485
12495
  return [4 /*yield*/, chainPromises(oldKeysToClean.map(function (key) { return function () { return _this.storage.remove(key); }; }))];
12486
12496
  case 11:
12487
- _a.sent();
12488
- _a.label = 12;
12497
+ _b.sent();
12498
+ _b.label = 12;
12489
12499
  case 12: return [3 /*break*/, 14];
12490
12500
  case 13:
12491
- err_1 = _a.sent();
12501
+ err_1 = _b.sent();
12492
12502
  console.error(err_1);
12493
12503
  throw { code: ErrorCodes$2.ENTITY_STORAGE_MIGRATION_FAILED, message: 'ERROR.ENTITY_STORAGE_MIGRATION_FAILED', details: err_1 };
12494
12504
  case 14:
@@ -12509,10 +12519,10 @@
12509
12519
  }
12510
12520
  };
12511
12521
  EntityStore.prototype.markAsPristine = function (opts) {
12512
- var e_1, _a;
12522
+ var e_1, _b;
12513
12523
  try {
12514
- for (var _b = __values(this._statusById.values()), _c = _b.next(); !_c.done; _c = _b.next()) {
12515
- var s = _c.value;
12524
+ for (var _c = __values(this._statusById.values()), _d = _c.next(); !_d.done; _d = _c.next()) {
12525
+ var s = _d.value;
12516
12526
  if (isNotNil(s)) {
12517
12527
  s.dirty = false;
12518
12528
  }
@@ -12521,7 +12531,7 @@
12521
12531
  catch (e_1_1) { e_1 = { error: e_1_1 }; }
12522
12532
  finally {
12523
12533
  try {
12524
- if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
12534
+ if (_d && !_d.done && (_b = _c.return)) _b.call(_c);
12525
12535
  }
12526
12536
  finally { if (e_1) throw e_1.error; }
12527
12537
  }
@@ -12542,8 +12552,8 @@
12542
12552
  EntityStore.prototype.loadFullEntity = function (id, opts) {
12543
12553
  return __awaiter(this, void 0, void 0, function () {
12544
12554
  var status, index, fullData;
12545
- return __generator(this, function (_a) {
12546
- switch (_a.label) {
12555
+ return __generator(this, function (_b) {
12556
+ switch (_b.label) {
12547
12557
  case 0:
12548
12558
  status = this._statusById.get(id);
12549
12559
  index = status && status.index;
@@ -12553,10 +12563,10 @@
12553
12563
  console.debug("[entity-storage] Full reloading " + this.name + "#" + id + "...");
12554
12564
  return [4 /*yield*/, this.storage.get(this._storageKey + '#' + id)];
12555
12565
  case 1:
12556
- fullData = _a.sent();
12566
+ fullData = _b.sent();
12557
12567
  if (fullData)
12558
12568
  return [2 /*return*/, fullData];
12559
- _a.label = 2;
12569
+ _b.label = 2;
12560
12570
  case 2:
12561
12571
  // Load from the cache, if dirty OR if storage is not splited by id
12562
12572
  return [2 /*return*/, this._cache[index]];
@@ -13223,11 +13233,17 @@
13223
13233
  console.warn("[entities-storage] Persisting " + entityName + ": store not found!");
13224
13234
  return;
13225
13235
  }
13226
- return entityStore.persist()
13236
+ // SKip store if not dirty
13237
+ if (!entityStore.dirty)
13238
+ return Promise.resolve(); // Skip
13239
+ // Persist store
13240
+ return (entityStore.dirty ? entityStore.persist() : Promise.resolve(entityStore.length))
13227
13241
  .then(function (count) {
13228
13242
  // If no entity found, remove from the entity names array
13229
13243
  if (!count) {
13230
- entityNames.splice(entityNames.findIndex(function (e) { return e === entityName; }), 1);
13244
+ var entityNameIndex = entityNames.findIndex(function (e) { return e === entityName; });
13245
+ if (entityNameIndex !== -1)
13246
+ entityNames.splice(entityNameIndex, 1);
13231
13247
  }
13232
13248
  });
13233
13249
  }; }))