@dbg-riskit/angular-file 15.0.2 → 15.1.1
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/package.json +5 -5
- package/esm2022/dbg-riskit-angular-file.mjs +0 -5
- package/esm2022/lib/abstract.file.download.directive.mjs +0 -139
- package/esm2022/lib/abstract.file.upload.component.mjs +0 -100
- package/esm2022/lib/binary.file.upload.component.mjs +0 -25
- package/esm2022/lib/binary.file.upload.service.mjs +0 -41
- package/esm2022/lib/csv.file.download.directive.mjs +0 -83
- package/esm2022/lib/csv.file.upload.component.mjs +0 -47
- package/esm2022/lib/csv.file.upload.service.mjs +0 -109
- package/esm2022/lib/download.menu.component.mjs +0 -34
- package/esm2022/lib/file.download.directive.mjs +0 -53
- package/esm2022/lib/file.module.mjs +0 -76
- package/esm2022/lib/file.size.pipe.mjs +0 -34
- package/esm2022/lib/file.types.mjs +0 -2
- package/esm2022/lib/text.file.upload.component.mjs +0 -26
- package/esm2022/lib/text.file.upload.service.mjs +0 -41
- package/esm2022/public_api.mjs +0 -15
- package/fesm2022/dbg-riskit-angular-file.mjs +0 -743
- package/fesm2022/dbg-riskit-angular-file.mjs.map +0 -1
|
@@ -1,743 +0,0 @@
|
|
|
1
|
-
import * as i0 from '@angular/core';
|
|
2
|
-
import { Pipe, Directive, Input, EventEmitter, ElementRef, Output, ViewChild, Injectable, Component, ChangeDetectionStrategy, NgModule } from '@angular/core';
|
|
3
|
-
import * as i1 from '@dbg-riskit/angular-view';
|
|
4
|
-
import { BaseComponent, CommonViewModule } from '@dbg-riskit/angular-view';
|
|
5
|
-
import * as i3 from '@dbg-riskit/common';
|
|
6
|
-
import { isEventObject, ObservableEventType, toString, ErrorType, base64encode, CONTENT_TYPE } from '@dbg-riskit/common';
|
|
7
|
-
import { saveAs } from 'file-saver';
|
|
8
|
-
import { Observable, of, Subject, EMPTY, forkJoin, throwError } from 'rxjs';
|
|
9
|
-
import { takeUntil, take, map, tap, filter, catchError, finalize, first, switchMap } from 'rxjs/operators';
|
|
10
|
-
import * as i2 from '@angular/common';
|
|
11
|
-
import { CommonModule } from '@angular/common';
|
|
12
|
-
import * as i3$1 from '@angular/material/button';
|
|
13
|
-
import { MatAnchor } from '@angular/material/button';
|
|
14
|
-
import * as i4 from '@angular/material/icon';
|
|
15
|
-
import * as i3$2 from '@angular/material/menu';
|
|
16
|
-
import * as i4$1 from '@angular/material/tooltip';
|
|
17
|
-
import { LoggingModule } from '@dbg-riskit/angular-logging';
|
|
18
|
-
|
|
19
|
-
class FileSizePipe {
|
|
20
|
-
constructor(decimalPipe) {
|
|
21
|
-
this.decimalPipe = decimalPipe;
|
|
22
|
-
this.base = 1024;
|
|
23
|
-
this.powerSuffixes = ['B', 'KB', 'MB', 'GB', 'TB', 'PB'];
|
|
24
|
-
}
|
|
25
|
-
transform(value) {
|
|
26
|
-
if (value == null) {
|
|
27
|
-
return '';
|
|
28
|
-
}
|
|
29
|
-
if (typeof value === 'string') {
|
|
30
|
-
value = parseFloat(value);
|
|
31
|
-
}
|
|
32
|
-
let divider = 1;
|
|
33
|
-
let power = 0;
|
|
34
|
-
while (value / divider > this.base && power < this.powerSuffixes.length - 1) {
|
|
35
|
-
divider *= this.base;
|
|
36
|
-
power += 1;
|
|
37
|
-
}
|
|
38
|
-
const formatted = this.decimalPipe.transform(value / divider, '1.2-2') || '';
|
|
39
|
-
const suffix = this.powerSuffixes[power];
|
|
40
|
-
return suffix ? `${formatted}${suffix}` : formatted;
|
|
41
|
-
}
|
|
42
|
-
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: FileSizePipe, deps: [{ token: i2.DecimalPipe }], target: i0.ɵɵFactoryTarget.Pipe }); }
|
|
43
|
-
static { this.ɵpipe = i0.ɵɵngDeclarePipe({ minVersion: "14.0.0", version: "16.2.12", ngImport: i0, type: FileSizePipe, name: "riskFileSize" }); }
|
|
44
|
-
}
|
|
45
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: FileSizePipe, decorators: [{
|
|
46
|
-
type: Pipe,
|
|
47
|
-
args: [{ name: 'riskFileSize' }]
|
|
48
|
-
}], ctorParameters: function () { return [{ type: i2.DecimalPipe }]; } });
|
|
49
|
-
|
|
50
|
-
class AbstractFileDownloadDirective extends BaseComponent {
|
|
51
|
-
constructor(elementRef, dialogService, fileSizePipe, logger) {
|
|
52
|
-
super();
|
|
53
|
-
this.elementRef = elementRef;
|
|
54
|
-
this.dialogService = dialogService;
|
|
55
|
-
this.fileSizePipe = fileSizePipe;
|
|
56
|
-
this.logger = logger;
|
|
57
|
-
}
|
|
58
|
-
isDisabled() {
|
|
59
|
-
if (this.elementRef.nativeElement.disabled === true) {
|
|
60
|
-
return true;
|
|
61
|
-
}
|
|
62
|
-
if (this.disabled == null) {
|
|
63
|
-
return false;
|
|
64
|
-
}
|
|
65
|
-
switch (typeof this.disabled) {
|
|
66
|
-
case 'boolean':
|
|
67
|
-
return this.disabled;
|
|
68
|
-
case 'string':
|
|
69
|
-
return this.disabled.toLowerCase() === 'disabled' || this.disabled.toLowerCase() === 'true';
|
|
70
|
-
}
|
|
71
|
-
return false;
|
|
72
|
-
}
|
|
73
|
-
download() {
|
|
74
|
-
if (this.isDisabled()) {
|
|
75
|
-
return;
|
|
76
|
-
}
|
|
77
|
-
if (this.data == null) {
|
|
78
|
-
this.logger.error(new Error('No data provided for download!'));
|
|
79
|
-
return;
|
|
80
|
-
}
|
|
81
|
-
this.getDataObservable(this.data).pipe(takeUntil(this.destroyed), take(1), map((data) => this.mapToFile(data))).subscribe((file) => this.store(file));
|
|
82
|
-
}
|
|
83
|
-
store(file) {
|
|
84
|
-
setTimeout(() => {
|
|
85
|
-
saveAs(file.content, file.filename || 'data.txt');
|
|
86
|
-
});
|
|
87
|
-
}
|
|
88
|
-
getDataObservable(data) {
|
|
89
|
-
if (!(data instanceof Observable)) {
|
|
90
|
-
return of(data);
|
|
91
|
-
}
|
|
92
|
-
return this.downloadWithProgress(data);
|
|
93
|
-
}
|
|
94
|
-
downloadWithProgress(observableWithProgress) {
|
|
95
|
-
const canceled = new Subject();
|
|
96
|
-
let dialog;
|
|
97
|
-
return observableWithProgress.pipe(takeUntil(canceled), takeUntil(this.destroyed), tap((event) => {
|
|
98
|
-
dialog = this.updateProgress(event, dialog, canceled);
|
|
99
|
-
}), filter((event) => !isEventObject(event)
|
|
100
|
-
|| event.type === ObservableEventType.Result), map((event) => {
|
|
101
|
-
if (isEventObject(event)) {
|
|
102
|
-
const resultEvent = event;
|
|
103
|
-
return resultEvent.result;
|
|
104
|
-
}
|
|
105
|
-
return event;
|
|
106
|
-
}), catchError((err) => this.processError(err)), finalize(() => {
|
|
107
|
-
if (dialog != null) {
|
|
108
|
-
dialog.close();
|
|
109
|
-
}
|
|
110
|
-
}));
|
|
111
|
-
}
|
|
112
|
-
updateProgress(event, dialog, canceledSubject) {
|
|
113
|
-
if (isEventObject(event) && event.type === ObservableEventType.Progress) {
|
|
114
|
-
const progressEvent = event;
|
|
115
|
-
if (dialog == null) {
|
|
116
|
-
dialog = this.dialogService.showProgressLoaderDialog({
|
|
117
|
-
title: 'Downloading file...',
|
|
118
|
-
cancel: () => {
|
|
119
|
-
canceledSubject.next();
|
|
120
|
-
canceledSubject.complete();
|
|
121
|
-
},
|
|
122
|
-
valueFormatter: this.fileSizePipe
|
|
123
|
-
});
|
|
124
|
-
}
|
|
125
|
-
dialog.value = progressEvent.current;
|
|
126
|
-
dialog.total = progressEvent.total;
|
|
127
|
-
}
|
|
128
|
-
return dialog;
|
|
129
|
-
}
|
|
130
|
-
processError(err) {
|
|
131
|
-
let title = 'Failed to download file:';
|
|
132
|
-
let message;
|
|
133
|
-
if ('errorType' in err) {
|
|
134
|
-
const errorMessage = err;
|
|
135
|
-
switch (errorMessage.status) {
|
|
136
|
-
case 401:
|
|
137
|
-
case 403:
|
|
138
|
-
message = 'You are not authorized to download this file.';
|
|
139
|
-
break;
|
|
140
|
-
case 404:
|
|
141
|
-
message = 'File not found.';
|
|
142
|
-
break;
|
|
143
|
-
default:
|
|
144
|
-
message = errorMessage.message;
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
else {
|
|
148
|
-
if ('message' in err) {
|
|
149
|
-
message = err.message;
|
|
150
|
-
}
|
|
151
|
-
else {
|
|
152
|
-
message = 'Failed to download file.';
|
|
153
|
-
title = undefined;
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
this.dialogService.showMessageDialog({
|
|
157
|
-
dialogType: 'error',
|
|
158
|
-
icon: 'cloud_off',
|
|
159
|
-
title,
|
|
160
|
-
message
|
|
161
|
-
});
|
|
162
|
-
return EMPTY;
|
|
163
|
-
}
|
|
164
|
-
/**
|
|
165
|
-
* Blob constructor for testing purposes.
|
|
166
|
-
*/
|
|
167
|
-
createBlob(data, contentType) {
|
|
168
|
-
return new Blob(data, contentType);
|
|
169
|
-
}
|
|
170
|
-
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: AbstractFileDownloadDirective, deps: [{ token: i0.ElementRef }, { token: i1.DialogService }, { token: FileSizePipe }, { token: i3.Logger }], target: i0.ɵɵFactoryTarget.Directive }); }
|
|
171
|
-
static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "16.2.12", type: AbstractFileDownloadDirective, inputs: { disabled: "disabled" }, usesInheritance: true, ngImport: i0 }); }
|
|
172
|
-
}
|
|
173
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: AbstractFileDownloadDirective, decorators: [{
|
|
174
|
-
type: Directive
|
|
175
|
-
}], ctorParameters: function () { return [{ type: i0.ElementRef }, { type: i1.DialogService }, { type: FileSizePipe }, { type: i3.Logger }]; }, propDecorators: { disabled: [{
|
|
176
|
-
type: Input
|
|
177
|
-
}] } });
|
|
178
|
-
|
|
179
|
-
class AbstractFileUploadComponent extends BaseComponent {
|
|
180
|
-
constructor(renderer) {
|
|
181
|
-
super();
|
|
182
|
-
this.renderer = renderer;
|
|
183
|
-
this.error = new EventEmitter(true);
|
|
184
|
-
this.multiple = true;
|
|
185
|
-
this.filesLoaded = new EventEmitter(true);
|
|
186
|
-
this.offset = 0;
|
|
187
|
-
this.fileInputHidden = false;
|
|
188
|
-
this.raised = true;
|
|
189
|
-
this.color = 'primary';
|
|
190
|
-
this.disabled = false;
|
|
191
|
-
}
|
|
192
|
-
ngAfterViewInit() {
|
|
193
|
-
this.offset = this.wrapper.nativeElement.getBoundingClientRect().left
|
|
194
|
-
- this.anchor.nativeElement.getBoundingClientRect().left
|
|
195
|
-
+ (this.wrapper.nativeElement.getBoundingClientRect().width / 2);
|
|
196
|
-
}
|
|
197
|
-
move(event) {
|
|
198
|
-
if (this.fileInput && event.target !== this.fileInput.nativeElement && this.anchor) {
|
|
199
|
-
const diff = event.target?.getBoundingClientRect().left
|
|
200
|
-
- event.currentTarget?.getBoundingClientRect().left
|
|
201
|
-
- this.offset;
|
|
202
|
-
this.renderer.setStyle(this.wrapper.nativeElement, 'left', `${event.offsetX + diff}px`);
|
|
203
|
-
}
|
|
204
|
-
}
|
|
205
|
-
handleFiles(fileList) {
|
|
206
|
-
// Check for the various File API support.
|
|
207
|
-
if ('FileReader' in window) {
|
|
208
|
-
this.readFiles(fileList).pipe(takeUntil(this.destroyed), first()).subscribe({
|
|
209
|
-
next: (files) => {
|
|
210
|
-
this.filesLoaded.emit(files);
|
|
211
|
-
this.resetInputField();
|
|
212
|
-
},
|
|
213
|
-
error: (error) => {
|
|
214
|
-
this.error.emit({
|
|
215
|
-
message: toString(error),
|
|
216
|
-
errorType: ErrorType.ERROR,
|
|
217
|
-
status: 0
|
|
218
|
-
});
|
|
219
|
-
this.resetInputField();
|
|
220
|
-
}
|
|
221
|
-
});
|
|
222
|
-
}
|
|
223
|
-
else {
|
|
224
|
-
this.error.emit({
|
|
225
|
-
message: 'FileReader is not supported in your browser! A newer browser (IE 11+, Chrome 50+, '
|
|
226
|
-
+ 'FireFox 50+, Safari 9+) is required to use this application.',
|
|
227
|
-
errorType: ErrorType.ERROR,
|
|
228
|
-
status: 0
|
|
229
|
-
});
|
|
230
|
-
}
|
|
231
|
-
}
|
|
232
|
-
// Hide and show the input field to reset the selection
|
|
233
|
-
resetInputField() {
|
|
234
|
-
this.fileInputHidden = true;
|
|
235
|
-
setTimeout(() => {
|
|
236
|
-
this.fileInputHidden = false;
|
|
237
|
-
});
|
|
238
|
-
}
|
|
239
|
-
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: AbstractFileUploadComponent, deps: [{ token: i0.Renderer2 }], target: i0.ɵɵFactoryTarget.Directive }); }
|
|
240
|
-
static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "16.2.12", type: AbstractFileUploadComponent, inputs: { label: "label", accept: "accept", multiple: "multiple", raised: "raised", color: "color", icon: "icon", disabled: "disabled" }, outputs: { error: "error", filesLoaded: "filesLoaded" }, viewQueries: [{ propertyName: "anchor", first: true, predicate: MatAnchor, descendants: true, read: ElementRef }, { propertyName: "fileInput", first: true, predicate: ["fileInput"], descendants: true }, { propertyName: "wrapper", first: true, predicate: ["wrapper"], descendants: true }], usesInheritance: true, ngImport: i0 }); }
|
|
241
|
-
}
|
|
242
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: AbstractFileUploadComponent, decorators: [{
|
|
243
|
-
type: Directive
|
|
244
|
-
}], ctorParameters: function () { return [{ type: i0.Renderer2 }]; }, propDecorators: { error: [{
|
|
245
|
-
type: Output
|
|
246
|
-
}], label: [{
|
|
247
|
-
type: Input
|
|
248
|
-
}], accept: [{
|
|
249
|
-
type: Input
|
|
250
|
-
}], multiple: [{
|
|
251
|
-
type: Input
|
|
252
|
-
}], filesLoaded: [{
|
|
253
|
-
type: Output
|
|
254
|
-
}], anchor: [{
|
|
255
|
-
type: ViewChild,
|
|
256
|
-
args: [MatAnchor, { read: ElementRef }]
|
|
257
|
-
}], fileInput: [{
|
|
258
|
-
type: ViewChild,
|
|
259
|
-
args: ['fileInput']
|
|
260
|
-
}], wrapper: [{
|
|
261
|
-
type: ViewChild,
|
|
262
|
-
args: ['wrapper']
|
|
263
|
-
}], raised: [{
|
|
264
|
-
type: Input
|
|
265
|
-
}], color: [{
|
|
266
|
-
type: Input
|
|
267
|
-
}], icon: [{
|
|
268
|
-
type: Input
|
|
269
|
-
}], disabled: [{
|
|
270
|
-
type: Input
|
|
271
|
-
}] } });
|
|
272
|
-
|
|
273
|
-
class BinaryFileUploadService {
|
|
274
|
-
readFiles(files) {
|
|
275
|
-
const fileOservables = [];
|
|
276
|
-
for (const file of Array.from(files)) {
|
|
277
|
-
fileOservables.push(new Observable((observer) => {
|
|
278
|
-
setTimeout(() => {
|
|
279
|
-
try {
|
|
280
|
-
const reader = new FileReader();
|
|
281
|
-
// Handle errors load
|
|
282
|
-
reader.onload = (event) => {
|
|
283
|
-
observer.next({
|
|
284
|
-
bodyBase64: base64encode((event.target.result)),
|
|
285
|
-
file
|
|
286
|
-
});
|
|
287
|
-
observer.complete();
|
|
288
|
-
};
|
|
289
|
-
reader.onerror = (event) => {
|
|
290
|
-
observer.error(event.target.error);
|
|
291
|
-
};
|
|
292
|
-
// Read file into memory as UTF-8
|
|
293
|
-
reader.readAsArrayBuffer(file);
|
|
294
|
-
}
|
|
295
|
-
catch (err) {
|
|
296
|
-
observer.error(err);
|
|
297
|
-
}
|
|
298
|
-
});
|
|
299
|
-
}));
|
|
300
|
-
}
|
|
301
|
-
return forkJoin(fileOservables);
|
|
302
|
-
}
|
|
303
|
-
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: BinaryFileUploadService, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
|
|
304
|
-
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: BinaryFileUploadService }); }
|
|
305
|
-
}
|
|
306
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: BinaryFileUploadService, decorators: [{
|
|
307
|
-
type: Injectable
|
|
308
|
-
}] });
|
|
309
|
-
|
|
310
|
-
class BinaryFileUploadComponent extends AbstractFileUploadComponent {
|
|
311
|
-
constructor(fileUploadService, renderer) {
|
|
312
|
-
super(renderer);
|
|
313
|
-
this.fileUploadService = fileUploadService;
|
|
314
|
-
}
|
|
315
|
-
readFiles(fileList) {
|
|
316
|
-
return this.fileUploadService.readFiles(fileList);
|
|
317
|
-
}
|
|
318
|
-
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: BinaryFileUploadComponent, deps: [{ token: BinaryFileUploadService }, { token: i0.Renderer2 }], target: i0.ɵɵFactoryTarget.Component }); }
|
|
319
|
-
static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "16.2.12", type: BinaryFileUploadComponent, selector: "risk-binary-file-upload", host: { properties: { "class.risk-binary-file-upload": "true" } }, usesInheritance: true, ngImport: i0, template: "<a *ngIf=\"raised; else notRaised\"\n mat-raised-button\n [disabled]=\"disabled\"\n [color]=\"color\"\n (mousemove)=\"move($event)\">\n <mat-icon *ngIf=\"icon\">{{icon}}</mat-icon>\n {{label}}\n <div #wrapper\n class=\"risk-file-upload-input-wrapper\">\n <input *ngIf=\"!fileInputHidden\" type=\"file\"\n id=\"fileInput\"\n #fileInput\n [multiple]=\"multiple\"\n [disabled]=\"disabled\"\n title=\"\"\n (change)=\"handleFiles($event.target.files)\"\n [accept]=\"accept\">\n </div>\n</a>\n<ng-template #notRaised>\n <a mat-button\n [disabled]=\"disabled\"\n [color]=\"color\"\n (mousemove)=\"move($event)\">\n <mat-icon *ngIf=\"icon\">{{icon}}</mat-icon>\n {{label}}\n <div #wrapper\n class=\"risk-file-upload-input-wrapper\">\n <input *ngIf=\"!fileInputHidden\" type=\"file\"\n id=\"fileInput\"\n #fileInput\n [multiple]=\"multiple\"\n [disabled]=\"disabled\"\n title=\"\"\n (change)=\"handleFiles($event.target.files)\"\n [accept]=\"accept\">\n </div>\n </a>\n</ng-template>\n", styles: [":host{display:block;padding:0;margin:0}:host>*{vertical-align:bottom}\n", ":host{display:inline-block}a{overflow:hidden}a .risk-file-upload-input-wrapper{width:30px;height:36px;margin-left:-15px;top:0;left:0;position:absolute;overflow:hidden;cursor:pointer;z-index:1}a .risk-file-upload-input-wrapper input{position:absolute;display:block;cursor:pointer;height:36px;font-size:36px;top:0;right:0;outline:0 none;opacity:0}\n"], dependencies: [{ kind: "directive", type: i2.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { kind: "component", type: i3$1.MatAnchor, selector: "a[mat-button], a[mat-raised-button], a[mat-flat-button], a[mat-stroked-button]", inputs: ["disabled", "disableRipple", "color", "tabIndex"], exportAs: ["matButton", "matAnchor"] }, { kind: "component", type: i4.MatIcon, selector: "mat-icon", inputs: ["color", "inline", "svgIcon", "fontSet", "fontIcon"], exportAs: ["matIcon"] }], changeDetection: i0.ChangeDetectionStrategy.OnPush }); }
|
|
320
|
-
}
|
|
321
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: BinaryFileUploadComponent, decorators: [{
|
|
322
|
-
type: Component,
|
|
323
|
-
args: [{ selector: 'risk-binary-file-upload', host: {
|
|
324
|
-
'[class.risk-binary-file-upload]': 'true'
|
|
325
|
-
}, changeDetection: ChangeDetectionStrategy.OnPush, preserveWhitespaces: false, template: "<a *ngIf=\"raised; else notRaised\"\n mat-raised-button\n [disabled]=\"disabled\"\n [color]=\"color\"\n (mousemove)=\"move($event)\">\n <mat-icon *ngIf=\"icon\">{{icon}}</mat-icon>\n {{label}}\n <div #wrapper\n class=\"risk-file-upload-input-wrapper\">\n <input *ngIf=\"!fileInputHidden\" type=\"file\"\n id=\"fileInput\"\n #fileInput\n [multiple]=\"multiple\"\n [disabled]=\"disabled\"\n title=\"\"\n (change)=\"handleFiles($event.target.files)\"\n [accept]=\"accept\">\n </div>\n</a>\n<ng-template #notRaised>\n <a mat-button\n [disabled]=\"disabled\"\n [color]=\"color\"\n (mousemove)=\"move($event)\">\n <mat-icon *ngIf=\"icon\">{{icon}}</mat-icon>\n {{label}}\n <div #wrapper\n class=\"risk-file-upload-input-wrapper\">\n <input *ngIf=\"!fileInputHidden\" type=\"file\"\n id=\"fileInput\"\n #fileInput\n [multiple]=\"multiple\"\n [disabled]=\"disabled\"\n title=\"\"\n (change)=\"handleFiles($event.target.files)\"\n [accept]=\"accept\">\n </div>\n </a>\n</ng-template>\n", styles: [":host{display:block;padding:0;margin:0}:host>*{vertical-align:bottom}\n", ":host{display:inline-block}a{overflow:hidden}a .risk-file-upload-input-wrapper{width:30px;height:36px;margin-left:-15px;top:0;left:0;position:absolute;overflow:hidden;cursor:pointer;z-index:1}a .risk-file-upload-input-wrapper input{position:absolute;display:block;cursor:pointer;height:36px;font-size:36px;top:0;right:0;outline:0 none;opacity:0}\n"] }]
|
|
326
|
-
}], ctorParameters: function () { return [{ type: BinaryFileUploadService }, { type: i0.Renderer2 }]; } });
|
|
327
|
-
|
|
328
|
-
class CSVFileDownloadDirective extends AbstractFileDownloadDirective {
|
|
329
|
-
constructor(dateFormatter, elementRef, dialogService, fileSizePipe, logger) {
|
|
330
|
-
super(elementRef, dialogService, fileSizePipe, logger);
|
|
331
|
-
this.dateFormatter = dateFormatter;
|
|
332
|
-
this.filename = 'data.csv';
|
|
333
|
-
this.crlfLineEnding = false;
|
|
334
|
-
}
|
|
335
|
-
mapToFile(data) {
|
|
336
|
-
let csvFile = '';
|
|
337
|
-
if (this.columns) {
|
|
338
|
-
csvFile += this.createHeader();
|
|
339
|
-
for (const row of data) {
|
|
340
|
-
csvFile += this.processRow(row);
|
|
341
|
-
}
|
|
342
|
-
}
|
|
343
|
-
return {
|
|
344
|
-
filename: this.filename,
|
|
345
|
-
content: this.createBlob([csvFile], { type: CONTENT_TYPE.TEXT_CSV })
|
|
346
|
-
};
|
|
347
|
-
}
|
|
348
|
-
processRow(row) {
|
|
349
|
-
return this.columns.map((column) => {
|
|
350
|
-
const value = column.get(row);
|
|
351
|
-
let innerValue = toString(value);
|
|
352
|
-
if (value instanceof Date) {
|
|
353
|
-
innerValue = this.dateFormatter.transform(value) || '';
|
|
354
|
-
}
|
|
355
|
-
let result = innerValue.replace(/"/g, '""');
|
|
356
|
-
if (result.search(/([",\n])/g) >= 0) {
|
|
357
|
-
result = `"${result}"`;
|
|
358
|
-
}
|
|
359
|
-
return result;
|
|
360
|
-
}).join(',') + this.getLineEnding();
|
|
361
|
-
}
|
|
362
|
-
createHeader() {
|
|
363
|
-
return this.columns.map((column) => {
|
|
364
|
-
const innerValue = toString(column.header);
|
|
365
|
-
let result = innerValue.replace(/"/g, '""');
|
|
366
|
-
if (result.search(/([",\n])/g) >= 0) {
|
|
367
|
-
result = `"${result}"`;
|
|
368
|
-
}
|
|
369
|
-
return result;
|
|
370
|
-
}).join(',') + this.getLineEnding();
|
|
371
|
-
}
|
|
372
|
-
getLineEnding() {
|
|
373
|
-
if (this.crlfLineEnding) {
|
|
374
|
-
return '\r\n';
|
|
375
|
-
}
|
|
376
|
-
return '\n';
|
|
377
|
-
}
|
|
378
|
-
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: CSVFileDownloadDirective, deps: [{ token: i1.DateFormatter }, { token: i0.ElementRef }, { token: i1.DialogService }, { token: FileSizePipe }, { token: i3.Logger }], target: i0.ɵɵFactoryTarget.Directive }); }
|
|
379
|
-
static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "16.2.12", type: CSVFileDownloadDirective, selector: "[risk-csv-download]", inputs: { columns: ["risk-csv-download-columns", "columns"], data: ["risk-csv-download", "data"], filename: ["risk-csv-download-filename", "filename"], crlfLineEnding: ["risk-csv-download-crlf", "crlfLineEnding"] }, host: { listeners: { "click": "download()" }, properties: { "class.risk-csv-download": "true" } }, usesInheritance: true, ngImport: i0 }); }
|
|
380
|
-
}
|
|
381
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: CSVFileDownloadDirective, decorators: [{
|
|
382
|
-
type: Directive,
|
|
383
|
-
args: [{
|
|
384
|
-
selector: '[risk-csv-download]',
|
|
385
|
-
host: {
|
|
386
|
-
'[class.risk-csv-download]': 'true',
|
|
387
|
-
'(click)': 'download()'
|
|
388
|
-
}
|
|
389
|
-
}]
|
|
390
|
-
}], ctorParameters: function () { return [{ type: i1.DateFormatter }, { type: i0.ElementRef }, { type: i1.DialogService }, { type: FileSizePipe }, { type: i3.Logger }]; }, propDecorators: { columns: [{
|
|
391
|
-
type: Input,
|
|
392
|
-
args: ['risk-csv-download-columns']
|
|
393
|
-
}], data: [{
|
|
394
|
-
type: Input,
|
|
395
|
-
args: ['risk-csv-download']
|
|
396
|
-
}], filename: [{
|
|
397
|
-
type: Input,
|
|
398
|
-
args: ['risk-csv-download-filename']
|
|
399
|
-
}], crlfLineEnding: [{
|
|
400
|
-
type: Input,
|
|
401
|
-
args: ['risk-csv-download-crlf']
|
|
402
|
-
}] } });
|
|
403
|
-
|
|
404
|
-
// Create a regular expression to parse the CSV values.
|
|
405
|
-
const CSV_FILE_PATTERN = new RegExp((
|
|
406
|
-
// Delimiters.
|
|
407
|
-
'([,;]|\\r?\\n|\\r|^)' +
|
|
408
|
-
// Quoted fields.
|
|
409
|
-
'(?:"([^"]*(?:""[^"]*)*)"|' +
|
|
410
|
-
// Standard fields.
|
|
411
|
-
'([^",;\\r\\n]*))'), 'gi');
|
|
412
|
-
class CSVFileUploadService {
|
|
413
|
-
readFiles(files, nameMapper = (name) => name) {
|
|
414
|
-
const fileOservables = [];
|
|
415
|
-
for (const file of Array.from(files)) {
|
|
416
|
-
fileOservables.push(new Observable((observer) => {
|
|
417
|
-
setTimeout(() => {
|
|
418
|
-
try {
|
|
419
|
-
const reader = new FileReader();
|
|
420
|
-
// Handle errors load
|
|
421
|
-
reader.onload = (event) => {
|
|
422
|
-
observer.next(CSVFileUploadService.getCSVFile(toString(event.target.result), file, nameMapper));
|
|
423
|
-
observer.complete();
|
|
424
|
-
};
|
|
425
|
-
reader.onerror = (event) => {
|
|
426
|
-
observer.error(event.target.error);
|
|
427
|
-
};
|
|
428
|
-
// Read file into memory as UTF-8
|
|
429
|
-
reader.readAsText(file);
|
|
430
|
-
}
|
|
431
|
-
catch (err) {
|
|
432
|
-
observer.error(err);
|
|
433
|
-
}
|
|
434
|
-
});
|
|
435
|
-
}));
|
|
436
|
-
}
|
|
437
|
-
return forkJoin(fileOservables);
|
|
438
|
-
}
|
|
439
|
-
static getCSVFile(content, file, nameMapper, startFromRow) {
|
|
440
|
-
// Create an array to hold our data. Give the array
|
|
441
|
-
// a default empty first row.
|
|
442
|
-
let arrData = [[]];
|
|
443
|
-
// Create an array to hold our individual pattern
|
|
444
|
-
// matching groups.
|
|
445
|
-
// Keep looping over the regular expression matches
|
|
446
|
-
// until we can no longer find a match.
|
|
447
|
-
while (true) {
|
|
448
|
-
const arrMatches = CSV_FILE_PATTERN.exec(content);
|
|
449
|
-
if (arrMatches == null) {
|
|
450
|
-
break;
|
|
451
|
-
}
|
|
452
|
-
// Get the delimiter that was found.
|
|
453
|
-
const strMatchedDelimiter = arrMatches[1];
|
|
454
|
-
// Check to see if the given delimiter has a length
|
|
455
|
-
// (is not the start of string) and if it matches
|
|
456
|
-
// field delimiter. If id does not, then we know
|
|
457
|
-
// that this delimiter is a row delimiter.
|
|
458
|
-
if (strMatchedDelimiter.length && strMatchedDelimiter !== ',' && strMatchedDelimiter !== ';') {
|
|
459
|
-
// Since we have reached a new row of data,
|
|
460
|
-
// add an empty row to our data array.
|
|
461
|
-
arrData.push([]);
|
|
462
|
-
}
|
|
463
|
-
let strMatchedValue;
|
|
464
|
-
// Now that we have our delimiter out of the way,
|
|
465
|
-
// let's check to see which kind of value we
|
|
466
|
-
// captured (quoted or unquoted).
|
|
467
|
-
if (arrMatches[2]) {
|
|
468
|
-
// We found a quoted value. When we capture
|
|
469
|
-
// this value, unescape any double quotes.
|
|
470
|
-
strMatchedValue = arrMatches[2].replace(new RegExp('""', 'g'), '"');
|
|
471
|
-
}
|
|
472
|
-
else {
|
|
473
|
-
// We found a non-quoted value.
|
|
474
|
-
strMatchedValue = arrMatches[3];
|
|
475
|
-
}
|
|
476
|
-
// Now that we have our value string, let's add
|
|
477
|
-
// it to the data array.
|
|
478
|
-
arrData[arrData.length - 1].push(strMatchedValue);
|
|
479
|
-
}
|
|
480
|
-
// Filter out empty rows
|
|
481
|
-
arrData = arrData.filter((dataRow) => {
|
|
482
|
-
return dataRow.some((item) => item != null && item.trim() !== '');
|
|
483
|
-
});
|
|
484
|
-
// Return the parsed data.
|
|
485
|
-
const fromRow = startFromRow ? startFromRow : 0;
|
|
486
|
-
return {
|
|
487
|
-
header: arrData[fromRow],
|
|
488
|
-
body: arrData.slice(fromRow + 1).map((dataRow) => {
|
|
489
|
-
const row = {};
|
|
490
|
-
for (let i = 0; i < arrData[fromRow].length; i++) {
|
|
491
|
-
row[nameMapper(arrData[fromRow][i])] = dataRow[i];
|
|
492
|
-
}
|
|
493
|
-
return row;
|
|
494
|
-
}),
|
|
495
|
-
file: {
|
|
496
|
-
name: file.name,
|
|
497
|
-
size: file.size,
|
|
498
|
-
type: file.type
|
|
499
|
-
}
|
|
500
|
-
};
|
|
501
|
-
}
|
|
502
|
-
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: CSVFileUploadService, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
|
|
503
|
-
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: CSVFileUploadService }); }
|
|
504
|
-
}
|
|
505
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: CSVFileUploadService, decorators: [{
|
|
506
|
-
type: Injectable
|
|
507
|
-
}] });
|
|
508
|
-
|
|
509
|
-
class CSVFileUploadComponent extends AbstractFileUploadComponent {
|
|
510
|
-
constructor(fileUploadService, renderer) {
|
|
511
|
-
super(renderer);
|
|
512
|
-
this.fileUploadService = fileUploadService;
|
|
513
|
-
}
|
|
514
|
-
readFiles(fileList) {
|
|
515
|
-
return this.fileUploadService.readFiles(fileList, this.nameMapper).pipe(switchMap((files) => {
|
|
516
|
-
const validationErrors = [];
|
|
517
|
-
if (!this.validator || files.every((file) => {
|
|
518
|
-
const result = this.validator(file);
|
|
519
|
-
if (!result.result && result.messages != null) {
|
|
520
|
-
result.messages.forEach((message) => {
|
|
521
|
-
validationErrors.push(message);
|
|
522
|
-
});
|
|
523
|
-
}
|
|
524
|
-
return result.result;
|
|
525
|
-
})) {
|
|
526
|
-
return of(files);
|
|
527
|
-
}
|
|
528
|
-
else {
|
|
529
|
-
return throwError(`<li>${validationErrors.join('</li><li>')}</li>`);
|
|
530
|
-
}
|
|
531
|
-
}));
|
|
532
|
-
}
|
|
533
|
-
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: CSVFileUploadComponent, deps: [{ token: CSVFileUploadService }, { token: i0.Renderer2 }], target: i0.ɵɵFactoryTarget.Component }); }
|
|
534
|
-
static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "16.2.12", type: CSVFileUploadComponent, selector: "risk-csv-file-upload", inputs: { validator: "validator", nameMapper: "nameMapper" }, host: { properties: { "class.risk-csv-file-upload": "true" } }, usesInheritance: true, ngImport: i0, template: "<a *ngIf=\"raised; else notRaised\"\n mat-raised-button\n [disabled]=\"disabled\"\n [color]=\"color\"\n (mousemove)=\"move($event)\">\n <mat-icon *ngIf=\"icon\">{{icon}}</mat-icon>\n {{label}}\n <div #wrapper\n class=\"risk-file-upload-input-wrapper\">\n <input *ngIf=\"!fileInputHidden\" type=\"file\"\n id=\"fileInput\"\n #fileInput\n [multiple]=\"multiple\"\n [disabled]=\"disabled\"\n title=\"\"\n (change)=\"handleFiles($event.target.files)\"\n [accept]=\"accept\">\n </div>\n</a>\n<ng-template #notRaised>\n <a mat-button\n [disabled]=\"disabled\"\n [color]=\"color\"\n (mousemove)=\"move($event)\">\n <mat-icon *ngIf=\"icon\">{{icon}}</mat-icon>\n {{label}}\n <div #wrapper\n class=\"risk-file-upload-input-wrapper\">\n <input *ngIf=\"!fileInputHidden\" type=\"file\"\n id=\"fileInput\"\n #fileInput\n [multiple]=\"multiple\"\n [disabled]=\"disabled\"\n title=\"\"\n (change)=\"handleFiles($event.target.files)\"\n [accept]=\"accept\">\n </div>\n </a>\n</ng-template>\n", styles: [":host{display:block;padding:0;margin:0}:host>*{vertical-align:bottom}\n", ":host{display:inline-block}a{overflow:hidden}a .risk-file-upload-input-wrapper{width:30px;height:36px;margin-left:-15px;top:0;left:0;position:absolute;overflow:hidden;cursor:pointer;z-index:1}a .risk-file-upload-input-wrapper input{position:absolute;display:block;cursor:pointer;height:36px;font-size:36px;top:0;right:0;outline:0 none;opacity:0}\n"], dependencies: [{ kind: "directive", type: i2.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { kind: "component", type: i3$1.MatAnchor, selector: "a[mat-button], a[mat-raised-button], a[mat-flat-button], a[mat-stroked-button]", inputs: ["disabled", "disableRipple", "color", "tabIndex"], exportAs: ["matButton", "matAnchor"] }, { kind: "component", type: i4.MatIcon, selector: "mat-icon", inputs: ["color", "inline", "svgIcon", "fontSet", "fontIcon"], exportAs: ["matIcon"] }], changeDetection: i0.ChangeDetectionStrategy.OnPush }); }
|
|
535
|
-
}
|
|
536
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: CSVFileUploadComponent, decorators: [{
|
|
537
|
-
type: Component,
|
|
538
|
-
args: [{ selector: 'risk-csv-file-upload', host: {
|
|
539
|
-
'[class.risk-csv-file-upload]': 'true'
|
|
540
|
-
}, changeDetection: ChangeDetectionStrategy.OnPush, preserveWhitespaces: false, template: "<a *ngIf=\"raised; else notRaised\"\n mat-raised-button\n [disabled]=\"disabled\"\n [color]=\"color\"\n (mousemove)=\"move($event)\">\n <mat-icon *ngIf=\"icon\">{{icon}}</mat-icon>\n {{label}}\n <div #wrapper\n class=\"risk-file-upload-input-wrapper\">\n <input *ngIf=\"!fileInputHidden\" type=\"file\"\n id=\"fileInput\"\n #fileInput\n [multiple]=\"multiple\"\n [disabled]=\"disabled\"\n title=\"\"\n (change)=\"handleFiles($event.target.files)\"\n [accept]=\"accept\">\n </div>\n</a>\n<ng-template #notRaised>\n <a mat-button\n [disabled]=\"disabled\"\n [color]=\"color\"\n (mousemove)=\"move($event)\">\n <mat-icon *ngIf=\"icon\">{{icon}}</mat-icon>\n {{label}}\n <div #wrapper\n class=\"risk-file-upload-input-wrapper\">\n <input *ngIf=\"!fileInputHidden\" type=\"file\"\n id=\"fileInput\"\n #fileInput\n [multiple]=\"multiple\"\n [disabled]=\"disabled\"\n title=\"\"\n (change)=\"handleFiles($event.target.files)\"\n [accept]=\"accept\">\n </div>\n </a>\n</ng-template>\n", styles: [":host{display:block;padding:0;margin:0}:host>*{vertical-align:bottom}\n", ":host{display:inline-block}a{overflow:hidden}a .risk-file-upload-input-wrapper{width:30px;height:36px;margin-left:-15px;top:0;left:0;position:absolute;overflow:hidden;cursor:pointer;z-index:1}a .risk-file-upload-input-wrapper input{position:absolute;display:block;cursor:pointer;height:36px;font-size:36px;top:0;right:0;outline:0 none;opacity:0}\n"] }]
|
|
541
|
-
}], ctorParameters: function () { return [{ type: CSVFileUploadService }, { type: i0.Renderer2 }]; }, propDecorators: { validator: [{
|
|
542
|
-
type: Input
|
|
543
|
-
}], nameMapper: [{
|
|
544
|
-
type: Input
|
|
545
|
-
}] } });
|
|
546
|
-
|
|
547
|
-
class TextFileUploadService {
|
|
548
|
-
readFiles(files) {
|
|
549
|
-
const fileOservables = [];
|
|
550
|
-
for (const file of Array.from(files)) {
|
|
551
|
-
fileOservables.push(new Observable((observer) => {
|
|
552
|
-
setTimeout(() => {
|
|
553
|
-
try {
|
|
554
|
-
const reader = new FileReader();
|
|
555
|
-
// Handle errors load
|
|
556
|
-
reader.onload = (event) => {
|
|
557
|
-
observer.next({
|
|
558
|
-
body: toString(event.target.result),
|
|
559
|
-
file
|
|
560
|
-
});
|
|
561
|
-
observer.complete();
|
|
562
|
-
};
|
|
563
|
-
reader.onerror = (event) => {
|
|
564
|
-
observer.error(event.target.error);
|
|
565
|
-
};
|
|
566
|
-
// Read file into memory as UTF-8
|
|
567
|
-
reader.readAsText(file);
|
|
568
|
-
}
|
|
569
|
-
catch (err) {
|
|
570
|
-
observer.error(err);
|
|
571
|
-
}
|
|
572
|
-
});
|
|
573
|
-
}));
|
|
574
|
-
}
|
|
575
|
-
return forkJoin(fileOservables);
|
|
576
|
-
}
|
|
577
|
-
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: TextFileUploadService, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
|
|
578
|
-
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: TextFileUploadService }); }
|
|
579
|
-
}
|
|
580
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: TextFileUploadService, decorators: [{
|
|
581
|
-
type: Injectable
|
|
582
|
-
}] });
|
|
583
|
-
|
|
584
|
-
class TextFileUploadComponent extends AbstractFileUploadComponent {
|
|
585
|
-
constructor(fileUploadService, renderer) {
|
|
586
|
-
super(renderer);
|
|
587
|
-
this.fileUploadService = fileUploadService;
|
|
588
|
-
}
|
|
589
|
-
readFiles(fileList) {
|
|
590
|
-
return this.fileUploadService
|
|
591
|
-
.readFiles(fileList);
|
|
592
|
-
}
|
|
593
|
-
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: TextFileUploadComponent, deps: [{ token: TextFileUploadService }, { token: i0.Renderer2 }], target: i0.ɵɵFactoryTarget.Component }); }
|
|
594
|
-
static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "16.2.12", type: TextFileUploadComponent, selector: "risk-text-file-upload", host: { properties: { "class.risk-text-file-upload": "true" } }, usesInheritance: true, ngImport: i0, template: "<a *ngIf=\"raised; else notRaised\"\n mat-raised-button\n [disabled]=\"disabled\"\n [color]=\"color\"\n (mousemove)=\"move($event)\">\n <mat-icon *ngIf=\"icon\">{{icon}}</mat-icon>\n {{label}}\n <div #wrapper\n class=\"risk-file-upload-input-wrapper\">\n <input *ngIf=\"!fileInputHidden\" type=\"file\"\n id=\"fileInput\"\n #fileInput\n [multiple]=\"multiple\"\n [disabled]=\"disabled\"\n title=\"\"\n (change)=\"handleFiles($event.target.files)\"\n [accept]=\"accept\">\n </div>\n</a>\n<ng-template #notRaised>\n <a mat-button\n [disabled]=\"disabled\"\n [color]=\"color\"\n (mousemove)=\"move($event)\">\n <mat-icon *ngIf=\"icon\">{{icon}}</mat-icon>\n {{label}}\n <div #wrapper\n class=\"risk-file-upload-input-wrapper\">\n <input *ngIf=\"!fileInputHidden\" type=\"file\"\n id=\"fileInput\"\n #fileInput\n [multiple]=\"multiple\"\n [disabled]=\"disabled\"\n title=\"\"\n (change)=\"handleFiles($event.target.files)\"\n [accept]=\"accept\">\n </div>\n </a>\n</ng-template>\n", styles: [":host{display:block;padding:0;margin:0}:host>*{vertical-align:bottom}\n", ":host{display:inline-block}a{overflow:hidden}a .risk-file-upload-input-wrapper{width:30px;height:36px;margin-left:-15px;top:0;left:0;position:absolute;overflow:hidden;cursor:pointer;z-index:1}a .risk-file-upload-input-wrapper input{position:absolute;display:block;cursor:pointer;height:36px;font-size:36px;top:0;right:0;outline:0 none;opacity:0}\n"], dependencies: [{ kind: "directive", type: i2.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { kind: "component", type: i3$1.MatAnchor, selector: "a[mat-button], a[mat-raised-button], a[mat-flat-button], a[mat-stroked-button]", inputs: ["disabled", "disableRipple", "color", "tabIndex"], exportAs: ["matButton", "matAnchor"] }, { kind: "component", type: i4.MatIcon, selector: "mat-icon", inputs: ["color", "inline", "svgIcon", "fontSet", "fontIcon"], exportAs: ["matIcon"] }], changeDetection: i0.ChangeDetectionStrategy.OnPush }); }
|
|
595
|
-
}
|
|
596
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: TextFileUploadComponent, decorators: [{
|
|
597
|
-
type: Component,
|
|
598
|
-
args: [{ selector: 'risk-text-file-upload', host: {
|
|
599
|
-
'[class.risk-text-file-upload]': 'true'
|
|
600
|
-
}, changeDetection: ChangeDetectionStrategy.OnPush, preserveWhitespaces: false, template: "<a *ngIf=\"raised; else notRaised\"\n mat-raised-button\n [disabled]=\"disabled\"\n [color]=\"color\"\n (mousemove)=\"move($event)\">\n <mat-icon *ngIf=\"icon\">{{icon}}</mat-icon>\n {{label}}\n <div #wrapper\n class=\"risk-file-upload-input-wrapper\">\n <input *ngIf=\"!fileInputHidden\" type=\"file\"\n id=\"fileInput\"\n #fileInput\n [multiple]=\"multiple\"\n [disabled]=\"disabled\"\n title=\"\"\n (change)=\"handleFiles($event.target.files)\"\n [accept]=\"accept\">\n </div>\n</a>\n<ng-template #notRaised>\n <a mat-button\n [disabled]=\"disabled\"\n [color]=\"color\"\n (mousemove)=\"move($event)\">\n <mat-icon *ngIf=\"icon\">{{icon}}</mat-icon>\n {{label}}\n <div #wrapper\n class=\"risk-file-upload-input-wrapper\">\n <input *ngIf=\"!fileInputHidden\" type=\"file\"\n id=\"fileInput\"\n #fileInput\n [multiple]=\"multiple\"\n [disabled]=\"disabled\"\n title=\"\"\n (change)=\"handleFiles($event.target.files)\"\n [accept]=\"accept\">\n </div>\n </a>\n</ng-template>\n", styles: [":host{display:block;padding:0;margin:0}:host>*{vertical-align:bottom}\n", ":host{display:inline-block}a{overflow:hidden}a .risk-file-upload-input-wrapper{width:30px;height:36px;margin-left:-15px;top:0;left:0;position:absolute;overflow:hidden;cursor:pointer;z-index:1}a .risk-file-upload-input-wrapper input{position:absolute;display:block;cursor:pointer;height:36px;font-size:36px;top:0;right:0;outline:0 none;opacity:0}\n"] }]
|
|
601
|
-
}], ctorParameters: function () { return [{ type: TextFileUploadService }, { type: i0.Renderer2 }]; } });
|
|
602
|
-
|
|
603
|
-
class CSVDownloadMenuComponent {
|
|
604
|
-
constructor() {
|
|
605
|
-
this.menuLabel = 'Download';
|
|
606
|
-
this.disabled = false;
|
|
607
|
-
}
|
|
608
|
-
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: CSVDownloadMenuComponent, deps: [], target: i0.ɵɵFactoryTarget.Component }); }
|
|
609
|
-
static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "16.2.12", type: CSVDownloadMenuComponent, selector: "risk-download-menu", inputs: { menuLabel: "menuLabel", menuTooltip: "menuTooltip", columns: "columns", data: "data", disabled: "disabled", filename: "filename" }, host: { properties: { "class.risk-download-menu": "true" } }, ngImport: i0, template: "<mat-menu #downloadMenu=\"matMenu\"\n [overlapTrigger]=\"false\">\n <a mat-menu-item\n [risk-csv-download]=\"data\"\n [risk-csv-download-columns]=\"columns\"\n [risk-csv-download-filename]=\"filename\"\n [risk-csv-download-crlf]=\"true\">\n As CSV file (Windows)\n </a>\n <a mat-menu-item\n [risk-csv-download]=\"data\"\n [risk-csv-download-columns]=\"columns\"\n [risk-csv-download-filename]=\"filename\">\n As CSV file (Unix)\n </a>\n</mat-menu>\n\n<button mat-button\n #menu=\"matMenuTrigger\"\n [disabled]=\"disabled\"\n [matMenuTriggerFor]=\"downloadMenu\"\n [class.risk-menu-open]=\"menu.menuOpen\"\n [matTooltip]=\"menuTooltip\">\n <mat-icon>file_download</mat-icon>\n {{ menuLabel }}\n</button>\n", styles: [":host{display:block;padding:0;margin:0}:host>*{vertical-align:bottom}\n", ":host{display:inline-block}\n"], dependencies: [{ kind: "component", type: i3$1.MatButton, selector: " button[mat-button], button[mat-raised-button], button[mat-flat-button], button[mat-stroked-button] ", inputs: ["disabled", "disableRipple", "color"], exportAs: ["matButton"] }, { kind: "component", type: i4.MatIcon, selector: "mat-icon", inputs: ["color", "inline", "svgIcon", "fontSet", "fontIcon"], exportAs: ["matIcon"] }, { kind: "component", type: i3$2.MatMenu, selector: "mat-menu", exportAs: ["matMenu"] }, { kind: "component", type: i3$2.MatMenuItem, selector: "[mat-menu-item]", inputs: ["disabled", "disableRipple", "role"], exportAs: ["matMenuItem"] }, { kind: "directive", type: i3$2.MatMenuTrigger, selector: "[mat-menu-trigger-for], [matMenuTriggerFor]", exportAs: ["matMenuTrigger"] }, { kind: "directive", type: i4$1.MatTooltip, selector: "[matTooltip]", exportAs: ["matTooltip"] }, { kind: "directive", type: CSVFileDownloadDirective, selector: "[risk-csv-download]", inputs: ["risk-csv-download-columns", "risk-csv-download", "risk-csv-download-filename", "risk-csv-download-crlf"] }], changeDetection: i0.ChangeDetectionStrategy.OnPush }); }
|
|
610
|
-
}
|
|
611
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: CSVDownloadMenuComponent, decorators: [{
|
|
612
|
-
type: Component,
|
|
613
|
-
args: [{ selector: 'risk-download-menu', host: {
|
|
614
|
-
'[class.risk-download-menu]': 'true'
|
|
615
|
-
}, changeDetection: ChangeDetectionStrategy.OnPush, preserveWhitespaces: false, template: "<mat-menu #downloadMenu=\"matMenu\"\n [overlapTrigger]=\"false\">\n <a mat-menu-item\n [risk-csv-download]=\"data\"\n [risk-csv-download-columns]=\"columns\"\n [risk-csv-download-filename]=\"filename\"\n [risk-csv-download-crlf]=\"true\">\n As CSV file (Windows)\n </a>\n <a mat-menu-item\n [risk-csv-download]=\"data\"\n [risk-csv-download-columns]=\"columns\"\n [risk-csv-download-filename]=\"filename\">\n As CSV file (Unix)\n </a>\n</mat-menu>\n\n<button mat-button\n #menu=\"matMenuTrigger\"\n [disabled]=\"disabled\"\n [matMenuTriggerFor]=\"downloadMenu\"\n [class.risk-menu-open]=\"menu.menuOpen\"\n [matTooltip]=\"menuTooltip\">\n <mat-icon>file_download</mat-icon>\n {{ menuLabel }}\n</button>\n", styles: [":host{display:block;padding:0;margin:0}:host>*{vertical-align:bottom}\n", ":host{display:inline-block}\n"] }]
|
|
616
|
-
}], propDecorators: { menuLabel: [{
|
|
617
|
-
type: Input
|
|
618
|
-
}], menuTooltip: [{
|
|
619
|
-
type: Input
|
|
620
|
-
}], columns: [{
|
|
621
|
-
type: Input
|
|
622
|
-
}], data: [{
|
|
623
|
-
type: Input
|
|
624
|
-
}], disabled: [{
|
|
625
|
-
type: Input
|
|
626
|
-
}], filename: [{
|
|
627
|
-
type: Input
|
|
628
|
-
}] } });
|
|
629
|
-
|
|
630
|
-
class FileDownloadDirective extends AbstractFileDownloadDirective {
|
|
631
|
-
constructor(elementRef, dialogService, fileSizePipe, logger) {
|
|
632
|
-
super(elementRef, dialogService, fileSizePipe, logger);
|
|
633
|
-
}
|
|
634
|
-
mapToFile(data) {
|
|
635
|
-
const filename = this.filename || 'data.txt';
|
|
636
|
-
if (data instanceof Blob) {
|
|
637
|
-
return {
|
|
638
|
-
content: data,
|
|
639
|
-
filename
|
|
640
|
-
};
|
|
641
|
-
}
|
|
642
|
-
if (typeof data === 'object' && 'content' in data && data.content instanceof Blob) {
|
|
643
|
-
return {
|
|
644
|
-
content: data.content,
|
|
645
|
-
filename: data.filename || filename
|
|
646
|
-
};
|
|
647
|
-
}
|
|
648
|
-
const stringData = typeof data === 'string' ? data : JSON.stringify(data);
|
|
649
|
-
return {
|
|
650
|
-
content: this.createBlob([stringData], { type: this.contentType }),
|
|
651
|
-
filename
|
|
652
|
-
};
|
|
653
|
-
}
|
|
654
|
-
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: FileDownloadDirective, deps: [{ token: i0.ElementRef }, { token: i1.DialogService }, { token: FileSizePipe }, { token: i3.Logger }], target: i0.ɵɵFactoryTarget.Directive }); }
|
|
655
|
-
static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "16.2.12", type: FileDownloadDirective, selector: "[risk-download]", inputs: { data: ["risk-download", "data"], contentType: ["risk-download-content-type", "contentType"], filename: ["risk-download-filename", "filename"] }, host: { listeners: { "click": "download()" }, properties: { "class.risk-download": "true" } }, usesInheritance: true, ngImport: i0 }); }
|
|
656
|
-
}
|
|
657
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: FileDownloadDirective, decorators: [{
|
|
658
|
-
type: Directive,
|
|
659
|
-
args: [{
|
|
660
|
-
selector: '[risk-download]',
|
|
661
|
-
host: {
|
|
662
|
-
'[class.risk-download]': 'true',
|
|
663
|
-
'(click)': 'download()'
|
|
664
|
-
}
|
|
665
|
-
}]
|
|
666
|
-
}], ctorParameters: function () { return [{ type: i0.ElementRef }, { type: i1.DialogService }, { type: FileSizePipe }, { type: i3.Logger }]; }, propDecorators: { data: [{
|
|
667
|
-
type: Input,
|
|
668
|
-
args: ['risk-download']
|
|
669
|
-
}], contentType: [{
|
|
670
|
-
type: Input,
|
|
671
|
-
args: ['risk-download-content-type']
|
|
672
|
-
}], filename: [{
|
|
673
|
-
type: Input,
|
|
674
|
-
args: ['risk-download-filename']
|
|
675
|
-
}] } });
|
|
676
|
-
|
|
677
|
-
class FileModule {
|
|
678
|
-
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: FileModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule }); }
|
|
679
|
-
static { this.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "16.2.12", ngImport: i0, type: FileModule, declarations: [BinaryFileUploadComponent,
|
|
680
|
-
CSVFileUploadComponent,
|
|
681
|
-
TextFileUploadComponent,
|
|
682
|
-
CSVFileDownloadDirective,
|
|
683
|
-
CSVDownloadMenuComponent,
|
|
684
|
-
FileDownloadDirective,
|
|
685
|
-
FileSizePipe], imports: [CommonModule,
|
|
686
|
-
CommonViewModule,
|
|
687
|
-
LoggingModule], exports: [BinaryFileUploadComponent,
|
|
688
|
-
CSVFileUploadComponent,
|
|
689
|
-
TextFileUploadComponent,
|
|
690
|
-
CSVFileDownloadDirective,
|
|
691
|
-
CSVDownloadMenuComponent,
|
|
692
|
-
FileDownloadDirective,
|
|
693
|
-
FileSizePipe] }); }
|
|
694
|
-
static { this.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: FileModule, providers: [
|
|
695
|
-
BinaryFileUploadService,
|
|
696
|
-
CSVFileUploadService,
|
|
697
|
-
TextFileUploadService,
|
|
698
|
-
FileSizePipe
|
|
699
|
-
], imports: [CommonModule,
|
|
700
|
-
CommonViewModule,
|
|
701
|
-
LoggingModule] }); }
|
|
702
|
-
}
|
|
703
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: FileModule, decorators: [{
|
|
704
|
-
type: NgModule,
|
|
705
|
-
args: [{
|
|
706
|
-
imports: [
|
|
707
|
-
CommonModule,
|
|
708
|
-
CommonViewModule,
|
|
709
|
-
LoggingModule
|
|
710
|
-
],
|
|
711
|
-
declarations: [
|
|
712
|
-
BinaryFileUploadComponent,
|
|
713
|
-
CSVFileUploadComponent,
|
|
714
|
-
TextFileUploadComponent,
|
|
715
|
-
CSVFileDownloadDirective,
|
|
716
|
-
CSVDownloadMenuComponent,
|
|
717
|
-
FileDownloadDirective,
|
|
718
|
-
FileSizePipe
|
|
719
|
-
],
|
|
720
|
-
exports: [
|
|
721
|
-
BinaryFileUploadComponent,
|
|
722
|
-
CSVFileUploadComponent,
|
|
723
|
-
TextFileUploadComponent,
|
|
724
|
-
CSVFileDownloadDirective,
|
|
725
|
-
CSVDownloadMenuComponent,
|
|
726
|
-
FileDownloadDirective,
|
|
727
|
-
FileSizePipe
|
|
728
|
-
],
|
|
729
|
-
providers: [
|
|
730
|
-
BinaryFileUploadService,
|
|
731
|
-
CSVFileUploadService,
|
|
732
|
-
TextFileUploadService,
|
|
733
|
-
FileSizePipe
|
|
734
|
-
]
|
|
735
|
-
}]
|
|
736
|
-
}] });
|
|
737
|
-
|
|
738
|
-
/**
|
|
739
|
-
* Generated bundle index. Do not edit.
|
|
740
|
-
*/
|
|
741
|
-
|
|
742
|
-
export { AbstractFileDownloadDirective, AbstractFileUploadComponent, BinaryFileUploadComponent, BinaryFileUploadService, CSVDownloadMenuComponent, CSVFileDownloadDirective, CSVFileUploadComponent, CSVFileUploadService, FileDownloadDirective, FileModule, FileSizePipe, TextFileUploadComponent, TextFileUploadService };
|
|
743
|
-
//# sourceMappingURL=dbg-riskit-angular-file.mjs.map
|