|
|
|
@ -32,10 +32,12 @@ import { Store } from '@ngrx/store'; |
|
|
|
import { AppState } from '@core/core.state'; |
|
|
|
import { ControlValueAccessor, NG_VALUE_ACCESSOR } from '@angular/forms'; |
|
|
|
import { Subscription } from 'rxjs'; |
|
|
|
import { coerceBooleanProperty } from '@angular/cdk/coercion'; |
|
|
|
import { FlowDirective } from '@flowjs/ngx-flow'; |
|
|
|
import { TranslateService } from '@ngx-translate/core'; |
|
|
|
import { UtilsService } from '@core/services/utils.service'; |
|
|
|
import { DialogService } from '@core/services/dialog.service'; |
|
|
|
import { FileSizePipe } from '@shared/pipe/file-size.pipe'; |
|
|
|
import { coerceBoolean } from '@shared/decorators/coercion'; |
|
|
|
|
|
|
|
@Component({ |
|
|
|
selector: 'tb-file-input', |
|
|
|
@ -73,43 +75,28 @@ export class FileInputComponent extends PageComponent implements AfterViewInit, |
|
|
|
dropLabel: string; |
|
|
|
|
|
|
|
@Input() |
|
|
|
contentConvertFunction: (content: string) => any; |
|
|
|
|
|
|
|
private requiredValue: boolean; |
|
|
|
|
|
|
|
get required(): boolean { |
|
|
|
return this.requiredValue; |
|
|
|
} |
|
|
|
maxSizeByte: number; |
|
|
|
|
|
|
|
@Input() |
|
|
|
set required(value: boolean) { |
|
|
|
const newVal = coerceBooleanProperty(value); |
|
|
|
if (this.requiredValue !== newVal) { |
|
|
|
this.requiredValue = newVal; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
private requiredAsErrorValue: boolean; |
|
|
|
contentConvertFunction: (content: string) => any; |
|
|
|
|
|
|
|
get requiredAsError(): boolean { |
|
|
|
return this.requiredAsErrorValue; |
|
|
|
} |
|
|
|
@Input() |
|
|
|
@coerceBoolean() |
|
|
|
required: boolean; |
|
|
|
|
|
|
|
@Input() |
|
|
|
set requiredAsError(value: boolean) { |
|
|
|
const newVal = coerceBooleanProperty(value); |
|
|
|
if (this.requiredAsErrorValue !== newVal) { |
|
|
|
this.requiredAsErrorValue = newVal; |
|
|
|
} |
|
|
|
} |
|
|
|
@coerceBoolean() |
|
|
|
requiredAsError: boolean; |
|
|
|
|
|
|
|
@Input() |
|
|
|
@coerceBoolean() |
|
|
|
disabled: boolean; |
|
|
|
|
|
|
|
@Input() |
|
|
|
existingFileName: string; |
|
|
|
|
|
|
|
@Input() |
|
|
|
@coerceBoolean() |
|
|
|
readAsBinary = false; |
|
|
|
|
|
|
|
@Input() |
|
|
|
@ -148,7 +135,9 @@ export class FileInputComponent extends PageComponent implements AfterViewInit, |
|
|
|
|
|
|
|
constructor(protected store: Store<AppState>, |
|
|
|
private utils: UtilsService, |
|
|
|
public translate: TranslateService) { |
|
|
|
private translate: TranslateService, |
|
|
|
private dialog: DialogService, |
|
|
|
private fileSize: FileSizePipe) { |
|
|
|
super(store); |
|
|
|
} |
|
|
|
|
|
|
|
@ -156,11 +145,22 @@ export class FileInputComponent extends PageComponent implements AfterViewInit, |
|
|
|
this.autoUploadSubscription = this.flow.events$.subscribe(event => { |
|
|
|
if (event.type === 'filesAdded') { |
|
|
|
const readers = []; |
|
|
|
let showMaxSizeAlert = false; |
|
|
|
(event.event[0] as flowjs.FlowFile[]).forEach(file => { |
|
|
|
if (this.filterFile(file)) { |
|
|
|
if (!this.checkMaxSize(file)) { |
|
|
|
showMaxSizeAlert = true; |
|
|
|
} else if (this.filterFile(file)) { |
|
|
|
readers.push(this.readerAsFile(file)); |
|
|
|
} |
|
|
|
}); |
|
|
|
|
|
|
|
if (showMaxSizeAlert) { |
|
|
|
this.dialog.alert( |
|
|
|
this.translate.instant('dashboard.cannot-upload-file'), |
|
|
|
this.translate.instant('dashboard.maximum-upload-file-size', {size: this.fileSize.transform(this.maxSizeByte)}) |
|
|
|
).subscribe(() => { }); |
|
|
|
} |
|
|
|
|
|
|
|
if (readers.length) { |
|
|
|
Promise.all(readers).then((files) => { |
|
|
|
files = files.filter(file => file.fileContent != null || file.files != null); |
|
|
|
@ -218,6 +218,10 @@ export class FileInputComponent extends PageComponent implements AfterViewInit, |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
private checkMaxSize(file: flowjs.FlowFile): boolean { |
|
|
|
return !(this.maxSizeByte && this.maxSizeByte < file.size); |
|
|
|
} |
|
|
|
|
|
|
|
private filterFile(file: flowjs.FlowFile): boolean { |
|
|
|
if (this.allowedExtensions) { |
|
|
|
return this.allowedExtensions.split(',').indexOf(file.getExtension()) > -1; |
|
|
|
|