Groups new fetch for API updates

pull/4/head
Alvaro Puente Mella 2024-06-21 12:29:12 +02:00
parent b14605f248
commit 67177c4237
3 changed files with 16 additions and 14 deletions

View File

@ -39,11 +39,10 @@ export class DataService {
} }
getChildren(uuid: string): Observable<any[]> { getChildren(uuid: string): Observable<any[]> {
console.log('uuid', uuid);
return this.http.get<any>(`${this.apiUrl}&parent=${uuid}`).pipe( return this.http.get<any>(`${this.apiUrl}&parent=${uuid}`).pipe(
map(response => { map(response => {
if (response['hydra:member'] && Array.isArray(response['hydra:member'])) { if (response['hydra:member'] && Array.isArray(response['hydra:member'])) {
return response['hydra:member'].filter((element: any) => element.parent === `/organizational-units/${uuid}`); return response['hydra:member'].filter((element: any) => element.parent && element.parent['@id'] === `/organizational-units/${uuid}`);
} else { } else {
throw new Error('Unexpected response format'); throw new Error('Unexpected response format');
} }
@ -55,12 +54,12 @@ export class DataService {
); );
} }
getClients(unidadId: string): Observable<any[]> { getClients(uuid: string): Observable<any[]> {
console.log('unidadId', unidadId); console.log('unidadId', uuid);
return this.http.get<any>(this.clientsUrl).pipe( return this.http.get<any>(this.clientsUrl).pipe(
map(response => { map(response => {
if (response['hydra:member'] && Array.isArray(response['hydra:member'])) { if (response['hydra:member'] && Array.isArray(response['hydra:member'])) {
return response['hydra:member'].filter((client: any) => client.organizationalUnit === `/organizational-units/${unidadId}`); return response['hydra:member'].filter((client: any) => client.organizationalUnit && client.organizationalUnit['@id'] === `/organizational-units/${uuid}`);
} else { } else {
throw new Error('Unexpected response format'); throw new Error('Unexpected response format');
} }
@ -71,4 +70,6 @@ export class DataService {
}) })
); );
} }
} }

View File

@ -15,10 +15,7 @@
<mat-icon>apartment</mat-icon> <mat-icon>apartment</mat-icon>
{{ unidad.nombre }} {{ unidad.nombre }}
</span> </span>
<span class="actions">
<mat-icon class="edit-icon" (click)="onEditClick(unidad, unidad.uuid)">edit</mat-icon>
<mat-icon class="delete-icon" (click)="onDeleteClick(unidad.uuid)">delete</mat-icon>
</span>
</mat-list-item> </mat-list-item>
</mat-list> </mat-list>
</mat-card-content> </mat-card-content>
@ -31,7 +28,7 @@
<mat-list-item *ngFor="let child of children" [ngClass]="{'clickable-item': true}"> <mat-list-item *ngFor="let child of children" [ngClass]="{'clickable-item': true}">
<div> <div>
<span (click)="onSelectChild(child)"> <span (click)="onSelectChild(child)">
<ng-container [ngSwitch]="getIcon(child['type'])"> <ng-container [ngSwitch]="getIcon(child.type)">
<mat-icon *ngSwitchCase="'apartment'">apartment</mat-icon> <mat-icon *ngSwitchCase="'apartment'">apartment</mat-icon>
<svg *ngSwitchCase="'classrooms-group-icon'" xmlns="http://www.w3.org/2000/svg" height="24px" <svg *ngSwitchCase="'classrooms-group-icon'" xmlns="http://www.w3.org/2000/svg" height="24px"
viewBox="0 -960 960 960" width="24px" fill="#5f6368"> viewBox="0 -960 960 960" width="24px" fill="#5f6368">
@ -65,4 +62,5 @@
</mat-list> </mat-list>
</mat-card-content> </mat-card-content>
</mat-card> </mat-card>
</div> </div>

View File

@ -27,21 +27,23 @@ export class GroupsComponent implements OnInit {
onSelectUnidad(unidad: UnidadOrganizativa): void { onSelectUnidad(unidad: UnidadOrganizativa): void {
this.selectedUnidad = unidad; this.selectedUnidad = unidad;
this.breadcrumb = [unidad.nombre]; this.breadcrumb = [unidad.nombre];
this.loadChildrenAndClients(unidad.uuid, unidad.id); this.loadChildrenAndClients(unidad.uuid);
} }
onSelectChild(child: any): void { onSelectChild(child: any): void {
if (child.uuid && child.id) { if (child.uuid && child.id) {
this.breadcrumb.push(child.name || child.nombre); this.breadcrumb.push(child.name || child.nombre);
this.loadChildrenAndClients(child.uuid, child.id); this.loadChildrenAndClients(child.uuid);
} }
} }
loadChildrenAndClients(uuid: string, id: number): void { loadChildrenAndClients(uuid: string): void {
this.dataService.getChildren(uuid).subscribe( this.dataService.getChildren(uuid).subscribe(
childrenData => { childrenData => {
console.log('Children data:', childrenData); // Depuración
this.dataService.getClients(uuid).subscribe( this.dataService.getClients(uuid).subscribe(
clientsData => { clientsData => {
console.log('Clients data:', clientsData); // Depuración
const newChildren = [...childrenData, ...clientsData]; const newChildren = [...childrenData, ...clientsData];
if (newChildren.length > 0) { if (newChildren.length > 0) {
this.children = newChildren; this.children = newChildren;
@ -57,6 +59,7 @@ export class GroupsComponent implements OnInit {
); );
} }
addOU(): void { addOU(): void {
this.dialog.open(CreateOrganizationalUnitComponent); this.dialog.open(CreateOrganizationalUnitComponent);
} }