@sumaris-net/ngx-components 1.15.9 → 1.15.10

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.
@@ -21324,6 +21324,7 @@ class BaseEntityService extends BaseGraphqlService {
21324
21324
  console.debug(this._logPrefix + `[WS] Listening for changes on ${this._logTypeName} {${id}}...`);
21325
21325
  return this.graphql.subscribe({
21326
21326
  query: opts && opts.query || this.subscriptions.listenChanges,
21327
+ fetchPolicy: opts && opts.fetchPolicy || 'no-cache',
21327
21328
  variables,
21328
21329
  error: {
21329
21330
  code: ErrorCodes$2.SUBSCRIBE_DATA_ERROR,
@@ -24110,23 +24111,31 @@ class AppEntityEditor extends AppTabEditor {
24110
24111
  }
24111
24112
  startListenRemoteChanges() {
24112
24113
  // Skip if disable, or already listening
24113
- if (this._listenChangesSubscription || !this._enableListenChanges || this.isNewData)
24114
+ if (this._listenChangesSubscription || !this._enableListenChanges)
24115
+ return;
24116
+ // Skip if new or local data
24117
+ if (this.isNewData || EntityUtils.isLocal(this.data))
24114
24118
  return;
24115
24119
  // Listen for changes on server
24116
- this._listenChangesSubscription = this.listenChanges(this.data.id, { interval: this._listenIntervalInSeconds })
24120
+ this._listenChangesSubscription = this.listenChanges(this.data.id, {
24121
+ interval: this._listenIntervalInSeconds
24122
+ })
24117
24123
  .pipe(filter(isNotNil))
24118
24124
  .subscribe((data) => {
24119
- if (isMoment(data.updateDate) && data.updateDate.isAfter(this.data.updateDate)) {
24120
- if (!this.dirty) {
24121
- if (this.debug)
24122
- console.debug(`[data-editor] Changes detected on server, at {${data.updateDate}}: reloading page...`);
24123
- this.updateView(data);
24124
- }
24125
- else {
24126
- if (this.debug)
24127
- console.debug(`[data-editor] Changes detected on server, at {${data.updateDate}}, but page is dirty: skip reloading.`);
24128
- // TODO: alter user (with a toast ?)
24129
- }
24125
+ const isNewer = isMoment(data.updateDate) && data.updateDate.isAfter(this.data.updateDate);
24126
+ if (!isNewer)
24127
+ return; // Skip
24128
+ // Editor has no changes: reload
24129
+ if (!this.dirty) {
24130
+ if (this.debug)
24131
+ console.debug(`[data-editor] Changes detected on server, at {${data.updateDate}}: reloading page...`);
24132
+ this.reload();
24133
+ }
24134
+ // Cannot reload: alert the user
24135
+ else {
24136
+ if (this.debug)
24137
+ console.debug(`[data-editor] Changes detected on server, at {${data.updateDate}}, but page is dirty: skip reloading.`);
24138
+ this.showToast({ message: 'ERROR.DATA_UPDATE_DATE_CHANGED', type: 'warning', showCloseButton: true });
24130
24139
  }
24131
24140
  });
24132
24141
  this._listenChangesSubscription.add(() => this._listenChangesSubscription = null);
@@ -24536,7 +24545,10 @@ class AppEntityEditor extends AppTabEditor {
24536
24545
  return parentUrl;
24537
24546
  }
24538
24547
  listenChanges(id, opts) {
24539
- return this.dataService.listenChanges(this.data.id, opts);
24548
+ return this.dataService.listenChanges(this.data.id, Object.assign({
24549
+ // Make sure to skip cache, because NOT the full graph will be fetched by subscription
24550
+ // When a changes occur, we call reload() to force refetching the full graph
24551
+ fetchPolicy: 'no-cache' }, opts));
24540
24552
  }
24541
24553
  markForCheck() {
24542
24554
  this.cd.markForCheck();