@sumaris-net/ngx-components 0.18.15 → 0.18.16

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.
@@ -8689,6 +8689,7 @@
8689
8689
  return !obj || obj[checkedAttribute] === null || obj[checkedAttribute] === undefined;
8690
8690
  };
8691
8691
  EntityUtils.equals = function (o1, o2, checkAttribute) {
8692
+ checkAttribute = checkAttribute || 'id';
8692
8693
  return (o1 === o2) || (isNil(o1) && isNil(o2)) || (o1 && o2 && o1[checkAttribute] === o2[checkAttribute]);
8693
8694
  };
8694
8695
  EntityUtils.getPropertyByPath = function (obj, path) {
@@ -16460,10 +16461,8 @@
16460
16461
  return __generator(this, function (_a) {
16461
16462
  if (!this.data)
16462
16463
  throw new Error('[memory-service] Could not delete, because value not set');
16463
- if (!this._equalsFn)
16464
- throw new Error("[memory-service] Could not delete, because no 'options.equals' has been set in the memory service");
16465
16464
  updatedData = this.data.filter(function (entity) {
16466
- var removed = dataToRemove.findIndex(function (entityToRemove) { return _this._equalsFn(entityToRemove, entity); }) !== -1;
16465
+ var removed = dataToRemove.findIndex(function (entityToRemove) { return _this.equals(entityToRemove, entity); }) !== -1;
16467
16466
  return !removed;
16468
16467
  });
16469
16468
  deleteCount = this.data.length - updatedData.length;
@@ -16488,6 +16487,11 @@
16488
16487
  InMemoryEntitiesService.prototype.addSortByReplacement = function (source, target) {
16489
16488
  this._sortByReplacement[source] = target;
16490
16489
  };
16490
+ InMemoryEntitiesService.prototype.equals = function (d1, d2) {
16491
+ if (this._equalsFn)
16492
+ return this._equalsFn(d1, d2);
16493
+ return d1 && d1.equals ? d1.equals(d2) : EntityUtils.equals(d1, d2, 'id');
16494
+ };
16491
16495
  /* -- protected methods -- */
16492
16496
  InMemoryEntitiesService.prototype.filter = function (data, _filter, hiddenData) {
16493
16497
  // if filter is DataFilter instance, use its test function
@@ -16513,9 +16517,6 @@
16513
16517
  return { data: data, total: total };
16514
16518
  }));
16515
16519
  };
16516
- InMemoryEntitiesService.prototype.equals = function (d1, d2) {
16517
- return d1 && d1.equals ? d1.equals(d2) : EntityUtils.equals(d1, d2, 'id');
16518
- };
16519
16520
  InMemoryEntitiesService.prototype.markAsSaving = function () {
16520
16521
  this._saving = true;
16521
16522
  };
@@ -23071,7 +23072,7 @@
23071
23072
  }
23072
23073
  };
23073
23074
  AppTable.prototype.markAsUntouched = function (opts) {
23074
- if (this.dirtySubject.value !== false || (this.editedRow && this.editedRow.id !== this.previouslySavedEditedRowId)) {
23075
+ if (this.dirtySubject.value !== false || (this.editedRow && this.editedRow.id !== this.previouslyEditedRowId)) {
23075
23076
  // Cancel the current editing row only if editing and if it was not previously saved
23076
23077
  this.dirtySubject.next(false);
23077
23078
  if (this.editedRow && this.editedRow.editing) {
@@ -23082,7 +23083,7 @@
23082
23083
  this.markForCheck();
23083
23084
  }
23084
23085
  }
23085
- this.previouslySavedEditedRowId = undefined;
23086
+ this.previouslyEditedRowId = undefined;
23086
23087
  };
23087
23088
  /**
23088
23089
  * @deprecated prefer to use markAllAsTouched()
@@ -23548,7 +23549,7 @@
23548
23549
  AppTable.prototype.save = function (opts) {
23549
23550
  var _a, _b;
23550
23551
  return __awaiter(this, void 0, void 0, function () {
23551
- var isOK, err_1;
23552
+ var previouslyEditedData, isOK, err_1;
23552
23553
  return __generator(this, function (_d) {
23553
23554
  switch (_d.label) {
23554
23555
  case 0:
@@ -23558,7 +23559,8 @@
23558
23559
  }
23559
23560
  this.resetError();
23560
23561
  // Keep edited row id (should be done BEFORE confirmEditCreate() )
23561
- this.previouslySavedEditedRowId = opts.keepEditing && ((_a = this.editedRow) === null || _a === void 0 ? void 0 : _a.editing) ? this.editedRow.id : undefined;
23562
+ this.previouslyEditedRowId = opts.keepEditing && ((_a = this.editedRow) === null || _a === void 0 ? void 0 : _a.editing) ? this.editedRow.id : undefined;
23563
+ previouslyEditedData = isNotNil(this.previouslyEditedRowId) && this.editedRow.currentData || ((_b = this.singleSelectedRow) === null || _b === void 0 ? void 0 : _b.currentData);
23562
23564
  if (!this.confirmEditCreate()) {
23563
23565
  throw { code: ErrorCodes$2.TABLE_INVALID_ROW_ERROR, message: 'ERROR.TABLE_INVALID_ROW_ERROR' };
23564
23566
  }
@@ -23566,7 +23568,7 @@
23566
23568
  this.markAsSaving();
23567
23569
  _d.label = 1;
23568
23570
  case 1:
23569
- _d.trys.push([1, 3, 4, 5]);
23571
+ _d.trys.push([1, 3, 4, 7]);
23570
23572
  // Calling service save()
23571
23573
  if (this.debug)
23572
23574
  console.debug('[table] Calling dataSource.save()...');
@@ -23582,18 +23584,13 @@
23582
23584
  throw err_1;
23583
23585
  case 4:
23584
23586
  this.markAsSaved();
23585
- // Restoring previous row
23586
- if (isNotNil(this.previouslySavedEditedRowId)) {
23587
- if (this.previouslySavedEditedRowId !== -1) {
23588
- // Select by row id
23589
- this.selectRowById(this.previouslySavedEditedRowId);
23590
- }
23591
- else {
23592
- this.selectRowByData((_b = this.singleSelectedRow) === null || _b === void 0 ? void 0 : _b.currentData);
23593
- }
23594
- }
23595
- return [7 /*endfinally*/];
23596
- case 5: return [2 /*return*/];
23587
+ if (!isNotNil(this.previouslyEditedRowId)) return [3 /*break*/, 6];
23588
+ return [4 /*yield*/, this.selectRowByIdOrData(this.previouslyEditedRowId, previouslyEditedData)];
23589
+ case 5:
23590
+ _d.sent();
23591
+ _d.label = 6;
23592
+ case 6: return [7 /*endfinally*/];
23593
+ case 7: return [2 /*return*/];
23597
23594
  }
23598
23595
  });
23599
23596
  });
@@ -23777,39 +23774,26 @@
23777
23774
  });
23778
23775
  });
23779
23776
  };
23780
- AppTable.prototype.editRow = function (event, row, opts) {
23781
- if (!this._enabled)
23782
- return false;
23783
- if (this.editedRow === row)
23784
- return true; // Already the edited row
23785
- if (event === null || event === void 0 ? void 0 : event.defaultPrevented)
23786
- return false;
23787
- if (!this.confirmEditCreate()) {
23788
- return false;
23789
- }
23790
- if (!row.editing && !this.loading) {
23791
- this._focusColumn = opts && opts.focusColumn || this._focusColumn;
23792
- this._dataSource.startEdit(row);
23793
- }
23794
- this.editedRow = row;
23795
- this.onStartEditingRow.emit(row);
23796
- return true;
23797
- };
23798
23777
  AppTable.prototype.selectRowById = function (id) {
23799
23778
  var _this = this;
23800
23779
  if (id === undefined)
23801
- return;
23802
- this.dataSource.waitIdle()
23780
+ return Promise.resolve(false);
23781
+ return this.dataSource.waitIdle()
23803
23782
  .then(function () { return _this.dataSource.getRow(id); })
23804
- .then(function (row) { return _this.clickRow(null, row); });
23783
+ .then(function (row) { return row && _this.clickRow(null, row); });
23805
23784
  };
23785
+ /**
23786
+ * Try to select row by data. Will use dataEquals() (that call EntityUtils.equals()) to find same row's data
23787
+ * @param data
23788
+ */
23806
23789
  AppTable.prototype.selectRowByData = function (data) {
23807
23790
  var _this = this;
23808
23791
  if (data === undefined)
23809
- return;
23810
- this.dataSource.waitIdle()
23792
+ return Promise.resolve(false);
23793
+ return this.dataSource.waitIdle()
23811
23794
  .then(function () { return _this.dataSource.getRows(); })
23812
- .then(function (rows) { var _a; return _this.selectRowById((_a = rows.find(function (row) { return _this.dataEquals(row.currentData, data); })) === null || _a === void 0 ? void 0 : _a.id); });
23795
+ .then(function (rows) { return rows.find(function (row) { return _this.equals(row.currentData, data); }); })
23796
+ .then(function (row) { return row && _this.clickRow(null, row); });
23813
23797
  };
23814
23798
  AppTable.prototype.clickRow = function (event, row) {
23815
23799
  var _this = this;
@@ -23827,8 +23811,6 @@
23827
23811
  return true; // Already in edition
23828
23812
  if (event === null || event === void 0 ? void 0 : event.defaultPrevented)
23829
23813
  return false; // Cancelled by event
23830
- if (this.loading)
23831
- return false; // Already busy
23832
23814
  // Open the detail page (if not inline editing)
23833
23815
  if (!this.inlineEdition) {
23834
23816
  if (this.dirty && this.debug) {
@@ -23841,10 +23823,10 @@
23841
23823
  // No ID defined: unable to open details
23842
23824
  if (isNil(row.currentData.id)) {
23843
23825
  console.warn('[table] Opening row details, but missing currentData.id!');
23844
- //return false;
23826
+ return false;
23845
23827
  }
23846
23828
  this.markAsLoading();
23847
- this.openRow(row.currentData.id, row)
23829
+ this.openRowDetail(row.currentData.id, row)
23848
23830
  .then(function () { return _this.markAsLoaded(); });
23849
23831
  return true;
23850
23832
  }
@@ -23955,8 +23937,70 @@
23955
23937
  }
23956
23938
  }
23957
23939
  };
23940
+ /* -- protected method -- */
23941
+ AppTable.prototype.editRow = function (event, row, opts) {
23942
+ if (!this._enabled)
23943
+ return false;
23944
+ if (this.editedRow === row)
23945
+ return true; // Already the edited row
23946
+ if (event === null || event === void 0 ? void 0 : event.defaultPrevented)
23947
+ return false;
23948
+ if (!this.confirmEditCreate()) {
23949
+ return false;
23950
+ }
23951
+ if (!row.editing && !this.loading) {
23952
+ this._focusColumn = opts && opts.focusColumn || this._focusColumn;
23953
+ this._dataSource.startEdit(row);
23954
+ }
23955
+ this.editedRow = row;
23956
+ this.onStartEditingRow.emit(row);
23957
+ return true;
23958
+ };
23959
+ /**
23960
+ * Try to select row, by row.id, or by data. WIll use EntityUtils.equals()
23961
+ * @param id
23962
+ * @param data
23963
+ * @protected
23964
+ */
23965
+ AppTable.prototype.selectRowByIdOrData = function (id, data) {
23966
+ return __awaiter(this, void 0, void 0, function () {
23967
+ var done, err_3;
23968
+ return __generator(this, function (_d) {
23969
+ switch (_d.label) {
23970
+ case 0:
23971
+ done = false;
23972
+ _d.label = 1;
23973
+ case 1:
23974
+ _d.trys.push([1, 6, , 7]);
23975
+ if (!(isNotNil(id) || id !== -1)) return [3 /*break*/, 3];
23976
+ return [4 /*yield*/, this.selectRowById(id)];
23977
+ case 2:
23978
+ done = _d.sent();
23979
+ if (done)
23980
+ return [2 /*return*/, true];
23981
+ console.warn('[app-table] Save: Cannot reselect row by row.id: ', id);
23982
+ _d.label = 3;
23983
+ case 3:
23984
+ if (!data) return [3 /*break*/, 5];
23985
+ return [4 /*yield*/, this.selectRowByData(data)];
23986
+ case 4:
23987
+ done = _d.sent();
23988
+ if (done)
23989
+ return [2 /*return*/, true];
23990
+ console.warn('[app-table] Save: Cannot reselect row by data: ', data);
23991
+ _d.label = 5;
23992
+ case 5: return [2 /*return*/, false];
23993
+ case 6:
23994
+ err_3 = _d.sent();
23995
+ // Log, but continue
23996
+ console.error(err_3 && err_3.message || err_3);
23997
+ return [2 /*return*/, false];
23998
+ case 7: return [2 /*return*/];
23999
+ }
24000
+ });
24001
+ });
24002
+ };
23958
24003
  Object.defineProperty(AppTable.prototype, "singleSelectedRow", {
23959
- /* -- protected method -- */
23960
24004
  /**
23961
24005
  * return the selected row if unique in selection
23962
24006
  */
@@ -23969,7 +24013,7 @@
23969
24013
  });
23970
24014
  AppTable.prototype.canDeleteRows = function (rows, opts) {
23971
24015
  return __awaiter(this, void 0, void 0, function () {
23972
- var canDelete, err_3;
24016
+ var canDelete, err_4;
23973
24017
  return __generator(this, function (_d) {
23974
24018
  switch (_d.label) {
23975
24019
  case 0:
@@ -23986,11 +24030,11 @@
23986
24030
  return [2 /*return*/, false];
23987
24031
  return [3 /*break*/, 4];
23988
24032
  case 3:
23989
- err_3 = _d.sent();
23990
- if (err_3 === 'CANCELLED')
24033
+ err_4 = _d.sent();
24034
+ if (err_4 === 'CANCELLED')
23991
24035
  return [2 /*return*/, false]; // User cancel
23992
- console.error('Error while checking if can delete rows', err_3);
23993
- throw err_3;
24036
+ console.error('Error while checking if can delete rows', err_4);
24037
+ throw err_4;
23994
24038
  case 4:
23995
24039
  // Ask user confirmation
23996
24040
  if (this.confirmBeforeDelete && (!opts || opts.interactive !== false)) {
@@ -24003,7 +24047,7 @@
24003
24047
  };
24004
24048
  AppTable.prototype.canCancelRows = function (rows, opts) {
24005
24049
  return __awaiter(this, void 0, void 0, function () {
24006
- var _d, isCancel, err_4;
24050
+ var _d, isCancel, err_5;
24007
24051
  return __generator(this, function (_e) {
24008
24052
  switch (_e.label) {
24009
24053
  case 0:
@@ -24031,11 +24075,11 @@
24031
24075
  return [2 /*return*/, false];
24032
24076
  return [3 /*break*/, 6];
24033
24077
  case 5:
24034
- err_4 = _e.sent();
24035
- if (err_4 === 'CANCELLED')
24078
+ err_5 = _e.sent();
24079
+ if (err_5 === 'CANCELLED')
24036
24080
  return [2 /*return*/, false]; // User cancel
24037
- console.error('Error while checking if can cancel rows', err_4);
24038
- throw err_4;
24081
+ console.error('Error while checking if can cancel rows', err_5);
24082
+ throw err_5;
24039
24083
  case 6:
24040
24084
  // Ask user confirmation
24041
24085
  if (this.confirmBeforeCancel && (!opts || opts.interactive !== false)) {
@@ -24048,7 +24092,7 @@
24048
24092
  };
24049
24093
  AppTable.prototype.saveBeforeAction = function (saveAction) {
24050
24094
  return __awaiter(this, void 0, void 0, function () {
24051
- var save, confirmed, res, err_5, saved;
24095
+ var save, confirmed, res, err_6, saved;
24052
24096
  return __generator(this, function (_d) {
24053
24097
  switch (_d.label) {
24054
24098
  case 0:
@@ -24084,11 +24128,11 @@
24084
24128
  save = res.save;
24085
24129
  return [3 /*break*/, 4];
24086
24130
  case 3:
24087
- err_5 = _d.sent();
24088
- if (err_5 === 'CANCELLED')
24131
+ err_6 = _d.sent();
24132
+ if (err_6 === 'CANCELLED')
24089
24133
  return [2 /*return*/, false]; // User cancel
24090
- console.error('Error while checking if can delete rows', err_5);
24091
- throw err_5;
24134
+ console.error('Error while checking if can delete rows', err_6);
24135
+ throw err_6;
24092
24136
  case 4:
24093
24137
  if (!confirmed) return [3 /*break*/, 7];
24094
24138
  if (!save) return [3 /*break*/, 6];
@@ -24103,7 +24147,7 @@
24103
24147
  });
24104
24148
  });
24105
24149
  };
24106
- AppTable.prototype.openRow = function (id, row) {
24150
+ AppTable.prototype.openRowDetail = function (id, row) {
24107
24151
  return __awaiter(this, void 0, void 0, function () {
24108
24152
  return __generator(this, function (_d) {
24109
24153
  switch (_d.label) {
@@ -24374,12 +24418,12 @@
24374
24418
  * Compare data equality (default by id)
24375
24419
  * Can be overridden to add additional properties to compare
24376
24420
  *
24377
- * @param t1
24378
- * @param t2
24421
+ * @param d1
24422
+ * @param d2
24379
24423
  * @protected
24380
24424
  */
24381
- AppTable.prototype.dataEquals = function (t1, t2) {
24382
- return EntityUtils.equals(t1, t2, 'id');
24425
+ AppTable.prototype.equals = function (d1, d2) {
24426
+ return EntityUtils.equals(d1, d2, 'id');
24383
24427
  };
24384
24428
  /* -- private method -- */
24385
24429
  AppTable.prototype.setLoading = function (value, opts) {
@@ -26068,6 +26112,9 @@
26068
26112
  this.onRefresh.emit();
26069
26113
  }
26070
26114
  };
26115
+ AppInMemoryTable.prototype.equals = function (t1, t2) {
26116
+ return this.memoryDataService.equals(t1, t2);
26117
+ };
26071
26118
  return AppInMemoryTable;
26072
26119
  }(AppTable));
26073
26120
  AppInMemoryTable.decorators = [