refs #2973. Refactor classroom status
parent
299ced8b27
commit
dd02d673bc
|
|
@ -76,6 +76,7 @@ export class GroupsComponent implements OnInit, OnDestroy {
|
|||
savedFilterNames: [string, string][] = [];
|
||||
selectedTreeFilter = '';
|
||||
syncingClientIds = new Set<string>();
|
||||
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<any>(`${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');
|
||||
},
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -77,6 +77,7 @@ export interface TreeNode {
|
|||
|
||||
export interface FlatNode {
|
||||
id?: string;
|
||||
uuid?: string;
|
||||
name: string;
|
||||
type: string;
|
||||
level: number;
|
||||
|
|
|
|||
Loading…
Reference in New Issue