@sumaris-net/ngx-components 1.15.8 → 1.15.11

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.
@@ -12314,7 +12314,7 @@
12314
12314
  _this.onNetworkStatusChanges = new rxjs.BehaviorSubject(null);
12315
12315
  _this.onResetNetworkCache = new i0.EventEmitter(true);
12316
12316
  _this._listeners = {};
12317
- _this._mobile = _this.platform.is('mobile');
12317
+ _this._mobile = _this.settings.mobile;
12318
12318
  if (_this._mobile) {
12319
12319
  _this._timerRefreshPeriod = NetworkRefreshTimerPeriod.MOBILE;
12320
12320
  _this._timerRefreshCondition = function () { return _this.online; }; // Check only when online, and stop when offline
@@ -12744,7 +12744,7 @@
12744
12744
  return __generator(this, function (_c) {
12745
12745
  switch (_c.label) {
12746
12746
  case 0:
12747
- console.info('[network] Starting network...', this._startingPeer);
12747
+ console.info('[network] Starting network...');
12748
12748
  _b = this._startingPeer;
12749
12749
  if (_b) return [3 /*break*/, 2];
12750
12750
  return [4 /*yield*/, this.restoreLocally()];
@@ -15746,7 +15746,9 @@
15746
15746
  return this._mutableWatchQueries.filter(function (q) { return q.id.startsWith(opts.queryName + '|'); });
15747
15747
  }
15748
15748
  if (opts.queryNames) {
15749
- return opts.queryNames.reduce(function (res, queryName) { return res.concat(_this._mutableWatchQueries.filter(function (q) { return q.id.startsWith(queryName + '|'); })); }, []);
15749
+ return opts.queryNames.map(function (queryName) { return _this._mutableWatchQueries.filter(function (q) { return q.id.startsWith(queryName + '|'); }); })
15750
+ // flatMap
15751
+ .reduce(function (res, array) { return res.concat.apply(res, __spread(array)); }, []);
15750
15752
  }
15751
15753
  // Search by query
15752
15754
  if (opts.query) {
@@ -15755,7 +15757,9 @@
15755
15757
  if (opts.queries) {
15756
15758
  return opts.queries
15757
15759
  .filter(isNotNil)
15758
- .reduce(function (res, query) { return res.concat(_this._mutableWatchQueries.filter(function (q) { return q.query === query; })); }, []);
15760
+ .map(function (query) { return _this._mutableWatchQueries.filter(function (q) { return q.query === query; }); })
15761
+ // flatMap
15762
+ .reduce(function (res, array) { return res.concat.apply(res, __spread(array)); }, []);
15759
15763
  }
15760
15764
  throw Error('Invalid options: only one property must be set');
15761
15765
  };
@@ -17525,12 +17529,12 @@
17525
17529
  case 0:
17526
17530
  now = Date.now();
17527
17531
  console.debug('[config] Clear server cache...');
17528
- variables = { name: opts && opts.cacheName } || undefined;
17532
+ variables = opts && opts.cacheName && { name: opts.cacheName } || undefined;
17529
17533
  return [4 /*yield*/, this.graphql.query({
17530
17534
  query: ClearCache,
17531
17535
  variables: variables,
17532
17536
  error: { code: ErrorCodes$2.LOAD_CONFIG_ERROR, message: 'ERROR.LOAD_CONFIG_ERROR' },
17533
- fetchPolicy: 'network-only'
17537
+ fetchPolicy: 'no-cache'
17534
17538
  })];
17535
17539
  case 1:
17536
17540
  res = _a.sent();
@@ -24620,6 +24624,7 @@
24620
24624
  console.debug(this._logPrefix + ("[WS] Listening for changes on " + this._logTypeName + " {" + id + "}..."));
24621
24625
  return this.graphql.subscribe({
24622
24626
  query: opts && opts.query || this.subscriptions.listenChanges,
24627
+ fetchPolicy: opts && opts.fetchPolicy || 'no-cache',
24623
24628
  variables: variables,
24624
24629
  error: {
24625
24630
  code: ErrorCodes$2.SUBSCRIBE_DATA_ERROR,
@@ -27958,23 +27963,31 @@
27958
27963
  AppEntityEditor.prototype.startListenRemoteChanges = function () {
27959
27964
  var _this = this;
27960
27965
  // Skip if disable, or already listening
27961
- if (this._listenChangesSubscription || !this._enableListenChanges || this.isNewData)
27966
+ if (this._listenChangesSubscription || !this._enableListenChanges)
27967
+ return;
27968
+ // Skip if new or local data
27969
+ if (this.isNewData || EntityUtils.isLocal(this.data))
27962
27970
  return;
27963
27971
  // Listen for changes on server
27964
- this._listenChangesSubscription = this.listenChanges(this.data.id, { interval: this._listenIntervalInSeconds })
27972
+ this._listenChangesSubscription = this.listenChanges(this.data.id, {
27973
+ interval: this._listenIntervalInSeconds
27974
+ })
27965
27975
  .pipe(operators.filter(isNotNil))
27966
27976
  .subscribe(function (data) {
27967
- if (momentImported.isMoment(data.updateDate) && data.updateDate.isAfter(_this.data.updateDate)) {
27968
- if (!_this.dirty) {
27969
- if (_this.debug)
27970
- console.debug("[data-editor] Changes detected on server, at {" + data.updateDate + "}: reloading page...");
27971
- _this.updateView(data);
27972
- }
27973
- else {
27974
- if (_this.debug)
27975
- console.debug("[data-editor] Changes detected on server, at {" + data.updateDate + "}, but page is dirty: skip reloading.");
27976
- // TODO: alter user (with a toast ?)
27977
- }
27977
+ var isNewer = momentImported.isMoment(data.updateDate) && data.updateDate.isAfter(_this.data.updateDate);
27978
+ if (!isNewer)
27979
+ return; // Skip
27980
+ // Editor has no changes: reload
27981
+ if (!_this.dirty) {
27982
+ if (_this.debug)
27983
+ console.debug("[data-editor] Changes detected on server, at {" + data.updateDate + "}: reloading page...");
27984
+ _this.reload();
27985
+ }
27986
+ // Cannot reload: alert the user
27987
+ else {
27988
+ if (_this.debug)
27989
+ console.debug("[data-editor] Changes detected on server, at {" + data.updateDate + "}, but page is dirty: skip reloading.");
27990
+ _this.showToast({ message: 'ERROR.DATA_UPDATE_DATE_CHANGED', type: 'warning', showCloseButton: true });
27978
27991
  }
27979
27992
  });
27980
27993
  this._listenChangesSubscription.add(function () { return _this._listenChangesSubscription = null; });
@@ -28513,7 +28526,11 @@
28513
28526
  return parentUrl;
28514
28527
  };
28515
28528
  AppEntityEditor.prototype.listenChanges = function (id, opts) {
28516
- return this.dataService.listenChanges(this.data.id, opts);
28529
+ return this.dataService.listenChanges(this.data.id, Object.assign({
28530
+ // Make sure to skip cache, because NOT the full graph will be fetched by subscription
28531
+ // When a changes occur, we call reload() to force refetching the full graph
28532
+ fetchPolicy: 'no-cache'
28533
+ }, opts));
28517
28534
  };
28518
28535
  AppEntityEditor.prototype.markForCheck = function () {
28519
28536
  this.cd.markForCheck();