feat: add schedule files upload
This commit is contained in:
@ -0,0 +1,57 @@
|
||||
import {Component, ElementRef, Input, ViewChild} from '@angular/core';
|
||||
import {ConfigurationCardComponent} from "@component/admin/configuration-card/configuration-card.component";
|
||||
import {MatDialog} from "@angular/material/dialog";
|
||||
import {
|
||||
ConfirmDeleteScheduleDialogComponent
|
||||
} from "@component/admin/confirm-delete-schedule-dialog/confirm-delete-schedule-dialog.component";
|
||||
import {Observable, of, switchMap} from "rxjs";
|
||||
import {MatButtonModule} from "@angular/material/button";
|
||||
import {MatIcon} from "@angular/material/icon";
|
||||
import {ScheduleService} from "@api/v1/configuration/schedule.service";
|
||||
import {DataSpinnerComponent} from "@component/common/data-spinner/data-spinner.component";
|
||||
|
||||
@Component({
|
||||
selector: 'app-schedule-file-upload',
|
||||
imports: [
|
||||
ConfigurationCardComponent,
|
||||
MatButtonModule,
|
||||
MatIcon,
|
||||
DataSpinnerComponent
|
||||
],
|
||||
templateUrl: './schedule-file-upload.component.html',
|
||||
providers: [ScheduleService]
|
||||
})
|
||||
export class ScheduleFileUploadComponent {
|
||||
selectedFiles: File[] = [];
|
||||
fileLoading: boolean = false;
|
||||
@ViewChild('fileInput') input!: ElementRef;
|
||||
|
||||
constructor(private dialog: MatDialog, private api: ScheduleService) {
|
||||
}
|
||||
|
||||
protected saveFunction() {
|
||||
return () => {
|
||||
const dialogRef = this.dialog.open(ConfirmDeleteScheduleDialogComponent);
|
||||
|
||||
return dialogRef.afterClosed().pipe(switchMap(result => {
|
||||
return this.api.uploadScheduleFile(this.selectedFiles, result);
|
||||
}));
|
||||
};
|
||||
}
|
||||
|
||||
onFileChooseClick() {
|
||||
this.fileLoading = true;
|
||||
this.input.nativeElement.click();
|
||||
}
|
||||
|
||||
onFileSelected(event: any): void {
|
||||
this.fileLoading = false;
|
||||
this.selectedFiles = Array.from(event.target.files);
|
||||
}
|
||||
|
||||
onUpload(data: Observable<any>): void {
|
||||
data.subscribe(_ => {
|
||||
this.selectedFiles = [];
|
||||
});
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user