mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2025-12-07 23:35:22 +01:00
58 lines
1.2 KiB
TypeScript
58 lines
1.2 KiB
TypeScript
import {
|
|
Component,
|
|
ElementRef,
|
|
EventEmitter,
|
|
Output,
|
|
ViewChild,
|
|
forwardRef,
|
|
} from '@angular/core'
|
|
import {
|
|
FormsModule,
|
|
NG_VALUE_ACCESSOR,
|
|
ReactiveFormsModule,
|
|
} from '@angular/forms'
|
|
import { AbstractInputComponent } from '../abstract-input'
|
|
|
|
@Component({
|
|
providers: [
|
|
{
|
|
provide: NG_VALUE_ACCESSOR,
|
|
useExisting: forwardRef(() => FileComponent),
|
|
multi: true,
|
|
},
|
|
],
|
|
selector: 'pngx-input-file',
|
|
templateUrl: './file.component.html',
|
|
styleUrl: './file.component.scss',
|
|
imports: [FormsModule, ReactiveFormsModule],
|
|
})
|
|
export class FileComponent extends AbstractInputComponent<string> {
|
|
@Output()
|
|
upload = new EventEmitter<File>()
|
|
|
|
public file: File
|
|
|
|
@ViewChild('fileInput') fileInput: ElementRef
|
|
|
|
get filename(): string {
|
|
return this.value
|
|
? this.value.substring(this.value.lastIndexOf('/') + 1)
|
|
: null
|
|
}
|
|
|
|
onFile(event: Event) {
|
|
this.file = (event.target as HTMLInputElement).files[0]
|
|
}
|
|
|
|
uploadClicked() {
|
|
this.upload.emit(this.file)
|
|
this.clear()
|
|
}
|
|
|
|
clear() {
|
|
this.file = undefined
|
|
this.fileInput.nativeElement.value = null
|
|
this.writeValue(null)
|
|
this.onChange(null)
|
|
}
|
|
}
|