@sumaris-net/ngx-components 1.10.1 → 1.10.4

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.
@@ -10672,11 +10672,11 @@
10672
10672
  },
10673
10673
  account: {
10674
10674
  enableListenChanges: true,
10675
- listenIntervalInSeconds: 30
10675
+ listenIntervalInSeconds: 60
10676
10676
  },
10677
10677
  entityEditor: {
10678
10678
  enableListenChanges: true,
10679
- listenIntervalInSeconds: 30
10679
+ listenIntervalInSeconds: 60
10680
10680
  }
10681
10681
  });
10682
10682
 
@@ -15465,7 +15465,8 @@
15465
15465
  };
15466
15466
  _this._$additionalFields = new rxjs.BehaviorSubject([]);
15467
15467
  _this._tokenType$ = new rxjs.BehaviorSubject(undefined);
15468
- _this._enableListenChanges = (!environment.account || environment.account.enableListenChanges !== false);
15468
+ _this._enableListenChanges = (!environment.account || environment.account.enableListenChanges !== false); // True by default
15469
+ _this._listenIntervalInSeconds = toNumber(environment.account && environment.account.listenIntervalInSeconds, 0); // no timer by default
15469
15470
  _this._debug = !environment.production;
15470
15471
  if (_this._debug)
15471
15472
  console.debug('[account-service] Creating service');
@@ -15711,7 +15712,7 @@
15711
15712
  this.onChange.next(this._data);
15712
15713
  // Listen remote changes
15713
15714
  if (this._enableListenChanges)
15714
- this.startListenChanges();
15715
+ this.startListenRemoteChanges();
15715
15716
  return [2 /*return*/, this._data];
15716
15717
  case 6:
15717
15718
  error_1 = _b.sent();
@@ -15867,7 +15868,7 @@
15867
15868
  this.onLogin.next(this._data);
15868
15869
  this.onChange.next(this._data);
15869
15870
  if (this._enableListenChanges)
15870
- this.startListenChanges();
15871
+ this.startListenRemoteChanges();
15871
15872
  return [2 /*return*/, this._data];
15872
15873
  }
15873
15874
  });
@@ -16007,7 +16008,6 @@
16007
16008
  if (hadAuthBasic)
16008
16009
  this.onAuthBasicChange.next(undefined);
16009
16010
  this.onChange.next(undefined);
16010
- this.stopListenChanges();
16011
16011
  return [2 /*return*/];
16012
16012
  }
16013
16013
  });
@@ -16170,7 +16170,7 @@
16170
16170
  AccountService.prototype.listenChanges = function (opts) {
16171
16171
  if (this._enableListenChanges)
16172
16172
  return new rxjs.Subscription(); // Already started: skip
16173
- return this.startListenChanges(opts);
16173
+ return this.startListenRemoteChanges(opts);
16174
16174
  };
16175
16175
  Object.defineProperty(AccountService.prototype, "additionalFields", {
16176
16176
  get: function () {
@@ -16200,7 +16200,7 @@
16200
16200
  };
16201
16201
  /* -- protected method -- */
16202
16202
  AccountService.prototype.resetData = function () {
16203
- this.stopListenChanges();
16203
+ this.stopListenRemoteChanges();
16204
16204
  this._cache.loaded = false;
16205
16205
  this._cache.keypair = null;
16206
16206
  this._cache.authToken = null;
@@ -16352,7 +16352,7 @@
16352
16352
  this.onLogin.next(this._data);
16353
16353
  this.onChange.next(this._data);
16354
16354
  if (this._enableListenChanges)
16355
- this.startListenChanges();
16355
+ this.startListenRemoteChanges();
16356
16356
  if (this._debug)
16357
16357
  console.debug("[account] Account restoration [OK] {pubkey: " + pubkey.substr(0, 8) + "}, {profile: " + this._cache.mainProfile + "}");
16358
16358
  return [2 /*return*/, account];
@@ -16602,13 +16602,13 @@
16602
16602
  });
16603
16603
  });
16604
16604
  };
16605
- AccountService.prototype.startListenChanges = function (opts) {
16605
+ AccountService.prototype.startListenRemoteChanges = function (opts) {
16606
16606
  var _this = this;
16607
16607
  if (this._listenChangesSubscription)
16608
- this.stopListenChanges(); // Stop previous subscription
16608
+ this.stopListenRemoteChanges(); // Stop previous subscription
16609
16609
  if (this.network.offline)
16610
16610
  return new rxjs.Subscription(); // Offline: skip
16611
- var subscription = this.watchChanges(opts)
16611
+ this._listenChangesSubscription = this.watchChanges(opts)
16612
16612
  .subscribe({
16613
16613
  next: function (data) {
16614
16614
  console.debug("[account] Remote update detected at " + data.updateDate);
@@ -16628,21 +16628,18 @@
16628
16628
  }
16629
16629
  }
16630
16630
  });
16631
- // Add close log
16632
- subscription.add(function () { return console.debug("[account] Stop watching remote changes"); });
16633
- this._listenChangesSubscription = subscription;
16634
- // Make sure to use the stop function, when unsubscribe
16635
- return new rxjs.Subscription(function () { return _this.stopListenChanges(); });
16631
+ this._listenChangesSubscription.add(function () {
16632
+ console.debug("[account] Stop watching remote changes");
16633
+ _this._listenChangesSubscription = null;
16634
+ });
16635
+ return this._listenChangesSubscription;
16636
16636
  };
16637
- AccountService.prototype.stopListenChanges = function () {
16638
- if (this._listenChangesSubscription) {
16639
- this._listenChangesSubscription.unsubscribe();
16640
- this._listenChangesSubscription = null;
16641
- }
16637
+ AccountService.prototype.stopListenRemoteChanges = function () {
16638
+ var _a;
16639
+ (_a = this._listenChangesSubscription) === null || _a === void 0 ? void 0 : _a.unsubscribe();
16642
16640
  };
16643
16641
  AccountService.prototype.watchChanges = function (opts) {
16644
16642
  var _this = this;
16645
- var _a;
16646
16643
  if (!this.started) {
16647
16644
  // Wait service ready, then loop
16648
16645
  return rxjs.from(this.ready())
@@ -16653,7 +16650,7 @@
16653
16650
  if (this.network.offline)
16654
16651
  throw new Error('Cannot watch account changes: network is offline.');
16655
16652
  var variables = {
16656
- interval: Math.max(0, (opts === null || opts === void 0 ? void 0 : opts.intervalInSeconds) || ((_a = this.environment.account) === null || _a === void 0 ? void 0 : _a.listenIntervalInSeconds) || 0)
16653
+ interval: toNumber(opts && opts.intervalInSeconds, this._listenIntervalInSeconds)
16657
16654
  };
16658
16655
  console.debug("[account] Watching remote changes, every " + variables.interval + "s");
16659
16656
  return this.graphql.subscribe({
@@ -16695,7 +16692,7 @@
16695
16692
  }(BaseGraphqlService));
16696
16693
  AccountService.ɵprov = i0__namespace.ɵɵdefineInjectable({ factory: function AccountService_Factory() { return new AccountService(i0__namespace.ɵɵinject(CryptoService), i0__namespace.ɵɵinject(NetworkService), i0__namespace.ɵɵinject(GraphqlService), i0__namespace.ɵɵinject(LocalSettingsService), i0__namespace.ɵɵinject(i3__namespace$1.Storage), i0__namespace.ɵɵinject(FileService), i0__namespace.ɵɵinject(i1__namespace$1.TranslateService, 8), i0__namespace.ɵɵinject(i1__namespace$4.ToastController, 8), i0__namespace.ɵɵinject(ENVIRONMENT)); }, token: AccountService, providedIn: "root" });
16697
16694
  AccountService.decorators = [
16698
- { type: i0.Injectable, args: [{ providedIn: 'root' },] }
16695
+ { type: i0.Injectable, args: [{ providedIn: 'root', deps: [ENVIRONMENT] },] }
16699
16696
  ];
16700
16697
  AccountService.ctorParameters = function () { return [
16701
16698
  { type: CryptoService },
@@ -23629,11 +23626,14 @@
23629
23626
  var CoreModule = /** @class */ (function () {
23630
23627
  function CoreModule() {
23631
23628
  }
23632
- CoreModule.forRoot = function () {
23629
+ CoreModule.forRoot = function (environment) {
23633
23630
  console.info('[core] Creating module (root)');
23634
23631
  return {
23635
23632
  ngModule: CoreModule,
23636
- providers: [PlatformService]
23633
+ providers: [
23634
+ PlatformService,
23635
+ { provide: ENVIRONMENT, useValue: environment }
23636
+ ]
23637
23637
  };
23638
23638
  };
23639
23639
  return CoreModule;
@@ -24222,7 +24222,7 @@
24222
24222
  throw Error('Not implemented!');
24223
24223
  var variables = opts && opts.variables || {
24224
24224
  id: id,
24225
- interval: opts && opts.interval || 10 // seconds
24225
+ interval: toNumber(opts && opts.interval, 0) // no timer by default
24226
24226
  };
24227
24227
  if (this._debug)
24228
24228
  console.debug(this._logPrefix + ("[WS] Listening for changes on " + this._logTypeName + " {" + id + "}..."));
@@ -27299,17 +27299,16 @@
27299
27299
  var AppEntityEditor = /** @class */ (function (_super) {
27300
27300
  __extends(AppEntityEditor, _super);
27301
27301
  function AppEntityEditor(injector, dataType, dataService, options) {
27302
- var _this = this;
27303
- var _a;
27304
- _this = _super.call(this, injector.get(i3.ActivatedRoute), injector.get(i3.Router), injector.get(i1$5.AlertController), injector.get(i1$2.TranslateService), options) || this;
27302
+ var _this = _super.call(this, injector.get(i3.ActivatedRoute), injector.get(i3.Router), injector.get(i1$5.AlertController), injector.get(i1$2.TranslateService), options) || this;
27305
27303
  _this.dataType = dataType;
27306
27304
  _this.dataService = dataService;
27307
27305
  _this.saving = false;
27308
27306
  _this.$title = new rxjs.Subject();
27309
27307
  _this.onUpdateView = new i0.EventEmitter();
27308
+ _this.environement = injector.get(ENVIRONMENT);
27310
27309
  options = Object.assign({
27311
27310
  // Default options
27312
- enableListenChanges: (((_a = injector.get(ENVIRONMENT).entityEditor) === null || _a === void 0 ? void 0 : _a.enableListenChanges) === true), pathIdAttribute: 'id', autoLoad: true, autoUpdateRoute: true, i18nPrefix: ''
27311
+ enableListenChanges: !_this.environement.entityEditor || _this.environement.entityEditor.enableListenChanges !== false, listenIntervalInSeconds: toNumber(_this.environement.entityEditor && _this.environement.entityEditor.listenIntervalInSeconds, 0), pathIdAttribute: 'id', autoLoad: true, autoUpdateRoute: true, i18nPrefix: ''
27313
27312
  }, options);
27314
27313
  _this.settings = injector.get(LocalSettingsService);
27315
27314
  _this.errorTranslator = injector.get(FormErrorTranslator);
@@ -27317,6 +27316,7 @@
27317
27316
  _this.dateFormat = injector.get(DateFormatPipe);
27318
27317
  _this.toastController = injector.get(i1$5.ToastController);
27319
27318
  _this._enableListenChanges = options.enableListenChanges;
27319
+ _this._listenIntervalInSeconds = options.listenIntervalInSeconds;
27320
27320
  _this._pathIdAttribute = options.pathIdAttribute;
27321
27321
  _this._autoLoad = options.autoLoad;
27322
27322
  _this._autoLoadDelay = options.autoLoadDelay;
@@ -27406,7 +27406,7 @@
27406
27406
  };
27407
27407
  AppEntityEditor.prototype.ngOnDestroy = function () {
27408
27408
  _super.prototype.ngOnDestroy.call(this);
27409
- this.listenRemoteSubscription = null; // already unsubscribe in the super function
27409
+ this._listenChangesSubscription = null; // already unsubscribe in the super function
27410
27410
  this.$title.complete();
27411
27411
  this.$title.unsubscribe();
27412
27412
  this.onUpdateView.complete();
@@ -27503,32 +27503,33 @@
27503
27503
  AppEntityEditor.prototype.startListenRemoteChanges = function () {
27504
27504
  var _this = this;
27505
27505
  // Skip if disable, or already listening
27506
- if (this.listenRemoteSubscription || !this._enableListenChanges || this.isNewData)
27506
+ if (this._listenChangesSubscription || !this._enableListenChanges || this.isNewData)
27507
27507
  return;
27508
27508
  // Listen for changes on server
27509
- this.listenRemoteSubscription = this.dataService.listenChanges(this.data.id)
27509
+ this._listenChangesSubscription = this.dataService.listenChanges(this.data.id, { interval: this._listenIntervalInSeconds })
27510
27510
  .pipe(operators.filter(isNotNil))
27511
27511
  .subscribe(function (data) {
27512
27512
  if (data.updateDate && data.updateDate.isAfter(_this.data.updateDate)) {
27513
27513
  if (!_this.dirty) {
27514
27514
  if (_this.debug)
27515
- console.debug("[data-editor] Changes detected on server, at {" + data.updateDate + "} : reloading page...");
27515
+ console.debug("[data-editor] Changes detected on server, at {" + data.updateDate + "}: reloading page...");
27516
27516
  _this.updateView(data);
27517
27517
  }
27518
27518
  else {
27519
27519
  if (_this.debug)
27520
27520
  console.debug("[data-editor] Changes detected on server, at {" + data.updateDate + "}, but page is dirty: skip reloading.");
27521
+ // TODO: alter user (with a toast ?)
27521
27522
  }
27522
27523
  }
27523
27524
  });
27524
- this.listenRemoteSubscription.add(function () { return _this.listenRemoteSubscription = null; });
27525
- this.registerSubscription(this.listenRemoteSubscription);
27525
+ this._listenChangesSubscription.add(function () { return _this._listenChangesSubscription = null; });
27526
+ this.registerSubscription(this._listenChangesSubscription);
27526
27527
  };
27527
27528
  AppEntityEditor.prototype.stopListenRemoteChanges = function () {
27528
- if (this.listenRemoteSubscription) {
27529
- this.unregisterSubscription(this.listenRemoteSubscription);
27530
- this.listenRemoteSubscription.unsubscribe();
27531
- this.listenRemoteSubscription = null;
27529
+ if (this._listenChangesSubscription) {
27530
+ this.unregisterSubscription(this._listenChangesSubscription);
27531
+ this._listenChangesSubscription.unsubscribe();
27532
+ this._listenChangesSubscription = null;
27532
27533
  }
27533
27534
  };
27534
27535
  AppEntityEditor.prototype.updateView = function (data, opts) {
@@ -27725,7 +27726,7 @@
27725
27726
  // Update the view (e.g metadata)
27726
27727
  _b.sent();
27727
27728
  // Subscribe to remote changes
27728
- if (!this.listenRemoteSubscription)
27729
+ if (!this._listenChangesSubscription)
27729
27730
  this.startListenRemoteChanges();
27730
27731
  this.submitted = false;
27731
27732
  return [2 /*return*/, true];