diff --git a/src/app/views/qualifications/qualifications.component.html b/src/app/views/qualifications/qualifications.component.html index ef816aa..396139a 100644 --- a/src/app/views/qualifications/qualifications.component.html +++ b/src/app/views/qualifications/qualifications.component.html @@ -2,9 +2,9 @@
Qualification - + -
diff --git a/src/app/views/qualifications/qualifications.component.ts b/src/app/views/qualifications/qualifications.component.ts index f4ab16b..b6d047b 100644 --- a/src/app/views/qualifications/qualifications.component.ts +++ b/src/app/views/qualifications/qualifications.component.ts @@ -79,6 +79,16 @@ export class QualificationsComponent { this.qualificationEdits.set(id, true); } + onAdd(qualificationField: HTMLInputElement){ + this.qualificationService.createQualification({requestBody: {skill: qualificationField.value}}).subscribe((qualification)=>{ + const data = this.qualificationDataSource.data; + data.push(qualification); + this.qualificationDataSource = new MatTableDataSource(data); + this.notifications.publish(`Added ${qualification.skill}`); + qualificationField.value=''; + }); + } + endEdit(oldQualification: Qualification, save: boolean) { const qualificationFormGroup = this.qualificationSkillFormGroups.get(oldQualification.id); @@ -128,6 +138,10 @@ export class QualificationsComponent { return; } this.qualificationService.getAllQualificationEmployees({id: qualification.id}).subscribe((employees: QualificationEmployees) => { + if (employees.employees.length==0){ + this.execDelete(qualification); + return; + } const requests: Array> = []; for (const employee of employees.employees) { requests.push(this.employeeService.removeQualificationFromEmployee({ @@ -142,17 +156,20 @@ export class QualificationsComponent { return; } } - this.qualificationService.deleteQualification({id: qualification.id}).subscribe(() => { - const data = this.qualificationDataSource.data; - const i = data.indexOf(qualification); - if (i != -1) { - data.splice(i, 1); - this.qualificationDataSource.data = data; - } - this.notifications.publish(`Deleted ${qualification.skill}`, NotificationType.Information); - }); + this.execDelete(qualification); }); }); }); } + execDelete(qualification: Qualification){ + this.qualificationService.deleteQualification({id: qualification.id}).subscribe(() => { + const data = this.qualificationDataSource.data; + const i = data.indexOf(qualification); + if (i != -1) { + data.splice(i, 1); + this.qualificationDataSource.data = data; + } + this.notifications.publish(`Deleted ${qualification.skill}`, NotificationType.Information); + }); + } }