feature/addQualifications #23
2 changed files with 28 additions and 11 deletions
|
@ -2,9 +2,9 @@
|
||||||
<div class="qualifications__action-row">
|
<div class="qualifications__action-row">
|
||||||
<mat-form-field>
|
<mat-form-field>
|
||||||
<mat-label>Qualification</mat-label>
|
<mat-label>Qualification</mat-label>
|
||||||
<input matInput>
|
<input matInput #qualificationInput minlength="1" maxlength="25">
|
||||||
</mat-form-field>
|
</mat-form-field>
|
||||||
<button mat-fab class="shadowless">
|
<button mat-fab class="shadowless" (click)="onAdd(qualificationInput)">
|
||||||
<mat-icon>add</mat-icon>
|
<mat-icon>add</mat-icon>
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -79,6 +79,16 @@ export class QualificationsComponent {
|
||||||
this.qualificationEdits.set(id, true);
|
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<Qualification>(data);
|
||||||
|
this.notifications.publish(`Added ${qualification.skill}`);
|
||||||
|
qualificationField.value='';
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
endEdit(oldQualification: Qualification, save: boolean) {
|
endEdit(oldQualification: Qualification, save: boolean) {
|
||||||
|
|
||||||
const qualificationFormGroup = this.qualificationSkillFormGroups.get(oldQualification.id);
|
const qualificationFormGroup = this.qualificationSkillFormGroups.get(oldQualification.id);
|
||||||
|
@ -128,6 +138,10 @@ export class QualificationsComponent {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this.qualificationService.getAllQualificationEmployees({id: qualification.id}).subscribe((employees: QualificationEmployees) => {
|
this.qualificationService.getAllQualificationEmployees({id: qualification.id}).subscribe((employees: QualificationEmployees) => {
|
||||||
|
if (employees.employees.length==0){
|
||||||
|
this.execDelete(qualification);
|
||||||
|
return;
|
||||||
|
}
|
||||||
const requests: Array<Observable<RemoveQualificationFromEmployeeResponse>> = [];
|
const requests: Array<Observable<RemoveQualificationFromEmployeeResponse>> = [];
|
||||||
for (const employee of employees.employees) {
|
for (const employee of employees.employees) {
|
||||||
requests.push(this.employeeService.removeQualificationFromEmployee({
|
requests.push(this.employeeService.removeQualificationFromEmployee({
|
||||||
|
@ -142,6 +156,12 @@ export class QualificationsComponent {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
this.execDelete(qualification);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
execDelete(qualification: Qualification){
|
||||||
this.qualificationService.deleteQualification({id: qualification.id}).subscribe(() => {
|
this.qualificationService.deleteQualification({id: qualification.id}).subscribe(() => {
|
||||||
const data = this.qualificationDataSource.data;
|
const data = this.qualificationDataSource.data;
|
||||||
const i = data.indexOf(qualification);
|
const i = data.indexOf(qualification);
|
||||||
|
@ -151,8 +171,5 @@ export class QualificationsComponent {
|
||||||
}
|
}
|
||||||
this.notifications.publish(`Deleted ${qualification.skill}`, NotificationType.Information);
|
this.notifications.publish(`Deleted ${qualification.skill}`, NotificationType.Information);
|
||||||
});
|
});
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue