refs #2973. Refactor classroom status
parent
299ced8b27
commit
dd02d673bc
|
|
@ -76,6 +76,7 @@ export class GroupsComponent implements OnInit, OnDestroy {
|
||||||
savedFilterNames: [string, string][] = [];
|
savedFilterNames: [string, string][] = [];
|
||||||
selectedTreeFilter = '';
|
selectedTreeFilter = '';
|
||||||
syncingClientIds = new Set<string>();
|
syncingClientIds = new Set<string>();
|
||||||
|
isCheckingNodeStatus = false;
|
||||||
private originalTreeData: TreeNode[] = [];
|
private originalTreeData: TreeNode[] = [];
|
||||||
arrayClients: any[] = [];
|
arrayClients: any[] = [];
|
||||||
filters: { [key: string]: string } = {};
|
filters: { [key: string]: string } = {};
|
||||||
|
|
@ -243,6 +244,7 @@ export class GroupsComponent implements OnInit, OnDestroy {
|
||||||
|
|
||||||
private transformer = (node: TreeNode, level: number): FlatNode => ({
|
private transformer = (node: TreeNode, level: number): FlatNode => ({
|
||||||
id: node.id,
|
id: node.id,
|
||||||
|
uuid: node.uuid,
|
||||||
name: node.name,
|
name: node.name,
|
||||||
type: node.type,
|
type: node.type,
|
||||||
level,
|
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
|
// Calcular estadísticas después de cargar los clientes
|
||||||
this.calculateLocalStats();
|
this.calculateLocalStats();
|
||||||
},
|
},
|
||||||
|
|
@ -843,23 +849,35 @@ export class GroupsComponent implements OnInit, OnDestroy {
|
||||||
|
|
||||||
|
|
||||||
getStatusForAllClientsInNode(node: any): void {
|
getStatusForAllClientsInNode(node: any): void {
|
||||||
this.http.get<any>(`${this.baseUrl}/clients?organizationalUnit.id=${node.id}&itemsPerPage=1000`).subscribe({
|
if (!node.uuid) return;
|
||||||
next: (response: any) => {
|
|
||||||
const clients: Client[] = response['hydra:member'];
|
this.isCheckingNodeStatus = true;
|
||||||
const validClients = clients.filter(client => client.uuid && client['@id']);
|
this.selectedClients.data.forEach(c => c.uuid && this.syncingClientIds.add(c.uuid));
|
||||||
if (validClients.length === 0) return;
|
|
||||||
|
|
||||||
validClients.forEach(client => {
|
|
||||||
this.syncingClientIds.add(client.uuid);
|
|
||||||
this.subscriptions.add(
|
this.subscriptions.add(
|
||||||
this.http.post(`${this.baseUrl}${client['@id']}/agent/status`, {}).subscribe({
|
this.http.post<{ results: Array<{ uuid: string; ip: string; status: string; success: boolean }> }>(
|
||||||
next: () => this.syncingClientIds.delete(client.uuid),
|
`${this.baseUrl}/organizational-units/${node.uuid}/agent/status`,
|
||||||
error: () => this.syncingClientIds.delete(client.uuid),
|
{}
|
||||||
|
).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 {
|
export interface FlatNode {
|
||||||
id?: string;
|
id?: string;
|
||||||
|
uuid?: string;
|
||||||
name: string;
|
name: string;
|
||||||
type: string;
|
type: string;
|
||||||
level: number;
|
level: number;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue