feat(qualifikationsverwaltung): add error handling for delete skill #76
2 changed files with 29 additions and 11 deletions
|
@ -12,7 +12,8 @@
|
|||
<h1>Qualifications</h1>
|
||||
</div>
|
||||
|
||||
<div class="header-actions">
|
||||
<div class="d-flex flex-column">
|
||||
<div class="row header-actions">
|
||||
<form [formGroup]="searchForm">
|
||||
<div class="search-bar">
|
||||
<input type="text" placeholder="Search employee" formControlName="search">
|
||||
|
@ -20,7 +21,16 @@
|
|||
</div>
|
||||
<p class="text-body-tertiary">Search for a propertiy of a Qualification. eg. Name</p>
|
||||
</form>
|
||||
<button (click)="createSkill()" class="add-button">Add qualification</button>
|
||||
<div class="d-flex">
|
||||
<button (click)="createSkill()" class="add-button me-auto">Add qualification</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@if (errorDeletingSkill) {
|
||||
<div class="row">
|
||||
<p class="alert alert-danger">This Qualification can not be deleted because it still has employees.</p>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
|
||||
<table class="employee-table">
|
||||
|
|
|
@ -14,8 +14,9 @@ import { Router } from '@angular/router';
|
|||
export class QualifikationsverwaltungComponent {
|
||||
skills: Array<QualificationGetDTO> = [];
|
||||
public searchForm!: FormGroup;
|
||||
public errorDeletingSkill = false;
|
||||
|
||||
constructor(private skillService: SkillService, private router: Router) {}
|
||||
constructor(private skillService: SkillService, private router: Router) { }
|
||||
|
||||
submit() {
|
||||
const searchTerm = this.searchForm.get("search")?.value || '';
|
||||
|
@ -44,8 +45,15 @@ export class QualifikationsverwaltungComponent {
|
|||
}
|
||||
|
||||
deleteSkill(id: number) {
|
||||
this.skillService.getEmployeesBySkill(id).subscribe(employees => {
|
||||
this.errorDeletingSkill = false;
|
||||
if (employees.employees.length == 0) {
|
||||
this.skillService.deleteSkill(id);
|
||||
this.skills = this.skills.filter(skill => skill.id != id);
|
||||
} else {
|
||||
this.errorDeletingSkill = true;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
ngOnInit(): void {
|
||||
|
|
Loading…
Add table
Reference in a new issue