@dbg-riskit/angular-file 12.3.0 → 13.0.3

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