@sumaris-net/ngx-components 1.12.4 → 1.12.5

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.
@@ -21924,9 +21924,15 @@ class AppTable {
21924
21924
  return false;
21925
21925
  }
21926
21926
  cancelOrDelete(event, row, opts) {
21927
+ // Delete new row
21927
21928
  if (row.id === -1) {
21928
21929
  this.deleteNewRow(event, row);
21929
21930
  }
21931
+ // Delete existing (bu not editing) row
21932
+ else if (!row.editing) {
21933
+ this.deleteExistingRow(event, row, opts);
21934
+ }
21935
+ // Cancel existing (and editing) row
21930
21936
  else {
21931
21937
  this.cancelExistingRow(event, row, opts);
21932
21938
  }
@@ -22083,10 +22089,12 @@ class AppTable {
22083
22089
  if (event === null || event === void 0 ? void 0 : event.defaultPrevented)
22084
22090
  return 0; // SKip
22085
22091
  event === null || event === void 0 ? void 0 : event.preventDefault();
22086
- if (!this._enabled)
22087
- return 0;
22088
- if (this.loading || isEmptyArray(rows))
22089
- return 0;
22092
+ if (!this._enabled || isEmptyArray(rows))
22093
+ return 0; // Skip is disabled, or no rows to delete
22094
+ if (this.loading && (!opts || opts.skipIfLoading !== true)) {
22095
+ console.warn('[app-table] Skip deleteRows() because table is busy (loading). Use opts.skipLoading = false to force deletion');
22096
+ return 0; // Skip if loading
22097
+ }
22090
22098
  // Make sure to keep newly created row
22091
22099
  if (((_a = this.editedRow) === null || _a === void 0 ? void 0 : _a.id) === -1 && this.editedRow.editing && !rows.includes(this.editedRow)) {
22092
22100
  const confirmed = this.confirmEditCreate();
@@ -22104,25 +22112,27 @@ class AppTable {
22104
22112
  .sort((a, b) => a.id > b.id ? -1 : 1);
22105
22113
  // If data need to be saved first
22106
22114
  if (this.saveBeforeDelete) {
22107
- // Cancel invalid rows (because of save() will fail, if invalid rows exists)
22108
- rows = rows.reduce((res, row) => {
22115
+ // Exclude invalid rows (because of save() will fail, when exists some invalid rows)
22116
+ rows = rows.filter(row => {
22109
22117
  if (row.validator && !row.validator.valid) {
22110
22118
  // When deleted (= newly created row) : decrement counter
22111
22119
  if (row.id === -1 || !row.editing) {
22112
22120
  row.delete();
22113
22121
  this.visibleRowCount--;
22114
22122
  this.totalRowCount--;
22115
- return res;
22123
+ return false; // Remove this row to the list, because already deleted
22116
22124
  }
22117
- // Mark row as pristine, to avoid row to be saved
22125
+ // Mark row as pristine, to avoid row to be saved even if still invalid
22118
22126
  else {
22119
- row.cancelOrDelete(); // Will cancel only (delete will always go into the previous 'if')
22120
- row.validator.markAsPristine();
22127
+ // Will cancel only (delete will always go into the previous 'if')
22128
+ row.cancelOrDelete();
22129
+ // Mark row as pristine (if possible)
22130
+ this.checkIfRowPristine(row, { emitEvent: false, onlySelf: true /*avoid propagation to table*/ });
22121
22131
  // Continue: the row will be deleted after the save
22122
22132
  }
22123
22133
  }
22124
- return res.concat(row);
22125
- }, []);
22134
+ return true;
22135
+ });
22126
22136
  // Apply save, only if there is still some rows to delete
22127
22137
  // WARN: If no more rows (e.g. because all has been cancelled) then continue anyway to clear editedRow and selection (issue IMAGINE-669)
22128
22138
  if (isNotEmptyArray(rows)) {
@@ -22287,21 +22297,31 @@ class AppTable {
22287
22297
  event.preventDefault();
22288
22298
  event.stopPropagation();
22289
22299
  }
22290
- // If new row is invalid: delete silently
22291
- if (row.id === -1 && row.validator.invalid) {
22292
- this.deleteNewRow(event, row);
22300
+ // If new row (no id)
22301
+ if (row.id === -1) {
22302
+ if (row.validator) {
22303
+ // If pending: Wait end of validation, then loop
22304
+ if (row.validator.pending) {
22305
+ AppFormUtils.waitWhilePending(row.validator).then(() => this.escapeEditingRow(event, row));
22306
+ return;
22307
+ }
22308
+ // Row is invalid: delete the row
22309
+ if (row.validator.invalid) {
22310
+ this.deleteNewRow(event, row);
22311
+ return;
22312
+ }
22313
+ }
22293
22314
  }
22294
- // If exists
22315
+ // If the row exists (has an id)
22295
22316
  else {
22296
- // cancel (if confirmation)
22317
+ // need to call cancel function (if confirmation will be call before before)
22297
22318
  if (this.confirmBeforeCancel) {
22298
22319
  this.cancelExistingRow(event, row, { keepEditing: false });
22299
- }
22300
- // Or validate, if no confirmation
22301
- else {
22302
- this.confirmEditCreate(event, row);
22320
+ return;
22303
22321
  }
22304
22322
  }
22323
+ // By default, try to confirm the row
22324
+ this.confirmEditCreate(event, row);
22305
22325
  }
22306
22326
  translateControlPath(path) {
22307
22327
  // Can be override by subclasses, to resolve all field name
@@ -22725,6 +22745,8 @@ class AppTable {
22725
22745
  }
22726
22746
  }
22727
22747
  deleteNewRow(event, row) {
22748
+ if (row.id !== -1)
22749
+ throw new Error('Row must have id = -1');
22728
22750
  event === null || event === void 0 ? void 0 : event.stopPropagation();
22729
22751
  this.selection.clear();
22730
22752
  this.editedRow = undefined; // unselect row
@@ -22734,8 +22756,20 @@ class AppTable {
22734
22756
  this.totalRowCount--;
22735
22757
  this.visibleRowCount--;
22736
22758
  }
22759
+ deleteExistingRow(event, row, opts) {
22760
+ // Make sure row will be cancelled, and NOT deleted
22761
+ if (row.id === -1)
22762
+ throw new Error('Row must have an id');
22763
+ if (event === null || event === void 0 ? void 0 : event.defaultPrevented)
22764
+ return 0; // SKip
22765
+ event === null || event === void 0 ? void 0 : event.preventDefault();
22766
+ this.deleteRow(null, row, opts);
22767
+ }
22737
22768
  cancelExistingRow(event, row, opts) {
22738
- var _a, _b, _c;
22769
+ var _a;
22770
+ // Make sure row will be cancelled, and NOT deleted
22771
+ if (row.id === -1 || !row.editing)
22772
+ throw new Error('Row cannot be canceling, but only deleting');
22739
22773
  const confirmed = (!opts || opts.interactive !== false);
22740
22774
  // Ask user confirmation, if cancel
22741
22775
  if (!confirmed && ((_a = row.validator) === null || _a === void 0 ? void 0 : _a.dirty) && (this.confirmBeforeCancel || this.onBeforeCancelRows.observers.length > 0)) {
@@ -22753,17 +22787,26 @@ class AppTable {
22753
22787
  this._dataSource.cancelOrDelete(row);
22754
22788
  this.onCancelOrDeleteRow.next(row);
22755
22789
  // Mark row as pristine
22756
- const markRowAsPristine = ((_b = this.dataSource) === null || _b === void 0 ? void 0 : _b.options.keepOriginalDataAfterConfirm) === true;
22757
- if (markRowAsPristine) {
22758
- (_c = row.validator) === null || _c === void 0 ? void 0 : _c.markAsPristine();
22759
- // Check if table is now pristine
22760
- this.checkIfPristine();
22761
- }
22790
+ this.checkIfRowPristine(row);
22762
22791
  // Restore editing state
22763
22792
  if (keepEditing) {
22764
22793
  this.editRow(undefined, row);
22765
22794
  }
22766
22795
  }
22796
+ checkIfRowPristine(row, opts) {
22797
+ var _a, _b;
22798
+ return __awaiter(this, void 0, void 0, function* () {
22799
+ // Mark row as pristine
22800
+ const markRowAsPristine = ((_a = this.dataSource) === null || _a === void 0 ? void 0 : _a.options.keepOriginalDataAfterConfirm) === true;
22801
+ if (markRowAsPristine) {
22802
+ (_b = row.validator) === null || _b === void 0 ? void 0 : _b.markAsPristine();
22803
+ // Check if table is now pristine
22804
+ if (!opts || opts.onlySelf !== true) {
22805
+ yield this.checkIfPristine(opts);
22806
+ }
22807
+ }
22808
+ });
22809
+ }
22767
22810
  checkIfPristine(opts) {
22768
22811
  return __awaiter(this, void 0, void 0, function* () {
22769
22812
  if (!this.dirty)