@sumaris-net/ngx-components 1.12.4 → 1.12.8

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.
@@ -4386,6 +4386,21 @@
4386
4386
  { type: FormErrorTranslator },
4387
4387
  { type: i0.ChangeDetectorRef }
4388
4388
  ]; };
4389
+ var FormControlGetPipe = /** @class */ (function () {
4390
+ function FormControlGetPipe() {
4391
+ }
4392
+ FormControlGetPipe.prototype.transform = function (form, path) {
4393
+ return form.get(path);
4394
+ };
4395
+ return FormControlGetPipe;
4396
+ }());
4397
+ FormControlGetPipe.ɵprov = i0__namespace.ɵɵdefineInjectable({ factory: function FormControlGetPipe_Factory() { return new FormControlGetPipe(); }, token: FormControlGetPipe, providedIn: "root" });
4398
+ FormControlGetPipe.decorators = [
4399
+ { type: i0.Pipe, args: [{
4400
+ name: 'formGet'
4401
+ },] },
4402
+ { type: i0.Injectable, args: [{ providedIn: 'root' },] }
4403
+ ];
4389
4404
 
4390
4405
  var SharedPipesModule = /** @class */ (function () {
4391
4406
  function SharedPipesModule() {
@@ -4431,7 +4446,8 @@
4431
4446
  TranslateContextPipe,
4432
4447
  TranslatablePipe,
4433
4448
  NgInitDirective,
4434
- FormErrorTranslatePipe
4449
+ FormErrorTranslatePipe,
4450
+ FormControlGetPipe
4435
4451
  ],
4436
4452
  exports: [
4437
4453
  PropertyGetPipe,
@@ -4465,7 +4481,8 @@
4465
4481
  TranslateContextPipe,
4466
4482
  TranslatablePipe,
4467
4483
  NgInitDirective,
4468
- FormErrorTranslatePipe
4484
+ FormErrorTranslatePipe,
4485
+ FormControlGetPipe
4469
4486
  ]
4470
4487
  },] }
4471
4488
  ];
@@ -25365,9 +25382,15 @@
25365
25382
  return false;
25366
25383
  };
25367
25384
  AppTable.prototype.cancelOrDelete = function (event, row, opts) {
25385
+ // Delete new row
25368
25386
  if (row.id === -1) {
25369
25387
  this.deleteNewRow(event, row);
25370
25388
  }
25389
+ // Delete existing (bu not editing) row
25390
+ else if (!row.editing) {
25391
+ this.deleteExistingRow(event, row, opts);
25392
+ }
25393
+ // Cancel existing (and editing) row
25371
25394
  else {
25372
25395
  this.cancelExistingRow(event, row, opts);
25373
25396
  }
@@ -25532,6 +25555,7 @@
25532
25555
  * @param event
25533
25556
  * @param row
25534
25557
  * @param opts Use interactive=false to avoid user interaction (e.g. user confirmation)
25558
+ * Use skipIfLoading=false to force deletion even if table is busy
25535
25559
  */
25536
25560
  AppTable.prototype.deleteRow = function (event, row, opts) {
25537
25561
  return __awaiter(this, void 0, void 0, function () {
@@ -25551,6 +25575,7 @@
25551
25575
  * @param event
25552
25576
  * @param rows
25553
25577
  * @param opts Use interactive=false to avoid user interaction (e.g. user confirmation)
25578
+ * Use skipIfLoading=false to force deletion even if table is busy
25554
25579
  */
25555
25580
  AppTable.prototype.deleteRows = function (event, rows, opts) {
25556
25581
  var _a;
@@ -25566,10 +25591,12 @@
25566
25591
  if (event === null || event === void 0 ? void 0 : event.defaultPrevented)
25567
25592
  return [2 /*return*/, 0]; // SKip
25568
25593
  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];
25594
+ if (!this._enabled || isEmptyArray(rows))
25595
+ return [2 /*return*/, 0]; // Skip is disabled, or no rows to delete
25596
+ if (this.loading && (!opts || opts.skipIfLoading !== false)) {
25597
+ console.warn('[app-table] Skip deleteRows() because table is busy (loading). Use opts.skipLoading = false to force deletion');
25598
+ return [2 /*return*/, 0]; // Skip if loading
25599
+ }
25573
25600
  // Make sure to keep newly created row
25574
25601
  if (((_a = this.editedRow) === null || _a === void 0 ? void 0 : _a.id) === -1 && this.editedRow.editing && !rows.includes(this.editedRow)) {
25575
25602
  confirmed = this.confirmEditCreate();
@@ -25587,25 +25614,27 @@
25587
25614
  rows = rows.slice()
25588
25615
  .sort(function (a, b) { return a.id > b.id ? -1 : 1; });
25589
25616
  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) {
25617
+ // Exclude invalid rows (because of save() will fail, when exists some invalid rows)
25618
+ rows = rows.filter(function (row) {
25592
25619
  if (row.validator && !row.validator.valid) {
25593
25620
  // When deleted (= newly created row) : decrement counter
25594
25621
  if (row.id === -1 || !row.editing) {
25595
25622
  row.delete();
25596
25623
  _this.visibleRowCount--;
25597
25624
  _this.totalRowCount--;
25598
- return res;
25625
+ return false; // Remove this row to the list, because already deleted
25599
25626
  }
25600
- // Mark row as pristine, to avoid row to be saved
25627
+ // Mark row as pristine, to avoid row to be saved even if still invalid
25601
25628
  else {
25602
- row.cancelOrDelete(); // Will cancel only (delete will always go into the previous 'if')
25603
- row.validator.markAsPristine();
25629
+ // Will cancel only (delete will always go into the previous 'if')
25630
+ row.cancelOrDelete();
25631
+ // Mark row as pristine (if possible)
25632
+ _this.checkIfRowPristine(row, { emitEvent: false, onlySelf: true /*avoid propagation to table*/ });
25604
25633
  // Continue: the row will be deleted after the save
25605
25634
  }
25606
25635
  }
25607
- return res.concat(row);
25608
- }, []);
25636
+ return true;
25637
+ });
25609
25638
  if (!isNotEmptyArray(rows)) return [3 /*break*/, 3];
25610
25639
  return [4 /*yield*/, this.saveBeforeAction('delete')];
25611
25640
  case 2:
@@ -25821,6 +25850,7 @@
25821
25850
  }); });
25822
25851
  };
25823
25852
  AppTable.prototype.escapeEditingRow = function (event, row) {
25853
+ var _this = this;
25824
25854
  row = row || this.editedRow;
25825
25855
  if (!row || !row.editing)
25826
25856
  return;
@@ -25831,21 +25861,31 @@
25831
25861
  event.preventDefault();
25832
25862
  event.stopPropagation();
25833
25863
  }
25834
- // If new row is invalid: delete silently
25835
- if (row.id === -1 && row.validator.invalid) {
25836
- this.deleteNewRow(event, row);
25864
+ // If new row (no id)
25865
+ if (row.id === -1) {
25866
+ if (row.validator) {
25867
+ // If pending: Wait end of validation, then loop
25868
+ if (row.validator.pending) {
25869
+ AppFormUtils.waitWhilePending(row.validator).then(function () { return _this.escapeEditingRow(event, row); });
25870
+ return;
25871
+ }
25872
+ // Row is invalid: delete the row
25873
+ if (row.validator.invalid) {
25874
+ this.deleteNewRow(event, row);
25875
+ return;
25876
+ }
25877
+ }
25837
25878
  }
25838
- // If exists
25879
+ // If the row exists (has an id)
25839
25880
  else {
25840
- // cancel (if confirmation)
25881
+ // need to call cancel function (if confirmation will be call before before)
25841
25882
  if (this.confirmBeforeCancel) {
25842
25883
  this.cancelExistingRow(event, row, { keepEditing: false });
25843
- }
25844
- // Or validate, if no confirmation
25845
- else {
25846
- this.confirmEditCreate(event, row);
25884
+ return;
25847
25885
  }
25848
25886
  }
25887
+ // By default, try to confirm the row
25888
+ this.confirmEditCreate(event, row);
25849
25889
  };
25850
25890
  AppTable.prototype.translateControlPath = function (path) {
25851
25891
  // Can be override by subclasses, to resolve all field name
@@ -26342,6 +26382,8 @@
26342
26382
  }
26343
26383
  };
26344
26384
  AppTable.prototype.deleteNewRow = function (event, row) {
26385
+ if (row.id !== -1)
26386
+ throw new Error('Row must have id = -1');
26345
26387
  event === null || event === void 0 ? void 0 : event.stopPropagation();
26346
26388
  this.selection.clear();
26347
26389
  this.editedRow = undefined; // unselect row
@@ -26351,9 +26393,21 @@
26351
26393
  this.totalRowCount--;
26352
26394
  this.visibleRowCount--;
26353
26395
  };
26396
+ AppTable.prototype.deleteExistingRow = function (event, row, opts) {
26397
+ // Make sure row will be cancelled, and NOT deleted
26398
+ if (row.id === -1)
26399
+ throw new Error('Row must have an id');
26400
+ if (event === null || event === void 0 ? void 0 : event.defaultPrevented)
26401
+ return 0; // SKip
26402
+ event === null || event === void 0 ? void 0 : event.preventDefault();
26403
+ this.deleteRow(null, row, opts);
26404
+ };
26354
26405
  AppTable.prototype.cancelExistingRow = function (event, row, opts) {
26355
26406
  var _this = this;
26356
- var _a, _b, _c;
26407
+ var _a;
26408
+ // Make sure row will be cancelled, and NOT deleted
26409
+ if (row.id === -1 || !row.editing)
26410
+ throw new Error('Row cannot be canceling, but only deleting');
26357
26411
  var confirmed = (!opts || opts.interactive !== false);
26358
26412
  // Ask user confirmation, if cancel
26359
26413
  if (!confirmed && ((_a = row.validator) === null || _a === void 0 ? void 0 : _a.dirty) && (this.confirmBeforeCancel || this.onBeforeCancelRows.observers.length > 0)) {
@@ -26371,17 +26425,32 @@
26371
26425
  this._dataSource.cancelOrDelete(row);
26372
26426
  this.onCancelOrDeleteRow.next(row);
26373
26427
  // 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
- }
26428
+ this.checkIfRowPristine(row);
26380
26429
  // Restore editing state
26381
26430
  if (keepEditing) {
26382
26431
  this.editRow(undefined, row);
26383
26432
  }
26384
26433
  };
26434
+ AppTable.prototype.checkIfRowPristine = function (row, opts) {
26435
+ var _a, _b;
26436
+ return __awaiter(this, void 0, void 0, function () {
26437
+ var markRowAsPristine;
26438
+ return __generator(this, function (_e) {
26439
+ switch (_e.label) {
26440
+ case 0:
26441
+ markRowAsPristine = ((_a = this.dataSource) === null || _a === void 0 ? void 0 : _a.options.keepOriginalDataAfterConfirm) === true;
26442
+ if (!markRowAsPristine) return [3 /*break*/, 2];
26443
+ (_b = row.validator) === null || _b === void 0 ? void 0 : _b.markAsPristine();
26444
+ if (!(!opts || opts.onlySelf !== true)) return [3 /*break*/, 2];
26445
+ return [4 /*yield*/, this.checkIfPristine(opts)];
26446
+ case 1:
26447
+ _e.sent();
26448
+ _e.label = 2;
26449
+ case 2: return [2 /*return*/];
26450
+ }
26451
+ });
26452
+ });
26453
+ };
26385
26454
  AppTable.prototype.checkIfPristine = function (opts) {
26386
26455
  return __awaiter(this, void 0, void 0, function () {
26387
26456
  var rows, pristine;
@@ -30692,6 +30761,7 @@
30692
30761
  exports.FormArrayHelper = FormArrayHelper;
30693
30762
  exports.FormButtonsBarComponent = FormButtonsBarComponent;
30694
30763
  exports.FormButtonsBarToken = FormButtonsBarToken;
30764
+ exports.FormControlGetPipe = FormControlGetPipe;
30695
30765
  exports.FormErrorTranslatePipe = FormErrorTranslatePipe;
30696
30766
  exports.FormErrorTranslator = FormErrorTranslator;
30697
30767
  exports.FormFieldValuesHolder = FormFieldValuesHolder;