2026-04-16 22:19:46 +03:30
|
|
|
import { Maybe } from '@/core';
|
|
|
|
|
import { Component, EventEmitter, Input, Output } from '@angular/core';
|
|
|
|
|
import { FileSelectEvent, FileUpload } from 'primeng/fileupload';
|
2026-04-18 12:14:39 +03:30
|
|
|
import { onSelectFileArgs } from './model';
|
2026-04-16 22:19:46 +03:30
|
|
|
|
|
|
|
|
@Component({
|
|
|
|
|
selector: 'app-shared-upload-file',
|
|
|
|
|
templateUrl: './upload-file.component.html',
|
|
|
|
|
imports: [FileUpload],
|
|
|
|
|
})
|
|
|
|
|
export class SharedUploadFileComponent {
|
|
|
|
|
@Input() currentImage: Maybe<string> = null;
|
|
|
|
|
@Input() loading: boolean = false;
|
|
|
|
|
@Input() name: string = 'file';
|
|
|
|
|
@Input() accept: string = 'image/*';
|
2026-04-18 12:14:39 +03:30
|
|
|
@Input() maxSize: Maybe<number> = 5 * 1024 * 1024;
|
2026-04-16 22:19:46 +03:30
|
|
|
@Input() error: Maybe<string> = null;
|
|
|
|
|
@Input() hint: Maybe<string> = null;
|
|
|
|
|
|
2026-04-18 12:14:39 +03:30
|
|
|
@Output() onSelect = new EventEmitter<onSelectFileArgs>();
|
2026-04-16 22:19:46 +03:30
|
|
|
|
|
|
|
|
onSelectedFile($event: FileSelectEvent) {
|
|
|
|
|
const file = $event.files?.[0];
|
|
|
|
|
if (!file) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
const payload = new FormData();
|
|
|
|
|
payload.append(this.name, file, file.name);
|
|
|
|
|
this.onSelect.emit({ data: payload, file });
|
|
|
|
|
}
|
|
|
|
|
}
|