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-form-field class="!w-1/2">
|
||||||
<mat-label>Postcode</mat-label>
|
<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>
|
</mat-form-field>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<mat-form-field class="!w-full">
|
<mat-form-field class="!w-full">
|
||||||
<mat-label>Phone</mat-label>
|
<mat-label>Phone</mat-label>
|
||||||
<input matInput formControlName="phone" required>
|
<input matInput formControlName="phone" required type="number">
|
||||||
</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>
|
|
||||||
</mat-form-field>
|
</mat-form-field>
|
||||||
|
|
||||||
<mat-dialog-actions align="end">
|
<mat-dialog-actions align="end">
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import {Component, inject, OnInit} from '@angular/core';
|
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 {MatFormField, MatLabel} from "@angular/material/form-field";
|
||||||
import {MatInput} from "@angular/material/input";
|
import {MatInput} from "@angular/material/input";
|
||||||
import {MatButton} from "@angular/material/button";
|
import {MatButton} from "@angular/material/button";
|
||||||
@ -12,11 +12,7 @@ import {
|
|||||||
} from "@angular/material/dialog";
|
} from "@angular/material/dialog";
|
||||||
import {Employee} from "../Employee";
|
import {Employee} from "../Employee";
|
||||||
import EmployeeApiService from "../../services/employee-api.service";
|
import EmployeeApiService from "../../services/employee-api.service";
|
||||||
import {Observable} from "rxjs";
|
import {NgIf} from "@angular/common";
|
||||||
import {MatOption, MatSelect} from "@angular/material/select";
|
|
||||||
import {AsyncPipe, NgForOf, NgIf} from "@angular/common";
|
|
||||||
import {Qualification} from "../../Qualification";
|
|
||||||
import QualificationService from "../../services/qualification.service";
|
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-create-employee',
|
selector: 'app-create-employee',
|
||||||
@ -30,11 +26,7 @@ import QualificationService from "../../services/qualification.service";
|
|||||||
MatDialogTitle,
|
MatDialogTitle,
|
||||||
MatDialogActions,
|
MatDialogActions,
|
||||||
MatDialogClose,
|
MatDialogClose,
|
||||||
MatSelect,
|
|
||||||
MatOption,
|
|
||||||
NgForOf,
|
|
||||||
NgIf,
|
NgIf,
|
||||||
AsyncPipe,
|
|
||||||
],
|
],
|
||||||
templateUrl: './create.component.html',
|
templateUrl: './create.component.html',
|
||||||
standalone: true,
|
standalone: true,
|
||||||
@ -45,9 +37,6 @@ export class CreateComponent implements OnInit {
|
|||||||
employeeService: EmployeeApiService = inject(EmployeeApiService);
|
employeeService: EmployeeApiService = inject(EmployeeApiService);
|
||||||
formBuilder: FormBuilder = inject(FormBuilder);
|
formBuilder: FormBuilder = inject(FormBuilder);
|
||||||
dialogRef: MatDialogRef<CreateComponent> = inject(MatDialogRef);
|
dialogRef: MatDialogRef<CreateComponent> = inject(MatDialogRef);
|
||||||
qualificationService: QualificationService = inject(QualificationService);
|
|
||||||
skills!: Observable<Qualification[]>
|
|
||||||
formSkills: FormArray = this.formBuilder.array([]);
|
|
||||||
|
|
||||||
ngOnInit(): void {
|
ngOnInit(): void {
|
||||||
this.employeeForm = this.formBuilder.group({
|
this.employeeForm = this.formBuilder.group({
|
||||||
@ -57,31 +46,16 @@ export class CreateComponent implements OnInit {
|
|||||||
postcode: ['', [Validators.required, Validators.minLength(5), Validators.maxLength(5)]],
|
postcode: ['', [Validators.required, Validators.minLength(5), Validators.maxLength(5)]],
|
||||||
city: ['', Validators.required],
|
city: ['', Validators.required],
|
||||||
phone: ['', 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() {
|
submit() {
|
||||||
console.log(this.employeeForm?.controls['skillSet'].value)
|
|
||||||
if (this.employeeForm === null || !this.employeeForm.valid) {
|
if (this.employeeForm === null || !this.employeeForm.valid) {
|
||||||
console.error('Form invalid');
|
console.error('Form invalid');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const newEmployee = this.employeeForm.value as Employee;
|
|
||||||
//newEmployee.skillSet = newEmployee.skillSet?.map((selected: boolean, index: number) => {return })
|
|
||||||
|
|
||||||
return;
|
this.employeeService.create(this.employeeForm.value as Employee).subscribe();
|
||||||
|
|
||||||
this.employeeService.create(newEmployee).subscribe();
|
|
||||||
this.dialogRef.close();
|
this.dialogRef.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user