From b4a389e5bdbff8b831dd7ba4cec16e01d48bbbf6 Mon Sep 17 00:00:00 2001 From: llara Date: Tue, 18 Feb 2025 14:16:52 +0100 Subject: [PATCH] refs #1529. Refactor task logs component: enhance client fetching logic with forkJoin for better performance --- .../task-logs/task-logs.component.html | 7 +++--- .../task-logs/task-logs.component.ts | 25 +++++++++++++++---- ogWebconsole/src/locale/en.json | 4 +-- ogWebconsole/src/locale/es.json | 4 +-- 4 files changed, 28 insertions(+), 12 deletions(-) diff --git a/ogWebconsole/src/app/components/commands/commands-task/task-logs/task-logs.component.html b/ogWebconsole/src/app/components/commands/commands-task/task-logs/task-logs.component.html index d49b789..9d1a425 100644 --- a/ogWebconsole/src/app/components/commands/commands-task/task-logs/task-logs.component.html +++ b/ogWebconsole/src/app/components/commands/commands-task/task-logs/task-logs.component.html @@ -20,7 +20,7 @@ + placeholder="{{ 'filterClientPlaceholder' | translate }}"> @@ -32,7 +32,7 @@ + placeholder="{{ 'filterCommandPlaceholder' | translate }}"> @@ -44,6 +44,7 @@ Estado + Todos Fallido Pendiente de ejecutar Ejecutando @@ -115,4 +116,4 @@ - + \ No newline at end of file diff --git a/ogWebconsole/src/app/components/commands/commands-task/task-logs/task-logs.component.ts b/ogWebconsole/src/app/components/commands/commands-task/task-logs/task-logs.component.ts index f991704..07be884 100644 --- a/ogWebconsole/src/app/components/commands/commands-task/task-logs/task-logs.component.ts +++ b/ogWebconsole/src/app/components/commands/commands-task/task-logs/task-logs.component.ts @@ -1,6 +1,6 @@ import { Component, OnInit } from '@angular/core'; import { HttpClient } from '@angular/common/http'; -import { Observable } from 'rxjs'; +import { Observable, forkJoin } from 'rxjs'; import { FormControl } from '@angular/forms'; import { map, startWith } from 'rxjs/operators'; import { DatePipe } from '@angular/common'; @@ -144,7 +144,11 @@ export class TaskLogsComponent implements OnInit { loadTraces(): void { this.loading = true; const url = `${this.baseUrl}/traces?page=${this.page + 1}&itemsPerPage=${this.itemsPerPage}`; - this.http.get(url, { params: this.filters }).subscribe( + const params = { ...this.filters }; + if (params['status'] === undefined) { + delete params['status']; + } + this.http.get(url, { params }).subscribe( (data) => { this.traces = data['hydra:member']; this.length = data['hydra:totalItems']; @@ -163,6 +167,7 @@ export class TaskLogsComponent implements OnInit { this.http.get(`${this.baseUrl}/commands?&page=1&itemsPerPage=10000`).subscribe( response => { this.commands = response['hydra:member']; + console.log(this.commands); this.loading = false; }, error => { @@ -176,10 +181,20 @@ export class TaskLogsComponent implements OnInit { this.loading = true; this.http.get(`${this.baseUrl}/clients?&page=1&itemsPerPage=10000`).subscribe( response => { - this.clients = response['hydra:member']; - this.loading = false; + const clientIds = response['hydra:member'].map((client: any) => client['@id']); + const clientDetailsRequests: Observable[] = clientIds.map((id: string) => this.http.get(`${this.baseUrl}${id}`)); + forkJoin(clientDetailsRequests).subscribe( + (clients: any[]) => { + this.clients = clients; + this.loading = false; + }, + (error: any) => { + console.error('Error fetching client details:', error); + this.loading = false; + } + ); }, - error => { + (error: any) => { console.error('Error fetching clients:', error); this.loading = false; } diff --git a/ogWebconsole/src/locale/en.json b/ogWebconsole/src/locale/en.json index 1b4d204..1ccfd67 100644 --- a/ogWebconsole/src/locale/en.json +++ b/ogWebconsole/src/locale/en.json @@ -99,9 +99,9 @@ "resetFiltersStepText": "Click to reset the applied filters and see all traces.", "resetFilters": "Reset filters", "clientSelectStepText": "Select a client to see the associated traces.", - "selectClientPlaceholder": "Select a client", + "filterClientPlaceholder": "Filter by client", "commandSelectStepText": "Select a command to see the specific traces of that command.", - "selectCommandPlaceholder": "Select a command", + "filterCommandPlaceholder": "Filter by command", "taskDetailsTitle": "Task Details", "taskId": "Task ID", "status": "Status", diff --git a/ogWebconsole/src/locale/es.json b/ogWebconsole/src/locale/es.json index 1a1e13f..4028d0f 100644 --- a/ogWebconsole/src/locale/es.json +++ b/ogWebconsole/src/locale/es.json @@ -100,9 +100,9 @@ "resetFiltersStepText": "Haz clic para reiniciar los filtros aplicados y ver todas las trazas.", "resetFilters": "Reiniciar filtros", "clientSelectStepText": "Selecciona un cliente para ver las trazas asociadas.", - "selectClientPlaceholder": "Seleccione un cliente", + "filterClientPlaceholder": "Filtrar por cliente", "commandSelectStepText": "Selecciona un comando para ver las trazas específicas de ese comando.", - "selectCommandPlaceholder": "Seleccione un comando", + "filterCommandPlaceholder": "Filtrar por comando", "taskDetailsTitle": "Detalles de la Tarea", "taskId": "ID de la Tarea", "status": "Estado",