@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.
@@ -24961,6 +24961,10 @@
24961
24961
  enumerable: false,
24962
24962
  configurable: true
24963
24963
  });
24964
+ EntitiesTableDataSource.prototype.connect = function (collectionViewer) {
24965
+ // DEBUG console.debug("[entities-datasource] connect");
24966
+ return _super_1.prototype.connect.call(this, collectionViewer);
24967
+ };
24964
24968
  EntitiesTableDataSource.prototype.disconnect = function (collectionViewer) {
24965
24969
  _super_1.prototype.disconnect.call(this, collectionViewer);
24966
24970
  this._stopWatching$.next();
@@ -25319,38 +25323,67 @@
25319
25323
  EntitiesTableDataSource.prototype.getRows = function () {
25320
25324
  return this.rowsSubject.toPromise();
25321
25325
  };
25322
- EntitiesTableDataSource.prototype.asyncCreateNew = function (insertAt) {
25326
+ EntitiesTableDataSource.prototype.createNew = function (insertAt) {
25323
25327
  var _super = Object.create(null, {
25324
25328
  createNew: { get: function () { return _super_1.prototype.createNew; } }
25325
25329
  });
25326
25330
  return __awaiter(this, void 0, void 0, function () {
25327
- var row, res, err_3;
25331
+ var done, row, err_3;
25328
25332
  return __generator(this, function (_a) {
25329
25333
  switch (_a.label) {
25330
25334
  case 0:
25331
25335
  if (this._creating)
25332
25336
  return [2 /*return*/]; // Avoid multiple call (should never occur)
25333
25337
  this._creating = true;
25334
- _super.createNew.call(this, insertAt);
25335
- row = this.getRow(-1);
25336
- if (!(row && this.config.onRowCreated)) return [3 /*break*/, 4];
25337
- res = this.config.onRowCreated(row);
25338
- if (!(res instanceof Promise)) return [3 /*break*/, 4];
25339
- _a.label = 1;
25338
+ return [4 /*yield*/, _super.createNew.call(this, insertAt)];
25340
25339
  case 1:
25341
- _a.trys.push([1, 3, , 4]);
25342
- return [4 /*yield*/, res];
25340
+ done = _a.sent();
25341
+ if (!(done && this.config.onRowCreated)) return [3 /*break*/, 5];
25342
+ row = this.getRow(-1);
25343
+ _a.label = 2;
25343
25344
  case 2:
25344
- _a.sent();
25345
- return [3 /*break*/, 4];
25345
+ _a.trys.push([2, 4, , 5]);
25346
+ return [4 /*yield*/, this.config.onRowCreated(row)];
25346
25347
  case 3:
25348
+ _a.sent();
25349
+ return [3 /*break*/, 5];
25350
+ case 4:
25347
25351
  err_3 = _a.sent();
25348
25352
  console.error(err_3 && err_3.message || err_3, err_3);
25349
- return [3 /*break*/, 4];
25350
- case 4:
25351
- this._editingRowCount++;
25353
+ return [3 /*break*/, 5];
25354
+ case 5:
25355
+ if (done)
25356
+ this._editingRowCount++;
25352
25357
  this._creating = false;
25353
- return [2 /*return*/];
25358
+ return [2 /*return*/, done];
25359
+ }
25360
+ });
25361
+ });
25362
+ };
25363
+ EntitiesTableDataSource.prototype.createRowValidator = function () {
25364
+ var _super = Object.create(null, {
25365
+ createRowValidator: { get: function () { return _super_1.prototype.createRowValidator; } }
25366
+ });
25367
+ return __awaiter(this, void 0, void 0, function () {
25368
+ var validator, err_4;
25369
+ return __generator(this, function (_a) {
25370
+ switch (_a.label) {
25371
+ case 0: return [4 /*yield*/, _super.createRowValidator.call(this)];
25372
+ case 1:
25373
+ validator = _a.sent();
25374
+ if (!(validator && this.config.onRowValidator)) return [3 /*break*/, 5];
25375
+ _a.label = 2;
25376
+ case 2:
25377
+ _a.trys.push([2, 4, , 5]);
25378
+ return [4 /*yield*/, this.config.onRowValidator(validator)];
25379
+ case 3:
25380
+ _a.sent();
25381
+ return [3 /*break*/, 5];
25382
+ case 4:
25383
+ err_4 = _a.sent();
25384
+ console.error(err_4 && err_4.message || err_4, err_4);
25385
+ return [3 /*break*/, 5];
25386
+ case 5: return [2 /*return*/, validator];
25354
25387
  }
25355
25388
  });
25356
25389
  });
@@ -26040,13 +26073,23 @@
26040
26073
  return true;
26041
26074
  };
26042
26075
  AppTable.prototype.confirmAndForward = function (event, row) {
26043
- row = row || this.editedRow;
26044
- if (!this.confirmEditCreate(event, row)) {
26045
- return false;
26046
- }
26047
- // Edit next row
26048
- this.editRowById(event, row.id + 1, { focusColumn: this.firstUserColumn });
26049
- return true;
26076
+ return __awaiter(this, void 0, void 0, function () {
26077
+ var done;
26078
+ return __generator(this, function (_e) {
26079
+ switch (_e.label) {
26080
+ case 0:
26081
+ row = row || this.editedRow;
26082
+ return [4 /*yield*/, this.confirmEditCreate(event, row)];
26083
+ case 1:
26084
+ done = _e.sent();
26085
+ if (done) {
26086
+ // Edit next row
26087
+ this.editRowById(event, row.id + 1, { focusColumn: this.firstUserColumn });
26088
+ }
26089
+ return [2 /*return*/, done];
26090
+ }
26091
+ });
26092
+ });
26050
26093
  };
26051
26094
  AppTable.prototype.editRowById = function (event, id, opts) {
26052
26095
  return __awaiter(this, void 0, void 0, function () {
@@ -26077,50 +26120,52 @@
26077
26120
  * @param row
26078
26121
  */
26079
26122
  AppTable.prototype.confirmEditCreate = function (event, row) {
26080
- var _this = this;
26081
26123
  var _a;
26082
- row = row || this.editedRow;
26083
- if (!row || !row.editing)
26084
- return true; // no row to confirm
26085
- // Stop event
26086
- event === null || event === void 0 ? void 0 : event.stopPropagation();
26087
- // Confirmation edition or creation
26088
- var confirmed = row.confirmEditCreate();
26089
- if (confirmed) {
26090
- // If edit finished, forget edited row
26091
- if (row === this.editedRow) {
26092
- this.editedRow = undefined;
26093
- }
26094
- // Mark table as dirty (if row is dirty)
26095
- if ((_a = row.validator) === null || _a === void 0 ? void 0 : _a.dirty) {
26096
- this.markAsDirty({ emitEvent: false /* because of resetError() */ });
26097
- }
26098
- // Clear error
26099
- this.resetError();
26100
- // Emit the confirm event
26101
- this.onConfirmEditCreateRow.next(row);
26102
- return true; // Continue
26103
- }
26104
- if (row.validator) {
26105
- // If pending: Wait end of validation, then loop
26106
- if (row.validator.pending) {
26107
- AppFormUtils.waitWhilePending(row.validator).then(function () { return _this.confirmEditCreate(event, row); });
26108
- return false;
26109
- }
26110
- // NOT confirmed = row has error
26111
- if (this.debug) {
26112
- console.warn('[table] Cannot confirm row, because invalid');
26113
- AppFormUtils.logFormErrors(row.validator, '[table] ');
26114
- }
26115
- // fix: mark all controls as touched to show errors
26116
- row.validator.markAllAsTouched();
26117
- // Compute row error, and propagate to table's error
26118
- if (this.propagateRowError) {
26119
- var error = this.getRowError(row);
26120
- this.setError(error);
26121
- }
26122
- }
26123
- return false;
26124
+ return __awaiter(this, void 0, void 0, function () {
26125
+ var done, error;
26126
+ return __generator(this, function (_e) {
26127
+ switch (_e.label) {
26128
+ case 0:
26129
+ row = row || this.editedRow;
26130
+ if (!row || !row.editing)
26131
+ return [2 /*return*/, true]; // no row to confirm
26132
+ // Stop event
26133
+ event === null || event === void 0 ? void 0 : event.stopPropagation();
26134
+ return [4 /*yield*/, row.confirmEditCreate()];
26135
+ case 1:
26136
+ done = _e.sent();
26137
+ if (done) {
26138
+ // If edit finished, forget edited row
26139
+ if (row === this.editedRow) {
26140
+ this.editedRow = undefined;
26141
+ }
26142
+ // Mark table as dirty (if row is dirty)
26143
+ if ((_a = row.validator) === null || _a === void 0 ? void 0 : _a.dirty) {
26144
+ this.markAsDirty({ emitEvent: false /* because of resetError() */ });
26145
+ }
26146
+ // Clear error
26147
+ this.resetError();
26148
+ // Emit the confirm event
26149
+ this.onConfirmEditCreateRow.next(row);
26150
+ }
26151
+ else if (row.validator) {
26152
+ // NOT confirmed = row has error
26153
+ if (this.debug) {
26154
+ console.warn('[table] Cannot confirm row, because invalid');
26155
+ AppFormUtils.logFormErrors(row.validator, '[table] ');
26156
+ }
26157
+ // fix: mark all controls as touched to show errors
26158
+ row.validator.markAllAsTouched();
26159
+ // Compute row error, and propagate to table's error
26160
+ if (this.propagateRowError) {
26161
+ error = this.getRowError(row);
26162
+ this.setError(error);
26163
+ }
26164
+ }
26165
+ return [2 /*return*/, done];
26166
+ }
26167
+ });
26168
+ });
26124
26169
  };
26125
26170
  AppTable.prototype.cancelOrDelete = function (event, row, opts) {
26126
26171
  // Delete new row
@@ -26980,13 +27025,16 @@
26980
27025
  };
26981
27026
  AppTable.prototype.addRowToTable = function (insertAt) {
26982
27027
  return __awaiter(this, void 0, void 0, function () {
27028
+ var done;
26983
27029
  return __generator(this, function (_e) {
26984
27030
  switch (_e.label) {
26985
27031
  case 0:
26986
27032
  this.focusFirstColumn = true;
26987
- return [4 /*yield*/, this._dataSource.asyncCreateNew(insertAt)];
27033
+ return [4 /*yield*/, this._dataSource.createNew(insertAt)];
26988
27034
  case 1:
26989
- _e.sent();
27035
+ done = _e.sent();
27036
+ if (!done)
27037
+ return [2 /*return*/, undefined];
26990
27038
  this.editedRow = this._dataSource.getRow(-1);
26991
27039
  // Emit start editing event
26992
27040
  this.onStartEditingRow.emit(this.editedRow);
@@ -27128,54 +27176,74 @@
27128
27176
  }
27129
27177
  };
27130
27178
  AppTable.prototype.deleteNewRow = function (event, row) {
27131
- if (row.id !== -1)
27132
- throw new Error('Row must have id = -1');
27133
- event === null || event === void 0 ? void 0 : event.stopPropagation();
27134
- this.selection.clear();
27135
- this.editedRow = undefined; // unselect row
27136
- this._dataSource.cancelOrDelete(row);
27137
- this.onCancelOrDeleteRow.next(row);
27138
- this.resetError();
27139
- this.totalRowCount--;
27140
- this.visibleRowCount--;
27179
+ return __awaiter(this, void 0, void 0, function () {
27180
+ var done;
27181
+ return __generator(this, function (_e) {
27182
+ switch (_e.label) {
27183
+ case 0:
27184
+ if (row.id !== -1)
27185
+ throw new Error('Row must have id = -1');
27186
+ event === null || event === void 0 ? void 0 : event.stopPropagation();
27187
+ this.selection.clear();
27188
+ this.editedRow = undefined; // unselect row
27189
+ return [4 /*yield*/, this._dataSource.cancelOrDelete(row)];
27190
+ case 1:
27191
+ done = _e.sent();
27192
+ if (done) {
27193
+ this.onCancelOrDeleteRow.next(row);
27194
+ this.resetError();
27195
+ this.totalRowCount--;
27196
+ this.visibleRowCount--;
27197
+ }
27198
+ return [2 /*return*/, done];
27199
+ }
27200
+ });
27201
+ });
27141
27202
  };
27142
27203
  AppTable.prototype.deleteExistingRow = function (event, row, opts) {
27143
27204
  // Make sure row will be cancelled, and NOT deleted
27144
27205
  if (row.id === -1)
27145
27206
  throw new Error('Row must have an id');
27146
27207
  if (event === null || event === void 0 ? void 0 : event.defaultPrevented)
27147
- return 0; // SKip
27208
+ return Promise.resolve(false); // SKip
27148
27209
  event === null || event === void 0 ? void 0 : event.preventDefault();
27149
- this.deleteRow(null, row, opts);
27210
+ return this.deleteRow(null, row, opts);
27150
27211
  };
27151
27212
  AppTable.prototype.cancelExistingRow = function (event, row, opts) {
27152
- var _this = this;
27153
27213
  var _a;
27154
- // Make sure row will be cancelled, and NOT deleted
27155
- if (row.id === -1 || !row.editing)
27156
- throw new Error('Row cannot be canceling, but only deleting');
27157
- var confirmed = (!opts || opts.interactive !== false);
27158
- // Ask user confirmation, if cancel
27159
- if (!confirmed && ((_a = row.validator) === null || _a === void 0 ? void 0 : _a.dirty) && (this.confirmBeforeCancel || this.onBeforeCancelRows.observers.length > 0)) {
27160
- event.stopPropagation();
27161
- this.canCancelRows([row], opts)
27162
- .then(function (confirm) {
27163
- // If confirmed, loop
27164
- if (confirm)
27165
- _this.cancelExistingRow(event, row, { interactive: false });
27214
+ return __awaiter(this, void 0, void 0, function () {
27215
+ var confirmed, confirm, keepEditing;
27216
+ return __generator(this, function (_e) {
27217
+ switch (_e.label) {
27218
+ case 0:
27219
+ // Make sure row will be cancelled, and NOT deleted
27220
+ if (row.id === -1 || !row.editing)
27221
+ throw new Error('Row cannot be canceling, but only deleting');
27222
+ confirmed = (!opts || opts.interactive !== false);
27223
+ if (!(!confirmed && ((_a = row.validator) === null || _a === void 0 ? void 0 : _a.dirty) && (this.confirmBeforeCancel || this.onBeforeCancelRows.observers.length > 0))) return [3 /*break*/, 2];
27224
+ event.stopPropagation();
27225
+ return [4 /*yield*/, this.canCancelRows([row], opts)];
27226
+ case 1:
27227
+ confirm = _e.sent();
27228
+ // If not confirmed: stop
27229
+ if (!confirm)
27230
+ return [2 /*return*/, false];
27231
+ _e.label = 2;
27232
+ case 2:
27233
+ keepEditing = row.editing && (!opts || opts.keepEditing !== false);
27234
+ this.editedRow = undefined; // unselect row
27235
+ this._dataSource.cancelOrDelete(row);
27236
+ this.onCancelOrDeleteRow.next(row);
27237
+ // Mark row as pristine
27238
+ this.checkIfRowPristine(row);
27239
+ // Restore editing state
27240
+ if (keepEditing) {
27241
+ this.editRow(undefined, row);
27242
+ }
27243
+ return [2 /*return*/, true];
27244
+ }
27166
27245
  });
27167
- return;
27168
- }
27169
- var keepEditing = row.editing && (!opts || opts.keepEditing !== false);
27170
- this.editedRow = undefined; // unselect row
27171
- this._dataSource.cancelOrDelete(row);
27172
- this.onCancelOrDeleteRow.next(row);
27173
- // Mark row as pristine
27174
- this.checkIfRowPristine(row);
27175
- // Restore editing state
27176
- if (keepEditing) {
27177
- this.editRow(undefined, row);
27178
- }
27246
+ });
27179
27247
  };
27180
27248
  AppTable.prototype.checkIfRowPristine = function (row, opts) {
27181
27249
  var _a, _b;