From dd02d673bc9ec394adf2aa6f2673def44a51869d Mon Sep 17 00:00:00 2001 From: Manuel Aranda Date: Mon, 20 Apr 2026 18:39:59 +0200 Subject: [PATCH] refs #2973. Refactor classroom status --- .../app/components/groups/groups.component.ts | 50 +++++++++++++------ .../src/app/components/groups/model/model.ts | 1 + 2 files changed, 35 insertions(+), 16 deletions(-) diff --git a/ogWebconsole/src/app/components/groups/groups.component.ts b/ogWebconsole/src/app/components/groups/groups.component.ts index 5334c38..53f8144 100644 --- a/ogWebconsole/src/app/components/groups/groups.component.ts +++ b/ogWebconsole/src/app/components/groups/groups.component.ts @@ -76,6 +76,7 @@ export class GroupsComponent implements OnInit, OnDestroy { savedFilterNames: [string, string][] = []; selectedTreeFilter = ''; syncingClientIds = new Set(); + isCheckingNodeStatus = false; private originalTreeData: TreeNode[] = []; arrayClients: any[] = []; filters: { [key: string]: string } = {}; @@ -243,6 +244,7 @@ export class GroupsComponent implements OnInit, OnDestroy { private transformer = (node: TreeNode, level: number): FlatNode => ({ id: node.id, + uuid: node.uuid, name: node.name, type: node.type, level, @@ -463,6 +465,10 @@ export class GroupsComponent implements OnInit, OnDestroy { } }); + if (this.isCheckingNodeStatus) { + members.forEach((c: Client) => c.uuid && this.syncingClientIds.add(c.uuid)); + } + // Calcular estadísticas después de cargar los clientes this.calculateLocalStats(); }, @@ -843,23 +849,35 @@ export class GroupsComponent implements OnInit, OnDestroy { getStatusForAllClientsInNode(node: any): void { - this.http.get(`${this.baseUrl}/clients?organizationalUnit.id=${node.id}&itemsPerPage=1000`).subscribe({ - next: (response: any) => { - const clients: Client[] = response['hydra:member']; - const validClients = clients.filter(client => client.uuid && client['@id']); - if (validClients.length === 0) return; + if (!node.uuid) return; - validClients.forEach(client => { - this.syncingClientIds.add(client.uuid); - this.subscriptions.add( - this.http.post(`${this.baseUrl}${client['@id']}/agent/status`, {}).subscribe({ - next: () => this.syncingClientIds.delete(client.uuid), - error: () => this.syncingClientIds.delete(client.uuid), - }) - ); - }); - } - }); + this.isCheckingNodeStatus = true; + this.selectedClients.data.forEach(c => c.uuid && this.syncingClientIds.add(c.uuid)); + + this.subscriptions.add( + this.http.post<{ results: Array<{ uuid: string; ip: string; status: string; success: boolean }> }>( + `${this.baseUrl}/organizational-units/${node.uuid}/agent/status`, + {} + ).subscribe({ + next: (response) => { + this.isCheckingNodeStatus = false; + const statusMap = new Map(response.results.map(r => [r.uuid, r.status])); + response.results.forEach(r => this.syncingClientIds.delete(r.uuid)); + this.selectedClients.data = this.selectedClients.data.map(client => { + const newStatus = statusMap.get(client.uuid); + return newStatus ? { ...client, status: newStatus } : client; + }); + this.arrayClients = this.selectedClients.data; + this.calculateLocalStats(); + this.toastr.success('Estado del aula actualizado'); + }, + error: () => { + this.isCheckingNodeStatus = false; + this.selectedClients.data.forEach(c => c.uuid && this.syncingClientIds.delete(c.uuid)); + this.toastr.error('Error al comprobar el estado del aula'); + }, + }) + ); } diff --git a/ogWebconsole/src/app/components/groups/model/model.ts b/ogWebconsole/src/app/components/groups/model/model.ts index f85cc05..d12df49 100644 --- a/ogWebconsole/src/app/components/groups/model/model.ts +++ b/ogWebconsole/src/app/components/groups/model/model.ts @@ -77,6 +77,7 @@ export interface TreeNode { export interface FlatNode { id?: string; + uuid?: string; name: string; type: string; level: number;