feat(qualifikation-form): implement submit functionality and navigation
This commit is contained in:
parent
8d778ae773
commit
6119621040
4 changed files with 32 additions and 9 deletions
|
@ -32,11 +32,7 @@
|
|||
<button (click)="addEmployee()" class="add-employee-button">Add employee</button>
|
||||
</div>
|
||||
}
|
||||
|
||||
|
||||
|
||||
</div>
|
||||
|
||||
<button class="save-button">Save</button>
|
||||
<button (click)="submit()" class="save-button">Save</button>
|
||||
</form>
|
||||
</div>
|
||||
|
|
|
@ -6,6 +6,7 @@ import { EmployeeService } from '../../service/employee.service';
|
|||
import { concatMap, every, from, lastValueFrom, Observable, of, switchMap, take, tap } from 'rxjs';
|
||||
import { EmployeeNameDataDTO, EmployeeResponseDTO } from '../../models/mitarbeiter';
|
||||
import { AsyncPipe } from '@angular/common';
|
||||
import { Router } from '@angular/router';
|
||||
|
||||
@Component({
|
||||
selector: 'app-qualifikation-form',
|
||||
|
@ -22,7 +23,7 @@ export class QualifikationFormComponent {
|
|||
public addableEmployees: Array<EmployeeResponseDTO> = [];
|
||||
public addedEmployees: Array<EmployeeNameDataDTO> = [];
|
||||
|
||||
constructor(private skillService: SkillService, private employeeService: EmployeeService) { }
|
||||
constructor(private skillService: SkillService, private employeeService: EmployeeService, private router: Router) { }
|
||||
|
||||
setUpForm() {
|
||||
this.skillForm = new FormGroup({
|
||||
|
@ -33,7 +34,6 @@ export class QualifikationFormComponent {
|
|||
|
||||
|
||||
addEmployee() {
|
||||
console.log("called");
|
||||
const employeeId = Number(this.skillForm.get("newEmployee")?.value);
|
||||
const employee = this.addableEmployees.find(emp => emp.id === employeeId);
|
||||
|
||||
|
@ -72,6 +72,23 @@ export class QualifikationFormComponent {
|
|||
}
|
||||
}
|
||||
|
||||
submit() {
|
||||
for (const employee of this.addedEmployees) {
|
||||
this.employeeService.getEmployeeById(employee.id).subscribe(employeeResponse => {
|
||||
this.employeeService.addSkillToEmployee(this.skill.id, employeeResponse);
|
||||
});
|
||||
}
|
||||
|
||||
for (const employee of this.addableEmployees) {
|
||||
this.employeeService.removeSkillFromEmployee(this.skill.id, employee);
|
||||
}
|
||||
|
||||
this.skill.skill = this.skillForm.get("name")?.value;
|
||||
this.skillChange.emit(this.skill);
|
||||
|
||||
this.router.navigate(["/qualifikationen"]);
|
||||
}
|
||||
|
||||
ngOnChanges(): void {
|
||||
this.setUpForm();
|
||||
this.updateEmployeeLists();
|
||||
|
|
|
@ -18,7 +18,7 @@ export class QualifikatonBearbeitenViewComponent {
|
|||
constructor(private skillService: SkillService, private route: ActivatedRoute) {}
|
||||
|
||||
submitted(skill: QualificationGetDTO) {
|
||||
|
||||
console.log(skill);
|
||||
}
|
||||
|
||||
ngOnInit(): void {
|
||||
|
|
|
@ -54,10 +54,20 @@ export class EmployeeService {
|
|||
return this.http.get<EmployeeResponseDTO>(`${SkillService.BASE_URL}/employees/${id}`);
|
||||
}
|
||||
|
||||
removeSkillFromEmployee(skillId: number, employee: EmployeeResponseDTO) {
|
||||
let employeePut = this.responseDtoToPutDto(employee);
|
||||
if (employeePut.skillSet.indexOf(skillId) != 1) {
|
||||
employeePut.skillSet = employeePut.skillSet.filter(skill => skill != skillId);
|
||||
}
|
||||
|
||||
this.http.put(`${SkillService.BASE_URL}/employees/${employee.id}`, employeePut).subscribe();
|
||||
}
|
||||
|
||||
addSkillToEmployee(skillId: number, employee: EmployeeResponseDTO) {
|
||||
let employeePut = this.responseDtoToPutDto(employee);
|
||||
employeePut.skillSet.push(skillId);
|
||||
if (employeePut.skillSet.indexOf(skillId) == -1) {
|
||||
employeePut.skillSet.push(skillId);
|
||||
}
|
||||
|
||||
this.http.put(`${SkillService.BASE_URL}/employees/${employee.id}`, employeePut).subscribe();
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue