|
|
|
@ -8,12 +8,15 @@ import {
|
|
|
|
|
MatDialogRef,
|
|
|
|
|
MatDialogTitle
|
|
|
|
|
} from "@angular/material/dialog";
|
|
|
|
|
import {NgIf} from "@angular/common";
|
|
|
|
|
import {NgForOf, NgIf} from "@angular/common";
|
|
|
|
|
import {MatFormField} from "@angular/material/form-field";
|
|
|
|
|
import {MatInput, MatLabel} from "@angular/material/input";
|
|
|
|
|
import {MatButton} from "@angular/material/button";
|
|
|
|
|
import {Employee} from "../Employee";
|
|
|
|
|
import EmployeeApiService from "../../services/employee-api.service";
|
|
|
|
|
import QualificationService from "../../services/qualification.service";
|
|
|
|
|
import {Qualification} from "../../qualification/Qualification";
|
|
|
|
|
import {MatOption, MatSelect} from "@angular/material/select";
|
|
|
|
|
|
|
|
|
|
@Component({
|
|
|
|
|
selector: 'app-edit',
|
|
|
|
@ -27,7 +30,10 @@ import EmployeeApiService from "../../services/employee-api.service";
|
|
|
|
|
MatDialogActions,
|
|
|
|
|
MatButton,
|
|
|
|
|
MatDialogClose,
|
|
|
|
|
MatLabel
|
|
|
|
|
MatLabel,
|
|
|
|
|
MatSelect,
|
|
|
|
|
MatOption,
|
|
|
|
|
NgForOf
|
|
|
|
|
],
|
|
|
|
|
templateUrl: './edit.component.html',
|
|
|
|
|
standalone: true,
|
|
|
|
@ -37,10 +43,13 @@ export class EditComponent implements OnInit {
|
|
|
|
|
employeeForm: FormGroup | null = null;
|
|
|
|
|
formBuilder: FormBuilder = inject(FormBuilder);
|
|
|
|
|
employeeService: EmployeeApiService = inject(EmployeeApiService);
|
|
|
|
|
qualificationService: QualificationService = inject(QualificationService);
|
|
|
|
|
dialogRef: MatDialogRef<EditComponent> = inject(MatDialogRef);
|
|
|
|
|
employee: Employee = inject(MAT_DIALOG_DATA);
|
|
|
|
|
qualifications: Qualification[] = [];
|
|
|
|
|
|
|
|
|
|
ngOnInit(): void {
|
|
|
|
|
this.loadQualifications();
|
|
|
|
|
this.employeeForm = this.formBuilder.group({
|
|
|
|
|
firstName: [this.employee.firstName, Validators.required],
|
|
|
|
|
lastName: [this.employee.lastName, Validators.required],
|
|
|
|
@ -48,9 +57,16 @@ export class EditComponent implements OnInit {
|
|
|
|
|
postcode: [this.employee.postcode, [Validators.required, Validators.minLength(5), Validators.maxLength(5)]],
|
|
|
|
|
city: [this.employee.city, Validators.required],
|
|
|
|
|
phone: [this.employee.phone, Validators.required],
|
|
|
|
|
qualifications: [this.employee.skillSet?.map(skill => skill.id) || []]
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
loadQualifications() {
|
|
|
|
|
this.qualificationService.getAll().subscribe(
|
|
|
|
|
qualifications => this.qualifications = qualifications
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
submit() {
|
|
|
|
|
if (this.employeeForm === null || !this.employeeForm.valid) {
|
|
|
|
|
console.error('Form invalid');
|
|
|
|
@ -62,7 +78,13 @@ export class EditComponent implements OnInit {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this.employeeService.update(this.employeeForm.value as Employee, this.employee.id).subscribe();
|
|
|
|
|
const formValue = this.employeeForm.value;
|
|
|
|
|
const employeeData = {
|
|
|
|
|
...formValue,
|
|
|
|
|
skillSet: formValue.qualifications
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
this.employeeService.update(employeeData as Employee, this.employee.id).subscribe();
|
|
|
|
|
this.dialogRef.close(true);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|