Groups new fetch for API updates
parent
b14605f248
commit
67177c4237
|
@ -39,11 +39,10 @@ export class DataService {
|
|||
}
|
||||
|
||||
getChildren(uuid: string): Observable<any[]> {
|
||||
console.log('uuid', uuid);
|
||||
return this.http.get<any>(`${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}`);
|
||||
return response['hydra:member'].filter((element: any) => element.parent && element.parent['@id'] === `/organizational-units/${uuid}`);
|
||||
} else {
|
||||
throw new Error('Unexpected response format');
|
||||
}
|
||||
|
@ -55,12 +54,12 @@ export class DataService {
|
|||
);
|
||||
}
|
||||
|
||||
getClients(unidadId: string): Observable<any[]> {
|
||||
console.log('unidadId', unidadId);
|
||||
getClients(uuid: string): Observable<any[]> {
|
||||
console.log('unidadId', uuid);
|
||||
return this.http.get<any>(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}`);
|
||||
return response['hydra:member'].filter((client: any) => client.organizationalUnit && client.organizationalUnit['@id'] === `/organizational-units/${uuid}`);
|
||||
} else {
|
||||
throw new Error('Unexpected response format');
|
||||
}
|
||||
|
@ -71,4 +70,6 @@ export class DataService {
|
|||
})
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -15,10 +15,7 @@
|
|||
<mat-icon>apartment</mat-icon>
|
||||
{{ unidad.nombre }}
|
||||
</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>
|
||||
</mat-card-content>
|
||||
|
@ -31,7 +28,7 @@
|
|||
<mat-list-item *ngFor="let child of children" [ngClass]="{'clickable-item': true}">
|
||||
<div>
|
||||
<span (click)="onSelectChild(child)">
|
||||
<ng-container [ngSwitch]="getIcon(child['type'])">
|
||||
<ng-container [ngSwitch]="getIcon(child.type)">
|
||||
<mat-icon *ngSwitchCase="'apartment'">apartment</mat-icon>
|
||||
<svg *ngSwitchCase="'classrooms-group-icon'" xmlns="http://www.w3.org/2000/svg" height="24px"
|
||||
viewBox="0 -960 960 960" width="24px" fill="#5f6368">
|
||||
|
@ -65,4 +62,5 @@
|
|||
</mat-list>
|
||||
</mat-card-content>
|
||||
</mat-card>
|
||||
|
||||
</div>
|
|
@ -27,21 +27,23 @@ export class GroupsComponent implements OnInit {
|
|||
onSelectUnidad(unidad: UnidadOrganizativa): void {
|
||||
this.selectedUnidad = unidad;
|
||||
this.breadcrumb = [unidad.nombre];
|
||||
this.loadChildrenAndClients(unidad.uuid, unidad.id);
|
||||
this.loadChildrenAndClients(unidad.uuid);
|
||||
}
|
||||
|
||||
onSelectChild(child: any): void {
|
||||
if (child.uuid && child.id) {
|
||||
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(
|
||||
childrenData => {
|
||||
console.log('Children data:', childrenData); // Depuración
|
||||
this.dataService.getClients(uuid).subscribe(
|
||||
clientsData => {
|
||||
console.log('Clients data:', clientsData); // Depuración
|
||||
const newChildren = [...childrenData, ...clientsData];
|
||||
if (newChildren.length > 0) {
|
||||
this.children = newChildren;
|
||||
|
@ -57,6 +59,7 @@ export class GroupsComponent implements OnInit {
|
|||
);
|
||||
}
|
||||
|
||||
|
||||
addOU(): void {
|
||||
this.dialog.open(CreateOrganizationalUnitComponent);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue