fuck this shit im deleting it fuck you fucking dumbass
This commit is contained in:
parent
8474cf73e4
commit
1a932601a2
@ -27,20 +27,13 @@
|
||||
|
||||
<mat-form-field class="!w-1/2">
|
||||
<mat-label>Postcode</mat-label>
|
||||
<input matInput formControlName="postcode" minlength="5" maxlength="5" required>
|
||||
<input matInput formControlName="postcode" minlength="5" maxlength="5" type="number" required>
|
||||
</mat-form-field>
|
||||
</div>
|
||||
|
||||
<mat-form-field class="!w-full">
|
||||
<mat-label>Phone</mat-label>
|
||||
<input matInput formControlName="phone" required>
|
||||
</mat-form-field>
|
||||
|
||||
<mat-form-field class="!w-full">
|
||||
<mat-label>Skills</mat-label>
|
||||
<mat-select formArrayName="skillSet" multiple>
|
||||
<mat-option *ngFor="let skill of skills | async; let i = index" [value]="skill.id" [formGroupName]="i">{{ skill.skill }}</mat-option>
|
||||
</mat-select>
|
||||
<input matInput formControlName="phone" required type="number">
|
||||
</mat-form-field>
|
||||
|
||||
<mat-dialog-actions align="end">
|
||||
|
@ -1,5 +1,5 @@
|
||||
import {Component, inject, OnInit} from '@angular/core';
|
||||
import {FormArray, FormBuilder, FormGroup, ReactiveFormsModule, Validators} from "@angular/forms";
|
||||
import {FormBuilder, FormGroup, ReactiveFormsModule, Validators} from "@angular/forms";
|
||||
import {MatFormField, MatLabel} from "@angular/material/form-field";
|
||||
import {MatInput} from "@angular/material/input";
|
||||
import {MatButton} from "@angular/material/button";
|
||||
@ -12,11 +12,7 @@ import {
|
||||
} from "@angular/material/dialog";
|
||||
import {Employee} from "../Employee";
|
||||
import EmployeeApiService from "../../services/employee-api.service";
|
||||
import {Observable} from "rxjs";
|
||||
import {MatOption, MatSelect} from "@angular/material/select";
|
||||
import {AsyncPipe, NgForOf, NgIf} from "@angular/common";
|
||||
import {Qualification} from "../../Qualification";
|
||||
import QualificationService from "../../services/qualification.service";
|
||||
import {NgIf} from "@angular/common";
|
||||
|
||||
@Component({
|
||||
selector: 'app-create-employee',
|
||||
@ -30,11 +26,7 @@ import QualificationService from "../../services/qualification.service";
|
||||
MatDialogTitle,
|
||||
MatDialogActions,
|
||||
MatDialogClose,
|
||||
MatSelect,
|
||||
MatOption,
|
||||
NgForOf,
|
||||
NgIf,
|
||||
AsyncPipe,
|
||||
],
|
||||
templateUrl: './create.component.html',
|
||||
standalone: true,
|
||||
@ -45,9 +37,6 @@ export class CreateComponent implements OnInit {
|
||||
employeeService: EmployeeApiService = inject(EmployeeApiService);
|
||||
formBuilder: FormBuilder = inject(FormBuilder);
|
||||
dialogRef: MatDialogRef<CreateComponent> = inject(MatDialogRef);
|
||||
qualificationService: QualificationService = inject(QualificationService);
|
||||
skills!: Observable<Qualification[]>
|
||||
formSkills: FormArray = this.formBuilder.array([]);
|
||||
|
||||
ngOnInit(): void {
|
||||
this.employeeForm = this.formBuilder.group({
|
||||
@ -57,31 +46,16 @@ export class CreateComponent implements OnInit {
|
||||
postcode: ['', [Validators.required, Validators.minLength(5), Validators.maxLength(5)]],
|
||||
city: ['', Validators.required],
|
||||
phone: ['', Validators.required],
|
||||
skillSet: this.formSkills
|
||||
});
|
||||
|
||||
this.skills = this.qualificationService.getAll();
|
||||
|
||||
this.skills.subscribe((qualifications: Qualification[]) => {
|
||||
qualifications.forEach((qualification: Qualification) => {
|
||||
|
||||
this.formSkills.push(this.formBuilder.group(qualification));
|
||||
});
|
||||
})
|
||||
}
|
||||
|
||||
submit() {
|
||||
console.log(this.employeeForm?.controls['skillSet'].value)
|
||||
if (this.employeeForm === null || !this.employeeForm.valid) {
|
||||
console.error('Form invalid');
|
||||
return;
|
||||
}
|
||||
const newEmployee = this.employeeForm.value as Employee;
|
||||
//newEmployee.skillSet = newEmployee.skillSet?.map((selected: boolean, index: number) => {return })
|
||||
|
||||
return;
|
||||
|
||||
this.employeeService.create(newEmployee).subscribe();
|
||||
this.employeeService.create(this.employeeForm.value as Employee).subscribe();
|
||||
this.dialogRef.close();
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user