@sumaris-net/ngx-components 1.23.1-rc5 → 1.23.3

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.
@@ -1056,32 +1056,47 @@
1056
1056
  function filterNotNil(obs) {
1057
1057
  return obs.pipe(operators.filter(isNotNil));
1058
1058
  }
1059
- function firstNotNil(obs, opts) {
1060
- if ((opts === null || opts === void 0 ? void 0 : opts.timeout) > 0) {
1061
- obs.pipe(operators.takeUntil(rxjs.timer(opts.timeout)), operators.first(isNotNil));
1062
- }
1063
- return obs.pipe(operators.first(isNotNil));
1064
- }
1065
1059
  function filterTrue(obs) {
1066
1060
  return obs.pipe(operators.filter(function (v) { return v === true; }));
1067
1061
  }
1068
- function filterFalse(obs) {
1062
+ function filterFalse(obs, opts) {
1069
1063
  return obs.pipe(operators.filter(function (v) { return v === false; }));
1070
1064
  }
1065
+ function decorateForFirst(obs, opts) {
1066
+ // Set take until notifier
1067
+ var takeUntil$ = (opts === null || opts === void 0 ? void 0 : opts.stop) || ((opts === null || opts === void 0 ? void 0 : opts.timeout) && rxjs.timer(opts.timeout));
1068
+ if (takeUntil$) {
1069
+ // When stop, throw an error (useful when used with a toPromise())
1070
+ if (opts.stopError) {
1071
+ return rxjs.merge(obs.pipe(operators.takeUntil(takeUntil$)), takeUntil$
1072
+ .pipe(operators.map(function () {
1073
+ throw new Error(opts.timeout ? "Timeout " + opts.timeout + "ms" : "Stop");
1074
+ })));
1075
+ }
1076
+ // Add a takeUntil
1077
+ return obs.pipe(operators.takeUntil(takeUntil$));
1078
+ }
1079
+ return obs;
1080
+ }
1081
+ function firstNotNil(obs, opts) {
1082
+ return decorateForFirst(obs, opts).pipe(operators.first(isNotNil));
1083
+ }
1084
+ function firstTrue(obs, opts) {
1085
+ return decorateForFirst(obs, opts).pipe(operators.first(function (v) { return v === true; }), operators.map(function (_) { }) // Convert to void
1086
+ );
1087
+ }
1088
+ function firstFalse(obs, opts) {
1089
+ return decorateForFirst(obs, opts).pipe(operators.first(function (v) { return v === false; }), operators.map(function (_) { }) // Convert to void
1090
+ );
1091
+ }
1071
1092
  function firstTruePromise(obs, opts) {
1072
- if ((opts === null || opts === void 0 ? void 0 : opts.timeout) > 0) {
1073
- return obs.pipe(operators.takeUntil(rxjs.timer(opts.timeout)), operators.first(function (v) { return v === true; })).toPromise();
1074
- }
1075
- return obs.pipe(operators.first(function (v) { return v === true; })).toPromise();
1093
+ return firstTrue(obs, Object.assign({ stopError: true }, opts)).toPromise();
1076
1094
  }
1077
1095
  function firstFalsePromise(obs, opts) {
1078
- if ((opts === null || opts === void 0 ? void 0 : opts.timeout) > 0) {
1079
- return obs.pipe(operators.takeUntil(rxjs.timer(opts.timeout)), operators.first(function (v) { return v === false; })).toPromise();
1080
- }
1081
- return obs.pipe(operators.first(function (v) { return v === false; })).toPromise();
1096
+ return firstFalse(obs, Object.assign({ stopError: true }, opts)).toPromise();
1082
1097
  }
1083
1098
  function firstNotNilPromise(obs, opts) {
1084
- return firstNotNil(obs, opts).toPromise();
1099
+ return firstNotNil(obs, Object.assign({ stopError: true }, opts)).toPromise();
1085
1100
  }
1086
1101
  function chainPromises(defers) {
1087
1102
  return (defers || []).reduce(function (previous, defer) {
@@ -1098,14 +1113,6 @@
1098
1113
  .then(function (jobRes) { return finalResult.concat(jobRes); }); });
1099
1114
  }, null);
1100
1115
  }
1101
- function firstTrue(obs) {
1102
- return obs.pipe(operators.first(function (value) { return value === true; }), operators.map(function (_) { }) // Convert to void
1103
- );
1104
- }
1105
- function firstFalse(obs) {
1106
- return obs.pipe(operators.first(function (value) { return value === false; }), operators.map(function (_) { }) // Convert to void
1107
- );
1108
- }
1109
1116
  /**
1110
1117
  * Wait form a predicate return true. This need to implement AppFormUtils.waitWhilePending(), AppFormUtils.waitIdle()
1111
1118
  * @param predicate
@@ -1113,7 +1120,7 @@
1113
1120
  */
1114
1121
  function waitFor(predicate, opts) {
1115
1122
  return __awaiter(this, void 0, void 0, function () {
1116
- var period, dueTime, wait$, $timeout;
1123
+ var period, dueTime, wait$;
1117
1124
  return __generator(this, function (_a) {
1118
1125
  switch (_a.label) {
1119
1126
  case 0:
@@ -1126,15 +1133,7 @@
1126
1133
  // For DEBUG :
1127
1134
  //tap(() => console.debug("Waiting form idle...", form)),
1128
1135
  operators.filter(function (_) { return predicate(); }), operators.map(function (_) { return true; }));
1129
- // Add timeout
1130
- if (opts && opts.timeout) {
1131
- $timeout = rxjs.timer(opts.timeout);
1132
- wait$ = rxjs.merge(wait$.pipe(operators.takeUntil($timeout)), $timeout
1133
- .pipe(operators.map(function () {
1134
- throw new Error("Timeout waitIdle() - after " + opts.timeout + "ms");
1135
- })));
1136
- }
1137
- return [4 /*yield*/, firstNotNilPromise(wait$)];
1136
+ return [4 /*yield*/, firstNotNilPromise(wait$, opts)];
1138
1137
  case 1:
1139
1138
  _a.sent();
1140
1139
  return [2 /*return*/];
@@ -1143,37 +1142,19 @@
1143
1142
  });
1144
1143
  }
1145
1144
  function waitForTrue(observable, opts) {
1146
- return __awaiter(this, void 0, void 0, function () {
1147
- var $timeout;
1148
- return __generator(this, function (_a) {
1149
- // Timeout (+ dueTime)
1150
- if (opts && opts.timeout > 0) {
1151
- $timeout = rxjs.timer(opts.timeout);
1152
- return [2 /*return*/, rxjs.merge(rxjs.timer(opts.dueTime || 0)
1153
- .pipe(operators.switchMap(function () { return firstTrue(observable); }), operators.takeUntil($timeout)), $timeout
1154
- .pipe(operators.map(function () {
1155
- throw new Error("Timeout ready() - after " + opts.timeout + "ms");
1156
- })))
1157
- .toPromise()];
1158
- }
1159
- // dueTime (without timeout)
1160
- if (opts && opts.dueTime > 0) {
1161
- return [2 /*return*/, rxjs.timer(opts.dueTime)
1162
- .pipe(operators.switchMap(function () { return firstTrue(observable); }))
1163
- .toPromise()];
1164
- }
1165
- return [2 /*return*/, firstTrue(observable).toPromise()];
1166
- });
1167
- });
1145
+ opts = Object.assign({ stopError: true }, opts);
1146
+ // dueTime (without timeout)
1147
+ if (opts && opts.dueTime > 0) {
1148
+ return rxjs.timer(opts.dueTime)
1149
+ .pipe(operators.switchMap(function () { return firstTrue(observable, opts); }))
1150
+ .toPromise();
1151
+ }
1152
+ return firstTrue(observable, opts).toPromise();
1168
1153
  }
1169
1154
  function waitForFalse(observable, opts) {
1170
- return __awaiter(this, void 0, void 0, function () {
1171
- return __generator(this, function (_a) {
1172
- return [2 /*return*/, waitForTrue(
1173
- // Inverse the logic
1174
- observable.pipe(operators.map(function (v) { return v === false; })), opts)];
1175
- });
1176
- });
1155
+ return waitForTrue(
1156
+ // Inverse the logic
1157
+ observable.pipe(operators.map(function (v) { return v === false; })), opts);
1177
1158
  }
1178
1159
 
1179
1160
  function createPromiseEventEmitter() {
@@ -25832,7 +25813,6 @@
25832
25813
  _this._creating = false;
25833
25814
  _this._saving = false;
25834
25815
  _this._stopWatching$ = new rxjs.Subject();
25835
- _this._editingRowCount = 0;
25836
25816
  _this._fetchMoreFn = null;
25837
25817
  _this.loadingSubject = new rxjs.BehaviorSubject(undefined);
25838
25818
  _this._entityName = removeEnd((new dataType()).__typename || 'UnknownVO', 'VO');
@@ -25901,7 +25881,6 @@
25901
25881
  EntitiesTableDataSource.prototype.watchAll = function (offset, size, sortBy, sortDirection, filter) {
25902
25882
  var _this = this;
25903
25883
  this._stopWatching$.next();
25904
- this._editingRowCount = 0;
25905
25884
  this._fetchMoreFn = null;
25906
25885
  this.markAsLoading();
25907
25886
  return this.dataService.watchAll(offset, size, sortBy, sortDirection, filter, this.serviceOptions)
@@ -25909,8 +25888,8 @@
25909
25888
  if (_this._saving) {
25910
25889
  console.info("[table-datasource] Received " + _this._entityName + " data (from service), but still saving: skip");
25911
25890
  }
25912
- else if (_this._editingRowCount > 0) {
25913
- console.warn("[table-datasource] Received " + _this._entityName + " data, while " + _this._editingRowCount + " rows still editing: skip; Please check save() implementation in the table!");
25891
+ else if (_this.hasSomeEditingRow()) {
25892
+ console.warn("[table-datasource] Received " + _this._entityName + " data, while some row still editing: skip; Please check save() implementation in the table!");
25914
25893
  }
25915
25894
  else {
25916
25895
  _this.updateDatasource((res.data || []));
@@ -25969,7 +25948,6 @@
25969
25948
  // Stop with an error
25970
25949
  throw { code: ErrorCodes.TABLE_INVALID_ROW_ERROR, message: 'ERROR.TABLE_INVALID_ROW_ERROR' };
25971
25950
  }
25972
- this._editingRowCount = 0;
25973
25951
  data = void 0;
25974
25952
  if (this.validatorService) {
25975
25953
  dataToSave_1 = [];
@@ -26049,7 +26027,6 @@
26049
26027
  console.warn('[table-datasource] Row still has {editing: true} after confirmCreate()! Force editing to false');
26050
26028
  row.validator.disable({ onlySelf: true, emitEvent: false });
26051
26029
  }
26052
- this._editingRowCount--;
26053
26030
  return true;
26054
26031
  };
26055
26032
  EntitiesTableDataSource.prototype.confirmEdit = function (row) {
@@ -26059,7 +26036,6 @@
26059
26036
  console.warn('[table-datasource] Row still has {editing: true} after confirmEdit()! Force editing to false');
26060
26037
  row.validator.disable({ onlySelf: true, emitEvent: false });
26061
26038
  }
26062
- this._editingRowCount--;
26063
26039
  return true;
26064
26040
  };
26065
26041
  EntitiesTableDataSource.prototype.startEdit = function (row) {
@@ -26069,7 +26045,6 @@
26069
26045
  console.warn('[table-datasource] Row still has {editing: false} after startEdit()! Force editing');
26070
26046
  row.validator.enable({ onlySelf: true, emitEvent: false });
26071
26047
  }
26072
- this._editingRowCount++;
26073
26048
  };
26074
26049
  EntitiesTableDataSource.prototype.handleError = function (error, message) {
26075
26050
  var errorMsg = error && error.message || error;
@@ -26094,9 +26069,7 @@
26094
26069
  console.error("[table-datasource] Row to delete with id=" + id + " not found");
26095
26070
  return;
26096
26071
  }
26097
- if (row.editing)
26098
- this._editingRowCount--;
26099
- this.loadingSubject.next(true);
26072
+ this.markAsLoading();
26100
26073
  this.dataService.deleteAll([row.currentData], this.serviceOptions)
26101
26074
  .catch(function (err) { return _this.handleServiceError(err); })
26102
26075
  .then(function () {
@@ -26105,7 +26078,7 @@
26105
26078
  var present = _this.getRow(id) === row;
26106
26079
  if (present)
26107
26080
  _super_1.prototype.delete.call(_this, id);
26108
- _this.loadingSubject.next(false);
26081
+ _this.markAsLoaded();
26109
26082
  }, 300);
26110
26083
  });
26111
26084
  };
@@ -26130,7 +26103,13 @@
26130
26103
  case 2:
26131
26104
  // Call service deletion
26132
26105
  _b.sent();
26133
- rowNotDeleted = this.getRows().filter(function (row) { return rows.includes(row); });
26106
+ rowNotDeleted = Object.getOwnPropertyNames(rowsById)
26107
+ .reduce(function (res, id) {
26108
+ var row = rowsById[id];
26109
+ var present = _this.getRow(+id) === row;
26110
+ return present ? res.concat(row) : res;
26111
+ }, []);
26112
+ //this.getRows().filter(row => rows.includes(row));
26134
26113
  // Apply missing deletion
26135
26114
  if (isNotEmptyArray(rowNotDeleted)) {
26136
26115
  console.warn("[table-datasource] Force deletion of " + rowNotDeleted.length + " rows (Is service update the cache ?)");
@@ -26142,7 +26121,7 @@
26142
26121
  return [3 /*break*/, 5];
26143
26122
  case 3:
26144
26123
  err_1 = _b.sent();
26145
- // Handle sservice error
26124
+ // Handle service error
26146
26125
  this.handleServiceError(err_1);
26147
26126
  return [3 /*break*/, 5];
26148
26127
  case 4:
@@ -26159,6 +26138,9 @@
26159
26138
  EntitiesTableDataSource.prototype.getRows = function () {
26160
26139
  return this.rowsSubject.getValue();
26161
26140
  };
26141
+ EntitiesTableDataSource.prototype.hasSomeEditingRow = function () {
26142
+ return (this.rowsSubject.value || []).some(function (row) { return row.editing; });
26143
+ };
26162
26144
  EntitiesTableDataSource.prototype.createNew = function (insertAt, options) {
26163
26145
  if (options === void 0) { options = { editing: true }; }
26164
26146
  var _super = Object.create(null, {
@@ -26194,10 +26176,7 @@
26194
26176
  // Log, then continue
26195
26177
  console.error(err_2 && err_2.message || err_2, err_2);
26196
26178
  return [3 /*break*/, 6];
26197
- case 6:
26198
- if (row.editing)
26199
- this._editingRowCount++;
26200
- return [2 /*return*/, row];
26179
+ case 6: return [2 /*return*/, row];
26201
26180
  case 7:
26202
26181
  this._creating = false;
26203
26182
  return [7 /*endfinally*/];
@@ -26222,8 +26201,8 @@
26222
26201
  case 0:
26223
26202
  if (!this._fetchMoreFn)
26224
26203
  return [2 /*return*/, false]; // Avoid multiple call
26225
- if (this._editingRowCount > 0) {
26226
- console.warn("Cannot fetch more " + this._entityName + " because " + this._editingRowCount + " row(s) still editing");
26204
+ if (this.hasSomeEditingRow()) {
26205
+ console.warn("Cannot fetch more " + this._entityName + " because some row) still editing");
26227
26206
  return [2 /*return*/];
26228
26207
  }
26229
26208
  console.debug("Will fetching more row(s) still...");
@@ -26302,7 +26281,6 @@
26302
26281
  this.savingSubject = new rxjs.BehaviorSubject(false);
26303
26282
  this.dirtySubject = new rxjs.BehaviorSubject(false);
26304
26283
  this.errorSubject = new rxjs.BehaviorSubject(undefined);
26305
- this.isRateLimitReached = false;
26306
26284
  this.selection = new collections.SelectionModel(true, []);
26307
26285
  this.editedRow = undefined;
26308
26286
  this.i18nColumnPrefix = 'COMMON.';
@@ -26710,7 +26688,7 @@
26710
26688
  return rxjs.of(undefined); // Continue
26711
26689
  }))
26712
26690
  .subscribe(function (res) { return _this.updateView(res); }));
26713
- // Listen dataSource events
26691
+ // Listen dataSource loading events
26714
26692
  if (this._dataSource)
26715
26693
  this.listenDatasourceLoading(this._dataSource);
26716
26694
  };
@@ -26792,7 +26770,6 @@
26792
26770
  if (!res)
26793
26771
  return [2 /*return*/]; // Skip (e.g error)
26794
26772
  if (res && res.data) {
26795
- this.isRateLimitReached = !this.paginator || (res.data.length < this.paginator.pageSize);
26796
26773
  this.visibleRowCount = res.data.length;
26797
26774
  this.totalRowCount = isNotNil(res.total) ? res.total : ((this.paginator && this.paginator.pageIndex * (this.paginator.pageSize || DEFAULT_PAGE_SIZE) || 0) + this.visibleRowCount);
26798
26775
  if (this.debug)
@@ -26800,7 +26777,6 @@
26800
26777
  }
26801
26778
  else {
26802
26779
  //if (this.debug) console.debug('[table] NO rows loaded');
26803
- this.isRateLimitReached = true;
26804
26780
  this.totalRowCount = 0;
26805
26781
  this.visibleRowCount = 0;
26806
26782
  }
@@ -26936,6 +26912,7 @@
26936
26912
  // Stop event
26937
26913
  event === null || event === void 0 ? void 0 : event.stopPropagation();
26938
26914
  // Confirmation edition or creation
26915
+ //const confirmed = this.dataSource.confirmEditCreate(row);
26939
26916
  var confirmed = row.confirmEditCreate();
26940
26917
  if (confirmed) {
26941
26918
  // If edit finished, forget edited row
@@ -27208,22 +27185,19 @@
27208
27185
  if (!this.saveBeforeDelete) return [3 /*break*/, 3];
27209
27186
  // Exclude invalid rows (because of save() will fail, when exists some invalid rows)
27210
27187
  rows = rows.filter(function (row) {
27211
- if (row.validator && !row.validator.valid) {
27212
- // When deleted (= newly created row) : decrement counter
27213
- if (row.id === -1 || !row.editing) {
27214
- row.delete();
27215
- _this.visibleRowCount--;
27216
- _this.totalRowCount--;
27217
- return false; // Remove this row to the list, because already deleted
27218
- }
27219
- // Mark row as pristine, to avoid row to be saved even if still invalid
27220
- else {
27221
- // Will cancel only (delete will always go into the previous 'if')
27222
- row.cancelOrDelete();
27223
- // Mark row as pristine (if possible)
27224
- _this.checkIfRowPristine(row, { emitEvent: false, onlySelf: true /*avoid propagation to table*/ });
27225
- // Continue: the row will be deleted after the save
27226
- }
27188
+ // Delete the row, if newly created row (id = -1), or if invalid and not editing (= not cancellable)
27189
+ if (row.id === -1 || (!row.valid && !row.editing)) {
27190
+ row.delete();
27191
+ _this.visibleRowCount--;
27192
+ _this.totalRowCount--;
27193
+ return false;
27194
+ }
27195
+ // Cancel the row (and mark as pristine), when not valid but in edition
27196
+ else if (!row.valid && row.editing) {
27197
+ row.cancel();
27198
+ // Mark row as pristine (if possible)
27199
+ _this.checkIfRowPristine(row, { emitEvent: false, onlySelf: true /*avoid propagation to table*/ });
27200
+ return true; // Keep the row. the row will be deleted after the save
27227
27201
  }
27228
27202
  return true;
27229
27203
  });
@@ -28068,8 +28042,9 @@
28068
28042
  if (this.debug)
28069
28043
  console.debug('[table] Many call to listenDatasource(): Cleaning previous subscriptions...');
28070
28044
  this._dataSourceLoadingSubscription.unsubscribe();
28071
- this._subscription.remove(this._dataSourceLoadingSubscription);
28045
+ this.unregisterSubscription(this._dataSourceLoadingSubscription);
28072
28046
  }
28047
+ // Propage loading to table
28073
28048
  this._dataSourceLoadingSubscription = this._dataSource.loadingSubject
28074
28049
  .pipe(operators.distinctUntilChanged(),
28075
28050
  // If changed to True: propagate as soon as possible
@@ -28077,7 +28052,7 @@
28077
28052
  // If changed to False: wait 250ms before propagate (to make sure the spinner has been displayed)
28078
28053
  operators.debounceTime(250), operators.tap(function (loading) { return !loading && _this.setLoading(false); }))
28079
28054
  .subscribe();
28080
- this._subscription.add(this._dataSourceLoadingSubscription);
28055
+ this.registerSubscription(this._dataSourceLoadingSubscription);
28081
28056
  };
28082
28057
  AppTable.prototype.startCellValueChanges = function (name, row) {
28083
28058
  var def = this._cellValueChangesDefs[name];