@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.
@@ -25365,9 +25365,15 @@
25365
25365
  return false;
25366
25366
  };
25367
25367
  AppTable.prototype.cancelOrDelete = function (event, row, opts) {
25368
+ // Delete new row
25368
25369
  if (row.id === -1) {
25369
25370
  this.deleteNewRow(event, row);
25370
25371
  }
25372
+ // Delete existing (bu not editing) row
25373
+ else if (!row.editing) {
25374
+ this.deleteExistingRow(event, row, opts);
25375
+ }
25376
+ // Cancel existing (and editing) row
25371
25377
  else {
25372
25378
  this.cancelExistingRow(event, row, opts);
25373
25379
  }
@@ -25566,10 +25572,12 @@
25566
25572
  if (event === null || event === void 0 ? void 0 : event.defaultPrevented)
25567
25573
  return [2 /*return*/, 0]; // SKip
25568
25574
  event === null || event === void 0 ? void 0 : event.preventDefault();
25569
- if (!this._enabled)
25570
- return [2 /*return*/, 0];
25571
- if (this.loading || isEmptyArray(rows))
25572
- return [2 /*return*/, 0];
25575
+ if (!this._enabled || isEmptyArray(rows))
25576
+ return [2 /*return*/, 0]; // Skip is disabled, or no rows to delete
25577
+ if (this.loading && (!opts || opts.skipIfLoading !== true)) {
25578
+ console.warn('[app-table] Skip deleteRows() because table is busy (loading). Use opts.skipLoading = false to force deletion');
25579
+ return [2 /*return*/, 0]; // Skip if loading
25580
+ }
25573
25581
  // Make sure to keep newly created row
25574
25582
  if (((_a = this.editedRow) === null || _a === void 0 ? void 0 : _a.id) === -1 && this.editedRow.editing && !rows.includes(this.editedRow)) {
25575
25583
  confirmed = this.confirmEditCreate();
@@ -25587,25 +25595,27 @@
25587
25595
  rows = rows.slice()
25588
25596
  .sort(function (a, b) { return a.id > b.id ? -1 : 1; });
25589
25597
  if (!this.saveBeforeDelete) return [3 /*break*/, 3];
25590
- // Cancel invalid rows (because of save() will fail, if invalid rows exists)
25591
- rows = rows.reduce(function (res, row) {
25598
+ // Exclude invalid rows (because of save() will fail, when exists some invalid rows)
25599
+ rows = rows.filter(function (row) {
25592
25600
  if (row.validator && !row.validator.valid) {
25593
25601
  // When deleted (= newly created row) : decrement counter
25594
25602
  if (row.id === -1 || !row.editing) {
25595
25603
  row.delete();
25596
25604
  _this.visibleRowCount--;
25597
25605
  _this.totalRowCount--;
25598
- return res;
25606
+ return false; // Remove this row to the list, because already deleted
25599
25607
  }
25600
- // Mark row as pristine, to avoid row to be saved
25608
+ // Mark row as pristine, to avoid row to be saved even if still invalid
25601
25609
  else {
25602
- row.cancelOrDelete(); // Will cancel only (delete will always go into the previous 'if')
25603
- row.validator.markAsPristine();
25610
+ // Will cancel only (delete will always go into the previous 'if')
25611
+ row.cancelOrDelete();
25612
+ // Mark row as pristine (if possible)
25613
+ _this.checkIfRowPristine(row, { emitEvent: false, onlySelf: true /*avoid propagation to table*/ });
25604
25614
  // Continue: the row will be deleted after the save
25605
25615
  }
25606
25616
  }
25607
- return res.concat(row);
25608
- }, []);
25617
+ return true;
25618
+ });
25609
25619
  if (!isNotEmptyArray(rows)) return [3 /*break*/, 3];
25610
25620
  return [4 /*yield*/, this.saveBeforeAction('delete')];
25611
25621
  case 2:
@@ -25821,6 +25831,7 @@
25821
25831
  }); });
25822
25832
  };
25823
25833
  AppTable.prototype.escapeEditingRow = function (event, row) {
25834
+ var _this = this;
25824
25835
  row = row || this.editedRow;
25825
25836
  if (!row || !row.editing)
25826
25837
  return;
@@ -25831,21 +25842,31 @@
25831
25842
  event.preventDefault();
25832
25843
  event.stopPropagation();
25833
25844
  }
25834
- // If new row is invalid: delete silently
25835
- if (row.id === -1 && row.validator.invalid) {
25836
- this.deleteNewRow(event, row);
25845
+ // If new row (no id)
25846
+ if (row.id === -1) {
25847
+ if (row.validator) {
25848
+ // If pending: Wait end of validation, then loop
25849
+ if (row.validator.pending) {
25850
+ AppFormUtils.waitWhilePending(row.validator).then(function () { return _this.escapeEditingRow(event, row); });
25851
+ return;
25852
+ }
25853
+ // Row is invalid: delete the row
25854
+ if (row.validator.invalid) {
25855
+ this.deleteNewRow(event, row);
25856
+ return;
25857
+ }
25858
+ }
25837
25859
  }
25838
- // If exists
25860
+ // If the row exists (has an id)
25839
25861
  else {
25840
- // cancel (if confirmation)
25862
+ // need to call cancel function (if confirmation will be call before before)
25841
25863
  if (this.confirmBeforeCancel) {
25842
25864
  this.cancelExistingRow(event, row, { keepEditing: false });
25843
- }
25844
- // Or validate, if no confirmation
25845
- else {
25846
- this.confirmEditCreate(event, row);
25865
+ return;
25847
25866
  }
25848
25867
  }
25868
+ // By default, try to confirm the row
25869
+ this.confirmEditCreate(event, row);
25849
25870
  };
25850
25871
  AppTable.prototype.translateControlPath = function (path) {
25851
25872
  // Can be override by subclasses, to resolve all field name
@@ -26342,6 +26363,8 @@
26342
26363
  }
26343
26364
  };
26344
26365
  AppTable.prototype.deleteNewRow = function (event, row) {
26366
+ if (row.id !== -1)
26367
+ throw new Error('Row must have id = -1');
26345
26368
  event === null || event === void 0 ? void 0 : event.stopPropagation();
26346
26369
  this.selection.clear();
26347
26370
  this.editedRow = undefined; // unselect row
@@ -26351,9 +26374,21 @@
26351
26374
  this.totalRowCount--;
26352
26375
  this.visibleRowCount--;
26353
26376
  };
26377
+ AppTable.prototype.deleteExistingRow = function (event, row, opts) {
26378
+ // Make sure row will be cancelled, and NOT deleted
26379
+ if (row.id === -1)
26380
+ throw new Error('Row must have an id');
26381
+ if (event === null || event === void 0 ? void 0 : event.defaultPrevented)
26382
+ return 0; // SKip
26383
+ event === null || event === void 0 ? void 0 : event.preventDefault();
26384
+ this.deleteRow(null, row, opts);
26385
+ };
26354
26386
  AppTable.prototype.cancelExistingRow = function (event, row, opts) {
26355
26387
  var _this = this;
26356
- var _a, _b, _c;
26388
+ var _a;
26389
+ // Make sure row will be cancelled, and NOT deleted
26390
+ if (row.id === -1 || !row.editing)
26391
+ throw new Error('Row cannot be canceling, but only deleting');
26357
26392
  var confirmed = (!opts || opts.interactive !== false);
26358
26393
  // Ask user confirmation, if cancel
26359
26394
  if (!confirmed && ((_a = row.validator) === null || _a === void 0 ? void 0 : _a.dirty) && (this.confirmBeforeCancel || this.onBeforeCancelRows.observers.length > 0)) {
@@ -26371,17 +26406,32 @@
26371
26406
  this._dataSource.cancelOrDelete(row);
26372
26407
  this.onCancelOrDeleteRow.next(row);
26373
26408
  // Mark row as pristine
26374
- var markRowAsPristine = ((_b = this.dataSource) === null || _b === void 0 ? void 0 : _b.options.keepOriginalDataAfterConfirm) === true;
26375
- if (markRowAsPristine) {
26376
- (_c = row.validator) === null || _c === void 0 ? void 0 : _c.markAsPristine();
26377
- // Check if table is now pristine
26378
- this.checkIfPristine();
26379
- }
26409
+ this.checkIfRowPristine(row);
26380
26410
  // Restore editing state
26381
26411
  if (keepEditing) {
26382
26412
  this.editRow(undefined, row);
26383
26413
  }
26384
26414
  };
26415
+ AppTable.prototype.checkIfRowPristine = function (row, opts) {
26416
+ var _a, _b;
26417
+ return __awaiter(this, void 0, void 0, function () {
26418
+ var markRowAsPristine;
26419
+ return __generator(this, function (_e) {
26420
+ switch (_e.label) {
26421
+ case 0:
26422
+ markRowAsPristine = ((_a = this.dataSource) === null || _a === void 0 ? void 0 : _a.options.keepOriginalDataAfterConfirm) === true;
26423
+ if (!markRowAsPristine) return [3 /*break*/, 2];
26424
+ (_b = row.validator) === null || _b === void 0 ? void 0 : _b.markAsPristine();
26425
+ if (!(!opts || opts.onlySelf !== true)) return [3 /*break*/, 2];
26426
+ return [4 /*yield*/, this.checkIfPristine(opts)];
26427
+ case 1:
26428
+ _e.sent();
26429
+ _e.label = 2;
26430
+ case 2: return [2 /*return*/];
26431
+ }
26432
+ });
26433
+ });
26434
+ };
26385
26435
  AppTable.prototype.checkIfPristine = function (opts) {
26386
26436
  return __awaiter(this, void 0, void 0, function () {
26387
26437
  var rows, pristine;