@sumaris-net/ngx-components 1.11.4 → 1.11.7
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.
- package/bundles/sumaris-net.ngx-components.umd.js +146 -82
- package/bundles/sumaris-net.ngx-components.umd.js.map +1 -1
- package/bundles/sumaris-net.ngx-components.umd.min.js +1 -1
- package/bundles/sumaris-net.ngx-components.umd.min.js.map +1 -1
- package/esm2015/public_api.js +2 -1
- package/esm2015/src/app/shared/files.js +59 -0
- package/esm2015/src/app/shared/upload-file/testing/upload-file.testing.js +1 -1
- package/esm2015/src/app/shared/upload-file/upload-file-popover.component.js +2 -4
- package/esm2015/src/app/shared/upload-file/upload-file.component.js +15 -13
- package/esm2015/src/app/shared/upload-file/upload-file.model.js +1 -1
- package/fesm2015/sumaris-net.ngx-components.js +70 -16
- package/fesm2015/sumaris-net.ngx-components.js.map +1 -1
- package/package.json +1 -1
- package/public_api.d.ts +1 -0
- package/src/app/shared/files.d.ts +9 -0
- package/src/app/shared/upload-file/testing/upload-file.testing.d.ts +1 -1
- package/src/app/shared/upload-file/upload-file-popover.component.d.ts +7 -7
- package/src/app/shared/upload-file/upload-file.component.d.ts +6 -6
- package/src/app/shared/upload-file/upload-file.model.d.ts +4 -4
- package/sumaris-net.ngx-components.metadata.json +1 -1
|
@@ -18002,8 +18002,8 @@
|
|
|
18002
18002
|
UploadFileComponent.prototype.deleteFile = function (index) {
|
|
18003
18003
|
return __awaiter(this, void 0, void 0, function () {
|
|
18004
18004
|
var file, deleted, err_1;
|
|
18005
|
-
return __generator(this, function (
|
|
18006
|
-
switch (
|
|
18005
|
+
return __generator(this, function (_d) {
|
|
18006
|
+
switch (_d.label) {
|
|
18007
18007
|
case 0:
|
|
18008
18008
|
file = this.files[index];
|
|
18009
18009
|
if (!(file.progress === 1 && this.deleteFn)) return [3 /*break*/, 6];
|
|
@@ -18011,18 +18011,18 @@
|
|
|
18011
18011
|
console.warn("[upload-file] This file already deleting");
|
|
18012
18012
|
return [2 /*return*/];
|
|
18013
18013
|
}
|
|
18014
|
-
|
|
18014
|
+
_d.label = 1;
|
|
18015
18015
|
case 1:
|
|
18016
|
-
|
|
18016
|
+
_d.trys.push([1, 3, 4, 5]);
|
|
18017
18017
|
file.deleting = true;
|
|
18018
18018
|
return [4 /*yield*/, this.deleteFn(file)];
|
|
18019
18019
|
case 2:
|
|
18020
|
-
deleted =
|
|
18020
|
+
deleted = _d.sent();
|
|
18021
18021
|
if (!deleted)
|
|
18022
18022
|
return [2 /*return*/];
|
|
18023
18023
|
return [3 /*break*/, 5];
|
|
18024
18024
|
case 3:
|
|
18025
|
-
err_1 =
|
|
18025
|
+
err_1 = _d.sent();
|
|
18026
18026
|
console.error(err_1 && err_1.message || err_1);
|
|
18027
18027
|
return [2 /*return*/];
|
|
18028
18028
|
case 4:
|
|
@@ -18039,7 +18039,7 @@
|
|
|
18039
18039
|
console.warn("[upload-file] Cannot remove this file while uploading");
|
|
18040
18040
|
return [2 /*return*/];
|
|
18041
18041
|
}
|
|
18042
|
-
|
|
18042
|
+
_d.label = 7;
|
|
18043
18043
|
case 7:
|
|
18044
18044
|
this.files.splice(index, 1);
|
|
18045
18045
|
this.cd.markForCheck();
|
|
@@ -18054,7 +18054,7 @@
|
|
|
18054
18054
|
* @param files (Files List)
|
|
18055
18055
|
*/
|
|
18056
18056
|
UploadFileComponent.prototype.prepareFilesList = function (files) {
|
|
18057
|
-
var
|
|
18057
|
+
var _d;
|
|
18058
18058
|
var items;
|
|
18059
18059
|
if (files instanceof FileList) {
|
|
18060
18060
|
items = [];
|
|
@@ -18066,7 +18066,7 @@
|
|
|
18066
18066
|
else {
|
|
18067
18067
|
items = files;
|
|
18068
18068
|
}
|
|
18069
|
-
(
|
|
18069
|
+
(_d = this.files).push.apply(_d, __spread(items));
|
|
18070
18070
|
this.fileDropEl.nativeElement.value = '';
|
|
18071
18071
|
// Start upload
|
|
18072
18072
|
if (this.instantUpload) {
|
|
@@ -18080,79 +18080,76 @@
|
|
|
18080
18080
|
return __awaiter(this, void 0, void 0, function () {
|
|
18081
18081
|
var $processingFileCountChange, $changes, jobs;
|
|
18082
18082
|
var _this = this;
|
|
18083
|
-
return __generator(this, function (
|
|
18084
|
-
|
|
18085
|
-
|
|
18086
|
-
|
|
18087
|
-
|
|
18088
|
-
|
|
18089
|
-
|
|
18090
|
-
|
|
18091
|
-
|
|
18092
|
-
|
|
18093
|
-
|
|
18094
|
-
|
|
18095
|
-
|
|
18096
|
-
|
|
18097
|
-
|
|
18098
|
-
|
|
18099
|
-
|
|
18100
|
-
|
|
18101
|
-
|
|
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
|
-
}
|
|
18083
|
+
return __generator(this, function (_d) {
|
|
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
|
-
|
|
18145
|
-
})
|
|
18146
|
-
|
|
18147
|
-
|
|
18148
|
-
|
|
18149
|
-
|
|
18150
|
-
|
|
18151
|
-
|
|
18152
|
-
|
|
18153
|
-
|
|
18154
|
-
|
|
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(
|
|
18115
|
+
// Log
|
|
18116
|
+
operators.tap(function (file) { return console.debug("[upload-file] " + file.name + ": uploading..."); }),
|
|
18117
|
+
// Start uploading
|
|
18118
|
+
operators.switchMap(function (file) { return _this.uploadFn(file)
|
|
18119
|
+
.pipe(operators.map(function (event) {
|
|
18120
|
+
var _a, _b, _c;
|
|
18121
|
+
// Progress event
|
|
18122
|
+
if ((event === null || event === void 0 ? void 0 : event.type) === i2$1.HttpEventType.UploadProgress || event.type === i2$1.HttpEventType.User) {
|
|
18123
|
+
var total = event.total || 1;
|
|
18124
|
+
var loaded = event.loaded || 0;
|
|
18125
|
+
file.progress = Math.min(1, loaded / total);
|
|
18126
|
+
}
|
|
18127
|
+
// Response event
|
|
18128
|
+
else if (event instanceof i2$1.HttpResponse || event instanceof FileResponse) {
|
|
18129
|
+
file.result = event.body;
|
|
18130
|
+
file.progress = 1;
|
|
18131
|
+
var message = ((_a = file.result) === null || _a === void 0 ? void 0 : _a.message) || event.statusText || 'OK';
|
|
18132
|
+
console.debug("[upload-file] " + file.name + ": " + message
|
|
18133
|
+
+ (((_b = file.result) === null || _b === void 0 ? void 0 : _b.finalName) ? " (finalName: " + ((_c = file.result) === null || _c === void 0 ? void 0 : _c.finalName) + ")" : ''));
|
|
18134
|
+
}
|
|
18135
|
+
// Other events
|
|
18136
|
+
else {
|
|
18137
|
+
console.warn('[upload-file] Unknown event, returned by uploadFn\'s observable:', event);
|
|
18138
|
+
}
|
|
18139
|
+
return file;
|
|
18140
|
+
}), operators.catchError(function (err) {
|
|
18141
|
+
var _a;
|
|
18142
|
+
console.error(err);
|
|
18143
|
+
file.error = err && (err.message || ((_a = err.error) === null || _a === void 0 ? void 0 : _a.message)) || 'FILE.UPLOAD.ERROR';
|
|
18144
|
+
return rxjs.of(file);
|
|
18145
|
+
}), operators.tap(function () {
|
|
18146
|
+
$changes.next();
|
|
18147
|
+
_this.cd.markForCheck();
|
|
18148
|
+
})); })); });
|
|
18149
|
+
// Wait jobs to finish
|
|
18150
|
+
return [2 /*return*/, rxjs.forkJoin(jobs)
|
|
18151
|
+
.pipe(operators.tap(function (_) { return $changes.complete(); }))
|
|
18152
|
+
.toPromise()];
|
|
18156
18153
|
});
|
|
18157
18154
|
});
|
|
18158
18155
|
};
|
|
@@ -18215,7 +18212,7 @@
|
|
|
18215
18212
|
});
|
|
18216
18213
|
UploadFilePopover.prototype.onValidate = function (event) {
|
|
18217
18214
|
return __awaiter(this, void 0, void 0, function () {
|
|
18218
|
-
var files, errors,
|
|
18215
|
+
var files, errors, err_1;
|
|
18219
18216
|
return __generator(this, function (_a) {
|
|
18220
18217
|
switch (_a.label) {
|
|
18221
18218
|
case 0:
|
|
@@ -18253,10 +18250,8 @@
|
|
|
18253
18250
|
errors.forEach(function (error) { return console.error(error); });
|
|
18254
18251
|
throw { message: 'FILE.UPLOAD.ERROR' };
|
|
18255
18252
|
}
|
|
18256
|
-
filenames = files
|
|
18257
|
-
.map(function (file) { return file.finalName || file.name; });
|
|
18258
18253
|
// return filenames
|
|
18259
|
-
return [4 /*yield*/, this.popoverController.dismiss(
|
|
18254
|
+
return [4 /*yield*/, this.popoverController.dismiss(files)];
|
|
18260
18255
|
case 5:
|
|
18261
18256
|
// return filenames
|
|
18262
18257
|
_a.sent();
|
|
@@ -19859,6 +19854,74 @@
|
|
|
19859
19854
|
return JobUtils;
|
|
19860
19855
|
}());
|
|
19861
19856
|
|
|
19857
|
+
var FilesUtils = /** @class */ (function () {
|
|
19858
|
+
function FilesUtils() {
|
|
19859
|
+
}
|
|
19860
|
+
FilesUtils.showUploadPopover = function (popoverController, event, opts) {
|
|
19861
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
19862
|
+
var modal, _a, data, role;
|
|
19863
|
+
return __generator(this, function (_b) {
|
|
19864
|
+
switch (_b.label) {
|
|
19865
|
+
case 0: return [4 /*yield*/, popoverController.create({
|
|
19866
|
+
component: UploadFilePopover,
|
|
19867
|
+
componentProps: opts,
|
|
19868
|
+
backdropDismiss: false,
|
|
19869
|
+
keyboardClose: false,
|
|
19870
|
+
event: event,
|
|
19871
|
+
translucent: true,
|
|
19872
|
+
cssClass: 'popover-large',
|
|
19873
|
+
})];
|
|
19874
|
+
case 1:
|
|
19875
|
+
modal = _b.sent();
|
|
19876
|
+
return [4 /*yield*/, modal.present()];
|
|
19877
|
+
case 2:
|
|
19878
|
+
_b.sent();
|
|
19879
|
+
return [4 /*yield*/, modal.onDidDismiss()];
|
|
19880
|
+
case 3:
|
|
19881
|
+
_a = _b.sent(), data = _a.data, role = _a.role;
|
|
19882
|
+
return [2 /*return*/, {
|
|
19883
|
+
role: role,
|
|
19884
|
+
data: data ? data : undefined
|
|
19885
|
+
}];
|
|
19886
|
+
}
|
|
19887
|
+
});
|
|
19888
|
+
});
|
|
19889
|
+
};
|
|
19890
|
+
FilesUtils.readAsText = function (file, encoding) {
|
|
19891
|
+
var $progress = new rxjs.Subject();
|
|
19892
|
+
var reader = new FileReader();
|
|
19893
|
+
encoding = (encoding || 'UTF-8').toLowerCase();
|
|
19894
|
+
// Listen progress
|
|
19895
|
+
reader.onprogress = function (e) {
|
|
19896
|
+
var total = e.total || 1;
|
|
19897
|
+
var loaded = e.total || 0;
|
|
19898
|
+
if (loaded < total)
|
|
19899
|
+
$progress.next({ type: i2$1.HttpEventType.UploadProgress, loaded: loaded, total: total });
|
|
19900
|
+
};
|
|
19901
|
+
// Listen end
|
|
19902
|
+
reader.onloadend = function (e) {
|
|
19903
|
+
var body = reader.result;
|
|
19904
|
+
if (typeof body === 'string') {
|
|
19905
|
+
$progress.next(new FileResponse({ body: body }));
|
|
19906
|
+
$progress.complete();
|
|
19907
|
+
}
|
|
19908
|
+
else {
|
|
19909
|
+
console.error("Cannot read file '" + file.name + "' as text");
|
|
19910
|
+
$progress.error("Cannot read file as text");
|
|
19911
|
+
}
|
|
19912
|
+
};
|
|
19913
|
+
// Listen error
|
|
19914
|
+
reader.onerror = function (event) {
|
|
19915
|
+
console.error('[files] Error while reading file:', event);
|
|
19916
|
+
$progress.error(event);
|
|
19917
|
+
};
|
|
19918
|
+
// Start reading the file
|
|
19919
|
+
reader.readAsText(file, encoding);
|
|
19920
|
+
return $progress.asObservable();
|
|
19921
|
+
};
|
|
19922
|
+
return FilesUtils;
|
|
19923
|
+
}());
|
|
19924
|
+
|
|
19862
19925
|
/**
|
|
19863
19926
|
* Define here theme colors
|
|
19864
19927
|
*/
|
|
@@ -30625,6 +30688,7 @@
|
|
|
30625
30688
|
exports.FileResponse = FileResponse;
|
|
30626
30689
|
exports.FileService = FileService;
|
|
30627
30690
|
exports.FileSizePipe = FileSizePipe;
|
|
30691
|
+
exports.FilesUtils = FilesUtils;
|
|
30628
30692
|
exports.FormArrayHelper = FormArrayHelper;
|
|
30629
30693
|
exports.FormButtonsBarComponent = FormButtonsBarComponent;
|
|
30630
30694
|
exports.FormButtonsBarToken = FormButtonsBarToken;
|