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

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.
@@ -21603,6 +21603,10 @@ class EntitiesTableDataSource extends TableDataSource {
21603
21603
  get loading() {
21604
21604
  return this.loadingSubject.value !== false; // Should be true when undefined (initial state)
21605
21605
  }
21606
+ connect(collectionViewer) {
21607
+ // DEBUG console.debug("[entities-datasource] connect");
21608
+ return super.connect(collectionViewer);
21609
+ }
21606
21610
  disconnect(collectionViewer) {
21607
21611
  super.disconnect(collectionViewer);
21608
21612
  this._stopWatching$.next();
@@ -21880,7 +21884,7 @@ class EntitiesTableDataSource extends TableDataSource {
21880
21884
  getRows() {
21881
21885
  return this.rowsSubject.toPromise();
21882
21886
  }
21883
- asyncCreateNew(insertAt) {
21887
+ createNew(insertAt) {
21884
21888
  const _super = Object.create(null, {
21885
21889
  createNew: { get: () => super.createNew }
21886
21890
  });
@@ -21888,22 +21892,39 @@ class EntitiesTableDataSource extends TableDataSource {
21888
21892
  if (this._creating)
21889
21893
  return; // Avoid multiple call (should never occur)
21890
21894
  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
- }
21895
+ const done = yield _super.createNew.call(this, insertAt);
21896
+ if (done && this.config.onRowCreated) {
21897
+ const row = this.getRow(-1);
21898
+ try {
21899
+ yield this.config.onRowCreated(row);
21900
+ }
21901
+ catch (err) {
21902
+ console.error(err && err.message || err, err);
21903
+ // Continue
21903
21904
  }
21904
21905
  }
21905
- this._editingRowCount++;
21906
+ if (done)
21907
+ this._editingRowCount++;
21906
21908
  this._creating = false;
21909
+ return done;
21910
+ });
21911
+ }
21912
+ createRowValidator() {
21913
+ const _super = Object.create(null, {
21914
+ createRowValidator: { get: () => super.createRowValidator }
21915
+ });
21916
+ return __awaiter(this, void 0, void 0, function* () {
21917
+ const validator = yield _super.createRowValidator.call(this);
21918
+ if (validator && this.config.onRowValidator) {
21919
+ try {
21920
+ yield this.config.onRowValidator(validator);
21921
+ }
21922
+ catch (err) {
21923
+ console.error(err && err.message || err, err);
21924
+ // Continue
21925
+ }
21926
+ }
21927
+ return validator;
21907
21928
  });
21908
21929
  }
21909
21930
  getData() {
@@ -22471,13 +22492,15 @@ class AppTable {
22471
22492
  return true;
22472
22493
  }
22473
22494
  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;
22495
+ return __awaiter(this, void 0, void 0, function* () {
22496
+ row = row || this.editedRow;
22497
+ const done = yield this.confirmEditCreate(event, row);
22498
+ if (done) {
22499
+ // Edit next row
22500
+ this.editRowById(event, row.id + 1, { focusColumn: this.firstUserColumn });
22501
+ }
22502
+ return done;
22503
+ });
22481
22504
  }
22482
22505
  editRowById(event, id, opts) {
22483
22506
  return __awaiter(this, void 0, void 0, function* () {
@@ -22501,48 +22524,44 @@ class AppTable {
22501
22524
  */
22502
22525
  confirmEditCreate(event, row) {
22503
22526
  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);
22527
+ return __awaiter(this, void 0, void 0, function* () {
22528
+ row = row || this.editedRow;
22529
+ if (!row || !row.editing)
22530
+ return true; // no row to confirm
22531
+ // Stop event
22532
+ event === null || event === void 0 ? void 0 : event.stopPropagation();
22533
+ // Confirmation edition or creation
22534
+ const done = yield row.confirmEditCreate();
22535
+ if (done) {
22536
+ // If edit finished, forget edited row
22537
+ if (row === this.editedRow) {
22538
+ this.editedRow = undefined;
22539
+ }
22540
+ // Mark table as dirty (if row is dirty)
22541
+ if ((_a = row.validator) === null || _a === void 0 ? void 0 : _a.dirty) {
22542
+ this.markAsDirty({ emitEvent: false /* because of resetError() */ });
22543
+ }
22544
+ // Clear error
22545
+ this.resetError();
22546
+ // Emit the confirm event
22547
+ this.onConfirmEditCreateRow.next(row);
22548
+ }
22549
+ else if (row.validator) {
22550
+ // NOT confirmed = row has error
22551
+ if (this.debug) {
22552
+ console.warn('[table] Cannot confirm row, because invalid');
22553
+ AppFormUtils.logFormErrors(row.validator, '[table] ');
22554
+ }
22555
+ // fix: mark all controls as touched to show errors
22556
+ row.validator.markAllAsTouched();
22557
+ // Compute row error, and propagate to table's error
22558
+ if (this.propagateRowError) {
22559
+ const error = this.getRowError(row);
22560
+ this.setError(error);
22561
+ }
22543
22562
  }
22544
- }
22545
- return false;
22563
+ return done;
22564
+ });
22546
22565
  }
22547
22566
  cancelOrDelete(event, row, opts) {
22548
22567
  // Delete new row
@@ -23242,7 +23261,9 @@ class AppTable {
23242
23261
  addRowToTable(insertAt) {
23243
23262
  return __awaiter(this, void 0, void 0, function* () {
23244
23263
  this.focusFirstColumn = true;
23245
- yield this._dataSource.asyncCreateNew(insertAt);
23264
+ const done = yield this._dataSource.createNew(insertAt);
23265
+ if (!done)
23266
+ return undefined;
23246
23267
  this.editedRow = this._dataSource.getRow(-1);
23247
23268
  // Emit start editing event
23248
23269
  this.onStartEditingRow.emit(this.editedRow);
@@ -23373,53 +23394,58 @@ class AppTable {
23373
23394
  }
23374
23395
  }
23375
23396
  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--;
23397
+ return __awaiter(this, void 0, void 0, function* () {
23398
+ if (row.id !== -1)
23399
+ throw new Error('Row must have id = -1');
23400
+ event === null || event === void 0 ? void 0 : event.stopPropagation();
23401
+ this.selection.clear();
23402
+ this.editedRow = undefined; // unselect row
23403
+ const done = yield this._dataSource.cancelOrDelete(row);
23404
+ if (done) {
23405
+ this.onCancelOrDeleteRow.next(row);
23406
+ this.resetError();
23407
+ this.totalRowCount--;
23408
+ this.visibleRowCount--;
23409
+ }
23410
+ return done;
23411
+ });
23386
23412
  }
23387
23413
  deleteExistingRow(event, row, opts) {
23388
23414
  // Make sure row will be cancelled, and NOT deleted
23389
23415
  if (row.id === -1)
23390
23416
  throw new Error('Row must have an id');
23391
23417
  if (event === null || event === void 0 ? void 0 : event.defaultPrevented)
23392
- return 0; // SKip
23418
+ return Promise.resolve(false); // SKip
23393
23419
  event === null || event === void 0 ? void 0 : event.preventDefault();
23394
- this.deleteRow(null, row, opts);
23420
+ return this.deleteRow(null, row, opts);
23395
23421
  }
23396
23422
  cancelExistingRow(event, row, opts) {
23397
23423
  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
- }
23424
+ return __awaiter(this, void 0, void 0, function* () {
23425
+ // Make sure row will be cancelled, and NOT deleted
23426
+ if (row.id === -1 || !row.editing)
23427
+ throw new Error('Row cannot be canceling, but only deleting');
23428
+ const confirmed = (!opts || opts.interactive !== false);
23429
+ // Ask user confirmation, if cancel
23430
+ if (!confirmed && ((_a = row.validator) === null || _a === void 0 ? void 0 : _a.dirty) && (this.confirmBeforeCancel || this.onBeforeCancelRows.observers.length > 0)) {
23431
+ event.stopPropagation();
23432
+ const confirm = yield this.canCancelRows([row], opts);
23433
+ // If not confirmed: stop
23434
+ if (!confirm)
23435
+ return false;
23436
+ }
23437
+ const keepEditing = row.editing && (!opts || opts.keepEditing !== false);
23438
+ this.editedRow = undefined; // unselect row
23439
+ this._dataSource.cancelOrDelete(row);
23440
+ this.onCancelOrDeleteRow.next(row);
23441
+ // Mark row as pristine
23442
+ this.checkIfRowPristine(row);
23443
+ // Restore editing state
23444
+ if (keepEditing) {
23445
+ this.editRow(undefined, row);
23446
+ }
23447
+ return true;
23448
+ });
23423
23449
  }
23424
23450
  checkIfRowPristine(row, opts) {
23425
23451
  var _a, _b;