From 417acde6ac71ce9de784f855d7e490eb128ea1e1 Mon Sep 17 00:00:00 2001 From: Huy Date: Wed, 15 Jan 2025 08:31:12 +0000 Subject: [PATCH] Fix employee details opened from qualification details not showing any skills (#34) Co-authored-by: Phan Huy Tran Reviewed-on: http://git.simonis.lol/angular/ems-frontend/pulls/34 Reviewed-by: Constantin Simonis --- .../details/details.component.html | 22 ++++++++++--------- .../details/details.component.ts | 18 ++++++++++----- src/app/services/employee-api.service.ts | 4 ++++ 3 files changed, 29 insertions(+), 15 deletions(-) diff --git a/src/app/qualification/details/details.component.html b/src/app/qualification/details/details.component.html index 33cbe2b..3197fa6 100644 --- a/src/app/qualification/details/details.component.html +++ b/src/app/qualification/details/details.component.html @@ -1,20 +1,22 @@

- Employees with {{ qualification.skill }} + {{ qualification.skill }} Developers

- + @if (employees$ | async; as employees) { @if (employees.length === 0) {

No employees found with this qualification.

} @else { - @for (employee of employees; track employee.id) { - - {{ employee.firstName }} {{ employee.lastName }} - - } +
+ @for (employee of employees; track employee.id) { + + {{ employee.firstName }} {{ employee.lastName }} + + } +
} }
diff --git a/src/app/qualification/details/details.component.ts b/src/app/qualification/details/details.component.ts index 593eeb1..9a2246d 100644 --- a/src/app/qualification/details/details.component.ts +++ b/src/app/qualification/details/details.component.ts @@ -1,6 +1,7 @@ import {Component, inject} from '@angular/core'; import { - MAT_DIALOG_DATA, MatDialog, + MAT_DIALOG_DATA, + MatDialog, MatDialogActions, MatDialogContent, MatDialogRef, @@ -10,8 +11,8 @@ import QualificationService from "../../services/qualification.service"; import {Qualification} from "../Qualification"; import {AsyncPipe} from "@angular/common"; import {MatButton} from "@angular/material/button"; -import {Employee} from "../../employee/Employee"; import {DetailsComponent as EmployeeDetailsComponent} from "../../employee/details/details.component"; +import EmployeeApiService from "../../services/employee-api.service"; @Component({ selector: 'app-details', @@ -27,6 +28,7 @@ import {DetailsComponent as EmployeeDetailsComponent} from "../../employee/detai }) export class DetailsComponent { private qualificationService = inject(QualificationService); + private employeeService = inject(EmployeeApiService); private dialogRef: MatDialogRef = inject(MatDialogRef); private dialog: MatDialog = inject(MatDialog); @@ -37,9 +39,15 @@ export class DetailsComponent { this.dialogRef.close(); } - openEmployeeDetailsModal(employee: Employee) { - this.dialog.open(EmployeeDetailsComponent, { - data: employee + openEmployeeDetailsModal(id: number | undefined) { + if (!id) { + throw new Error("ID must not be undefined"); + } + + this.employeeService.getById(id).subscribe(employee => { + this.dialog.open(EmployeeDetailsComponent, { + data: employee + }); }); } } diff --git a/src/app/services/employee-api.service.ts b/src/app/services/employee-api.service.ts index 16aded1..b8e6d8b 100644 --- a/src/app/services/employee-api.service.ts +++ b/src/app/services/employee-api.service.ts @@ -12,6 +12,10 @@ export default class EmployeeApiService { private static readonly BASE_URL = 'http://localhost:8089'; + public getById(id: number): Observable { + return this.http.get(`${EmployeeApiService.BASE_URL}/employees/${id}`) + } + public deleteById(id: number): Observable { return this.http.delete(`${EmployeeApiService.BASE_URL}/employees/${id}`) }