@sumaris-net/ngx-components 1.20.0-rc2 → 1.20.0-rc3

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.
@@ -21880,7 +21880,7 @@ class EntitiesTableDataSource extends TableDataSource {
21880
21880
  getRows() {
21881
21881
  return this.rowsSubject.toPromise();
21882
21882
  }
21883
- asyncCreateNew(insertAt) {
21883
+ createNew(insertAt) {
21884
21884
  const _super = Object.create(null, {
21885
21885
  createNew: { get: () => super.createNew }
21886
21886
  });
@@ -21888,22 +21888,39 @@ class EntitiesTableDataSource extends TableDataSource {
21888
21888
  if (this._creating)
21889
21889
  return; // Avoid multiple call (should never occur)
21890
21890
  this._creating = true;
21891
- _super.createNew.call(this, insertAt);
21892
- const row = this.getRow(-1);
21893
- if (row && this.config.onRowCreated) {
21894
- const res = this.config.onRowCreated(row);
21895
- // If async function, wait the end before ending
21896
- if (res instanceof Promise) {
21897
- try {
21898
- yield res;
21899
- }
21900
- catch (err) {
21901
- console.error(err && err.message || err, err);
21902
- }
21891
+ const done = yield _super.createNew.call(this, insertAt);
21892
+ if (done && this.config.onRowCreated) {
21893
+ const row = this.getRow(-1);
21894
+ try {
21895
+ yield this.config.onRowCreated(row);
21896
+ }
21897
+ catch (err) {
21898
+ console.error(err && err.message || err, err);
21899
+ // Continue
21903
21900
  }
21904
21901
  }
21905
- this._editingRowCount++;
21902
+ if (done)
21903
+ this._editingRowCount++;
21906
21904
  this._creating = false;
21905
+ return done;
21906
+ });
21907
+ }
21908
+ createRowValidator() {
21909
+ const _super = Object.create(null, {
21910
+ createRowValidator: { get: () => super.createRowValidator }
21911
+ });
21912
+ return __awaiter(this, void 0, void 0, function* () {
21913
+ const validator = yield _super.createRowValidator.call(this);
21914
+ if (validator && this.config.onRowValidator) {
21915
+ try {
21916
+ yield this.config.onRowValidator(validator);
21917
+ }
21918
+ catch (err) {
21919
+ console.error(err && err.message || err, err);
21920
+ // Continue
21921
+ }
21922
+ }
21923
+ return validator;
21907
21924
  });
21908
21925
  }
21909
21926
  getData() {
@@ -22471,13 +22488,15 @@ class AppTable {
22471
22488
  return true;
22472
22489
  }
22473
22490
  confirmAndForward(event, row) {
22474
- row = row || this.editedRow;
22475
- if (!this.confirmEditCreate(event, row)) {
22476
- return false;
22477
- }
22478
- // Edit next row
22479
- this.editRowById(event, row.id + 1, { focusColumn: this.firstUserColumn });
22480
- return true;
22491
+ return __awaiter(this, void 0, void 0, function* () {
22492
+ row = row || this.editedRow;
22493
+ const done = yield this.confirmEditCreate(event, row);
22494
+ if (done) {
22495
+ // Edit next row
22496
+ this.editRowById(event, row.id + 1, { focusColumn: this.firstUserColumn });
22497
+ }
22498
+ return done;
22499
+ });
22481
22500
  }
22482
22501
  editRowById(event, id, opts) {
22483
22502
  return __awaiter(this, void 0, void 0, function* () {
@@ -22501,48 +22520,44 @@ class AppTable {
22501
22520
  */
22502
22521
  confirmEditCreate(event, row) {
22503
22522
  var _a;
22504
- row = row || this.editedRow;
22505
- if (!row || !row.editing)
22506
- return true; // no row to confirm
22507
- // Stop event
22508
- event === null || event === void 0 ? void 0 : event.stopPropagation();
22509
- // Confirmation edition or creation
22510
- const confirmed = row.confirmEditCreate();
22511
- if (confirmed) {
22512
- // If edit finished, forget edited row
22513
- if (row === this.editedRow) {
22514
- this.editedRow = undefined;
22515
- }
22516
- // Mark table as dirty (if row is dirty)
22517
- if ((_a = row.validator) === null || _a === void 0 ? void 0 : _a.dirty) {
22518
- this.markAsDirty({ emitEvent: false /* because of resetError() */ });
22519
- }
22520
- // Clear error
22521
- this.resetError();
22522
- // Emit the confirm event
22523
- this.onConfirmEditCreateRow.next(row);
22524
- return true; // Continue
22525
- }
22526
- if (row.validator) {
22527
- // If pending: Wait end of validation, then loop
22528
- if (row.validator.pending) {
22529
- AppFormUtils.waitWhilePending(row.validator).then(() => this.confirmEditCreate(event, row));
22530
- return false;
22531
- }
22532
- // NOT confirmed = row has error
22533
- if (this.debug) {
22534
- console.warn('[table] Cannot confirm row, because invalid');
22535
- AppFormUtils.logFormErrors(row.validator, '[table] ');
22536
- }
22537
- // fix: mark all controls as touched to show errors
22538
- row.validator.markAllAsTouched();
22539
- // Compute row error, and propagate to table's error
22540
- if (this.propagateRowError) {
22541
- const error = this.getRowError(row);
22542
- this.setError(error);
22523
+ return __awaiter(this, void 0, void 0, function* () {
22524
+ row = row || this.editedRow;
22525
+ if (!row || !row.editing)
22526
+ return true; // no row to confirm
22527
+ // Stop event
22528
+ event === null || event === void 0 ? void 0 : event.stopPropagation();
22529
+ // Confirmation edition or creation
22530
+ const done = yield row.confirmEditCreate();
22531
+ if (done) {
22532
+ // If edit finished, forget edited row
22533
+ if (row === this.editedRow) {
22534
+ this.editedRow = undefined;
22535
+ }
22536
+ // Mark table as dirty (if row is dirty)
22537
+ if ((_a = row.validator) === null || _a === void 0 ? void 0 : _a.dirty) {
22538
+ this.markAsDirty({ emitEvent: false /* because of resetError() */ });
22539
+ }
22540
+ // Clear error
22541
+ this.resetError();
22542
+ // Emit the confirm event
22543
+ this.onConfirmEditCreateRow.next(row);
22544
+ }
22545
+ else if (row.validator) {
22546
+ // NOT confirmed = row has error
22547
+ if (this.debug) {
22548
+ console.warn('[table] Cannot confirm row, because invalid');
22549
+ AppFormUtils.logFormErrors(row.validator, '[table] ');
22550
+ }
22551
+ // fix: mark all controls as touched to show errors
22552
+ row.validator.markAllAsTouched();
22553
+ // Compute row error, and propagate to table's error
22554
+ if (this.propagateRowError) {
22555
+ const error = this.getRowError(row);
22556
+ this.setError(error);
22557
+ }
22543
22558
  }
22544
- }
22545
- return false;
22559
+ return done;
22560
+ });
22546
22561
  }
22547
22562
  cancelOrDelete(event, row, opts) {
22548
22563
  // Delete new row
@@ -23242,7 +23257,9 @@ class AppTable {
23242
23257
  addRowToTable(insertAt) {
23243
23258
  return __awaiter(this, void 0, void 0, function* () {
23244
23259
  this.focusFirstColumn = true;
23245
- yield this._dataSource.asyncCreateNew(insertAt);
23260
+ const done = yield this._dataSource.createNew(insertAt);
23261
+ if (!done)
23262
+ return undefined;
23246
23263
  this.editedRow = this._dataSource.getRow(-1);
23247
23264
  // Emit start editing event
23248
23265
  this.onStartEditingRow.emit(this.editedRow);
@@ -23373,53 +23390,58 @@ class AppTable {
23373
23390
  }
23374
23391
  }
23375
23392
  deleteNewRow(event, row) {
23376
- if (row.id !== -1)
23377
- throw new Error('Row must have id = -1');
23378
- event === null || event === void 0 ? void 0 : event.stopPropagation();
23379
- this.selection.clear();
23380
- this.editedRow = undefined; // unselect row
23381
- this._dataSource.cancelOrDelete(row);
23382
- this.onCancelOrDeleteRow.next(row);
23383
- this.resetError();
23384
- this.totalRowCount--;
23385
- this.visibleRowCount--;
23393
+ return __awaiter(this, void 0, void 0, function* () {
23394
+ if (row.id !== -1)
23395
+ throw new Error('Row must have id = -1');
23396
+ event === null || event === void 0 ? void 0 : event.stopPropagation();
23397
+ this.selection.clear();
23398
+ this.editedRow = undefined; // unselect row
23399
+ const done = yield this._dataSource.cancelOrDelete(row);
23400
+ if (done) {
23401
+ this.onCancelOrDeleteRow.next(row);
23402
+ this.resetError();
23403
+ this.totalRowCount--;
23404
+ this.visibleRowCount--;
23405
+ }
23406
+ return done;
23407
+ });
23386
23408
  }
23387
23409
  deleteExistingRow(event, row, opts) {
23388
23410
  // Make sure row will be cancelled, and NOT deleted
23389
23411
  if (row.id === -1)
23390
23412
  throw new Error('Row must have an id');
23391
23413
  if (event === null || event === void 0 ? void 0 : event.defaultPrevented)
23392
- return 0; // SKip
23414
+ return Promise.resolve(false); // SKip
23393
23415
  event === null || event === void 0 ? void 0 : event.preventDefault();
23394
- this.deleteRow(null, row, opts);
23416
+ return this.deleteRow(null, row, opts);
23395
23417
  }
23396
23418
  cancelExistingRow(event, row, opts) {
23397
23419
  var _a;
23398
- // Make sure row will be cancelled, and NOT deleted
23399
- if (row.id === -1 || !row.editing)
23400
- throw new Error('Row cannot be canceling, but only deleting');
23401
- const confirmed = (!opts || opts.interactive !== false);
23402
- // Ask user confirmation, if cancel
23403
- if (!confirmed && ((_a = row.validator) === null || _a === void 0 ? void 0 : _a.dirty) && (this.confirmBeforeCancel || this.onBeforeCancelRows.observers.length > 0)) {
23404
- event.stopPropagation();
23405
- this.canCancelRows([row], opts)
23406
- .then(confirm => {
23407
- // If confirmed, loop
23408
- if (confirm)
23409
- this.cancelExistingRow(event, row, { interactive: false });
23410
- });
23411
- return;
23412
- }
23413
- const keepEditing = row.editing && (!opts || opts.keepEditing !== false);
23414
- this.editedRow = undefined; // unselect row
23415
- this._dataSource.cancelOrDelete(row);
23416
- this.onCancelOrDeleteRow.next(row);
23417
- // Mark row as pristine
23418
- this.checkIfRowPristine(row);
23419
- // Restore editing state
23420
- if (keepEditing) {
23421
- this.editRow(undefined, row);
23422
- }
23420
+ return __awaiter(this, void 0, void 0, function* () {
23421
+ // Make sure row will be cancelled, and NOT deleted
23422
+ if (row.id === -1 || !row.editing)
23423
+ throw new Error('Row cannot be canceling, but only deleting');
23424
+ const confirmed = (!opts || opts.interactive !== false);
23425
+ // Ask user confirmation, if cancel
23426
+ if (!confirmed && ((_a = row.validator) === null || _a === void 0 ? void 0 : _a.dirty) && (this.confirmBeforeCancel || this.onBeforeCancelRows.observers.length > 0)) {
23427
+ event.stopPropagation();
23428
+ const confirm = yield this.canCancelRows([row], opts);
23429
+ // If not confirmed: stop
23430
+ if (!confirm)
23431
+ return false;
23432
+ }
23433
+ const keepEditing = row.editing && (!opts || opts.keepEditing !== false);
23434
+ this.editedRow = undefined; // unselect row
23435
+ this._dataSource.cancelOrDelete(row);
23436
+ this.onCancelOrDeleteRow.next(row);
23437
+ // Mark row as pristine
23438
+ this.checkIfRowPristine(row);
23439
+ // Restore editing state
23440
+ if (keepEditing) {
23441
+ this.editRow(undefined, row);
23442
+ }
23443
+ return true;
23444
+ });
23423
23445
  }
23424
23446
  checkIfRowPristine(row, opts) {
23425
23447
  var _a, _b;