@sumaris-net/ngx-components 0.25.4 → 0.25.8

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.
@@ -15678,7 +15678,7 @@
15678
15678
  this.browser = browser;
15679
15679
  this.downloader = downloader;
15680
15680
  this._started = false;
15681
- this._downloadingPromise = new Map();
15681
+ this._downloadingJobs = new Map();
15682
15682
  this._debug = !environment.production;
15683
15683
  if (this._debug)
15684
15684
  console.debug('[platform] Creating service');
@@ -15808,56 +15808,43 @@
15808
15808
  window.open(url, target, features, replace);
15809
15809
  }
15810
15810
  };
15811
- PlatformService.prototype.getDownloadingPromise = function (uri) {
15812
- return __awaiter(this, void 0, void 0, function () {
15813
- return __generator(this, function (_a) {
15814
- return [2 /*return*/, this._downloadingPromise.get(uri)];
15815
- });
15816
- });
15811
+ PlatformService.prototype.getDownloadingJob = function (uri) {
15812
+ return this._downloadingJobs.get(uri);
15817
15813
  };
15818
15814
  PlatformService.prototype.download = function (request) {
15819
- return __awaiter(this, void 0, void 0, function () {
15820
- var promise, location, err_1;
15821
- return __generator(this, function (_a) {
15822
- switch (_a.label) {
15823
- case 0:
15824
- if (!request || !request.uri)
15825
- throw new Error('Missing argument \'request\' or \'request.uri\'');
15826
- if (!(this._android && this.downloader)) return [3 /*break*/, 6];
15827
- promise = this._downloadingPromise.get(request.uri);
15828
- if (promise)
15829
- return [2 /*return*/, promise];
15830
- request = Object.assign({ visibleInDownloadsUi: true, notificationVisibility: ngx$6.NotificationVisibility.VisibleNotifyCompleted, title: request.title || request.filename }, request);
15831
- _a.label = 1;
15832
- case 1:
15833
- _a.trys.push([1, 3, 4, 5]);
15834
- console.debug('[platform] Downloading, using request: ' + JSON.stringify(request));
15835
- // Start download
15836
- promise = this.downloader.download(request);
15837
- // Remember this request uri
15838
- this._downloadingPromise.set(request.uri, promise);
15839
- return [4 /*yield*/, promise];
15840
- case 2:
15841
- location = _a.sent();
15842
- console.info('[platform] File successfully downloaded at:' + location);
15843
- return [2 /*return*/, location];
15844
- case 3:
15845
- err_1 = _a.sent();
15846
- console.error('[platform] Unable to download: ' + (err_1 && err_1.message || err_1));
15847
- throw err_1;
15848
- case 4:
15849
- // Forget the request
15850
- this._downloadingPromise.delete(request.uri);
15851
- return [7 /*endfinally*/];
15852
- case 5: return [3 /*break*/, 7];
15853
- case 6:
15854
- console.warn('[platform] Cannot use Android downloader: using browser open()');
15855
- this.open(request.uri, '_system', 'location=no', true);
15856
- return [2 /*return*/, undefined];
15857
- case 7: return [2 /*return*/];
15858
- }
15859
- });
15860
- });
15815
+ var _this = this;
15816
+ if (!request || !request.uri)
15817
+ throw new Error('Missing argument \'request\' or \'request.uri\'');
15818
+ if (this._android && this.downloader) {
15819
+ // Check if not already downloading file
15820
+ var location$ = this._downloadingJobs.get(request.uri);
15821
+ if (location$)
15822
+ return location$;
15823
+ request = Object.assign({ visibleInDownloadsUi: true, notificationVisibility: ngx$6.NotificationVisibility.VisibleNotifyCompleted, title: request.title || request.filename }, request);
15824
+ console.debug('[platform] Downloading, using request: ' + JSON.stringify(request));
15825
+ // Start download
15826
+ location$ = rxjs.from(this.downloader.download(request));
15827
+ // Remember this request uri
15828
+ this._downloadingJobs.set(request.uri, location$);
15829
+ return location$
15830
+ .pipe(operators.tap(function (location) {
15831
+ console.info('[platform] File successfully downloaded at:' + location);
15832
+ // Forget the request
15833
+ _this._downloadingJobs.delete(request.uri);
15834
+ }), operators.catchError(function (err) {
15835
+ console.error('[platform] Unable to download: ' + (err && err.message || err));
15836
+ // Forget the request
15837
+ _this._downloadingJobs.delete(request.uri);
15838
+ throw err;
15839
+ }));
15840
+ }
15841
+ // Fallback (if not Android and Cordova): opening the URI using the browser
15842
+ // TODO: find a way to download under iOS (see https://www.c-sharpcorner.com/article/how-to-download-a-file-using-file-transfer-plugin-in-ionic-3/)
15843
+ else {
15844
+ console.warn('[platform] Cannot use Android downloader: using browser open()');
15845
+ this.open(request.uri, '_system', 'location=no', true);
15846
+ return rxjs.of();
15847
+ }
15861
15848
  };
15862
15849
  /* -- protected methods -- */
15863
15850
  PlatformService.prototype.configureCordovaPlugins = function (mobile) {
@@ -15953,7 +15940,7 @@
15953
15940
  };
15954
15941
  PlatformService.prototype.migrateStorage = function (forage) {
15955
15942
  return __awaiter(this, void 0, void 0, function () {
15956
- var canMigrate, oldForage, keys, now, toast_1, duration, err_2;
15943
+ var canMigrate, oldForage, keys, now, toast_1, duration, err_1;
15957
15944
  return __generator(this, function (_a) {
15958
15945
  switch (_a.label) {
15959
15946
  case 0:
@@ -16006,8 +15993,8 @@
16006
15993
  _a.sent();
16007
15994
  return [3 /*break*/, 12];
16008
15995
  case 9:
16009
- err_2 = _a.sent();
16010
- console.error(err_2 && err_2.message || err_2, err_2);
15996
+ err_1 = _a.sent();
15997
+ console.error(err_1 && err_1.message || err_1, err_1);
16011
15998
  return [4 /*yield*/, toast_1.dismiss()];
16012
15999
  case 10:
16013
16000
  _a.sent();
@@ -21329,6 +21316,7 @@
21329
21316
  this._subscription = new rxjs.Subscription();
21330
21317
  this._showUpdateOfflineFeature = false;
21331
21318
  this.loading = true;
21319
+ this.downloading = false;
21332
21320
  this.waitingNetwork = false;
21333
21321
  this.showUpgradeWarning = true;
21334
21322
  this.showOfflineWarning = true;
@@ -21359,7 +21347,7 @@
21359
21347
  this.offline = this.network.offline;
21360
21348
  // Listen pod config
21361
21349
  this._subscription.add(this.configService.config
21362
- .pipe(operators.debounceTime(1000))
21350
+ .pipe(operators.debounceTime(1000), operators.filter(function () { return _this.network.online; }))
21363
21351
  .subscribe(function (config) { return _this.checkNeedInstallOrUpdate(config); }));
21364
21352
  // Listen network changes
21365
21353
  this._subscription.add(this.network.onNetworkStatusChanges
@@ -21387,19 +21375,17 @@
21387
21375
  };
21388
21376
  AppInstallUpgradeCard.prototype.download = function (event, link) {
21389
21377
  return __awaiter(this, void 0, void 0, function () {
21390
- var job;
21391
21378
  return __generator(this, function (_a) {
21392
21379
  if (!link || !link.url) {
21393
21380
  console.error('[install-upgrade-card] Missing required argument \'link.url\'');
21394
21381
  return [2 /*return*/]; // Skip
21395
21382
  }
21396
- job = this.platform.download({
21397
- uri: link.url,
21398
- title: link.title,
21399
- filename: link.filename,
21400
- mimeType: link.mimeType
21401
- });
21402
- return [2 /*return*/, this.listenDownloadPromise(link, job)];
21383
+ return [2 /*return*/, this.listenDownloadJob(link.url, this.platform.download({
21384
+ uri: link.url,
21385
+ title: link.title,
21386
+ filename: link.filename,
21387
+ mimeType: link.mimeType
21388
+ }))];
21403
21389
  });
21404
21390
  });
21405
21391
  };
@@ -21447,6 +21433,7 @@
21447
21433
  AppInstallUpgradeCard.prototype.checkNeedInstallOrUpdate = function (config) {
21448
21434
  return __awaiter(this, void 0, void 0, function () {
21449
21435
  var links;
21436
+ var _this = this;
21450
21437
  return __generator(this, function (_a) {
21451
21438
  switch (_a.label) {
21452
21439
  case 0:
@@ -21459,7 +21446,7 @@
21459
21446
  this.upgradeLinks = this.getCompatibleUpgradeLinks(links, config);
21460
21447
  // Check for install links (if no upgrade need)
21461
21448
  this.installLinks = !this.upgradeLinks && this.getCompatibleInstallLinks(links);
21462
- return [4 /*yield*/, sleep(500)];
21449
+ return [4 /*yield*/, sleep(1000)];
21463
21450
  case 2:
21464
21451
  _a.sent(); // Add a delay, for animation
21465
21452
  return [3 /*break*/, 4];
@@ -21467,7 +21454,14 @@
21467
21454
  this.loading = false;
21468
21455
  this.markForCheck();
21469
21456
  return [7 /*endfinally*/];
21470
- case 4: return [2 /*return*/];
21457
+ case 4:
21458
+ // Listening downloading promise, if exists
21459
+ (this.upgradeLinks || []).forEach(function (link) {
21460
+ var job = _this.platform.getDownloadingJob(link.url);
21461
+ if (job)
21462
+ _this.listenDownloadJob(link.url, job);
21463
+ });
21464
+ return [2 /*return*/];
21471
21465
  }
21472
21466
  });
21473
21467
  });
@@ -21498,12 +21492,6 @@
21498
21492
  // Use min version as default version
21499
21493
  upgradeLinks.forEach(function (link) {
21500
21494
  link.version = link.version || appMinVersionFromPod;
21501
- var promise = _this.platform.getDownloadingPromise(link.url);
21502
- // Listening download promise, if exists
21503
- if (promise) {
21504
- console.info("[install-upgrade-card] Platform is already downloading this file '" + link.url + "': listening promise...");
21505
- _this.listenDownloadPromise(link, promise);
21506
- }
21507
21495
  });
21508
21496
  return isNotEmptyArray(upgradeLinks) ? upgradeLinks : undefined;
21509
21497
  };
@@ -21584,36 +21572,40 @@
21584
21572
  });
21585
21573
  });
21586
21574
  };
21587
- AppInstallUpgradeCard.prototype.listenDownloadPromise = function (link, promise) {
21575
+ AppInstallUpgradeCard.prototype.listenDownloadJob = function (url, job) {
21588
21576
  return __awaiter(this, void 0, void 0, function () {
21589
21577
  var location, err_1;
21590
21578
  return __generator(this, function (_a) {
21591
21579
  switch (_a.label) {
21592
21580
  case 0:
21593
- if (!link || !promise)
21581
+ if (!url || !job)
21594
21582
  return [2 /*return*/]; // Skip
21595
- if (!link.downloading) {
21596
- link.downloading = true;
21597
- this.markForCheck();
21598
- }
21599
21583
  _a.label = 1;
21600
21584
  case 1:
21601
21585
  _a.trys.push([1, 3, 4, 5]);
21602
- return [4 /*yield*/, promise];
21586
+ // Mark as downloading
21587
+ if (!this.downloading) {
21588
+ console.info("[install-upgrade-card] Platform is downloading '" + url + "' ...");
21589
+ this.downloading = true;
21590
+ this.markForCheck();
21591
+ }
21592
+ return [4 /*yield*/, job.toPromise()];
21603
21593
  case 2:
21604
21594
  location = _a.sent();
21605
- console.info('[install-upgrade-card] File downloaded at: ' + location);
21595
+ if (location) {
21596
+ console.info('[install-upgrade-card] File downloaded at: ' + location);
21597
+ return [2 /*return*/, this.showDownloadCompleteDialog()];
21598
+ }
21606
21599
  return [3 /*break*/, 5];
21607
21600
  case 3:
21608
21601
  err_1 = _a.sent();
21609
21602
  console.error('[install-upgrade] Download failed: ' + (err_1 && err_1.message || err_1));
21610
- this.showDownloadFailedToast(err_1);
21611
- return [3 /*break*/, 5];
21603
+ return [2 /*return*/, this.showDownloadFailedToast(err_1)];
21612
21604
  case 4:
21613
- link.downloading = false;
21605
+ this.downloading = false;
21614
21606
  this.markForCheck();
21615
21607
  return [7 /*endfinally*/];
21616
- case 5: return [2 /*return*/, this.showDownloadCompleteDialog()];
21608
+ case 5: return [2 /*return*/];
21617
21609
  }
21618
21610
  });
21619
21611
  });
@@ -21636,14 +21628,14 @@
21636
21628
  return [2 /*return*/]; // Skip if component has been destroyed
21637
21629
  return [4 /*yield*/, this.translate.get([
21638
21630
  'INFO.ALERT_HEADER',
21639
- 'INFO.DOWNLOAD_UPDATE_SUCCEED',
21631
+ 'INFO.UPDATE_APP_DOWNLOADED',
21640
21632
  'COMMON.BTN_CLOSE'
21641
21633
  ]).toPromise()];
21642
21634
  case 1:
21643
21635
  translations = _a.sent();
21644
21636
  return [4 /*yield*/, this.alertController.create({
21645
21637
  header: translations['INFO.ALERT_HEADER'],
21646
- message: translations['INFO.DOWNLOAD_UPDATE_SUCCEED'],
21638
+ message: translations['INFO.UPDATE_APP_DOWNLOADED'],
21647
21639
  buttons: [
21648
21640
  {
21649
21641
  text: translations['COMMON.BTN_CLOSE'],