@sumaris-net/ngx-components 1.11.4 → 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,78 +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
- // Progress event
18118
- if ((event === null || event === void 0 ? void 0 : event.type) === i2$1.HttpEventType.UploadProgress || event.type === i2$1.HttpEventType.User) {
18119
- var total = event.total || 1;
18120
- var loaded = event.loaded || 0;
18121
- file.progress = Math.min(1, loaded / total);
18122
- }
18123
- // Response event
18124
- else if (event instanceof i2$1.HttpResponse || event instanceof FileResponse) {
18125
- var body = event.body;
18126
- file.finalName = body === null || body === void 0 ? void 0 : body.finalName;
18127
- file.progress = 1;
18128
- var message = (body === null || body === void 0 ? void 0 : body.message) || event.statusText || 'OK';
18129
- console.debug("[upload-file] " + file.name + ": " + message
18130
- + (file.finalName ? " (finalName: " + file.finalName + ")" : ''));
18131
- }
18132
- else {
18133
- // Other events
18134
- console.warn('[upload-file] Unknown event, returned by uploadFn\'s observable:', event);
18135
- }
18136
- return file;
18137
- }), operators.catchError(function (err) {
18138
- var _a;
18139
- console.error(err);
18140
- file.error = err && (err.message || ((_a = err.error) === null || _a === void 0 ? void 0 : _a.message)) || 'FILE.UPLOAD.ERROR';
18141
- return rxjs.of(file);
18142
- }), operators.tap(function () {
18143
18105
  $changes.next();
18144
- _this.cd.markForCheck();
18145
- })); })); });
18146
- return [4 /*yield*/, rxjs.forkJoin(jobs).toPromise()
18147
- .then(function (files) {
18148
- $changes.complete();
18149
- $changes.unsubscribe();
18150
- return files;
18151
- })];
18152
- case 1:
18153
- // Wait jobs to finish
18154
- return [2 /*return*/, _b.sent()];
18155
- }
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()];
18156
18148
  });
18157
18149
  });
18158
18150
  };
@@ -18215,7 +18207,7 @@
18215
18207
  });
18216
18208
  UploadFilePopover.prototype.onValidate = function (event) {
18217
18209
  return __awaiter(this, void 0, void 0, function () {
18218
- var files, errors, filenames, err_1;
18210
+ var files, errors, err_1;
18219
18211
  return __generator(this, function (_a) {
18220
18212
  switch (_a.label) {
18221
18213
  case 0:
@@ -18253,10 +18245,8 @@
18253
18245
  errors.forEach(function (error) { return console.error(error); });
18254
18246
  throw { message: 'FILE.UPLOAD.ERROR' };
18255
18247
  }
18256
- filenames = files
18257
- .map(function (file) { return file.finalName || file.name; });
18258
18248
  // return filenames
18259
- return [4 /*yield*/, this.popoverController.dismiss({ filenames: filenames })];
18249
+ return [4 /*yield*/, this.popoverController.dismiss(files)];
18260
18250
  case 5:
18261
18251
  // return filenames
18262
18252
  _a.sent();
@@ -19859,6 +19849,74 @@
19859
19849
  return JobUtils;
19860
19850
  }());
19861
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
+
19862
19920
  /**
19863
19921
  * Define here theme colors
19864
19922
  */
@@ -30625,6 +30683,7 @@
30625
30683
  exports.FileResponse = FileResponse;
30626
30684
  exports.FileService = FileService;
30627
30685
  exports.FileSizePipe = FileSizePipe;
30686
+ exports.FilesUtils = FilesUtils;
30628
30687
  exports.FormArrayHelper = FormArrayHelper;
30629
30688
  exports.FormButtonsBarComponent = FormButtonsBarComponent;
30630
30689
  exports.FormButtonsBarToken = FormButtonsBarToken;