@sumaris-net/ngx-components 1.11.2 → 1.11.5

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.
@@ -18081,74 +18081,70 @@
18081
18081
  var $processingFileCountChange, $changes, jobs;
18082
18082
  var _this = this;
18083
18083
  return __generator(this, function (_b) {
18084
- switch (_b.label) {
18085
- case 0:
18086
- if (!files) {
18087
- console.info('[upload-file] Uploading all files...');
18088
- files = this.files;
18089
- }
18090
- $processingFileCountChange = new rxjs.BehaviorSubject(this.processingFilesCount);
18091
- $changes = new rxjs.Subject();
18092
- $changes.subscribe(function (_) {
18093
- _this.cd.markForCheck();
18094
- $processingFileCountChange.next(_this.processingFilesCount);
18095
- });
18096
- jobs = files
18097
- .map(function (f) { return f; })
18098
- .filter(function (file) { return isNil(file.progress) && !file.error; }) // Skip if already started or in error
18099
- .map(function (file, i) {
18100
- // Wait if need
18101
- if (isNotNil(_this.maxParallelUpload)) {
18102
- return $processingFileCountChange.pipe(operators.debounceTime(i), // call of filter() must be different for waiting job
18103
- operators.filter(function (count) { return count < _this.maxParallelUpload; }), operators.map(function (_) {
18104
- // Start uploading
18105
- if (isNil(file.progress))
18106
- file.progress = 0;
18107
- $changes.next();
18108
- return file;
18109
- }), operators.first());
18110
- }
18084
+ if (!files) {
18085
+ console.info('[upload-file] Uploading all files...');
18086
+ files = this.files;
18087
+ }
18088
+ $processingFileCountChange = new rxjs.BehaviorSubject(this.processingFilesCount);
18089
+ $changes = new rxjs.Subject();
18090
+ $changes.subscribe(function (_) {
18091
+ _this.cd.markForCheck();
18092
+ $processingFileCountChange.next(_this.processingFilesCount);
18093
+ });
18094
+ jobs = files
18095
+ .map(function (f) { return f; })
18096
+ .filter(function (file) { return isNil(file.progress) && !file.error; }) // Skip if already started or in error
18097
+ .map(function (file, i) {
18098
+ // Wait if need
18099
+ if (isNotNil(_this.maxParallelUpload)) {
18100
+ return $processingFileCountChange.pipe(operators.debounceTime(i), // call of filter() must be different for waiting job
18101
+ operators.filter(function (count) { return count < _this.maxParallelUpload; }), operators.map(function (_) {
18111
18102
  // Start uploading
18112
18103
  if (isNil(file.progress))
18113
18104
  file.progress = 0;
18114
- return rxjs.of(file);
18115
- })
18116
- .map(function (file$) { return file$.pipe(operators.tap(function (file) { return console.debug("[upload-file] " + file.name + ": uploading..."); }), operators.switchMap(function (file) { return _this.uploadFn(file).pipe(operators.map(function (event) {
18117
- if ((event === null || event === void 0 ? void 0 : event.type) === i2$1.HttpEventType.UploadProgress || event.type === i2$1.HttpEventType.User) {
18118
- var total = event.total || 1;
18119
- var loaded = event.loaded || 0;
18120
- file.progress = Math.min(1, loaded / total);
18121
- }
18122
- else if (event instanceof i2$1.HttpResponse || event instanceof FileResponse) {
18123
- var content = event.body;
18124
- file.finalName = content === null || content === void 0 ? void 0 : content.finalName;
18125
- file.progress = 1;
18126
- var message = content.message || event.statusText || 'succeed';
18127
- console.info("[upload-file] " + file.name + ": " + message + " (finalName: " + file.finalName + ")");
18128
- }
18129
- else {
18130
- console.warn("[upload-file] " + file.name + ": Unknown event received by uploadFn : ", event);
18131
- }
18132
- return file;
18133
- }), operators.catchError(function (err) {
18134
- var _a;
18135
- console.error(err);
18136
- file.error = ((_a = err.error) === null || _a === void 0 ? void 0 : _a.message) || 'FILE.UPLOAD.ERROR';
18137
- return rxjs.of(file);
18138
- }), operators.tap(function () {
18139
18105
  $changes.next();
18140
- _this.cd.markForCheck();
18141
- })); })); });
18142
- return [4 /*yield*/, rxjs.forkJoin(jobs).toPromise()
18143
- .then(function (files) {
18144
- $changes.complete();
18145
- $changes.unsubscribe();
18146
- return files;
18147
- })];
18148
- case 1:
18149
- // Wait jobs to finish
18150
- return [2 /*return*/, _b.sent()];
18151
- }
18106
+ return file;
18107
+ }), operators.first());
18108
+ }
18109
+ // Start uploading
18110
+ if (isNil(file.progress))
18111
+ file.progress = 0;
18112
+ return rxjs.of(file);
18113
+ })
18114
+ .map(function (file$) { return file$.pipe(operators.tap(function (file) { return console.debug("[upload-file] " + file.name + ": uploading..."); }), operators.switchMap(function (file) { return _this.uploadFn(file).pipe(operators.map(function (event) {
18115
+ // Progress event
18116
+ if ((event === null || event === void 0 ? void 0 : event.type) === i2$1.HttpEventType.UploadProgress || event.type === i2$1.HttpEventType.User) {
18117
+ var total = event.total || 1;
18118
+ var loaded = event.loaded || 0;
18119
+ file.progress = Math.min(1, loaded / total);
18120
+ }
18121
+ // Response event
18122
+ else if (event instanceof i2$1.HttpResponse || event instanceof FileResponse) {
18123
+ var body = event.body;
18124
+ file.finalName = body === null || body === void 0 ? void 0 : body.finalName;
18125
+ file.progress = 1;
18126
+ var message = (body === null || body === void 0 ? void 0 : body.message) || event.statusText || 'OK';
18127
+ console.debug("[upload-file] " + file.name + ": " + message
18128
+ + (file.finalName ? " (finalName: " + file.finalName + ")" : ''));
18129
+ }
18130
+ // Other events
18131
+ else {
18132
+ console.warn('[upload-file] Unknown event, returned by uploadFn\'s observable:', event);
18133
+ }
18134
+ return file;
18135
+ }), operators.catchError(function (err) {
18136
+ var _a;
18137
+ console.error(err);
18138
+ file.error = err && (err.message || ((_a = err.error) === null || _a === void 0 ? void 0 : _a.message)) || 'FILE.UPLOAD.ERROR';
18139
+ return rxjs.of(file);
18140
+ }), operators.tap(function () {
18141
+ $changes.next();
18142
+ _this.cd.markForCheck();
18143
+ })); })); });
18144
+ // Wait jobs to finish
18145
+ return [2 /*return*/, rxjs.forkJoin(jobs)
18146
+ .pipe(operators.tap(function (_) { return $changes.complete(); }))
18147
+ .toPromise()];
18152
18148
  });
18153
18149
  });
18154
18150
  };
@@ -18211,7 +18207,7 @@
18211
18207
  });
18212
18208
  UploadFilePopover.prototype.onValidate = function (event) {
18213
18209
  return __awaiter(this, void 0, void 0, function () {
18214
- var files, errors, filenames, err_1;
18210
+ var files, errors, err_1;
18215
18211
  return __generator(this, function (_a) {
18216
18212
  switch (_a.label) {
18217
18213
  case 0:
@@ -18249,10 +18245,8 @@
18249
18245
  errors.forEach(function (error) { return console.error(error); });
18250
18246
  throw { message: 'FILE.UPLOAD.ERROR' };
18251
18247
  }
18252
- filenames = files
18253
- .map(function (file) { return file.finalName || file.name; });
18254
18248
  // return filenames
18255
- return [4 /*yield*/, this.popoverController.dismiss({ filenames: filenames })];
18249
+ return [4 /*yield*/, this.popoverController.dismiss(files)];
18256
18250
  case 5:
18257
18251
  // return filenames
18258
18252
  _a.sent();
@@ -19855,6 +19849,74 @@
19855
19849
  return JobUtils;
19856
19850
  }());
19857
19851
 
19852
+ var FilesUtils = /** @class */ (function () {
19853
+ function FilesUtils() {
19854
+ }
19855
+ FilesUtils.showUploadPopover = function (popoverController, event, opts) {
19856
+ return __awaiter(this, void 0, void 0, function () {
19857
+ var modal, _a, data, role;
19858
+ return __generator(this, function (_b) {
19859
+ switch (_b.label) {
19860
+ case 0: return [4 /*yield*/, popoverController.create({
19861
+ component: UploadFilePopover,
19862
+ componentProps: opts,
19863
+ backdropDismiss: false,
19864
+ keyboardClose: false,
19865
+ event: event,
19866
+ translucent: true,
19867
+ cssClass: 'popover-large',
19868
+ })];
19869
+ case 1:
19870
+ modal = _b.sent();
19871
+ return [4 /*yield*/, modal.present()];
19872
+ case 2:
19873
+ _b.sent();
19874
+ return [4 /*yield*/, modal.onDidDismiss()];
19875
+ case 3:
19876
+ _a = _b.sent(), data = _a.data, role = _a.role;
19877
+ return [2 /*return*/, {
19878
+ role: role,
19879
+ data: data ? data : undefined
19880
+ }];
19881
+ }
19882
+ });
19883
+ });
19884
+ };
19885
+ FilesUtils.readAsText = function (file, encoding) {
19886
+ var $progress = new rxjs.Subject();
19887
+ var reader = new FileReader();
19888
+ encoding = (encoding || 'UTF-8').toLowerCase();
19889
+ // Listen progress
19890
+ reader.onprogress = function (e) {
19891
+ var total = e.total || 1;
19892
+ var loaded = e.total || 0;
19893
+ if (loaded < total)
19894
+ $progress.next({ type: i2$1.HttpEventType.UploadProgress, loaded: loaded, total: total });
19895
+ };
19896
+ // Listen end
19897
+ reader.onloadend = function (e) {
19898
+ var body = reader.result;
19899
+ if (typeof body === 'string') {
19900
+ $progress.next(new FileResponse({ body: body }));
19901
+ $progress.complete();
19902
+ }
19903
+ else {
19904
+ console.error("Cannot read file '" + file.name + "' as text");
19905
+ $progress.error("Cannot read file as text");
19906
+ }
19907
+ };
19908
+ // Listen error
19909
+ reader.onerror = function (event) {
19910
+ console.error('[files] Error while reading file:', event);
19911
+ $progress.error(event);
19912
+ };
19913
+ // Start reading the file
19914
+ reader.readAsText(file, encoding);
19915
+ return $progress.asObservable();
19916
+ };
19917
+ return FilesUtils;
19918
+ }());
19919
+
19858
19920
  /**
19859
19921
  * Define here theme colors
19860
19922
  */
@@ -30621,6 +30683,7 @@
30621
30683
  exports.FileResponse = FileResponse;
30622
30684
  exports.FileService = FileService;
30623
30685
  exports.FileSizePipe = FileSizePipe;
30686
+ exports.FilesUtils = FilesUtils;
30624
30687
  exports.FormArrayHelper = FormArrayHelper;
30625
30688
  exports.FormButtonsBarComponent = FormButtonsBarComponent;
30626
30689
  exports.FormButtonsBarToken = FormButtonsBarToken;