@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.
@@ -25319,38 +25319,67 @@
25319
25319
  EntitiesTableDataSource.prototype.getRows = function () {
25320
25320
  return this.rowsSubject.toPromise();
25321
25321
  };
25322
- EntitiesTableDataSource.prototype.asyncCreateNew = function (insertAt) {
25322
+ EntitiesTableDataSource.prototype.createNew = function (insertAt) {
25323
25323
  var _super = Object.create(null, {
25324
25324
  createNew: { get: function () { return _super_1.prototype.createNew; } }
25325
25325
  });
25326
25326
  return __awaiter(this, void 0, void 0, function () {
25327
- var row, res, err_3;
25327
+ var done, row, err_3;
25328
25328
  return __generator(this, function (_a) {
25329
25329
  switch (_a.label) {
25330
25330
  case 0:
25331
25331
  if (this._creating)
25332
25332
  return [2 /*return*/]; // Avoid multiple call (should never occur)
25333
25333
  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;
25334
+ return [4 /*yield*/, _super.createNew.call(this, insertAt)];
25340
25335
  case 1:
25341
- _a.trys.push([1, 3, , 4]);
25342
- return [4 /*yield*/, res];
25336
+ done = _a.sent();
25337
+ if (!(done && this.config.onRowCreated)) return [3 /*break*/, 5];
25338
+ row = this.getRow(-1);
25339
+ _a.label = 2;
25343
25340
  case 2:
25344
- _a.sent();
25345
- return [3 /*break*/, 4];
25341
+ _a.trys.push([2, 4, , 5]);
25342
+ return [4 /*yield*/, this.config.onRowCreated(row)];
25346
25343
  case 3:
25344
+ _a.sent();
25345
+ return [3 /*break*/, 5];
25346
+ case 4:
25347
25347
  err_3 = _a.sent();
25348
25348
  console.error(err_3 && err_3.message || err_3, err_3);
25349
- return [3 /*break*/, 4];
25350
- case 4:
25351
- this._editingRowCount++;
25349
+ return [3 /*break*/, 5];
25350
+ case 5:
25351
+ if (done)
25352
+ this._editingRowCount++;
25352
25353
  this._creating = false;
25353
- return [2 /*return*/];
25354
+ return [2 /*return*/, done];
25355
+ }
25356
+ });
25357
+ });
25358
+ };
25359
+ EntitiesTableDataSource.prototype.createRowValidator = function () {
25360
+ var _super = Object.create(null, {
25361
+ createRowValidator: { get: function () { return _super_1.prototype.createRowValidator; } }
25362
+ });
25363
+ return __awaiter(this, void 0, void 0, function () {
25364
+ var validator, err_4;
25365
+ return __generator(this, function (_a) {
25366
+ switch (_a.label) {
25367
+ case 0: return [4 /*yield*/, _super.createRowValidator.call(this)];
25368
+ case 1:
25369
+ validator = _a.sent();
25370
+ if (!(validator && this.config.onRowValidator)) return [3 /*break*/, 5];
25371
+ _a.label = 2;
25372
+ case 2:
25373
+ _a.trys.push([2, 4, , 5]);
25374
+ return [4 /*yield*/, this.config.onRowValidator(validator)];
25375
+ case 3:
25376
+ _a.sent();
25377
+ return [3 /*break*/, 5];
25378
+ case 4:
25379
+ err_4 = _a.sent();
25380
+ console.error(err_4 && err_4.message || err_4, err_4);
25381
+ return [3 /*break*/, 5];
25382
+ case 5: return [2 /*return*/, validator];
25354
25383
  }
25355
25384
  });
25356
25385
  });
@@ -26040,13 +26069,23 @@
26040
26069
  return true;
26041
26070
  };
26042
26071
  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;
26072
+ return __awaiter(this, void 0, void 0, function () {
26073
+ var done;
26074
+ return __generator(this, function (_e) {
26075
+ switch (_e.label) {
26076
+ case 0:
26077
+ row = row || this.editedRow;
26078
+ return [4 /*yield*/, this.confirmEditCreate(event, row)];
26079
+ case 1:
26080
+ done = _e.sent();
26081
+ if (done) {
26082
+ // Edit next row
26083
+ this.editRowById(event, row.id + 1, { focusColumn: this.firstUserColumn });
26084
+ }
26085
+ return [2 /*return*/, done];
26086
+ }
26087
+ });
26088
+ });
26050
26089
  };
26051
26090
  AppTable.prototype.editRowById = function (event, id, opts) {
26052
26091
  return __awaiter(this, void 0, void 0, function () {
@@ -26077,50 +26116,52 @@
26077
26116
  * @param row
26078
26117
  */
26079
26118
  AppTable.prototype.confirmEditCreate = function (event, row) {
26080
- var _this = this;
26081
26119
  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;
26120
+ return __awaiter(this, void 0, void 0, function () {
26121
+ var done, error;
26122
+ return __generator(this, function (_e) {
26123
+ switch (_e.label) {
26124
+ case 0:
26125
+ row = row || this.editedRow;
26126
+ if (!row || !row.editing)
26127
+ return [2 /*return*/, true]; // no row to confirm
26128
+ // Stop event
26129
+ event === null || event === void 0 ? void 0 : event.stopPropagation();
26130
+ return [4 /*yield*/, row.confirmEditCreate()];
26131
+ case 1:
26132
+ done = _e.sent();
26133
+ if (done) {
26134
+ // If edit finished, forget edited row
26135
+ if (row === this.editedRow) {
26136
+ this.editedRow = undefined;
26137
+ }
26138
+ // Mark table as dirty (if row is dirty)
26139
+ if ((_a = row.validator) === null || _a === void 0 ? void 0 : _a.dirty) {
26140
+ this.markAsDirty({ emitEvent: false /* because of resetError() */ });
26141
+ }
26142
+ // Clear error
26143
+ this.resetError();
26144
+ // Emit the confirm event
26145
+ this.onConfirmEditCreateRow.next(row);
26146
+ }
26147
+ else if (row.validator) {
26148
+ // NOT confirmed = row has error
26149
+ if (this.debug) {
26150
+ console.warn('[table] Cannot confirm row, because invalid');
26151
+ AppFormUtils.logFormErrors(row.validator, '[table] ');
26152
+ }
26153
+ // fix: mark all controls as touched to show errors
26154
+ row.validator.markAllAsTouched();
26155
+ // Compute row error, and propagate to table's error
26156
+ if (this.propagateRowError) {
26157
+ error = this.getRowError(row);
26158
+ this.setError(error);
26159
+ }
26160
+ }
26161
+ return [2 /*return*/, done];
26162
+ }
26163
+ });
26164
+ });
26124
26165
  };
26125
26166
  AppTable.prototype.cancelOrDelete = function (event, row, opts) {
26126
26167
  // Delete new row
@@ -26980,13 +27021,16 @@
26980
27021
  };
26981
27022
  AppTable.prototype.addRowToTable = function (insertAt) {
26982
27023
  return __awaiter(this, void 0, void 0, function () {
27024
+ var done;
26983
27025
  return __generator(this, function (_e) {
26984
27026
  switch (_e.label) {
26985
27027
  case 0:
26986
27028
  this.focusFirstColumn = true;
26987
- return [4 /*yield*/, this._dataSource.asyncCreateNew(insertAt)];
27029
+ return [4 /*yield*/, this._dataSource.createNew(insertAt)];
26988
27030
  case 1:
26989
- _e.sent();
27031
+ done = _e.sent();
27032
+ if (!done)
27033
+ return [2 /*return*/, undefined];
26990
27034
  this.editedRow = this._dataSource.getRow(-1);
26991
27035
  // Emit start editing event
26992
27036
  this.onStartEditingRow.emit(this.editedRow);
@@ -27128,54 +27172,74 @@
27128
27172
  }
27129
27173
  };
27130
27174
  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--;
27175
+ return __awaiter(this, void 0, void 0, function () {
27176
+ var done;
27177
+ return __generator(this, function (_e) {
27178
+ switch (_e.label) {
27179
+ case 0:
27180
+ if (row.id !== -1)
27181
+ throw new Error('Row must have id = -1');
27182
+ event === null || event === void 0 ? void 0 : event.stopPropagation();
27183
+ this.selection.clear();
27184
+ this.editedRow = undefined; // unselect row
27185
+ return [4 /*yield*/, this._dataSource.cancelOrDelete(row)];
27186
+ case 1:
27187
+ done = _e.sent();
27188
+ if (done) {
27189
+ this.onCancelOrDeleteRow.next(row);
27190
+ this.resetError();
27191
+ this.totalRowCount--;
27192
+ this.visibleRowCount--;
27193
+ }
27194
+ return [2 /*return*/, done];
27195
+ }
27196
+ });
27197
+ });
27141
27198
  };
27142
27199
  AppTable.prototype.deleteExistingRow = function (event, row, opts) {
27143
27200
  // Make sure row will be cancelled, and NOT deleted
27144
27201
  if (row.id === -1)
27145
27202
  throw new Error('Row must have an id');
27146
27203
  if (event === null || event === void 0 ? void 0 : event.defaultPrevented)
27147
- return 0; // SKip
27204
+ return Promise.resolve(false); // SKip
27148
27205
  event === null || event === void 0 ? void 0 : event.preventDefault();
27149
- this.deleteRow(null, row, opts);
27206
+ return this.deleteRow(null, row, opts);
27150
27207
  };
27151
27208
  AppTable.prototype.cancelExistingRow = function (event, row, opts) {
27152
- var _this = this;
27153
27209
  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 });
27210
+ return __awaiter(this, void 0, void 0, function () {
27211
+ var confirmed, confirm, keepEditing;
27212
+ return __generator(this, function (_e) {
27213
+ switch (_e.label) {
27214
+ case 0:
27215
+ // Make sure row will be cancelled, and NOT deleted
27216
+ if (row.id === -1 || !row.editing)
27217
+ throw new Error('Row cannot be canceling, but only deleting');
27218
+ confirmed = (!opts || opts.interactive !== false);
27219
+ if (!(!confirmed && ((_a = row.validator) === null || _a === void 0 ? void 0 : _a.dirty) && (this.confirmBeforeCancel || this.onBeforeCancelRows.observers.length > 0))) return [3 /*break*/, 2];
27220
+ event.stopPropagation();
27221
+ return [4 /*yield*/, this.canCancelRows([row], opts)];
27222
+ case 1:
27223
+ confirm = _e.sent();
27224
+ // If not confirmed: stop
27225
+ if (!confirm)
27226
+ return [2 /*return*/, false];
27227
+ _e.label = 2;
27228
+ case 2:
27229
+ keepEditing = row.editing && (!opts || opts.keepEditing !== false);
27230
+ this.editedRow = undefined; // unselect row
27231
+ this._dataSource.cancelOrDelete(row);
27232
+ this.onCancelOrDeleteRow.next(row);
27233
+ // Mark row as pristine
27234
+ this.checkIfRowPristine(row);
27235
+ // Restore editing state
27236
+ if (keepEditing) {
27237
+ this.editRow(undefined, row);
27238
+ }
27239
+ return [2 /*return*/, true];
27240
+ }
27166
27241
  });
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
- }
27242
+ });
27179
27243
  };
27180
27244
  AppTable.prototype.checkIfRowPristine = function (row, opts) {
27181
27245
  var _a, _b;