@sumaris-net/ngx-components 0.26.7 → 0.27.0

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.
@@ -8537,13 +8537,14 @@
8537
8537
  };
8538
8538
 
8539
8539
  var StartableService = /** @class */ (function () {
8540
- function StartableService(platform) {
8540
+ function StartableService(prerequisiteService) {
8541
8541
  this.onStart = new rxjs.Subject();
8542
8542
  this._debug = false;
8543
+ this._startByReadyFunction = true; // should start when calling ready() ?
8543
8544
  this._data = null;
8544
8545
  this._started = false;
8545
- this._startPrerequisite = platform
8546
- ? function () { return platform.ready(); }
8546
+ this._startPrerequisite = prerequisiteService
8547
+ ? function () { return prerequisiteService.ready(); }
8547
8548
  : function () { return Promise.resolve(); };
8548
8549
  }
8549
8550
  StartableService.prototype.start = function () {
@@ -8628,9 +8629,15 @@
8628
8629
  configurable: true
8629
8630
  });
8630
8631
  StartableService.prototype.ready = function () {
8632
+ var _this = this;
8631
8633
  if (this._started)
8632
8634
  return Promise.resolve(this._data);
8633
- return this.start();
8635
+ if (this._startPromise)
8636
+ return this._startPromise;
8637
+ if (this._startByReadyFunction)
8638
+ return this.start();
8639
+ return waitFor(function () { return _this._started; })
8640
+ .then(function () { return _this._data; });
8634
8641
  };
8635
8642
  StartableService.prototype.ngOnStop = function () {
8636
8643
  return __awaiter(this, void 0, void 0, function () {
@@ -14078,7 +14085,6 @@
14078
14085
  .append('Authorization', authorization);
14079
14086
  //.append('X-App-Name', environment.name)
14080
14087
  //.append('X-App-Version', environment.version)
14081
- ;
14082
14088
  // Use the setContext method to set the HTTP headers.
14083
14089
  operation.setContext(Object.assign(Object.assign({}, operation.getContext()), { headers: headers }));
14084
14090
  // Call the next link in the middleware chain.
@@ -16464,41 +16470,38 @@
16464
16470
  var templateObject_1$3, templateObject_2$3, templateObject_3$2, templateObject_4$2, templateObject_5$1;
16465
16471
 
16466
16472
  var moment$2 = momentImported__namespace;
16467
- var PlatformService = /** @class */ (function () {
16473
+ var PlatformService = /** @class */ (function (_super) {
16474
+ __extends(PlatformService, _super);
16468
16475
  function PlatformService(platform, cdkPlatform, toastController, translate, dateAdapter, entitiesStorage, settings, networkService, accountService, configService, cache, storage, audioProvider, environment, statusBar, keyboard, splashScreen, browser, downloader) {
16469
- this.platform = platform;
16470
- this.cdkPlatform = cdkPlatform;
16471
- this.toastController = toastController;
16472
- this.translate = translate;
16473
- this.dateAdapter = dateAdapter;
16474
- this.entitiesStorage = entitiesStorage;
16475
- this.settings = settings;
16476
- this.networkService = networkService;
16477
- this.accountService = accountService;
16478
- this.configService = configService;
16479
- this.cache = cache;
16480
- this.storage = storage;
16481
- this.audioProvider = audioProvider;
16482
- this.environment = environment;
16483
- this.statusBar = statusBar;
16484
- this.keyboard = keyboard;
16485
- this.splashScreen = splashScreen;
16486
- this.browser = browser;
16487
- this.downloader = downloader;
16488
- this._started = false;
16489
- this._downloadingJobs = new Map();
16490
- this._debug = !environment.production;
16491
- if (this._debug)
16476
+ var _this = _super.call(this, platform) || this;
16477
+ _this.platform = platform;
16478
+ _this.cdkPlatform = cdkPlatform;
16479
+ _this.toastController = toastController;
16480
+ _this.translate = translate;
16481
+ _this.dateAdapter = dateAdapter;
16482
+ _this.entitiesStorage = entitiesStorage;
16483
+ _this.settings = settings;
16484
+ _this.networkService = networkService;
16485
+ _this.accountService = accountService;
16486
+ _this.configService = configService;
16487
+ _this.cache = cache;
16488
+ _this.storage = storage;
16489
+ _this.audioProvider = audioProvider;
16490
+ _this.environment = environment;
16491
+ _this.statusBar = statusBar;
16492
+ _this.keyboard = keyboard;
16493
+ _this.splashScreen = splashScreen;
16494
+ _this.browser = browser;
16495
+ _this.downloader = downloader;
16496
+ _this._downloadingJobs = new Map();
16497
+ _this._debug = !environment.production;
16498
+ if (_this._debug)
16492
16499
  console.debug('[platform] Creating service');
16493
- this.start();
16500
+ _this.start()
16501
+ // Manage error
16502
+ .catch(function (err) { return _this.onStartupError(err); });
16503
+ return _this;
16494
16504
  }
16495
- Object.defineProperty(PlatformService.prototype, "started", {
16496
- get: function () {
16497
- return this._started;
16498
- },
16499
- enumerable: false,
16500
- configurable: true
16501
- });
16502
16505
  Object.defineProperty(PlatformService.prototype, "mobile", {
16503
16506
  get: function () {
16504
16507
  return isNotNil(this._mobile) ? this._mobile : this.platform.is('mobile');
@@ -16532,80 +16535,81 @@
16532
16535
  PlatformService.prototype.height = function () {
16533
16536
  return this.platform.height();
16534
16537
  };
16535
- PlatformService.prototype.start = function () {
16536
- var _this = this;
16537
- if (this._startPromise)
16538
- return this._startPromise;
16539
- if (this._started)
16540
- return Promise.resolve();
16541
- this._started = false;
16542
- var now = Date.now();
16543
- this.accountService.tokenType = undefined;
16544
- console.info('[platform] Starting platform...');
16545
- this._startPromise = this.platform.ready()
16546
- .then(function () {
16547
- _this._mobile = _this.platform.is('mobile');
16548
- _this._cordova = _this.platform.is('cordova');
16549
- _this._android = _this.platform.is('android');
16550
- _this.configureCordovaPlugins(_this._mobile);
16551
- _this.touchUi = _this._mobile || _this.platform.is('tablet') || _this.platform.is('phablet');
16552
- // Force mobile in settings
16553
- if (_this._mobile) {
16554
- _this.settings.mobile = _this._mobile;
16555
- _this.settings.touchUi = _this.touchUi;
16556
- }
16557
- _this.configureTranslate();
16558
- })
16559
- .then(function () { return _this.storageReady(); })
16560
- .then(function (forage) { return _this.migrateStorage(forage); })
16561
- .then(function () { return Promise.all([
16562
- _this.entitiesStorage.ready(),
16563
- _this.cache.ready().then(function () { return _this.configureCache(); }),
16564
- _this.settings.ready(),
16565
- _this.networkService.ready(),
16566
- _this.audioProvider.ready()
16567
- ]); })
16568
- .then(function () {
16569
- _this._started = true;
16570
- _this._startPromise = undefined;
16571
- console.info("[platform] Starting platform [OK] {mobile: " + _this._mobile + ", touchUi: " + _this.touchUi + ", canDownload: " + _this.canDownload + "} in " + (Date.now() - now) + "ms");
16572
- // Update cache configuration when network changed
16573
- _this.networkService.onNetworkStatusChanges.subscribe(function (type) { return _this.configureCache(type !== 'none'); });
16574
- // Update authentication type
16575
- _this.configService.config
16576
- .pipe(operators.map(function (config) { return config === null || config === void 0 ? void 0 : config.getProperty(CORE_CONFIG_OPTIONS.AUTH_TOKEN_TYPE); }), operators.filter(isNotNilOrBlank), operators.distinctUntilChanged())
16577
- .subscribe(function (tokenType) {
16578
- console.info("[platform] Using auth token type {" + tokenType + "}");
16579
- _this.accountService.tokenType = tokenType;
16580
- });
16581
- // Wait 1 more seconds, before hiding the splash screen
16582
- setTimeout(function () {
16583
- if (_this.splashScreen)
16584
- _this.splashScreen.hide();
16585
- // Play startup sound
16586
- _this.audioProvider.playStartupSound();
16587
- }, 1000);
16588
- })
16589
- // Manage error
16590
- .catch(function (err) { return _this.onStartupError(err); });
16591
- return this._startPromise;
16592
- };
16593
- /**
16594
- * Wait platform is ready.<br/>
16595
- * Important: this will NOT start the platform, has it should be started by the AppComponent
16596
- *
16597
- * @param opts
16598
- */
16599
- PlatformService.prototype.ready = function (opts) {
16600
- var _this = this;
16601
- var period = opts && opts.checkPeriod || 300;
16602
- if (this._started)
16603
- return Promise.resolve();
16604
- return rxjs.timer(period, period)
16605
- .pipe(
16606
- // For DEBUG :
16607
- //tap(() => this._debug && console.debug("Waiting platform ready...")),
16608
- operators.filter(function () { return _this._started; }), operators.first()).toPromise();
16538
+ PlatformService.prototype.ngOnStart = function () {
16539
+ return __awaiter(this, void 0, void 0, function () {
16540
+ var now, forage, err_1;
16541
+ var _this = this;
16542
+ return __generator(this, function (_b) {
16543
+ switch (_b.label) {
16544
+ case 0:
16545
+ now = Date.now();
16546
+ this.accountService.tokenType = undefined;
16547
+ console.info('[platform] Starting platform...');
16548
+ _b.label = 1;
16549
+ case 1:
16550
+ _b.trys.push([1, 6, , 7]);
16551
+ this._mobile = this.platform.is('mobile');
16552
+ this._cordova = this.platform.is('cordova');
16553
+ this._android = this.platform.is('android');
16554
+ this.configureCordovaPlugins(this._mobile);
16555
+ this.touchUi = this._mobile || this.platform.is('tablet') || this.platform.is('phablet');
16556
+ // Force mobile in settings
16557
+ if (this._mobile) {
16558
+ this.settings.mobile = this._mobile;
16559
+ this.settings.touchUi = this.touchUi;
16560
+ }
16561
+ // Configure translation
16562
+ return [4 /*yield*/, this.configureTranslate()];
16563
+ case 2:
16564
+ // Configure translation
16565
+ _b.sent();
16566
+ return [4 /*yield*/, this.storageReady()];
16567
+ case 3:
16568
+ forage = _b.sent();
16569
+ return [4 /*yield*/, this.migrateStorage(forage)];
16570
+ case 4:
16571
+ _b.sent();
16572
+ // Start root services
16573
+ return [4 /*yield*/, Promise.all([
16574
+ this.entitiesStorage.ready(),
16575
+ this.cache.ready().then(function () { return _this.configureCache(); }),
16576
+ this.settings.ready(),
16577
+ this.networkService.ready(),
16578
+ this.audioProvider.ready()
16579
+ ])];
16580
+ case 5:
16581
+ // Start root services
16582
+ _b.sent();
16583
+ console.info("[platform] Starting platform [OK] {mobile: " + this._mobile + ", touchUi: " + this.touchUi + ", downloader: " + this.canDownload + "} in " + (Date.now() - now) + "ms");
16584
+ // Update cache configuration when network changed
16585
+ this.networkService.onNetworkStatusChanges
16586
+ .pipe(operators.skip(1)) // Skip the first event (behavior subject send event immediately)
16587
+ .subscribe(function (type) { return _this.configureCache(type !== 'none'); });
16588
+ // Update authentication type
16589
+ this.configService.config
16590
+ .pipe(operators.map(function (config) { return config === null || config === void 0 ? void 0 : config.getProperty(CORE_CONFIG_OPTIONS.AUTH_TOKEN_TYPE); }), operators.filter(isNotNilOrBlank), operators.distinctUntilChanged())
16591
+ .subscribe(function (tokenType) {
16592
+ console.info("[platform] Using auth token type {" + tokenType + "}");
16593
+ _this.accountService.tokenType = tokenType;
16594
+ });
16595
+ // Hide the splashscreen (if mobile) - after 1s
16596
+ if (this.mobile) {
16597
+ setTimeout(function () {
16598
+ var _a;
16599
+ (_a = _this.splashScreen) === null || _a === void 0 ? void 0 : _a.hide();
16600
+ // Play startup sound
16601
+ _this.audioProvider.playStartupSound();
16602
+ }, 1000);
16603
+ }
16604
+ return [3 /*break*/, 7];
16605
+ case 6:
16606
+ err_1 = _b.sent();
16607
+ // Manage startup error
16608
+ return [2 /*return*/, this.onStartupError(err_1)];
16609
+ case 7: return [2 /*return*/];
16610
+ }
16611
+ });
16612
+ });
16609
16613
  };
16610
16614
  PlatformService.prototype.open = function (url, target, features, replace) {
16611
16615
  console.info("[platform] Opening link: " + url);
@@ -16718,22 +16722,22 @@
16718
16722
  });
16719
16723
  };
16720
16724
  PlatformService.prototype.configureCache = function (online) {
16721
- online = isNotNil(online) ? online : this.cache.isOnline();
16725
+ online = toBoolean(online, this.cache.isOnline());
16722
16726
  var cacheTTL = online ? 3600 /* 1h */ : 3600 * 24 * 30; /* 1 month */
16723
- console.info("[platform] Configuring cache [OK] {online: " + online + "}, {timeToLive: " + cacheTTL / 3600 + "h}, {offlineInvalidate: false}");
16727
+ console.info("[platform] Configuring cache [OK] {online: " + online + ", timeToLive: " + cacheTTL / 3600 + "h, offlineInvalidate: false}");
16724
16728
  this.cache.setDefaultTTL(cacheTTL);
16725
16729
  this.cache.setOfflineInvalidate(false); // Do not invalidate cache when offline
16726
16730
  };
16727
16731
  PlatformService.prototype.storageReady = function () {
16728
16732
  return __awaiter(this, void 0, void 0, function () {
16729
16733
  var forage, driver;
16730
- return __generator(this, function (_a) {
16731
- switch (_a.label) {
16734
+ return __generator(this, function (_b) {
16735
+ switch (_b.label) {
16732
16736
  case 0:
16733
16737
  console.info("[platform] Starting storage...");
16734
16738
  return [4 /*yield*/, this.storage.ready()];
16735
16739
  case 1:
16736
- forage = _a.sent();
16740
+ forage = _b.sent();
16737
16741
  driver = forage.driver();
16738
16742
  if (isNil(driver)) {
16739
16743
  console.error('[platform] NO DRIVER DEFINED IN STORAGE. Local storage cannot be used !');
@@ -16748,9 +16752,9 @@
16748
16752
  };
16749
16753
  PlatformService.prototype.migrateStorage = function (forage) {
16750
16754
  return __awaiter(this, void 0, void 0, function () {
16751
- var canMigrate, oldForage, keys, now, toast_1, duration, err_1;
16752
- return __generator(this, function (_a) {
16753
- switch (_a.label) {
16755
+ var canMigrate, oldForage, keys, now, toast_1, duration, err_2;
16756
+ return __generator(this, function (_b) {
16757
+ switch (_b.label) {
16754
16758
  case 0:
16755
16759
  canMigrate = forage &&
16756
16760
  ((forage.driver() === 'cordovaSQLiteDriver' && (forage.supports(forage.INDEXEDDB) || forage.supports(forage.WEBSQL))) ||
@@ -16764,13 +16768,13 @@
16764
16768
  });
16765
16769
  return [4 /*yield*/, oldForage.keys()];
16766
16770
  case 1:
16767
- keys = _a.sent();
16771
+ keys = _b.sent();
16768
16772
  if (!isEmptyArray(keys)) return [3 /*break*/, 3];
16769
16773
  // Drop the old instance (not need anymore)
16770
16774
  console.debug("[platform] Old storage is empty: dropping unused instance {name: '" + forage.config().name + "', driver: '" + oldForage.driver() + "'}");
16771
16775
  return [4 /*yield*/, oldForage.dropInstance()];
16772
16776
  case 2:
16773
- _a.sent();
16777
+ _b.sent();
16774
16778
  return [3 /*break*/, 12];
16775
16779
  case 3:
16776
16780
  now = Date.now();
@@ -16778,13 +16782,13 @@
16778
16782
  return [4 /*yield*/, this.showToast({ message: 'INFO.DATA_MIGRATION_STARTED',
16779
16783
  duration: 30000 })];
16780
16784
  case 4:
16781
- toast_1 = _a.sent();
16782
- _a.label = 5;
16785
+ toast_1 = _b.sent();
16786
+ _b.label = 5;
16783
16787
  case 5:
16784
- _a.trys.push([5, 9, , 12]);
16788
+ _b.trys.push([5, 9, , 12]);
16785
16789
  return [4 /*yield*/, StorageUtils.copy(oldForage, forage, { keys: keys, deleteAfterCopy: false })];
16786
16790
  case 6:
16787
- _a.sent();
16791
+ _b.sent();
16788
16792
  duration = Date.now() - now;
16789
16793
  setTimeout(function () { return toast_1.dismiss(); }, Math.max(2000 - duration, 0));
16790
16794
  return [4 /*yield*/, this.showToast({ message: 'INFO.DATA_MIGRATION_SUCCEED',
@@ -16792,26 +16796,26 @@
16792
16796
  showCloseButton: true
16793
16797
  })];
16794
16798
  case 7:
16795
- _a.sent();
16799
+ _b.sent();
16796
16800
  console.info('[platform] Starting storage migration [OK]');
16797
16801
  // Drop the old instance
16798
16802
  console.info("[platform] Drop old storage {name: '" + forage.config().name + "', driver: '" + oldForage.driver() + "'}");
16799
16803
  return [4 /*yield*/, oldForage.dropInstance()];
16800
16804
  case 8:
16801
- _a.sent();
16805
+ _b.sent();
16802
16806
  return [3 /*break*/, 12];
16803
16807
  case 9:
16804
- err_1 = _a.sent();
16805
- console.error(err_1 && err_1.message || err_1, err_1);
16808
+ err_2 = _b.sent();
16809
+ console.error(err_2 && err_2.message || err_2, err_2);
16806
16810
  return [4 /*yield*/, toast_1.dismiss()];
16807
16811
  case 10:
16808
- _a.sent();
16812
+ _b.sent();
16809
16813
  return [4 /*yield*/, this.showToast({ message: 'ERROR.DATA_MIGRATION_FAILED',
16810
16814
  type: 'error',
16811
16815
  showCloseButton: true
16812
16816
  })];
16813
16817
  case 11:
16814
- _a.sent();
16818
+ _b.sent();
16815
16819
  return [3 /*break*/, 12];
16816
16820
  case 12: return [2 /*return*/];
16817
16821
  }
@@ -16827,8 +16831,8 @@
16827
16831
  PlatformService.prototype.onStartupError = function (err) {
16828
16832
  return __awaiter(this, void 0, void 0, function () {
16829
16833
  var message, detailsMessage;
16830
- return __generator(this, function (_a) {
16831
- switch (_a.label) {
16834
+ return __generator(this, function (_b) {
16835
+ switch (_b.label) {
16832
16836
  case 0:
16833
16837
  console.error('[platform] Failed starting the platform! ', err);
16834
16838
  message = err && err.message || err;
@@ -16840,14 +16844,14 @@
16840
16844
  if (!this.translate) return [3 /*break*/, 2];
16841
16845
  return [4 /*yield*/, this.translate.get(message).toPromise()];
16842
16846
  case 1:
16843
- message = _a.sent();
16847
+ message = _b.sent();
16844
16848
  if (err && err.code) {
16845
16849
  message += " {code: " + err.code + "}";
16846
16850
  }
16847
16851
  return [3 /*break*/, 3];
16848
16852
  case 2:
16849
16853
  message = "Fatal error: Please contact your administrator.\n\n{code: " + (err && err.code || 'null') + ", message: \"" + message + "\"}";
16850
- _a.label = 3;
16854
+ _b.label = 3;
16851
16855
  case 3:
16852
16856
  if (!this.toastController) return [3 /*break*/, 5];
16853
16857
  if (detailsMessage) {
@@ -16860,7 +16864,7 @@
16860
16864
  message: message
16861
16865
  })];
16862
16866
  case 4:
16863
- _a.sent();
16867
+ _b.sent();
16864
16868
  return [3 /*break*/, 6];
16865
16869
  case 5:
16866
16870
  if (window) {
@@ -16874,14 +16878,14 @@
16874
16878
  if (err && err.details)
16875
16879
  console.error('cause', err.details);
16876
16880
  }
16877
- _a.label = 6;
16881
+ _b.label = 6;
16878
16882
  case 6: return [2 /*return*/];
16879
16883
  }
16880
16884
  });
16881
16885
  });
16882
16886
  };
16883
16887
  return PlatformService;
16884
- }());
16888
+ }(StartableService));
16885
16889
  PlatformService.ɵprov = i0__namespace.ɵɵdefineInjectable({ factory: function PlatformService_Factory() { return new PlatformService(i0__namespace.ɵɵinject(i1__namespace$4.Platform), i0__namespace.ɵɵinject(i2__namespace$4.Platform), i0__namespace.ɵɵinject(i1__namespace$4.ToastController), i0__namespace.ɵɵinject(i1__namespace$1.TranslateService), i0__namespace.ɵɵinject(i1__namespace.MomentDateAdapter), i0__namespace.ɵɵinject(EntitiesStorage), i0__namespace.ɵɵinject(LocalSettingsService), i0__namespace.ɵɵinject(NetworkService), i0__namespace.ɵɵinject(AccountService), i0__namespace.ɵɵinject(ConfigService), i0__namespace.ɵɵinject(i6__namespace.CacheService), i0__namespace.ɵɵinject(i3__namespace$1.Storage), i0__namespace.ɵɵinject(AudioProvider), i0__namespace.ɵɵinject(ENVIRONMENT), i0__namespace.ɵɵinject(i14__namespace.StatusBar, 8), i0__namespace.ɵɵinject(i15__namespace.Keyboard, 8), i0__namespace.ɵɵinject(i10__namespace.SplashScreen, 8), i0__namespace.ɵɵinject(i17__namespace.InAppBrowser, 8), i0__namespace.ɵɵinject(i18__namespace.Downloader, 8)); }, token: PlatformService, providedIn: "root" });
16886
16890
  PlatformService.decorators = [
16887
16891
  { type: i0.Injectable, args: [{ providedIn: 'root' },] }