@sumaris-net/ngx-components 0.28.5 → 1.0.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.
Files changed (29) hide show
  1. package/bundles/sumaris-net.ngx-components.umd.js +301 -312
  2. package/bundles/sumaris-net.ngx-components.umd.js.map +1 -1
  3. package/bundles/sumaris-net.ngx-components.umd.min.js +2 -2
  4. package/bundles/sumaris-net.ngx-components.umd.min.js.map +1 -1
  5. package/doc/changelog.md +5 -0
  6. package/esm2015/src/app/core/graphql/graphql.service.js +5 -8
  7. package/esm2015/src/app/core/services/account.service.js +177 -188
  8. package/esm2015/src/app/core/services/base-entity-service.class.js +9 -7
  9. package/esm2015/src/app/core/services/base-graphql-service.class.js +7 -2
  10. package/esm2015/src/app/core/services/config.service.js +9 -54
  11. package/esm2015/src/app/core/services/model/account.model.js +1 -1
  12. package/esm2015/src/app/core/services/model/settings.model.js +29 -2
  13. package/esm2015/src/app/core/services/network.service.js +5 -7
  14. package/esm2015/src/app/core/services/storage/entities-storage.service.js +3 -6
  15. package/esm2015/src/app/shared/functions.js +15 -9
  16. package/esm2015/src/app/shared/services/startable-service.class.js +13 -2
  17. package/fesm2015/sumaris-net.ngx-components.js +255 -270
  18. package/fesm2015/sumaris-net.ngx-components.js.map +1 -1
  19. package/package.json +1 -1
  20. package/src/app/core/graphql/graphql.service.d.ts +0 -1
  21. package/src/app/core/services/account.service.d.ts +8 -21
  22. package/src/app/core/services/base-entity-service.class.d.ts +1 -0
  23. package/src/app/core/services/base-graphql-service.class.d.ts +3 -2
  24. package/src/app/core/services/config.service.d.ts +2 -9
  25. package/src/app/core/services/model/settings.model.d.ts +2 -0
  26. package/src/app/core/services/network.service.d.ts +2 -2
  27. package/src/app/core/services/storage/entities-storage.service.d.ts +0 -1
  28. package/src/app/shared/services/startable-service.class.d.ts +3 -1
  29. package/sumaris-net.ngx-components.metadata.json +1 -1
@@ -518,26 +518,32 @@
518
518
  return { data: [value] };
519
519
  value = (typeof value === 'string' && value !== '*') && value.toUpperCase() || undefined;
520
520
  var keys = opts && (opts.searchAttribute && [opts.searchAttribute] || opts.searchAttributes) || ['label'];
521
+ if (!items) {
522
+ return { data: [], total: 0 };
523
+ }
521
524
  // Filter items
522
- if (isNotNilOrBlank(value) && items) {
525
+ var target = items;
526
+ if (isNotNilOrBlank(value)) {
523
527
  // If wildcard, search using regexp
524
528
  if (value.indexOf('*') !== -1) {
525
529
  value = value.replace('*', '.*');
526
- items = items.filter(function (v) { return keys.findIndex(function (key) { return matchUpperCase(getPropertyByPathAsString(v, key), value); }) !== -1; });
530
+ target = target.filter(function (v) { return keys.findIndex(function (key) { return matchUpperCase(getPropertyByPathAsString(v, key), value); }) !== -1; });
527
531
  }
528
532
  // Else (no wildcard), search using startsWith
529
533
  else {
530
- items = items.filter(function (v) { return keys.findIndex(function (key) { return startsWithUpperCase(getPropertyByPathAsString(v, key), value); }) !== -1; });
534
+ target = target.filter(function (v) { return keys.findIndex(function (key) { return startsWithUpperCase(getPropertyByPathAsString(v, key), value); }) !== -1; });
531
535
  }
532
536
  }
533
537
  // Exclude ids
534
- if (items && isNotEmptyArray(opts === null || opts === void 0 ? void 0 : opts.excludedIds)) {
535
- items = items.filter(function (v) { return !opts.excludedIds.includes(+v['id']); });
536
- }
537
- // Sort
538
- items = items.sort(propertiesPathComparator(keys));
538
+ if (isNotEmptyArray(opts === null || opts === void 0 ? void 0 : opts.excludedIds)) {
539
+ target = target.filter(function (v) { return !opts.excludedIds.includes(+v['id']); });
540
+ }
541
+ // Sort (copy if need, before sorting)
542
+ if (target === items)
543
+ target = target.slice();
544
+ target.sort(propertiesPathComparator(keys));
545
+ var total = items.length || 0;
539
546
  // Truncate if need
540
- var total = (items === null || items === void 0 ? void 0 : items.length) || 0;
541
547
  if (opts) {
542
548
  if (opts.offset > 0) {
543
549
  items = items.slice(opts.offset);
@@ -8700,6 +8706,9 @@
8700
8706
  this._startByReadyFunction = true; // should start when calling ready() ?
8701
8707
  this._data = null;
8702
8708
  this._started = false;
8709
+ this._startPromise = null;
8710
+ this._startPrerequisite = null;
8711
+ this._subscription = null;
8703
8712
  this._startPrerequisite = prerequisiteService
8704
8713
  ? function () { return prerequisiteService.ready(); }
8705
8714
  : function () { return Promise.resolve(); };
@@ -8734,6 +8743,10 @@
8734
8743
  switch (_a.label) {
8735
8744
  case 0:
8736
8745
  _a.trys.push([0, 2, , 3]);
8746
+ if (this._subscription) {
8747
+ this._subscription.unsubscribe();
8748
+ this._subscription = null;
8749
+ }
8737
8750
  return [4 /*yield*/, this.ngOnStop()];
8738
8751
  case 1:
8739
8752
  _a.sent();
@@ -8796,6 +8809,10 @@
8796
8809
  return waitFor(function () { return _this._started; })
8797
8810
  .then(function () { return _this._data; });
8798
8811
  };
8812
+ StartableService.prototype.registerSubscription = function (sub) {
8813
+ this._subscription = this._subscription || new rxjs.Subscription();
8814
+ return this._subscription.add(sub);
8815
+ };
8799
8816
  StartableService.prototype.ngOnStop = function () {
8800
8817
  return __awaiter(this, void 0, void 0, function () {
8801
8818
  return __generator(this, function (_a) {
@@ -11349,7 +11366,6 @@
11349
11366
  _this.onPeerChanges = _this.onStart.pipe(operators.map(function (peer) { return peer && peer.url; }), operators.filter(isNotNilOrBlank), operators.distinctUntilChanged());
11350
11367
  _this.onNetworkStatusChanges = new rxjs.BehaviorSubject(null);
11351
11368
  _this.onResetNetworkCache = new i0.EventEmitter(true);
11352
- _this._subscription = new rxjs.Subscription();
11353
11369
  _this._listeners = {};
11354
11370
  _this._mobile = _this.platform.is('mobile');
11355
11371
  if (_this._mobile) {
@@ -11562,7 +11578,8 @@
11562
11578
  /**
11563
11579
  * Check if the peer is alive
11564
11580
  *
11565
- * @param email
11581
+ * @param peer
11582
+ * @param opts
11566
11583
  */
11567
11584
  NetworkService.prototype.checkPeerAlive = function (peer, opts) {
11568
11585
  return __awaiter(this, void 0, void 0, function () {
@@ -11758,8 +11775,8 @@
11758
11775
  this.startRefreshTimer();
11759
11776
  // Listen for device network changes
11760
11777
  if (this.network) {
11761
- this._subscription.add(this.network.onDisconnect().subscribe(function () { return _this.onDeviceConnectionChanged('none'); }));
11762
- this._subscription.add(this.network.onConnect().subscribe(function () { return _this.onDeviceConnectionChanged(_this.network.type); }));
11778
+ this.registerSubscription(this.network.onDisconnect().subscribe(function () { return _this.onDeviceConnectionChanged('none'); }));
11779
+ this.registerSubscription(this.network.onConnect().subscribe(function () { return _this.onDeviceConnectionChanged(_this.network.type); }));
11763
11780
  }
11764
11781
  return [2 /*return*/];
11765
11782
  }
@@ -11774,8 +11791,6 @@
11774
11791
  if (this._timerRefreshCondition() === false) {
11775
11792
  this.stopRefreshTimer();
11776
11793
  }
11777
- this._subscription.unsubscribe();
11778
- this._subscription = new rxjs.Subscription();
11779
11794
  return [2 /*return*/];
11780
11795
  });
11781
11796
  });
@@ -12575,7 +12590,6 @@
12575
12590
  _this.progressBarService = progressBarService;
12576
12591
  _this.storage = storage;
12577
12592
  _this.environment = environment;
12578
- _this._subscription = new rxjs.Subscription();
12579
12593
  _this._$save = new i0.EventEmitter(true);
12580
12594
  _this._dirty = false;
12581
12595
  _this._saving = false;
@@ -13024,7 +13038,7 @@
13024
13038
  // Restore sequences
13025
13039
  _a.sent();
13026
13040
  // Start a save timer
13027
- this._subscription.add(rxjs.merge(this._$save, rxjs.timer(this._saveTimerPeriod, this._saveTimerPeriod))
13041
+ this.registerSubscription(rxjs.merge(this._$save, rxjs.timer(this._saveTimerPeriod, this._saveTimerPeriod))
13028
13042
  .pipe(
13029
13043
  // Avoid to many call (e.g. when $save AND timer are triggered
13030
13044
  operators.throttleTime(this._saveTimerPeriod))
@@ -13040,8 +13054,6 @@
13040
13054
  return __generator(this, function (_a) {
13041
13055
  switch (_a.label) {
13042
13056
  case 0:
13043
- this._subscription.unsubscribe();
13044
- this._subscription = new rxjs.Subscription();
13045
13057
  if (!this.dirty) return [3 /*break*/, 2];
13046
13058
  return [4 /*yield*/, this.storeLocally()];
13047
13059
  case 1:
@@ -13259,8 +13271,36 @@
13259
13271
  }
13260
13272
  this.nonce = source.nonce;
13261
13273
  };
13274
+ UserSettings.prototype.merge = function (source, includesProperties) {
13275
+ var _this = this;
13276
+ if (!source)
13277
+ return; // Skip
13278
+ // Reset content
13279
+ this.content = {};
13280
+ var hasChanges = false;
13281
+ // For each property of source object
13282
+ Object.keys(source)
13283
+ .forEach(function (key) {
13284
+ // If property exists in UserSettings class: store it directly
13285
+ if (UserSettings_1.SETTINGS_PROPERTIES.includes(key)) {
13286
+ if (!equals(_this[key], source[key])) {
13287
+ _this[key] = source[key];
13288
+ hasChanges = true;
13289
+ }
13290
+ }
13291
+ // Else, store property into the 'content' map
13292
+ else if (includesProperties && includesProperties.includes(key)) {
13293
+ if (!equals(_this.content[key], source[key])) {
13294
+ _this.content[key] = Object.assign({}, source[key]);
13295
+ hasChanges = true;
13296
+ }
13297
+ }
13298
+ });
13299
+ return hasChanges;
13300
+ };
13262
13301
  return UserSettings;
13263
13302
  }(Entity));
13303
+ exports.UserSettings.SETTINGS_PROPERTIES = ['locale', 'latLongFormat'];
13264
13304
  exports.UserSettings = UserSettings_1 = __decorate([
13265
13305
  EntityClass({ typename: 'UserSettingsVO' })
13266
13306
  ], exports.UserSettings);
@@ -13711,7 +13751,6 @@
13711
13751
  _this.cryptoService = cryptoService;
13712
13752
  _this.environment = environment;
13713
13753
  _this.typePolicies = typePolicies;
13714
- _this._subscription = new rxjs.Subscription();
13715
13754
  _this.connectionParams = {};
13716
13755
  _this.onNetworkError = new rxjs.Subject();
13717
13756
  _this.customErrors = {};
@@ -14275,7 +14314,7 @@
14275
14314
  debug: true
14276
14315
  });
14277
14316
  queueLink_1 = new QueueLink__default["default"]();
14278
- this._subscription.add(this._networkStatusChanged$
14317
+ this.registerSubscription(this._networkStatusChanged$
14279
14318
  .subscribe(function (type) {
14280
14319
  // Network is offline: start buffering into queue
14281
14320
  if (type === 'none') {
@@ -14343,9 +14382,9 @@
14343
14382
  return [3 /*break*/, 8];
14344
14383
  case 8:
14345
14384
  // Listen for network restart
14346
- this._subscription.add(this.network.on('start', function () { return _this.restart(); }));
14385
+ this.registerSubscription(this.network.on('start', function () { return _this.restart(); }));
14347
14386
  // Listen for clear cache request, from network
14348
- this._subscription.add(this.network.on('resetCache', function () { return _this.clearCache(); }));
14387
+ this.registerSubscription(this.network.on('resetCache', function () { return _this.clearCache(); }));
14349
14388
  console.info('[graphql] Starting graphql [OK]');
14350
14389
  return [2 /*return*/, client];
14351
14390
  }
@@ -14358,8 +14397,6 @@
14358
14397
  switch (_a.label) {
14359
14398
  case 0:
14360
14399
  console.info('[graphql] Stopping graphql service...');
14361
- this._subscription.unsubscribe();
14362
- this._subscription = new rxjs.Subscription();
14363
14400
  return [4 /*yield*/, this.resetClient()];
14364
14401
  case 1:
14365
14402
  _a.sent();
@@ -14495,18 +14532,21 @@
14495
14532
  return BaseGraphqlServiceOptions;
14496
14533
  }());
14497
14534
  // eslint-disable-next-line @angular-eslint/directive-class-suffix
14498
- var BaseGraphqlService = /** @class */ (function () {
14535
+ var BaseGraphqlService = /** @class */ (function (_super) {
14536
+ __extends(BaseGraphqlService, _super);
14499
14537
  function BaseGraphqlService(graphql, options) {
14500
- this.graphql = graphql;
14501
- this._mutableWatchQueries = [];
14538
+ var _this = _super.call(this, graphql) || this;
14539
+ _this.graphql = graphql;
14540
+ _this._mutableWatchQueries = [];
14502
14541
  // Max updated queries, for this entity.
14503
14542
  // - Can be override by subclasses (in constructor)
14504
14543
  // - Use value -1 for no max size
14505
14544
  // - Default value to 3, because it usually enough (e.g. OperationService and LandingService need at least 2)
14506
- this._mutableWatchQueriesMaxCount = 3;
14545
+ _this._mutableWatchQueriesMaxCount = 3;
14507
14546
  // for DEV only
14508
- this._debug = toBoolean(options && !options.production, !environment.production);
14509
- this._logPrefix = "[base-graphql-service] ";
14547
+ _this._debug = toBoolean(options && !options.production, !environment.production);
14548
+ _this._logPrefix = "[base-graphql-service] ";
14549
+ return _this;
14510
14550
  }
14511
14551
  BaseGraphqlService.prototype.mutableWatchQuery = function (opts) {
14512
14552
  opts.fetchPolicy = opts.fetchPolicy || this.graphql.defaultFetchPolicy;
@@ -14704,8 +14744,11 @@
14704
14744
  return { query: query, variables: variables };
14705
14745
  });
14706
14746
  };
14747
+ BaseGraphqlService.prototype.ngOnStart = function () {
14748
+ return Promise.resolve(null);
14749
+ };
14707
14750
  return BaseGraphqlService;
14708
- }());
14751
+ }(StartableService));
14709
14752
  BaseGraphqlService.decorators = [
14710
14753
  { type: i0.Directive }
14711
14754
  ];
@@ -14758,18 +14801,16 @@
14758
14801
  _this.onChange = new rxjs.Subject();
14759
14802
  _this.onAuthTokenChange = new rxjs.Subject();
14760
14803
  _this.onAuthBasicChange = new rxjs.Subject();
14761
- _this._data = {
14804
+ _this._cache = {
14762
14805
  loaded: false,
14763
14806
  keypair: null,
14764
14807
  authToken: null,
14765
14808
  authBasic: null,
14766
14809
  pubkey: null,
14767
14810
  mainProfile: null,
14768
- account: null,
14769
14811
  person: null,
14770
14812
  department: null
14771
14813
  };
14772
- _this._started = false;
14773
14814
  _this._$additionalFields = new rxjs.BehaviorSubject([]);
14774
14815
  _this._tokenType$ = new rxjs.BehaviorSubject(undefined);
14775
14816
  _this._debug = !environment.production;
@@ -14779,33 +14820,22 @@
14779
14820
  // Send auth token to the graphql layer, when changed
14780
14821
  _this.onAuthTokenChange.subscribe(function (token) { return _this.graphql.setAuthToken(token); });
14781
14822
  _this.onAuthBasicChange.subscribe(function (basic) { return _this.graphql.setAuthBasic(basic); });
14782
- // Listen graphql start (or restart)
14783
- _this.graphql.onStart.subscribe(function () { return __awaiter(_this, void 0, void 0, function () {
14784
- return __generator(this, function (_b) {
14785
- if (!this._started) {
14786
- this.ready();
14787
- }
14788
- if (this._started && this.isLogin()) {
14789
- console.debug('[account] Restarting, to retry to authenticate...');
14790
- this.restart();
14791
- }
14792
- return [2 /*return*/];
14793
- });
14794
- }); });
14795
14823
  // Force network to wait account service, after getting connection to the peer
14796
14824
  _this.network.on('beforeTryOnlineFinish', function (online) { return __awaiter(_this, void 0, void 0, function () {
14797
14825
  return __generator(this, function (_b) {
14798
14826
  switch (_b.label) {
14799
14827
  case 0:
14800
- if (!(online && (!this._started || this.isLogin()))) return [3 /*break*/, 2];
14801
- console.debug('[account] Force networkService.tryOnline() to wait, that account service is restarted...');
14802
- //await this.stop();
14828
+ if (!(online && (!this.started || this.isLogin()))) return [3 /*break*/, 3];
14829
+ console.debug('[account] Force networkService.tryOnline() to wait, that graphql and account service is restarted...');
14803
14830
  return [4 /*yield*/, sleep(500)];
14804
14831
  case 1:
14805
- //await this.stop();
14832
+ _b.sent(); // wait graphql service to be restarted
14833
+ if (!!this.started) return [3 /*break*/, 3];
14834
+ return [4 /*yield*/, this.ready()];
14835
+ case 2:
14806
14836
  _b.sent();
14807
- return [2 /*return*/, this.ready()];
14808
- case 2: return [2 /*return*/];
14837
+ _b.label = 3;
14838
+ case 3: return [2 /*return*/];
14809
14839
  }
14810
14840
  });
14811
14841
  }); });
@@ -14813,27 +14843,27 @@
14813
14843
  }
14814
14844
  Object.defineProperty(AccountService.prototype, "account", {
14815
14845
  get: function () {
14816
- return this._data.loaded ? this._data.account : undefined;
14846
+ return this._cache.loaded ? this._data : undefined;
14817
14847
  },
14818
14848
  enumerable: false,
14819
14849
  configurable: true
14820
14850
  });
14821
14851
  Object.defineProperty(AccountService.prototype, "person", {
14822
14852
  get: function () {
14823
- if (this._data.loaded && !this._data.person) {
14824
- this._data.person = this._data.loaded ? this._data.account.asPerson() : undefined;
14853
+ if (this._cache.loaded && !this._cache.person) {
14854
+ this._cache.person = this._cache.loaded ? this._data.asPerson() : undefined;
14825
14855
  }
14826
- return this._data.person;
14856
+ return this._cache.person;
14827
14857
  },
14828
14858
  enumerable: false,
14829
14859
  configurable: true
14830
14860
  });
14831
14861
  Object.defineProperty(AccountService.prototype, "department", {
14832
14862
  get: function () {
14833
- if (this._data.loaded && !this._data.department) {
14834
- this._data.department = this._data.loaded ? this._data.account.asPerson().department : undefined;
14863
+ if (this._cache.loaded && !this._cache.department) {
14864
+ this._cache.department = this._cache.loaded ? this._data.asPerson().department : undefined;
14835
14865
  }
14836
- return this._data.department;
14866
+ return this._cache.department;
14837
14867
  },
14838
14868
  enumerable: false,
14839
14869
  configurable: true
@@ -14847,109 +14877,91 @@
14847
14877
  console.info('[account] Using authentication token type: ' + value);
14848
14878
  this._tokenType$.next(value);
14849
14879
  // Reset values
14850
- this._data.authToken = undefined;
14880
+ this._cache.authToken = undefined;
14851
14881
  this.onAuthTokenChange.next(undefined);
14852
- this._data.authBasic = undefined;
14882
+ this._cache.authBasic = undefined;
14853
14883
  this.onAuthBasicChange.next(undefined);
14854
14884
  }
14855
14885
  },
14856
14886
  enumerable: false,
14857
14887
  configurable: true
14858
14888
  });
14859
- AccountService.prototype.start = function () {
14860
- var _this = this;
14861
- if (this._startPromise)
14862
- return this._startPromise;
14863
- if (this._started)
14864
- return Promise.resolve(this.account);
14865
- // Restoring local settings
14866
- this._startPromise = Promise.all([
14867
- this.settings.ready(),
14868
- // Wait token type to be set
14869
- firstNotNilPromise(this._tokenType$)
14870
- ])
14871
- .then(function () { return _this.restoreLocally(); })
14872
- .then(function () {
14873
- _this._started = true;
14874
- _this._startPromise = undefined;
14875
- return _this.account;
14876
- });
14877
- return this._startPromise;
14878
- };
14879
- Object.defineProperty(AccountService.prototype, "started", {
14880
- get: function () {
14881
- return this._started;
14882
- },
14883
- enumerable: false,
14884
- configurable: true
14885
- });
14886
- AccountService.prototype.stop = function () {
14889
+ AccountService.prototype.ngOnStart = function () {
14887
14890
  return __awaiter(this, void 0, void 0, function () {
14888
- var hadAuthToken, hadAuthBasic, hadAuth;
14891
+ var _this = this;
14889
14892
  return __generator(this, function (_b) {
14890
- if (this._started || this._startPromise) {
14891
- this._started = false;
14892
- this._startPromise = undefined;
14893
- hadAuthToken = this._data.authToken && true;
14894
- hadAuthBasic = this._data.authBasic && true;
14895
- hadAuth = hadAuthToken || hadAuthBasic;
14896
- this.resetData();
14897
- if (hadAuth) {
14898
- this.onLogout.next();
14899
- this.onChange.next(undefined);
14900
- if (hadAuthToken)
14901
- this.onAuthTokenChange.next(undefined);
14902
- if (hadAuthBasic)
14903
- this.onAuthBasicChange.next(undefined);
14904
- }
14893
+ switch (_b.label) {
14894
+ case 0: return [4 /*yield*/, Promise.all([
14895
+ this.settings.ready(),
14896
+ // Wait token type to be set
14897
+ firstNotNilPromise(this._tokenType$)
14898
+ ])];
14899
+ case 1:
14900
+ _b.sent();
14901
+ // Listen graphql start (or restart)
14902
+ this.registerSubscription(this.graphql.onStart.subscribe(function () {
14903
+ if (_this.started && _this.isLogin()) {
14904
+ console.debug('[account] Restarting, to retry to authenticate...');
14905
+ _this.restart();
14906
+ }
14907
+ }));
14908
+ return [4 /*yield*/, this.restoreLocally()];
14909
+ case 2:
14910
+ _b.sent();
14911
+ return [4 /*yield*/, this.listenSettings()];
14912
+ case 3:
14913
+ _b.sent();
14914
+ return [2 /*return*/, this._data];
14905
14915
  }
14906
- return [2 /*return*/];
14907
14916
  });
14908
14917
  });
14909
14918
  };
14910
- AccountService.prototype.restart = function () {
14919
+ AccountService.prototype.ngOnStop = function () {
14911
14920
  return __awaiter(this, void 0, void 0, function () {
14921
+ var hadAuthToken, hadAuthBasic, hadAuth;
14912
14922
  return __generator(this, function (_b) {
14913
- switch (_b.label) {
14914
- case 0: return [4 /*yield*/, this.stop()];
14915
- case 1:
14916
- _b.sent();
14917
- return [2 /*return*/, this.start()];
14923
+ hadAuthToken = this._cache.authToken && true;
14924
+ hadAuthBasic = this._cache.authBasic && true;
14925
+ hadAuth = hadAuthToken || hadAuthBasic;
14926
+ this.resetData();
14927
+ if (hadAuth) {
14928
+ this.onLogout.next();
14929
+ this.onChange.next(undefined);
14930
+ if (hadAuthToken)
14931
+ this.onAuthTokenChange.next(undefined);
14932
+ if (hadAuthBasic)
14933
+ this.onAuthBasicChange.next(undefined);
14918
14934
  }
14935
+ return [2 /*return*/];
14919
14936
  });
14920
14937
  });
14921
14938
  };
14922
- AccountService.prototype.ready = function () {
14923
- if (this._started)
14924
- return Promise.resolve(this.account);
14925
- return this.start();
14926
- };
14927
14939
  AccountService.prototype.isLogin = function () {
14928
- return !!(this._data.pubkey && this._data.loaded);
14940
+ return !!(this._cache.pubkey && this._cache.loaded);
14929
14941
  };
14930
14942
  AccountService.prototype.isAuth = function () {
14931
- return !!(this._data.pubkey && this._data.keypair && this._data.keypair.secretKey);
14943
+ return !!(this._cache.pubkey && this._cache.keypair && this._cache.keypair.secretKey);
14932
14944
  };
14933
14945
  AccountService.prototype.hasMinProfile = function (userProfile) {
14934
14946
  // should be login, and status ENABLE or TEMPORARY
14935
- if (!this._data.account || !this._data.account.pubkey ||
14936
- (this._data.account.statusId !== StatusIds.ENABLE && this._data.account.statusId !== StatusIds.TEMPORARY)) {
14947
+ if (!this._data || !this._data.pubkey ||
14948
+ (this._data.statusId !== StatusIds.ENABLE && this._data.statusId !== StatusIds.TEMPORARY)) {
14937
14949
  return false;
14938
14950
  }
14939
- return PersonUtils.hasUpperOrEqualsProfile(this._data.account.profiles, userProfile);
14951
+ return PersonUtils.hasUpperOrEqualsProfile(this._data.profiles, userProfile);
14940
14952
  };
14941
14953
  AccountService.prototype.hasExactProfile = function (label) {
14942
14954
  // should be login, and status ENABLE or TEMPORARY
14943
- if (!this._data.account || !this._data.account.pubkey ||
14944
- (this._data.account.statusId !== StatusIds.ENABLE && this._data.account.statusId !== StatusIds.TEMPORARY))
14955
+ if (!this._data || !this._data.pubkey ||
14956
+ (this._data.statusId !== StatusIds.ENABLE && this._data.statusId !== StatusIds.TEMPORARY))
14945
14957
  return false;
14946
- return this._data.account.profiles.some(function (profile) { return profile === label; });
14958
+ return this._data.profiles.some(function (profile) { return profile === label; });
14947
14959
  };
14948
14960
  AccountService.prototype.hasProfileAndIsEnable = function (userProfile) {
14949
14961
  // should be login, and status ENABLE
14950
- if (!this._data.account || !this._data.account.pubkey || this._data.account.statusId !== StatusIds.ENABLE)
14962
+ if (!this._data || !this._data.pubkey || this._data.statusId !== StatusIds.ENABLE)
14951
14963
  return false;
14952
- return PersonUtils.hasUpperOrEqualsProfile(this._data.account.profiles, userProfile);
14964
+ return PersonUtils.hasUpperOrEqualsProfile(this._data.profiles, userProfile);
14953
14965
  };
14954
14966
  AccountService.prototype.isAdmin = function () {
14955
14967
  return this.hasProfileAndIsEnable('ADMIN');
@@ -14969,11 +14981,11 @@
14969
14981
  };
14970
14982
  AccountService.prototype.isOnlyGuest = function () {
14971
14983
  // Should be login, and status ENABLE or TEMPORARY
14972
- if (!this._data.account || !this._data.account.pubkey ||
14973
- (this._data.account.statusId !== StatusIds.ENABLE && this._data.account.statusId !== StatusIds.TEMPORARY))
14984
+ if (!this._data || !this._data.pubkey ||
14985
+ (this._data.statusId !== StatusIds.ENABLE && this._data.statusId !== StatusIds.TEMPORARY))
14974
14986
  return false;
14975
14987
  // Profile less then user
14976
- return !PersonUtils.hasUpperOrEqualsProfile(this._data.account.profiles, 'USER');
14988
+ return !PersonUtils.hasUpperOrEqualsProfile(this._data.profiles, 'USER');
14977
14989
  };
14978
14990
  AccountService.prototype.canUserWriteDataForDepartment = function (recorderDepartment) {
14979
14991
  if (ReferentialUtils.isEmpty(recorderDepartment)) {
@@ -14982,17 +14994,17 @@
14982
14994
  return this.isAdmin();
14983
14995
  }
14984
14996
  // Should be login, and status ENABLE
14985
- if (!this._data.account || !this._data.account.pubkey || this._data.account.statusId !== StatusIds.ENABLE)
14997
+ if (!this._data || !this._data.pubkey || this._data.statusId !== StatusIds.ENABLE)
14986
14998
  return false;
14987
- if (!this._data.account.department || !this._data.account.department.id) {
14999
+ if (!this._data.department || !this._data.department.id) {
14988
15000
  console.warn('User account has no department ! Unable to check write right against recorderDepartment');
14989
15001
  return false;
14990
15002
  }
14991
15003
  // Same recorder department: OK, user can write
14992
- if (this._data.account.department.id === recorderDepartment.id)
15004
+ if (this._data.department.id === recorderDepartment.id)
14993
15005
  return true;
14994
15006
  // Else, check if supervisor (or more)
14995
- return PersonUtils.hasUpperOrEqualsProfile(this._data.account.profiles, 'SUPERVISOR');
15007
+ return PersonUtils.hasUpperOrEqualsProfile(this._data.profiles, 'SUPERVISOR');
14996
15008
  };
14997
15009
  AccountService.prototype.register = function (data) {
14998
15010
  return __awaiter(this, void 0, void 0, function () {
@@ -15007,7 +15019,7 @@
15007
15019
  throw new Error('Missing required username or password');
15008
15020
  if (this._debug)
15009
15021
  console.debug('[account] Register new user account...', data.account);
15010
- this._data.loaded = false;
15022
+ this._cache.loaded = false;
15011
15023
  now = Date.now();
15012
15024
  _b.label = 1;
15013
15025
  case 1:
@@ -15021,29 +15033,29 @@
15021
15033
  data.account.settings.locale = this.settings.locale;
15022
15034
  data.account.settings.latLongFormat = this.settings.latLongFormat;
15023
15035
  data.account.department.id = data.account.department.id || this.environment.defaultDepartmentId;
15024
- this._data.keypair = keypair;
15036
+ this._cache.keypair = keypair;
15025
15037
  return [4 /*yield*/, this.saveRemotely(data.account, keypair)];
15026
15038
  case 3:
15027
15039
  account = _b.sent();
15028
15040
  // Default values
15029
15041
  account.avatar = account.avatar || (this.environment.baseUrl + DEFAULT_AVATAR_IMAGE);
15030
- this._data.mainProfile = PersonUtils.getMainProfile(account.profiles);
15031
- this._data.account = account;
15032
- this._data.pubkey = account.pubkey;
15042
+ this._cache.mainProfile = PersonUtils.getMainProfile(account.profiles);
15043
+ this._data = account;
15044
+ this._cache.pubkey = account.pubkey;
15033
15045
  // Try to auth on pod
15034
15046
  return [4 /*yield*/, this.authenticate(data)];
15035
15047
  case 4:
15036
15048
  // Try to auth on pod
15037
15049
  _b.sent();
15038
- this._data.loaded = true;
15050
+ this._cache.loaded = true;
15039
15051
  return [4 /*yield*/, this.saveLocally()];
15040
15052
  case 5:
15041
15053
  _b.sent();
15042
15054
  console.debug("[account] Account successfully registered in " + (Date.now() - now) + "ms");
15043
15055
  // Emit events
15044
- this.onLogin.next(this._data.account);
15045
- this.onChange.next(this._data.account);
15046
- return [2 /*return*/, this._data.account];
15056
+ this.onLogin.next(this._data);
15057
+ this.onChange.next(this._data);
15058
+ return [2 /*return*/, this._data];
15047
15059
  case 6:
15048
15060
  error_1 = _b.sent();
15049
15061
  console.error(error_1 && error_1.message || error_1);
@@ -15065,22 +15077,22 @@
15065
15077
  // Basic auth
15066
15078
  if (tokenType === 'basic' || tokenType === 'basic-and-token') {
15067
15079
  // Generate the authBasic, if used
15068
- if (!this._data.authBasic) {
15080
+ if (!this._cache.authBasic) {
15069
15081
  // Skip if token already provided
15070
- if (!(this._data.authToken && tokenType === 'basic-and-token')) {
15082
+ if (!(this._cache.authToken && tokenType === 'basic-and-token')) {
15071
15083
  if (!data || !data.username || !data.password)
15072
15084
  throw new Error('Missing username and password');
15073
- this._data.authBasic = this.cryptoService.encodeBase64(data.username + ":" + data.password);
15085
+ this._cache.authBasic = this.cryptoService.encodeBase64(data.username + ":" + data.password);
15074
15086
  }
15075
15087
  }
15076
- this.onAuthBasicChange.next(this._data.authBasic);
15088
+ this.onAuthBasicChange.next(this._cache.authBasic);
15077
15089
  }
15078
15090
  if (!(tokenType === 'token' || tokenType === 'basic-and-token')) return [3 /*break*/, 5];
15079
15091
  _c.label = 2;
15080
15092
  case 2:
15081
15093
  _c.trys.push([2, 4, , 5]);
15082
- _b = this._data;
15083
- return [4 /*yield*/, this.authenticateAndGetToken(this._data.authToken)];
15094
+ _b = this._cache;
15095
+ return [4 /*yield*/, this.authenticateAndGetToken(this._cache.authToken)];
15084
15096
  case 3:
15085
15097
  _b.authToken = _c.sent();
15086
15098
  return [3 /*break*/, 5];
@@ -15093,7 +15105,7 @@
15093
15105
  case 5:
15094
15106
  // Forget authBasic, to switch to authToken
15095
15107
  if (tokenType === 'basic-and-token') {
15096
- this._data.authBasic = undefined;
15108
+ this._cache.authBasic = undefined;
15097
15109
  this.onAuthBasicChange.next(undefined);
15098
15110
  }
15099
15111
  return [2 /*return*/];
@@ -15124,18 +15136,18 @@
15124
15136
  throw { code: ErrorCodes$2.UNKNOWN_ERROR, message: 'ERROR.SCRYPT_ERROR' };
15125
15137
  case 4:
15126
15138
  // Store pubkey+keypair
15127
- this._data.pubkey = Base58.encode(keypair.publicKey);
15128
- this._data.keypair = keypair;
15139
+ this._cache.pubkey = Base58.encode(keypair.publicKey);
15140
+ this._cache.keypair = keypair;
15129
15141
  return [4 /*yield*/, this.storage.get(TOKEN_STORAGE_KEY)];
15130
15142
  case 5:
15131
15143
  previousToken = _b.sent();
15132
- previousToken = previousToken && previousToken.startsWith(this._data.pubkey) && previousToken || null;
15144
+ previousToken = previousToken && previousToken.startsWith(this._cache.pubkey) && previousToken || null;
15133
15145
  offline = this.settings.hasOfflineFeature() && (this.network.offline || data.offline === true);
15134
15146
  if (!offline) return [3 /*break*/, 6];
15135
- this._data.authToken = previousToken;
15147
+ this._cache.authToken = previousToken;
15136
15148
  // Make sure network if set as offline
15137
15149
  this.network.setForceOffline(true, { showToast: false });
15138
- console.info("[account] Login [OK] {pubkey: " + this._data.pubkey.substr(0, 8) + "}, {offline: true}");
15150
+ console.info("[account] Login [OK] {pubkey: " + this._cache.pubkey.substr(0, 8) + "}, {offline: true}");
15139
15151
  return [3 /*break*/, 9];
15140
15152
  case 6:
15141
15153
  _b.trys.push([6, 8, , 9]);
@@ -15195,9 +15207,9 @@
15195
15207
  throw error_5;
15196
15208
  case 21:
15197
15209
  // Emit event to observers
15198
- this.onLogin.next(this._data.account);
15199
- this.onChange.next(this._data.account);
15200
- return [2 /*return*/, this._data.account];
15210
+ this.onLogin.next(this._data);
15211
+ this.onChange.next(this._data);
15212
+ return [2 /*return*/, this._data];
15201
15213
  }
15202
15214
  });
15203
15215
  });
@@ -15207,7 +15219,7 @@
15207
15219
  return __generator(this, function (_b) {
15208
15220
  switch (_b.label) {
15209
15221
  case 0:
15210
- if (!this._data.pubkey)
15222
+ if (!this._cache.pubkey)
15211
15223
  throw new Error('User not logged');
15212
15224
  if (this.network.offline)
15213
15225
  throw new Error('Cannot check account in offline mode');
@@ -15219,9 +15231,9 @@
15219
15231
  _b.sent();
15220
15232
  console.debug('[account] Successfully reload account');
15221
15233
  // Emit login event to subscribers
15222
- this.onLogin.next(this._data.account);
15223
- this.onChange.next(this._data.account);
15224
- return [2 /*return*/, this._data.account];
15234
+ this.onLogin.next(this._data);
15235
+ this.onChange.next(this._data);
15236
+ return [2 /*return*/, this._data];
15225
15237
  }
15226
15238
  });
15227
15239
  });
@@ -15236,27 +15248,27 @@
15236
15248
  return __generator(this, function (_b) {
15237
15249
  switch (_b.label) {
15238
15250
  case 0:
15239
- if (!this._data.pubkey)
15251
+ if (!this._cache.pubkey)
15240
15252
  return [2 /*return*/, Promise.reject('User not logged')];
15241
- if (this._data.pubkey !== account.pubkey)
15253
+ if (this._cache.pubkey !== account.pubkey)
15242
15254
  return [2 /*return*/, Promise.reject('Not user account')];
15243
- return [4 /*yield*/, this.saveRemotely(account, this._data.keypair)];
15255
+ return [4 /*yield*/, this.saveRemotely(account, this._cache.keypair)];
15244
15256
  case 1:
15245
15257
  account = _b.sent();
15246
15258
  // Set defaults
15247
15259
  account.avatar = account.avatar || (this.environment.baseUrl + DEFAULT_AVATAR_IMAGE);
15248
- this._data.mainProfile = PersonUtils.getMainProfile(account.profiles);
15249
- this._data.account = account;
15250
- this._data.loaded = true;
15260
+ this._cache.mainProfile = PersonUtils.getMainProfile(account.profiles);
15261
+ this._data = account;
15262
+ this._cache.loaded = true;
15251
15263
  // Save locally (in storage)
15252
15264
  return [4 /*yield*/, this.saveLocally()];
15253
15265
  case 2:
15254
15266
  // Save locally (in storage)
15255
15267
  _b.sent();
15256
15268
  // Send event
15257
- this.onLogin.next(this._data.account);
15258
- this.onChange.next(this._data.account);
15259
- return [2 /*return*/, this._data.account];
15269
+ this.onLogin.next(this._data);
15270
+ this.onChange.next(this._data);
15271
+ return [2 /*return*/, this._data];
15260
15272
  }
15261
15273
  });
15262
15274
  });
@@ -15267,9 +15279,9 @@
15267
15279
  return __generator(this, function (_b) {
15268
15280
  switch (_b.label) {
15269
15281
  case 0:
15270
- hadAuthToken = this._data.authToken && true;
15271
- hadAuthBasic = this._data.authBasic && true;
15272
- pubkey = this._data && this._data.pubkey;
15282
+ hadAuthToken = this._cache.authToken && true;
15283
+ hadAuthBasic = this._cache.authBasic && true;
15284
+ pubkey = this._cache && this._cache.pubkey;
15273
15285
  this.resetData();
15274
15286
  if (!!this.settings.hasOfflineFeature()) return [3 /*break*/, 2];
15275
15287
  // Remove all data from the local storage
@@ -15341,9 +15353,9 @@
15341
15353
  case 1:
15342
15354
  json = _b.sent();
15343
15355
  json = json && (typeof json === 'string') && JSON.parse(json) || json;
15344
- json = json && this._data.pubkey && (json.pubkey === this._data.pubkey) && json || null;
15345
- if (!(!json && this._data.pubkey)) return [3 /*break*/, 3];
15346
- return [4 /*yield*/, this.storage.get(ACCOUNT_STORAGE_KEY + '#' + this._data.pubkey)];
15356
+ json = json && this._cache.pubkey && (json.pubkey === this._cache.pubkey) && json || null;
15357
+ if (!(!json && this._cache.pubkey)) return [3 /*break*/, 3];
15358
+ return [4 /*yield*/, this.storage.get(ACCOUNT_STORAGE_KEY + '#' + this._cache.pubkey)];
15347
15359
  case 2:
15348
15360
  json = _b.sent();
15349
15361
  json = json && (typeof json === 'string') && JSON.parse(json) || json;
@@ -15475,7 +15487,7 @@
15475
15487
  };
15476
15488
  AccountService.prototype.listenChanges = function () {
15477
15489
  var _this = this;
15478
- if (!this._data.pubkey)
15490
+ if (!this._cache.pubkey)
15479
15491
  return rxjs.Subscription.EMPTY;
15480
15492
  var self = this;
15481
15493
  console.debug('[account] [WS] Listening account changes');
@@ -15498,7 +15510,7 @@
15498
15510
  case 0:
15499
15511
  if (!data)
15500
15512
  return [2 /*return*/];
15501
- existingUpdateDate = toDateISOString((_a = self._data.account) === null || _a === void 0 ? void 0 : _a.updateDate);
15513
+ existingUpdateDate = toDateISOString((_a = self._data) === null || _a === void 0 ? void 0 : _a.updateDate);
15502
15514
  if (!(existingUpdateDate !== data.updateDate)) return [3 /*break*/, 2];
15503
15515
  console.debug("[account] [WS] Detected update on {" + data.updateDate + "}");
15504
15516
  return [4 /*yield*/, self.refresh()];
@@ -15542,27 +15554,6 @@
15542
15554
  subscription.add(function () { return console.debug('[account] [WS] Stop listening account changes'); });
15543
15555
  return subscription;
15544
15556
  };
15545
- /**
15546
- * @deprecated
15547
- */
15548
- AccountService.prototype.getPageSettings = function (pageId, propertyName) {
15549
- return this.settings.getPageSettings(pageId, propertyName);
15550
- };
15551
- /**
15552
- * @deprecated
15553
- */
15554
- AccountService.prototype.savePageSetting = function (pageId, value, propertyName) {
15555
- return __awaiter(this, void 0, void 0, function () {
15556
- return __generator(this, function (_b) {
15557
- switch (_b.label) {
15558
- case 0: return [4 /*yield*/, this.settings.savePageSetting(pageId, value, propertyName)];
15559
- case 1:
15560
- _b.sent();
15561
- return [2 /*return*/];
15562
- }
15563
- });
15564
- });
15565
- };
15566
15557
  Object.defineProperty(AccountService.prototype, "additionalFields", {
15567
15558
  get: function () {
15568
15559
  return this._$additionalFields.getValue();
@@ -15591,28 +15582,28 @@
15591
15582
  };
15592
15583
  /* -- protected method -- */
15593
15584
  AccountService.prototype.resetData = function () {
15594
- this._data.loaded = false;
15595
- this._data.keypair = null;
15596
- this._data.authToken = null;
15597
- this._data.authBasic = null;
15598
- this._data.pubkey = null;
15599
- this._data.mainProfile = null;
15600
- this._data.account = new exports.Account();
15601
- this._data.person = null;
15602
- this._data.department = null;
15585
+ this._cache.loaded = false;
15586
+ this._cache.keypair = null;
15587
+ this._cache.authToken = null;
15588
+ this._cache.authBasic = null;
15589
+ this._cache.pubkey = null;
15590
+ this._cache.mainProfile = null;
15591
+ this._cache.person = null;
15592
+ this._cache.department = null;
15593
+ this._data = new exports.Account();
15603
15594
  };
15604
15595
  AccountService.prototype.loadData = function (opts) {
15605
15596
  return __awaiter(this, void 0, void 0, function () {
15606
- var account, error_6;
15597
+ var account, accountSettingsContentKeys, settings, error_6;
15607
15598
  return __generator(this, function (_b) {
15608
15599
  switch (_b.label) {
15609
15600
  case 0:
15610
- if (!this._data.pubkey)
15601
+ if (!this._cache.pubkey)
15611
15602
  throw new Error('User not logged');
15612
- this._data.loaded = false;
15603
+ this._cache.loaded = false;
15613
15604
  _b.label = 1;
15614
15605
  case 1:
15615
- _b.trys.push([1, 3, , 4]);
15606
+ _b.trys.push([1, 5, , 6]);
15616
15607
  return [4 /*yield*/, this.load(opts)];
15617
15608
  case 2:
15618
15609
  account = (_b.sent()) || new exports.Account();
@@ -15621,18 +15612,27 @@
15621
15612
  account.settings = account.settings || new exports.UserSettings();
15622
15613
  account.settings.locale = account.settings.locale || this.settings.locale;
15623
15614
  account.settings.latLongFormat = account.settings.latLongFormat || this.settings.latLongFormat || 'DDMM';
15615
+ account.settings.content = account.settings.content || {};
15624
15616
  // Read main profile
15625
- this._data.mainProfile = PersonUtils.getMainProfile(account.profiles);
15617
+ this._cache.mainProfile = PersonUtils.getMainProfile(account.profiles);
15626
15618
  // Update, instead of replace it
15627
- if (this._data.account) {
15628
- this._data.account.fromObject(account);
15619
+ if (this._data) {
15620
+ this._data.fromObject(account);
15629
15621
  }
15630
15622
  else {
15631
- this._data.account = account;
15623
+ this._data = account;
15632
15624
  }
15633
- this._data.loaded = true;
15634
- return [2 /*return*/, this._data.account];
15625
+ this._cache.loaded = true;
15626
+ accountSettingsContentKeys = Object.keys(account.settings.content);
15627
+ if (!isNotEmptyArray(accountSettingsContentKeys)) return [3 /*break*/, 4];
15628
+ settings = Object.assign(Object.assign(Object.assign({}, this.settings.settings), account.settings.content), account.settings);
15629
+ delete settings.content; // Remove content attribute
15630
+ return [4 /*yield*/, this.settings.apply(settings)];
15635
15631
  case 3:
15632
+ _b.sent();
15633
+ _b.label = 4;
15634
+ case 4: return [2 /*return*/, this._data];
15635
+ case 5:
15636
15636
  error_6 = _b.sent();
15637
15637
  this.resetData();
15638
15638
  if (error_6.code && error_6.message)
@@ -15642,11 +15642,23 @@
15642
15642
  code: ErrorCodes$2.LOAD_ACCOUNT_ERROR,
15643
15643
  message: 'ERROR.LOAD_ACCOUNT_ERROR'
15644
15644
  };
15645
- case 4: return [2 /*return*/];
15645
+ case 6: return [2 /*return*/];
15646
15646
  }
15647
15647
  });
15648
15648
  });
15649
15649
  };
15650
+ AccountService.prototype.listenSettings = function () {
15651
+ return __awaiter(this, void 0, void 0, function () {
15652
+ var _this = this;
15653
+ return __generator(this, function (_b) {
15654
+ // When settings changed: save it remotely
15655
+ this.registerSubscription(this.settings.onChange
15656
+ .pipe(operators.debounceTime(1000), operators.filter(function () { return _this.isLogin() && _this.network.online; }))
15657
+ .subscribe(function (settings) { return _this.saveLocalSettingsRemotely(settings); }));
15658
+ return [2 /*return*/];
15659
+ });
15660
+ });
15661
+ };
15650
15662
  AccountService.prototype.restoreLocally = function () {
15651
15663
  return __awaiter(this, void 0, void 0, function () {
15652
15664
  var values, pubkey, token, seckey, canRemoteAuth, error_7, jsonAccount, accountStr, account;
@@ -15670,9 +15682,9 @@
15670
15682
  return [2 /*return*/];
15671
15683
  if (this._debug)
15672
15684
  console.debug("[account] Account restoration...");
15673
- this._data.authToken = token;
15674
- this._data.pubkey = pubkey;
15675
- this._data.keypair = seckey && {
15685
+ this._cache.authToken = token;
15686
+ this._cache.pubkey = pubkey;
15687
+ this._cache.keypair = seckey && {
15676
15688
  publicKey: Base58.decode(pubkey),
15677
15689
  secretKey: Base58.decode(seckey)
15678
15690
  } || null;
@@ -15683,7 +15695,7 @@
15683
15695
  return [4 /*yield*/, this.authenticate()];
15684
15696
  case 3:
15685
15697
  _b.sent();
15686
- if (!this._data.authToken && !this._data.authBasic)
15698
+ if (!this._cache.authToken && !this._cache.authBasic)
15687
15699
  throw new Error('Authentication failed');
15688
15700
  return [3 /*break*/, 5];
15689
15701
  case 4:
@@ -15716,14 +15728,14 @@
15716
15728
  return [2 /*return*/];
15717
15729
  account = exports.Account.fromObject(jsonAccount);
15718
15730
  // Update data
15719
- this._data.account = account;
15720
- this._data.mainProfile = PersonUtils.getMainProfile(account.profiles);
15721
- this._data.loaded = true;
15731
+ this._data = account;
15732
+ this._cache.mainProfile = PersonUtils.getMainProfile(account.profiles);
15733
+ this._cache.loaded = true;
15722
15734
  // Emit event
15723
- this.onLogin.next(this._data.account);
15724
- this.onChange.next(this._data.account);
15735
+ this.onLogin.next(this._data);
15736
+ this.onChange.next(this._data);
15725
15737
  if (this._debug)
15726
- console.debug("[account] Account restoration [OK] {pubkey: " + pubkey.substr(0, 8) + "}, {profile: " + this._data.mainProfile + "}");
15738
+ console.debug("[account] Account restoration [OK] {pubkey: " + pubkey.substr(0, 8) + "}, {profile: " + this._cache.mainProfile + "}");
15727
15739
  return [2 /*return*/, account];
15728
15740
  }
15729
15741
  });
@@ -15739,12 +15751,12 @@
15739
15751
  return __generator(this, function (_b) {
15740
15752
  switch (_b.label) {
15741
15753
  case 0:
15742
- if (!this._data.pubkey)
15754
+ if (!this._cache.pubkey)
15743
15755
  throw new Error('User not logged');
15744
15756
  if (this._debug)
15745
- console.debug("[account] Saving account {" + this._data.pubkey.substring(0, 6) + "} in local storage...");
15746
- json = this._data.account.asObject({ keepTypename: true });
15747
- seckey = this._data.keypair && this._data.keypair.secretKey && Base58.encode(this._data.keypair.secretKey) || null;
15757
+ console.debug("[account] Saving account {" + this._cache.pubkey.substring(0, 6) + "} in local storage...");
15758
+ json = this._data.asObject({ keepTypename: true });
15759
+ seckey = this._cache.keypair && this._cache.keypair.secretKey && Base58.encode(this._cache.keypair.secretKey) || null;
15748
15760
  hasAvatarUrl = json.avatar && !json.avatar.endsWith(DEFAULT_AVATAR_IMAGE) &&
15749
15761
  (json.avatar.startsWith('http://') || (json.avatar.startsWith('https://')));
15750
15762
  if (!(hasAvatarUrl && this.network.online)) return [3 /*break*/, 2];
@@ -15767,9 +15779,9 @@
15767
15779
  case 2:
15768
15780
  _b.trys.push([2, 4, , 5]);
15769
15781
  return [4 /*yield*/, Promise.all([
15770
- this.storage.set(PUBKEY_STORAGE_KEY, this._data.pubkey),
15771
- this.storage.set(TOKEN_STORAGE_KEY, this._data.authToken),
15772
- this.storage.set(ACCOUNT_STORAGE_KEY + "#" + this._data.pubkey, json),
15782
+ this.storage.set(PUBKEY_STORAGE_KEY, this._cache.pubkey),
15783
+ this.storage.set(TOKEN_STORAGE_KEY, this._cache.authToken),
15784
+ this.storage.set(ACCOUNT_STORAGE_KEY + "#" + this._cache.pubkey, json),
15773
15785
  // Secret key (optional)
15774
15786
  seckey && this.storage.set(SECKEY_STORAGE_KEY, seckey) || this.storage.remove(SECKEY_STORAGE_KEY),
15775
15787
  // Remove old storage key
@@ -15789,6 +15801,30 @@
15789
15801
  });
15790
15802
  });
15791
15803
  };
15804
+ AccountService.prototype.saveLocalSettingsRemotely = function (source) {
15805
+ return __awaiter(this, void 0, void 0, function () {
15806
+ var account, settings, hasChanges;
15807
+ return __generator(this, function (_b) {
15808
+ switch (_b.label) {
15809
+ case 0:
15810
+ if (!source || !this.isLogin())
15811
+ return [2 /*return*/]; // Skip
15812
+ account = this.account;
15813
+ settings = exports.UserSettings.fromObject(account.settings) || new exports.UserSettings();
15814
+ hasChanges = settings.merge(source, ['locale', 'latLongFormat', 'properties']);
15815
+ if (!hasChanges) return [3 /*break*/, 2];
15816
+ if (this._debug)
15817
+ console.debug('[account] Save local settings remotely', settings);
15818
+ account.settings = settings;
15819
+ return [4 /*yield*/, this.saveRemotely(account)];
15820
+ case 1:
15821
+ _b.sent();
15822
+ _b.label = 2;
15823
+ case 2: return [2 /*return*/];
15824
+ }
15825
+ });
15826
+ });
15827
+ };
15792
15828
  /**
15793
15829
  * Create or update an user account
15794
15830
  *
@@ -15846,7 +15882,7 @@
15846
15882
  return __generator(this, function (_b) {
15847
15883
  switch (_b.label) {
15848
15884
  case 0:
15849
- if (!this._data.pubkey)
15885
+ if (!this._cache.pubkey)
15850
15886
  throw new Error('User not logged');
15851
15887
  if (!counter)
15852
15888
  console.info('[account] Authentication on pod...');
@@ -15873,7 +15909,7 @@
15873
15909
  if (data_1 && data_1.authenticate) {
15874
15910
  // Store the token
15875
15911
  this.onAuthTokenChange.next(token);
15876
- console.info("[account] Authentication on pod [OK] {pubkey: '" + this._data.pubkey.substr(0, 8) + "'}");
15912
+ console.info("[account] Authentication on pod [OK] {pubkey: '" + this._cache.pubkey.substr(0, 8) + "'}");
15877
15913
  return [2 /*return*/, token]; // return the token
15878
15914
  }
15879
15915
  _b.label = 2;
@@ -15899,10 +15935,10 @@
15899
15935
  if (!signatureOK) {
15900
15936
  console.warn('FIXME: Bad peer signature on auth challenge !', data.authChallenge);
15901
15937
  }
15902
- return [4 /*yield*/, this.cryptoService.sign(data.authChallenge.challenge, this._data.keypair)];
15938
+ return [4 /*yield*/, this.cryptoService.sign(data.authChallenge.challenge, this._cache.keypair)];
15903
15939
  case 5:
15904
15940
  signature = _b.sent();
15905
- newToken = this._data.pubkey + ":" + data.authChallenge.challenge + "|" + signature;
15941
+ newToken = this._cache.pubkey + ":" + data.authChallenge.challenge + "|" + signature;
15906
15942
  return [4 /*yield*/, this.authenticateAndGetToken(newToken, (counter || 1) + 1 /* increment */)];
15907
15943
  case 6:
15908
15944
  // iterate with the new token
@@ -16207,94 +16243,42 @@
16207
16243
  _this.toastController = toastController;
16208
16244
  _this.translate = translate;
16209
16245
  _this.environment = environment;
16210
- _this._started = false;
16211
- _this._subscription = new rxjs.Subscription();
16212
16246
  _this.$data = new rxjs.BehaviorSubject(null);
16213
16247
  _this._debug = !environment.production;
16214
16248
  if (_this._debug)
16215
16249
  console.debug('[config] Creating service');
16216
16250
  _this._optionDefs = Object.values(Object.assign(Object.assign({}, CORE_CONFIG_OPTIONS), defaultOptionsMap));
16217
- // Restart if graphql service restart
16218
- _this.graphql.onStart.subscribe(function () { return _this.restart(); });
16219
- // Start
16220
- if (_this.graphql.started) {
16221
- _this.start();
16222
- }
16223
16251
  return _this;
16224
16252
  }
16225
- Object.defineProperty(ConfigService.prototype, "started", {
16226
- get: function () {
16227
- return this._started;
16228
- },
16229
- enumerable: false,
16230
- configurable: true
16231
- });
16232
16253
  Object.defineProperty(ConfigService.prototype, "config", {
16233
16254
  get: function () {
16234
16255
  // If first call: start loading
16235
- if (!this._started)
16256
+ if (!this.started)
16236
16257
  this.start();
16237
16258
  return this.$data.pipe(operators.filter(isNotNil));
16238
16259
  },
16239
16260
  enumerable: false,
16240
16261
  configurable: true
16241
16262
  });
16242
- ConfigService.prototype.start = function () {
16243
- var _this = this;
16244
- if (this._startPromise)
16245
- return this._startPromise;
16246
- if (this._started)
16247
- return;
16248
- console.info('[config] Starting configuration...');
16249
- this._startPromise = this.graphql.ready()
16250
- .then(function () { return _this.loadOrRestoreLocally(); })
16251
- .then(function (data) {
16252
- _this._started = true;
16253
- _this._startPromise = undefined;
16254
- _this.$data.next(data);
16255
- return data;
16256
- })
16257
- .catch(function (err) {
16258
- console.error(err && err.message || err, err);
16259
- _this._started = false;
16260
- _this._startPromise = undefined;
16261
- return null;
16262
- });
16263
- return this._startPromise;
16264
- };
16265
- ConfigService.prototype.stop = function () {
16266
- return __awaiter(this, void 0, void 0, function () {
16267
- return __generator(this, function (_a) {
16268
- this._subscription.unsubscribe();
16269
- this._subscription = new rxjs.Subscription();
16270
- this._started = false;
16271
- this._startPromise = undefined;
16272
- return [2 /*return*/];
16273
- });
16274
- });
16275
- };
16276
- ConfigService.prototype.restart = function () {
16263
+ ConfigService.prototype.ngOnStart = function () {
16277
16264
  return __awaiter(this, void 0, void 0, function () {
16265
+ var data;
16266
+ var _this = this;
16278
16267
  return __generator(this, function (_a) {
16279
16268
  switch (_a.label) {
16280
16269
  case 0:
16281
- if (!this.started) return [3 /*break*/, 2];
16282
- return [4 /*yield*/, this.stop()];
16270
+ console.info('[config] Starting configuration...');
16271
+ return [4 /*yield*/, this.loadOrRestoreLocally()];
16283
16272
  case 1:
16284
- _a.sent();
16285
- _a.label = 2;
16286
- case 2: return [2 /*return*/, this.start()];
16273
+ data = _a.sent();
16274
+ this.$data.next(data);
16275
+ // Restart if graphql service restart
16276
+ this.registerSubscription(this.graphql.onStart.subscribe(function () { return _this.restart(); }));
16277
+ return [2 /*return*/, data];
16287
16278
  }
16288
16279
  });
16289
16280
  });
16290
16281
  };
16291
- ConfigService.prototype.ready = function () {
16292
- if (this._started)
16293
- return Promise.resolve(this.$data.value);
16294
- if (this._startPromise)
16295
- return this._startPromise;
16296
- return this.start();
16297
- };
16298
16282
  ConfigService.prototype.loadDefault = function (opts) {
16299
16283
  return __awaiter(this, void 0, void 0, function () {
16300
16284
  var now, query, variables, res, data;
@@ -22832,12 +22816,6 @@
22832
22816
  _this.defaultSortBy = options.defaultSortBy || 'id';
22833
22817
  _this.defaultSortDirection = options.defaultSortDirection || 'asc';
22834
22818
  _this.watchQueriesUpdatePolicy = options.watchQueriesUpdatePolicy || 'update-cache';
22835
- platform.ready().then(function () {
22836
- // No limit for updatable watch queries, if desktop
22837
- if (!platform.mobile) {
22838
- _this._mutableWatchQueriesMaxCount = -1;
22839
- }
22840
- });
22841
22819
  var obj = new dataType();
22842
22820
  _this._typename = obj.__typename || 'UnknownVO';
22843
22821
  _this._logTypeName = removeEnd(_this._typename, 'VO');
@@ -23293,6 +23271,17 @@
23293
23271
  return EntityFilterUtils.fromObject(source, this.filterType);
23294
23272
  };
23295
23273
  /* -- protected functions -- */
23274
+ BaseEntityService.prototype.ngOnStart = function () {
23275
+ return __awaiter(this, void 0, void 0, function () {
23276
+ return __generator(this, function (_b) {
23277
+ // No limit for updatable watch queries, if desktop
23278
+ if (!this.platform.mobile) {
23279
+ this._mutableWatchQueriesMaxCount = -1;
23280
+ }
23281
+ return [2 /*return*/];
23282
+ });
23283
+ });
23284
+ };
23296
23285
  BaseEntityService.prototype.fillDefaultProperties = function (source) {
23297
23286
  // Can be override by subclasses
23298
23287
  };