From 3089ca92fc45273c4dd20c8fe826faf25d2956b0 Mon Sep 17 00:00:00 2001 From: apuente Date: Wed, 2 Oct 2024 14:31:50 +0200 Subject: [PATCH] refs #798 Add styling to task-logs component and implement filtering functionality --- .../detail-command-group.component.html | 85 ++++++++++++------- .../detail-command-group.component.ts | 66 ++++++++++++-- .../task-logs/task-logs.component.css | 3 + .../task-logs/task-logs.component.html | 81 ++++++++++++------ .../task-logs/task-logs.component.ts | 24 ++++++ .../edit-organizational-unit.component.ts | 2 +- 6 files changed, 195 insertions(+), 66 deletions(-) diff --git a/ogWebconsole/src/app/components/commands/commands-groups/detail-command-group/detail-command-group.component.html b/ogWebconsole/src/app/components/commands/commands-groups/detail-command-group/detail-command-group.component.html index e70d6ca..82c143f 100644 --- a/ogWebconsole/src/app/components/commands/commands-groups/detail-command-group/detail-command-group.component.html +++ b/ogWebconsole/src/app/components/commands/commands-groups/detail-command-group/detail-command-group.component.html @@ -1,36 +1,57 @@
-

Detalles del Grupo de Comandos

+

Detalles del Grupo de Comandos

+ + + + {{ data.name }} + Creado por: {{ data.createdBy }} + - - - {{ data.name }} - Creado por: {{ data.createdBy }} - + +

ID del Grupo: {{ data.uuid }}

+

Fecha de Creación: {{ data.createdAt | date:'short' }}

- -

ID del Grupo: {{ data.uuid }}

-

Fecha de Creación: {{ data.createdAt | date:'short' }}

- -

Comandos Incluidos:

- - - - - - - - - - - - - -
Nombre {{ command.name }} UUID {{ command.uuid }}
-
- -
-
- -
+

Comandos Incluidos:

+ + + + + + + + + + + + + +
Nombre {{ command.name }} UUID {{ command.uuid }}
+ + +
+ + +
+
+

Selecciona los clientes:

+ + Clientes + + + {{ client.name }} + + + + Debes seleccionar al menos un cliente. + + +
- \ No newline at end of file + +
+ + +
+
diff --git a/ogWebconsole/src/app/components/commands/commands-groups/detail-command-group/detail-command-group.component.ts b/ogWebconsole/src/app/components/commands/commands-groups/detail-command-group/detail-command-group.component.ts index 15f7b02..636e3da 100644 --- a/ogWebconsole/src/app/components/commands/commands-groups/detail-command-group/detail-command-group.component.ts +++ b/ogWebconsole/src/app/components/commands/commands-groups/detail-command-group/detail-command-group.component.ts @@ -1,18 +1,74 @@ -import { Component, Inject } from '@angular/core'; +import { Component, Inject, OnInit } from '@angular/core'; +import { FormBuilder, FormGroup, Validators } from '@angular/forms'; import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material/dialog'; +import { HttpClient } from '@angular/common/http'; +import { ToastrService } from 'ngx-toastr'; @Component({ selector: 'app-detail-command-group', templateUrl: './detail-command-group.component.html', styleUrls: ['./detail-command-group.component.css'] }) -export class DetailCommandGroupComponent { +export class DetailCommandGroupComponent implements OnInit { + baseUrl: string = import.meta.env.NG_APP_BASE_API_URL; + form!: FormGroup; + clients: any[] = []; + showClientSelect = false; // Ocultar selección de clientes inicialmente + canExecute = false; + constructor( @Inject(MAT_DIALOG_DATA) public data: any, - private dialogRef: MatDialogRef - ) {} + private dialogRef: MatDialogRef, + private fb: FormBuilder, + private http: HttpClient, + private toastService: ToastrService + ) { } + + ngOnInit(): void { + this.form = this.fb.group({ + selectedClients: [[], Validators.required], + }); + + // Obtener la lista de clientes + this.http.get(`${this.baseUrl}/clients?page=1&itemsPerPage=30`).subscribe(response => { + this.clients = response['hydra:member']; + }); + } + + toggleClientSelect(): void { + if (!this.showClientSelect) { + this.showClientSelect = true; // Mostrar selección de clientes + } else { + this.execute(); // Ejecutar si ya está visible + } + } + + execute(): void { + if (this.form.get('selectedClients')?.value.length > 0) { + const payload = { + clients: this.form.value.selectedClients.map((uuid: any) => `/clients/${uuid}`) + }; + + const apiUrl = `${this.baseUrl}/command-groups/${this.data.uuid}/execute`; + this.http.post(apiUrl, payload).subscribe({ + next: () => { + this.dialogRef.close(); + this.toastService.success('Grupo de comandos ejecutado exitosamente'); + }, + error: (error) => { + console.error('Error ejecutando grupo de comandos:', error); + } + }); + } else { + this.form.get('selectedClients')?.markAsTouched(); + } + } + + onClientSelectionChange(event: any): void { + this.canExecute = this.form.get('selectedClients')?.value.length > 0; + } close(): void { - this.dialogRef.close(); + this.dialogRef.close(); } } diff --git a/ogWebconsole/src/app/components/commands/commands-task/task-logs/task-logs.component.css b/ogWebconsole/src/app/components/commands/commands-task/task-logs/task-logs.component.css index e69de29..482cf8c 100644 --- a/ogWebconsole/src/app/components/commands/commands-task/task-logs/task-logs.component.css +++ b/ogWebconsole/src/app/components/commands/commands-task/task-logs/task-logs.component.css @@ -0,0 +1,3 @@ +mat-form-field{ + margin: 10px; +} \ No newline at end of file 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 be8b0ea..d77f900 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 @@ -1,40 +1,65 @@
-

Trazas de ejecuciones

-
+

Trazas de ejecuciones

- - + + Buscar por comando + + + + + Buscar por cliente + + + + + Buscar por estado + + + + + Buscar por usuario + + + + + Buscar por fecha + + + + + +
+ - - - + + + - - - + + + - - - + + + - - - + + + - - - - -
Comando {{ trace.command.name }} Cliente {{ trace.client.name }} Estado {{ trace.status }} Ejecutado En {{ trace.executedAt | date:'short' }} Creado Por {{ trace.createdBy }}
- - - - \ 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 be98a09..a9a41ab 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 @@ -10,12 +10,20 @@ export class TaskLogsComponent implements OnInit { baseUrl: string = import.meta.env.NG_APP_BASE_API_URL; // Utilizando baseUrl desde el env traces: any[] = []; + filteredTraces: any[] = []; // Nueva variable para las trazas filtradas length: number = 0; itemsPerPage: number = 20; page: number = 1; pageSizeOptions: number[] = [10, 20, 30, 50]; displayedColumns: string[] = ['commandName', 'clientName', 'status', 'executedAt', 'createdBy']; + // Variables para los términos de búsqueda + searchCommand: string = ''; + searchClient: string = ''; + searchStatus: string = ''; + searchCreatedBy: string = ''; + searchExecutedAt: string = ''; + constructor(private http: HttpClient) {} ngOnInit(): void { @@ -30,6 +38,7 @@ export class TaskLogsComponent implements OnInit { (data) => { this.traces = data['hydra:member']; this.length = data['hydra:totalItems']; + this.filteredTraces = this.traces; // Inicializa con todas las trazas console.log('Traces:', this.traces); }, (error) => { @@ -44,4 +53,19 @@ export class TaskLogsComponent implements OnInit { this.itemsPerPage = event.pageSize; // Actualiza los ítems por página this.loadTraces(); // Recarga las trazas con los nuevos parámetros de paginación } + + // Método para filtrar las trazas + filterTraces(): void { + this.filteredTraces = this.traces.filter(trace => { + const commandMatch = trace.command.name.toLowerCase().includes(this.searchCommand.toLowerCase()); + const clientMatch = trace.client.name.toLowerCase().includes(this.searchClient.toLowerCase()); + const statusMatch = trace.status.toLowerCase().includes(this.searchStatus.toLowerCase()); + const createdByMatch = trace.createdBy.toLowerCase().includes(this.searchCreatedBy.toLowerCase()); + const executedAtMatch = trace.executedAt.toLowerCase().includes(this.searchExecutedAt.toLowerCase()); + + return commandMatch && clientMatch && statusMatch && createdByMatch && executedAtMatch; + }); + + this.length = this.filteredTraces.length; // Actualiza la longitud para el paginador + } } diff --git a/ogWebconsole/src/app/components/groups/shared/organizational-units/edit-organizational-unit/edit-organizational-unit.component.ts b/ogWebconsole/src/app/components/groups/shared/organizational-units/edit-organizational-unit/edit-organizational-unit.component.ts index f202140..73a7024 100644 --- a/ogWebconsole/src/app/components/groups/shared/organizational-units/edit-organizational-unit/edit-organizational-unit.component.ts +++ b/ogWebconsole/src/app/components/groups/shared/organizational-units/edit-organizational-unit/edit-organizational-unit.component.ts @@ -22,7 +22,7 @@ export class EditOrganizationalUnitComponent implements OnInit { parentUnits: any[] = []; hardwareProfiles: any[] = []; isEditMode: boolean; - currentCalendar: any; + currentCalendar: any = []; protected p2pModeOptions = [ {"name": 'Leecher', "value": "p2p-mode-leecher"}, {"name": 'Peer', "value": "p2p-mode-peer"},