From 3d77c179ba42cb0f5cfb2e9844ebb2dd968ad861 Mon Sep 17 00:00:00 2001 From: apuente Date: Thu, 20 Jun 2024 21:37:42 +0200 Subject: [PATCH] Groups base structure new container --- .../src/app/components/groups/data.service.ts | 21 ++++++++++- .../components/groups/groups.component.css | 35 ++++++++++--------- .../components/groups/groups.component.html | 18 +++++++++- .../app/components/groups/groups.component.ts | 31 ++++++++++++++++ 4 files changed, 86 insertions(+), 19 deletions(-) diff --git a/ogWebconsole/src/app/components/groups/data.service.ts b/ogWebconsole/src/app/components/groups/data.service.ts index b2f9ee8..795ebec 100644 --- a/ogWebconsole/src/app/components/groups/data.service.ts +++ b/ogWebconsole/src/app/components/groups/data.service.ts @@ -10,6 +10,7 @@ import { UnidadOrganizativa } from './model'; export class DataService { private apiUrl = 'http://127.0.0.1:8080/organizational-units?page=1&itemsPerPage=30'; + private clientsUrl = 'http://127.0.0.1:8080/clients?page=1&itemsPerPage=30'; constructor(private http: HttpClient) {} @@ -38,7 +39,8 @@ export class DataService { } getChildren(uuid: string): Observable { - return this.http.get(this.apiUrl).pipe( + console.log('uuid', uuid); + return this.http.get(`${this.apiUrl}&parent=${uuid}`).pipe( map(response => { if (response['hydra:member'] && Array.isArray(response['hydra:member'])) { return response['hydra:member'].filter((element: any) => element.parent === `/organizational-units/${uuid}`); @@ -52,4 +54,21 @@ export class DataService { }) ); } + + getClients(unidadId: string): Observable { + console.log('unidadId', unidadId); + return this.http.get(this.clientsUrl).pipe( + map(response => { + if (response['hydra:member'] && Array.isArray(response['hydra:member'])) { + return response['hydra:member'].filter((client: any) => client.organizationalUnit === `/organizational-units/${unidadId}`); + } else { + throw new Error('Unexpected response format'); + } + }), + catchError(error => { + console.error('Error fetching clients', error); + return throwError(error); + }) + ); + } } diff --git a/ogWebconsole/src/app/components/groups/groups.component.css b/ogWebconsole/src/app/components/groups/groups.component.css index 8dcc781..5b9e321 100644 --- a/ogWebconsole/src/app/components/groups/groups.component.css +++ b/ogWebconsole/src/app/components/groups/groups.component.css @@ -1,25 +1,26 @@ -.groupLists-container{ - display: flex; +.groupLists-container { + display: flex; + flex-wrap: wrap; } mat-card { - margin: 10px; + margin: 10px; } .groups-button-row { - display: flex; - flex-grow: 1; + display: flex; + flex-grow: 1; } -button { - margin-left: 10px; - - margin-bottom: 20px; -} - .clickable-item:hover { - cursor: pointer; - } - .selected-item { - background-color: #e0e0e0; - } - \ No newline at end of file +button { + margin-left: 10px; + margin-bottom: 20px; +} + +.clickable-item:hover { + cursor: pointer; +} + +.selected-item { + background-color: #e0e0e0; +} diff --git a/ogWebconsole/src/app/components/groups/groups.component.html b/ogWebconsole/src/app/components/groups/groups.component.html index d9eaaed..efeb674 100644 --- a/ogWebconsole/src/app/components/groups/groups.component.html +++ b/ogWebconsole/src/app/components/groups/groups.component.html @@ -12,7 +12,23 @@ - {{ unidad.nombre }} +
+ apartment + {{ unidad.nombre }} +
+
+ + + + + + {{ breadcrumb.join(' > ') }} + + + + {{ child.name || child.nombre }} diff --git a/ogWebconsole/src/app/components/groups/groups.component.ts b/ogWebconsole/src/app/components/groups/groups.component.ts index fae8627..6009b91 100644 --- a/ogWebconsole/src/app/components/groups/groups.component.ts +++ b/ogWebconsole/src/app/components/groups/groups.component.ts @@ -12,6 +12,8 @@ import { CreateOrganizationalUnitComponent } from './organizational-units/create export class GroupsComponent implements OnInit { unidadesOrganizativas: UnidadOrganizativa[] = []; selectedUnidad: UnidadOrganizativa | null = null; + children: any[] = []; + breadcrumb: string[] = []; constructor(private dataService: DataService, public dialog: MatDialog) {} @@ -24,6 +26,35 @@ export class GroupsComponent implements OnInit { onSelectUnidad(unidad: UnidadOrganizativa): void { this.selectedUnidad = unidad; + this.breadcrumb = [unidad.nombre]; + this.loadChildrenAndClients(unidad.uuid); + } + + onSelectChild(child: any): void { + if (child.uuid && child.id) { + this.breadcrumb.push(child.name || child.nombre); + this.loadChildrenAndClients(child.uuid); + } + } + + loadChildrenAndClients(uuid: string): void { + this.dataService.getChildren(uuid).subscribe( + childrenData => { + this.dataService.getClients(uuid).subscribe( + clientsData => { + const newChildren = [...childrenData, ...clientsData]; + if (newChildren.length > 0) { + this.children = newChildren; + } else { + // No se encontraron elementos hijos o clientes, revertimos el breadcrumb + this.breadcrumb.pop(); + } + }, + error => console.error('Error fetching clients', error) + ); + }, + error => console.error('Error fetching children', error) + ); } addOU(): void {