@sumaris-net/ngx-components 1.5.10 → 1.6.2

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.
@@ -1117,6 +1117,14 @@
1117
1117
  .then(function (jobRes) { return finalResult.concat(jobRes); }); });
1118
1118
  }, null);
1119
1119
  }
1120
+ function firstTrue(obs) {
1121
+ return obs.pipe(operators.first(function (v) { return v === true; }), operators.map(function (_) { }) // Convert to void
1122
+ );
1123
+ }
1124
+ function firstFalse(obs) {
1125
+ return obs.pipe(operators.first(function (v) { return v === false; }), operators.map(function (_) { }) // Convert to void
1126
+ );
1127
+ }
1120
1128
  /**
1121
1129
  * Wait form a predicate return true. This need to implement AppFormUtils.waitWhilePending(), AppFormUtils.waitIdle()
1122
1130
  * @param predicate
@@ -1157,8 +1165,7 @@
1157
1165
  return __awaiter(this, void 0, void 0, function () {
1158
1166
  var firstTrueObservable, $timeout;
1159
1167
  return __generator(this, function (_a) {
1160
- firstTrueObservable = observable.pipe(operators.first(function (v) { return v === true; }), operators.map(function () { }) // convert to void
1161
- );
1168
+ firstTrueObservable = firstTrue(observable);
1162
1169
  // Timeout (+ dueTime)
1163
1170
  if (opts && opts.timeout > 0) {
1164
1171
  $timeout = rxjs.timer(opts.timeout);
@@ -19531,6 +19538,9 @@
19531
19538
  this.onSubmit.complete();
19532
19539
  this.onSubmit.unsubscribe();
19533
19540
  this._$ready.complete();
19541
+ this._$ready.unsubscribe();
19542
+ this._$loading.complete();
19543
+ this._$loading.unsubscribe();
19534
19544
  };
19535
19545
  AppForm.prototype.cancel = function () {
19536
19546
  this.onCancel.emit();
@@ -19636,16 +19646,7 @@
19636
19646
  * @param opts
19637
19647
  */
19638
19648
  AppForm.prototype.ready = function (opts) {
19639
- return __awaiter(this, void 0, void 0, function () {
19640
- return __generator(this, function (_b) {
19641
- switch (_b.label) {
19642
- case 0: return [4 /*yield*/, firstTruePromise(this._$ready)];
19643
- case 1:
19644
- _b.sent();
19645
- return [2 /*return*/];
19646
- }
19647
- });
19648
- });
19649
+ return waitForTrue(this._$ready, opts);
19649
19650
  };
19650
19651
  /**
19651
19652
  * Wait form is idle (not loading)
@@ -23672,6 +23673,7 @@
23672
23673
  _this._useValidator = false;
23673
23674
  _this._stopWatching$ = new rxjs.Subject();
23674
23675
  _this._editingRowCount = 0;
23676
+ _this._fetchMoreFn = null;
23675
23677
  _this.loadingSubject = new rxjs.BehaviorSubject(undefined);
23676
23678
  _this._options = Object.assign({ dataServiceOptions: {}, debug: config && config.suppressErrors === false, keepOriginalDataAfterConfirm: false }, config);
23677
23679
  _this._useValidator = isNotNil(validatorService);
@@ -23722,6 +23724,7 @@
23722
23724
  var _this = this;
23723
23725
  this._stopWatching$.next();
23724
23726
  this._editingRowCount = 0;
23727
+ this._fetchMoreFn = null;
23725
23728
  this.markAsLoading();
23726
23729
  return this.dataService.watchAll(offset, size, sortBy, sortDirection, filter, this.serviceOptions)
23727
23730
  .pipe(
@@ -23735,6 +23738,7 @@
23735
23738
  }
23736
23739
  else {
23737
23740
  _this.updateDatasource((res.data || []));
23741
+ _this._fetchMoreFn = res.fetchMore;
23738
23742
  }
23739
23743
  return res;
23740
23744
  }));
@@ -23985,6 +23989,53 @@
23985
23989
  });
23986
23990
  });
23987
23991
  };
23992
+ EntitiesTableDataSource.prototype.getData = function () {
23993
+ return __awaiter(this, void 0, void 0, function () {
23994
+ var rows;
23995
+ return __generator(this, function (_a) {
23996
+ switch (_a.label) {
23997
+ case 0: return [4 /*yield*/, this.getRows()];
23998
+ case 1:
23999
+ rows = _a.sent();
24000
+ return [2 /*return*/, this.getDataFromRows(rows)];
24001
+ }
24002
+ });
24003
+ });
24004
+ };
24005
+ EntitiesTableDataSource.prototype.fetchMore = function (opts) {
24006
+ var _super = Object.create(null, {
24007
+ updateDatasource: { get: function () { return _super_1.prototype.updateDatasource; } }
24008
+ });
24009
+ return __awaiter(this, void 0, void 0, function () {
24010
+ var res, existingData;
24011
+ return __generator(this, function (_a) {
24012
+ switch (_a.label) {
24013
+ case 0:
24014
+ if (!this._fetchMoreFn)
24015
+ return [2 /*return*/, false]; // Avoid multiple call
24016
+ if (this._editingRowCount > 0) {
24017
+ console.warn('Cannot fetch more because still editing row');
24018
+ return [2 /*return*/];
24019
+ }
24020
+ // Fetch next page
24021
+ this._fetchMoreFn = null; // Avoid multiple call
24022
+ return [4 /*yield*/, this._fetchMoreFn()];
24023
+ case 1:
24024
+ res = _a.sent();
24025
+ // Skip if empty (no more data)
24026
+ if (isNotEmptyArray(res === null || res === void 0 ? void 0 : res.data))
24027
+ return [2 /*return*/, false];
24028
+ return [4 /*yield*/, this.getData()];
24029
+ case 2:
24030
+ existingData = _a.sent();
24031
+ _super.updateDatasource.call(this, existingData.concat.apply(existingData, __spread(res.data)), opts);
24032
+ // Remember fetchMore
24033
+ this._fetchMoreFn = res.fetchMore;
24034
+ return [2 /*return*/, true];
24035
+ }
24036
+ });
24037
+ });
24038
+ };
23988
24039
  /* -- protected method -- */
23989
24040
  EntitiesTableDataSource.prototype.markAsLoading = function () {
23990
24041
  if (this.loadingSubject.value !== true) {
@@ -24423,7 +24474,12 @@
24423
24474
  rxjs.combineLatest([
24424
24475
  _this.onStartEditingRow,
24425
24476
  _this._destroy$
24426
- ])), operators.map(function () { var _a; return (_a = row.validator) === null || _a === void 0 ? void 0 : _a.dirty; }), operators.filter(function (dirty) { return dirty === true; }), operators.first()); }))
24477
+ ])
24478
+ // DEBUG
24479
+ //.pipe(
24480
+ // tap(() => console.debug('TODO stopping previous row listener'))
24481
+ //)
24482
+ ), operators.map(function () { var _a; return (_a = row.validator) === null || _a === void 0 ? void 0 : _a.dirty; }), operators.filter(function (dirty) { return dirty === true; }), operators.first()); }))
24427
24483
  .subscribe(function () { return _this.markAsDirty(); }));
24428
24484
  // Call datasource refresh, on each refresh events
24429
24485
  this.registerSubscription(this.onRefresh
@@ -24922,16 +24978,21 @@
24922
24978
  return [2 /*return*/, 0]; // Cannot delete
24923
24979
  if (!this.saveBeforeDelete) return [3 /*break*/, 3];
24924
24980
  // Cancel invalid rows (because of save() will fail, if invalid rows exists)
24925
- rows.filter(function (row) { var _a; return !((_a = row.validator) === null || _a === void 0 ? void 0 : _a.valid); })
24926
- .forEach(function (row) {
24927
- var deleted = row.id === -1;
24928
- row.cancelOrDelete();
24929
- // When deleted (= newly created row) : decrement counter
24930
- if (deleted) {
24931
- _this.visibleRowCount--;
24932
- _this.totalRowCount--;
24981
+ rows = rows.reduce(function (res, row) {
24982
+ if (row.validator && !row.validator.valid) {
24983
+ var deleted = row.id === -1;
24984
+ row.cancelOrDelete();
24985
+ // When deleted (= newly created row) : decrement counter
24986
+ if (deleted) {
24987
+ _this.visibleRowCount--;
24988
+ _this.totalRowCount--;
24989
+ return res;
24990
+ }
24933
24991
  }
24934
- });
24992
+ return res.concat(row);
24993
+ }, []);
24994
+ if (isEmptyArray(rows))
24995
+ return [2 /*return*/, 0];
24935
24996
  return [4 /*yield*/, this.saveBeforeAction('delete')];
24936
24997
  case 2:
24937
24998
  saved = _d.sent();
@@ -25873,13 +25934,29 @@
25873
25934
  this._subscription = new rxjs.Subscription();
25874
25935
  this._enabled = false;
25875
25936
  this._dirty = false;
25876
- this._loading = true;
25877
25937
  this._$ready = new rxjs.BehaviorSubject(false);
25938
+ this._$loading = new rxjs.BehaviorSubject(true);
25878
25939
  this.debug = false;
25879
25940
  this.submitted = false;
25880
25941
  this.toolbar = null;
25881
25942
  this.formButtonsBar = null;
25882
25943
  }
25944
+ Object.defineProperty(AppEditor.prototype, "_loading", {
25945
+ /**
25946
+ * @deprecated
25947
+ */
25948
+ get: function () {
25949
+ return this._$loading.value;
25950
+ },
25951
+ /**
25952
+ * @deprecated
25953
+ */
25954
+ set: function (value) {
25955
+ this._$loading.next(value);
25956
+ },
25957
+ enumerable: false,
25958
+ configurable: true
25959
+ });
25883
25960
  Object.defineProperty(AppEditor.prototype, "tables", {
25884
25961
  get: function () {
25885
25962
  return this._children && this._children.filter(function (c) { return c instanceof AppTable; });
@@ -25932,7 +26009,7 @@
25932
26009
  Object.defineProperty(AppEditor.prototype, "loading", {
25933
26010
  get: function () {
25934
26011
  var _a;
25935
- return this._loading || (((_a = this._children) === null || _a === void 0 ? void 0 : _a.findIndex(function (c) { return c.enabled && c.loading; })) !== -1) || false;
26012
+ return this._$loading.value || (((_a = this._children) === null || _a === void 0 ? void 0 : _a.findIndex(function (c) { return c.enabled && c.loading; })) !== -1) || false;
25936
26013
  },
25937
26014
  enumerable: false,
25938
26015
  configurable: true
@@ -25978,6 +26055,8 @@
25978
26055
  this._subscription.unsubscribe();
25979
26056
  this._$ready.complete();
25980
26057
  this._$ready.unsubscribe();
26058
+ this._$loading.complete();
26059
+ this._$loading.unsubscribe();
25981
26060
  };
25982
26061
  AppEditor.prototype.addChildForm = function (form) {
25983
26062
  if (!form)
@@ -28742,9 +28821,11 @@
28742
28821
  exports.filterNumberInput = filterNumberInput;
28743
28822
  exports.filterTrue = filterTrue;
28744
28823
  exports.firstArrayValue = firstArrayValue;
28824
+ exports.firstFalse = firstFalse;
28745
28825
  exports.firstFalsePromise = firstFalsePromise;
28746
28826
  exports.firstNotNil = firstNotNil;
28747
28827
  exports.firstNotNilPromise = firstNotNilPromise;
28828
+ exports.firstTrue = firstTrue;
28748
28829
  exports.firstTruePromise = firstTruePromise;
28749
28830
  exports.focusInput = focusInput;
28750
28831
  exports.focusNextInput = focusNextInput;