@sumaris-net/ngx-components 0.25.7 → 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.
@@ -36,7 +36,7 @@ import { MatAutocomplete, MatAutocompleteTrigger, MatAutocompleteModule, MAT_AUT
36
36
  import { __awaiter, __decorate } from 'tslib';
37
37
  import * as i1$6 from '@angular/forms';
38
38
  import { NG_VALUE_ACCESSOR, FormGroupDirective, ReactiveFormsModule, AbstractControl, Validators, FormBuilder, FormControl, FormGroup, FormArray } from '@angular/forms';
39
- import { timer, merge, fromEvent, Subscription, BehaviorSubject, Subject, isObservable, of, noop as noop$8, Observable, defer, combineLatest, EMPTY } from 'rxjs';
39
+ import { timer, merge, fromEvent, Subscription, BehaviorSubject, Subject, isObservable, of, noop as noop$8, Observable, defer, from, combineLatest, EMPTY } from 'rxjs';
40
40
  import { filter, first, map, takeUntil, startWith, debounceTime, takeWhile, switchMap, tap, distinctUntilChanged, mergeMap, catchError, throttleTime } from 'rxjs/operators';
41
41
  import * as i1$1 from '@ngx-translate/core';
42
42
  import { TranslateService, TranslateModule } from '@ngx-translate/core';
@@ -13659,7 +13659,7 @@ class PlatformService {
13659
13659
  this.browser = browser;
13660
13660
  this.downloader = downloader;
13661
13661
  this._started = false;
13662
- this._downloadingPromise = new Map();
13662
+ this._downloadingJobs = new Map();
13663
13663
  this._debug = !environment.production;
13664
13664
  if (this._debug)
13665
13665
  console.debug('[platform] Creating service');
@@ -13775,48 +13775,42 @@ class PlatformService {
13775
13775
  window.open(url, target, features, replace);
13776
13776
  }
13777
13777
  }
13778
- getDownloadingPromise(uri) {
13779
- return __awaiter(this, void 0, void 0, function* () {
13780
- return this._downloadingPromise.get(uri);
13781
- });
13778
+ getDownloadingJob(uri) {
13779
+ return this._downloadingJobs.get(uri);
13782
13780
  }
13783
13781
  download(request) {
13784
- return __awaiter(this, void 0, void 0, function* () {
13785
- if (!request || !request.uri)
13786
- throw new Error('Missing argument \'request\' or \'request.uri\'');
13787
- if (this._android && this.downloader) {
13788
- // Check if not already downloading file
13789
- let promise = this._downloadingPromise.get(request.uri);
13790
- if (promise)
13791
- return promise;
13792
- request = Object.assign({ visibleInDownloadsUi: true, notificationVisibility: NotificationVisibility.VisibleNotifyCompleted, title: request.title || request.filename }, request);
13793
- try {
13794
- console.debug('[platform] Downloading, using request: ' + JSON.stringify(request));
13795
- // Start download
13796
- promise = this.downloader.download(request);
13797
- // Remember this request uri
13798
- this._downloadingPromise.set(request.uri, promise);
13799
- const location = yield promise;
13800
- console.info('[platform] File successfully downloaded at:' + location);
13801
- return location;
13802
- }
13803
- catch (err) {
13804
- console.error('[platform] Unable to download: ' + (err && err.message || err));
13805
- throw err;
13806
- }
13807
- finally {
13808
- // Forget the request
13809
- this._downloadingPromise.delete(request.uri);
13810
- }
13811
- }
13812
- // Fallback (if not Android and Cordova): opening the URI using the browser
13813
- // 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/)
13814
- else {
13815
- console.warn('[platform] Cannot use Android downloader: using browser open()');
13816
- this.open(request.uri, '_system', 'location=no', true);
13817
- return undefined;
13818
- }
13819
- });
13782
+ if (!request || !request.uri)
13783
+ throw new Error('Missing argument \'request\' or \'request.uri\'');
13784
+ if (this._android && this.downloader) {
13785
+ // Check if not already downloading file
13786
+ let location$ = this._downloadingJobs.get(request.uri);
13787
+ if (location$)
13788
+ return location$;
13789
+ request = Object.assign({ visibleInDownloadsUi: true, notificationVisibility: NotificationVisibility.VisibleNotifyCompleted, title: request.title || request.filename }, request);
13790
+ console.debug('[platform] Downloading, using request: ' + JSON.stringify(request));
13791
+ // Start download
13792
+ location$ = from(this.downloader.download(request));
13793
+ // Remember this request uri
13794
+ this._downloadingJobs.set(request.uri, location$);
13795
+ return location$
13796
+ .pipe(tap(location => {
13797
+ console.info('[platform] File successfully downloaded at:' + location);
13798
+ // Forget the request
13799
+ this._downloadingJobs.delete(request.uri);
13800
+ }), catchError(err => {
13801
+ console.error('[platform] Unable to download: ' + (err && err.message || err));
13802
+ // Forget the request
13803
+ this._downloadingJobs.delete(request.uri);
13804
+ throw err;
13805
+ }));
13806
+ }
13807
+ // Fallback (if not Android and Cordova): opening the URI using the browser
13808
+ // 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/)
13809
+ else {
13810
+ console.warn('[platform] Cannot use Android downloader: using browser open()');
13811
+ this.open(request.uri, '_system', 'location=no', true);
13812
+ return of();
13813
+ }
13820
13814
  }
13821
13815
  /* -- protected methods -- */
13822
13816
  configureCordovaPlugins(mobile) {
@@ -18544,7 +18538,7 @@ class AppInstallUpgradeCard {
18544
18538
  console.error('[install-upgrade-card] Missing required argument \'link.url\'');
18545
18539
  return; // Skip
18546
18540
  }
18547
- return this.listenDownloadPromise(link.url, this.platform.download({
18541
+ return this.listenDownloadJob(link.url, this.platform.download({
18548
18542
  uri: link.url,
18549
18543
  title: link.title,
18550
18544
  filename: link.filename,
@@ -18600,9 +18594,9 @@ class AppInstallUpgradeCard {
18600
18594
  }
18601
18595
  // Listening downloading promise, if exists
18602
18596
  (this.upgradeLinks || []).forEach(link => {
18603
- const promise = this.platform.getDownloadingPromise(link.url);
18604
- if (promise)
18605
- this.listenDownloadPromise(link.url, promise);
18597
+ const job = this.platform.getDownloadingJob(link.url);
18598
+ if (job)
18599
+ this.listenDownloadJob(link.url, job);
18606
18600
  });
18607
18601
  });
18608
18602
  }
@@ -18704,9 +18698,9 @@ class AppInstallUpgradeCard {
18704
18698
  yield Toasts.show(this.toastController, this.translate, opts);
18705
18699
  });
18706
18700
  }
18707
- listenDownloadPromise(url, promise) {
18701
+ listenDownloadJob(url, job) {
18708
18702
  return __awaiter(this, void 0, void 0, function* () {
18709
- if (!url || !promise)
18703
+ if (!url || !job)
18710
18704
  return; // Skip
18711
18705
  try {
18712
18706
  // Mark as downloading
@@ -18715,8 +18709,11 @@ class AppInstallUpgradeCard {
18715
18709
  this.downloading = true;
18716
18710
  this.markForCheck();
18717
18711
  }
18718
- const location = yield promise;
18719
- console.info('[install-upgrade-card] File downloaded at: ' + location);
18712
+ const location = yield job.toPromise();
18713
+ if (location) {
18714
+ console.info('[install-upgrade-card] File downloaded at: ' + location);
18715
+ return this.showDownloadCompleteDialog();
18716
+ }
18720
18717
  }
18721
18718
  // Failed: display a toast
18722
18719
  catch (err) {
@@ -18727,7 +18724,6 @@ class AppInstallUpgradeCard {
18727
18724
  this.downloading = false;
18728
18725
  this.markForCheck();
18729
18726
  }
18730
- return this.showDownloadCompleteDialog();
18731
18727
  });
18732
18728
  }
18733
18729
  showDownloadFailedToast(err) {