From 50fe2d830d52e6a03bf680391342f45ecb5c3e12 Mon Sep 17 00:00:00 2001 From: apuente Date: Tue, 1 Oct 2024 19:53:07 +0200 Subject: [PATCH] refs #798 Added task logs view --- ogWebconsole/src/app/app-routing.module.ts | 2 + ogWebconsole/src/app/app.module.ts | 4 +- .../create-calendar-rule.component.spec.ts | 47 ++++++++++++++--- .../commands-groups.component.spec.ts | 50 +++++++++++++++++-- .../detail-command-group.component.html | 1 - .../commands-task.component.html | 2 +- .../create-task/create-task.component.html | 1 + .../create-task/create-task.component.ts | 23 +++++---- .../task-logs/task-logs.component.css | 0 .../task-logs/task-logs.component.html | 40 +++++++++++++++ .../task-logs/task-logs.component.ts | 47 +++++++++++++++++ .../main-commands/commands.component.ts | 6 +-- .../create-command.component.html | 2 +- .../create-command.component.ts | 3 +- .../command-detail.component.html | 6 +-- .../command-detail.component.ts | 8 ++- .../create-organizational-unit.component.html | 2 - .../edit-organizational-unit.component.html | 12 +++++ .../app/layout/sidebar/sidebar.component.html | 6 +++ .../delete-modal.component.spec.ts | 17 +++++-- 20 files changed, 236 insertions(+), 43 deletions(-) create mode 100644 ogWebconsole/src/app/components/commands/commands-task/task-logs/task-logs.component.css create mode 100644 ogWebconsole/src/app/components/commands/commands-task/task-logs/task-logs.component.html create mode 100644 ogWebconsole/src/app/components/commands/commands-task/task-logs/task-logs.component.ts diff --git a/ogWebconsole/src/app/app-routing.module.ts b/ogWebconsole/src/app/app-routing.module.ts index fc0ea8a..5665fc6 100644 --- a/ogWebconsole/src/app/app-routing.module.ts +++ b/ogWebconsole/src/app/app-routing.module.ts @@ -19,6 +19,7 @@ import { CalendarComponent } from "./components/calendar/calendar.component"; import { CommandsComponent } from './components/commands/main-commands/commands.component'; import { CommandsGroupsComponent } from './components/commands/commands-groups/commands-groups.component'; import { CommandsTaskComponent } from './components/commands/commands-task/commands-task.component'; +import { TaskLogsComponent } from './components/commands/commands-task/task-logs/task-logs.component'; const routes: Routes = [ { path: '', redirectTo: 'auth/login', pathMatch: 'full' }, { @@ -39,6 +40,7 @@ const routes: Routes = [ { path: 'commands', component: CommandsComponent }, { path: 'commands-groups', component: CommandsGroupsComponent }, { path: 'commands-task', component: CommandsTaskComponent }, + { path: 'commands-logs', component: TaskLogsComponent }, { path: 'calendars', component: CalendarComponent }, ], }, diff --git a/ogWebconsole/src/app/app.module.ts b/ogWebconsole/src/app/app.module.ts index 3f5dde5..f35957b 100644 --- a/ogWebconsole/src/app/app.module.ts +++ b/ogWebconsole/src/app/app.module.ts @@ -99,6 +99,7 @@ import { CreateTaskComponent } from './components/commands/commands-task/create- import { DetailTaskComponent } from './components/commands/commands-task/detail-task/detail-task.component'; import { ClientTabViewComponent } from './components/groups/components/client-tab-view/client-tab-view.component'; import { AdvancedSearchComponent } from './components/groups/components/advanced-search/advanced-search.component'; +import { TaskLogsComponent } from './components/commands/commands-task/task-logs/task-logs.component'; @NgModule({ declarations: [ AppComponent, @@ -154,7 +155,8 @@ import { AdvancedSearchComponent } from './components/groups/components/advanced CreateTaskComponent, DetailTaskComponent, ClientTabViewComponent, - AdvancedSearchComponent + AdvancedSearchComponent, + TaskLogsComponent ], bootstrap: [AppComponent], imports: [BrowserModule, diff --git a/ogWebconsole/src/app/components/calendar/create-calendar-rule/create-calendar-rule.component.spec.ts b/ogWebconsole/src/app/components/calendar/create-calendar-rule/create-calendar-rule.component.spec.ts index 607fb50..85be416 100644 --- a/ogWebconsole/src/app/components/calendar/create-calendar-rule/create-calendar-rule.component.spec.ts +++ b/ogWebconsole/src/app/components/calendar/create-calendar-rule/create-calendar-rule.component.spec.ts @@ -1,23 +1,58 @@ import { ComponentFixture, TestBed } from '@angular/core/testing'; - import { CreateCalendarRuleComponent } from './create-calendar-rule.component'; +import { MatDialogRef, MAT_DIALOG_DATA } from '@angular/material/dialog'; +import { ToastrService } from 'ngx-toastr'; +import { HttpClientModule } from '@angular/common/http'; // Importar HttpClientModule +import { provideHttpClientTesting } from '@angular/common/http/testing'; // Importar el nuevo método +import { MatDialogModule } from '@angular/material/dialog'; +import { MatFormFieldModule } from '@angular/material/form-field'; +import { MatInputModule } from '@angular/material/input'; +import { MatCheckboxModule } from '@angular/material/checkbox'; +import { MatSlideToggleModule } from '@angular/material/slide-toggle'; +import { MatDatepickerModule } from '@angular/material/datepicker'; +import { MatNativeDateModule } from '@angular/material/core'; describe('CreateCalendarRuleComponent', () => { let component: CreateCalendarRuleComponent; let fixture: ComponentFixture; + let dialogRefMock: any; + let toastrServiceMock: any; beforeEach(async () => { + dialogRefMock = { + close: jasmine.createSpy('close') + }; + + toastrServiceMock = { + success: jasmine.createSpy('success'), + error: jasmine.createSpy('error') + }; + await TestBed.configureTestingModule({ - declarations: [CreateCalendarRuleComponent] - }) - .compileComponents(); + imports: [ + HttpClientModule, // Importar el módulo HttpClient + MatDialogModule, + MatFormFieldModule, + MatInputModule, + MatCheckboxModule, + MatSlideToggleModule, + MatDatepickerModule, + MatNativeDateModule + ], + declarations: [CreateCalendarRuleComponent], + providers: [ + provideHttpClientTesting(), // Usar el nuevo método para pruebas de HttpClient + { provide: MatDialogRef, useValue: dialogRefMock }, + { provide: MAT_DIALOG_DATA, useValue: {} }, + { provide: ToastrService, useValue: toastrServiceMock }, + ] + }).compileComponents(); fixture = TestBed.createComponent(CreateCalendarRuleComponent); component = fixture.componentInstance; - fixture.detectChanges(); }); - it('should create', () => { + it('should create the component', () => { expect(component).toBeTruthy(); }); }); diff --git a/ogWebconsole/src/app/components/commands/commands-groups/commands-groups.component.spec.ts b/ogWebconsole/src/app/components/commands/commands-groups/commands-groups.component.spec.ts index f9a69a0..18fc406 100644 --- a/ogWebconsole/src/app/components/commands/commands-groups/commands-groups.component.spec.ts +++ b/ogWebconsole/src/app/components/commands/commands-groups/commands-groups.component.spec.ts @@ -1,23 +1,63 @@ import { ComponentFixture, TestBed } from '@angular/core/testing'; - +import { HttpClientModule } from '@angular/common/http'; +import { MatDialogModule, MatDialogRef } from '@angular/material/dialog'; +import { MatPaginatorModule } from '@angular/material/paginator'; +import { MatDividerModule } from '@angular/material/divider'; +import { MatButtonModule } from '@angular/material/button'; +import { MatIconModule } from '@angular/material/icon'; +import { MatFormFieldModule } from '@angular/material/form-field'; +import { MatInputModule } from '@angular/material/input'; +import { MatTableModule } from '@angular/material/table'; +import { MatMenuModule } from '@angular/material/menu'; +import { FormsModule } from '@angular/forms'; +import { BrowserAnimationsModule } from '@angular/platform-browser/animations'; +import { ToastrService } from 'ngx-toastr'; import { CommandsGroupsComponent } from './commands-groups.component'; +class MockToastrService { + success() {} +} + +class MockMatDialogRef { + close() {} +} + describe('CommandsGroupsComponent', () => { let component: CommandsGroupsComponent; let fixture: ComponentFixture; + let toastService: ToastrService; beforeEach(async () => { await TestBed.configureTestingModule({ - declarations: [CommandsGroupsComponent] - }) - .compileComponents(); + declarations: [CommandsGroupsComponent], + imports: [ + HttpClientModule, + MatDialogModule, + MatPaginatorModule, + MatDividerModule, + MatButtonModule, + MatIconModule, + MatFormFieldModule, + MatInputModule, + MatTableModule, + MatMenuModule, + FormsModule, + BrowserAnimationsModule, + ], + providers: [ + { provide: ToastrService, useClass: MockToastrService }, + { provide: MatDialogRef, useClass: MockMatDialogRef } + ] + }).compileComponents(); fixture = TestBed.createComponent(CommandsGroupsComponent); component = fixture.componentInstance; + toastService = TestBed.inject(ToastrService); fixture.detectChanges(); }); - it('should create', () => { + it('should create the component', () => { expect(component).toBeTruthy(); }); + }); 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 6054d00..e70d6ca 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 @@ -9,7 +9,6 @@

ID del Grupo: {{ data.uuid }}

-

Posición: {{ data.position }}

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

Comandos Incluidos:

diff --git a/ogWebconsole/src/app/components/commands/commands-task/commands-task.component.html b/ogWebconsole/src/app/components/commands/commands-task/commands-task.component.html index a53db86..63ae0c0 100644 --- a/ogWebconsole/src/app/components/commands/commands-task/commands-task.component.html +++ b/ogWebconsole/src/app/components/commands/commands-task/commands-task.component.html @@ -57,4 +57,4 @@ [pageSize]="itemsPerPage" [pageSizeOptions]="pageSizeOptions" (page)="onPageChange($event)"> - + \ No newline at end of file diff --git a/ogWebconsole/src/app/components/commands/commands-task/create-task/create-task.component.html b/ogWebconsole/src/app/components/commands/commands-task/create-task/create-task.component.html index 136f66c..1c203ee 100644 --- a/ogWebconsole/src/app/components/commands/commands-task/create-task/create-task.component.html +++ b/ogWebconsole/src/app/components/commands/commands-task/create-task/create-task.component.html @@ -11,6 +11,7 @@ + Selecciona Comandos diff --git a/ogWebconsole/src/app/components/commands/commands-task/create-task/create-task.component.ts b/ogWebconsole/src/app/components/commands/commands-task/create-task/create-task.component.ts index 88a8813..586127d 100644 --- a/ogWebconsole/src/app/components/commands/commands-task/create-task/create-task.component.ts +++ b/ogWebconsole/src/app/components/commands/commands-task/create-task/create-task.component.ts @@ -137,16 +137,21 @@ export class CreateTaskComponent implements OnInit { const formData = this.taskForm.value; const dateTime = this.combineDateAndTime(formData.date, formData.time); - const selectedCommands = formData.extraCommands.length > 0 - ? formData.extraCommands.map((id: any) => `/commands/${id}`) - : [""]; + const selectedCommands = formData.extraCommands && formData.extraCommands.length > 0 + ? formData.extraCommands.map((id: any) => `/commands/${id}`) + : null; // No asignamos nada si no hay comandos seleccionados - const payload = { - commandGroups: [formData.commandGroup ? `/command-groups/${formData.commandGroup}` : [""]], - commands: selectedCommands, - dateTime: dateTime, - notes: formData.notes || '' - }; + // Creamos el objeto payload + const payload: any = { + commandGroups: formData.commandGroup ? [`/command-groups/${formData.commandGroup}`] : null, + dateTime: dateTime, + notes: formData.notes || '' + }; + + // Solo agregamos commands al payload si hay comandos seleccionados + if (selectedCommands) { + payload.commands = selectedCommands; + } if (this.editing) { const taskId = this.data.task.uuid; 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 new file mode 100644 index 0000000..e69de29 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 new file mode 100644 index 0000000..be8b0ea --- /dev/null +++ b/ogWebconsole/src/app/components/commands/commands-task/task-logs/task-logs.component.html @@ -0,0 +1,40 @@ +
+

Trazas de ejecuciones

+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
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 new file mode 100644 index 0000000..be98a09 --- /dev/null +++ b/ogWebconsole/src/app/components/commands/commands-task/task-logs/task-logs.component.ts @@ -0,0 +1,47 @@ +import { Component, OnInit } from '@angular/core'; +import { HttpClient } from '@angular/common/http'; + +@Component({ + selector: 'app-task-logs', + templateUrl: './task-logs.component.html', + styleUrls: ['./task-logs.component.css'] +}) +export class TaskLogsComponent implements OnInit { + + baseUrl: string = import.meta.env.NG_APP_BASE_API_URL; // Utilizando baseUrl desde el env + traces: any[] = []; + length: number = 0; + itemsPerPage: number = 20; + page: number = 1; + pageSizeOptions: number[] = [10, 20, 30, 50]; + displayedColumns: string[] = ['commandName', 'clientName', 'status', 'executedAt', 'createdBy']; + + constructor(private http: HttpClient) {} + + ngOnInit(): void { + this.loadTraces(); + } + + // Método para cargar las trazas con paginación + loadTraces(): void { + const url = `${this.baseUrl}/traces?page=${this.page}&itemsPerPage=${this.itemsPerPage}`; + + this.http.get(url).subscribe( + (data) => { + this.traces = data['hydra:member']; + this.length = data['hydra:totalItems']; + console.log('Traces:', this.traces); + }, + (error) => { + console.error('Error fetching traces', error); + } + ); + } + + // Método que se llama cuando cambia la paginación + onPageChange(event: any): void { + this.page = event.pageIndex + 1; // Actualiza el número de página + this.itemsPerPage = event.pageSize; // Actualiza los ítems por página + this.loadTraces(); // Recarga las trazas con los nuevos parámetros de paginación + } +} diff --git a/ogWebconsole/src/app/components/commands/main-commands/commands.component.ts b/ogWebconsole/src/app/components/commands/main-commands/commands.component.ts index 2eec6ff..04d7925 100644 --- a/ogWebconsole/src/app/components/commands/main-commands/commands.component.ts +++ b/ogWebconsole/src/app/components/commands/main-commands/commands.component.ts @@ -16,9 +16,9 @@ export class CommandsComponent implements OnInit { commands: any[] = []; filters: { [key: string]: string | boolean } = {}; length: number = 0; - itemsPerPage: number = 10; + itemsPerPage: number = 20; page: number = 1; - pageSizeOptions: number[] = [5, 10, 20, 40, 100]; + pageSizeOptions: number[] = [10, 20, 40, 100]; displayedColumns: string[] = ['name', 'createdBy', 'createdAt', 'actions']; private apiUrl = `${this.baseUrl}/commands`; @@ -80,7 +80,7 @@ export class CommandsComponent implements OnInit { } onPageChange(event: any): void { - this.page = event.pageIndex; + this.page = event.pageIndex === 0 ? 1 : event.pageIndex; this.itemsPerPage = event.pageSize; this.search(); } diff --git a/ogWebconsole/src/app/components/commands/main-commands/create-command/create-command.component.html b/ogWebconsole/src/app/components/commands/main-commands/create-command/create-command.component.html index c228b15..3f31bc8 100644 --- a/ogWebconsole/src/app/components/commands/main-commands/create-command/create-command.component.html +++ b/ogWebconsole/src/app/components/commands/main-commands/create-command/create-command.component.html @@ -22,7 +22,7 @@
- +
diff --git a/ogWebconsole/src/app/components/commands/main-commands/create-command/create-command.component.ts b/ogWebconsole/src/app/components/commands/main-commands/create-command/create-command.component.ts index f4cf673..4733069 100644 --- a/ogWebconsole/src/app/components/commands/main-commands/create-command/create-command.component.ts +++ b/ogWebconsole/src/app/components/commands/main-commands/create-command/create-command.component.ts @@ -33,7 +33,8 @@ export class CreateCommandComponent { }); } - onCancel(): void { + onCancel(event: Event): void { + event.preventDefault(); this.dialogRef.close(); } diff --git a/ogWebconsole/src/app/components/commands/main-commands/detail-command/command-detail.component.html b/ogWebconsole/src/app/components/commands/main-commands/detail-command/command-detail.component.html index 34a38fe..18fdfc7 100644 --- a/ogWebconsole/src/app/components/commands/main-commands/detail-command/command-detail.component.html +++ b/ogWebconsole/src/app/components/commands/main-commands/detail-command/command-detail.component.html @@ -18,7 +18,7 @@ Clientes - + {{ client.name }} @@ -26,7 +26,7 @@ Debes seleccionar al menos un cliente. - + diff --git a/ogWebconsole/src/app/components/commands/main-commands/detail-command/command-detail.component.ts b/ogWebconsole/src/app/components/commands/main-commands/detail-command/command-detail.component.ts index d2cc7d9..59b41c3 100644 --- a/ogWebconsole/src/app/components/commands/main-commands/detail-command/command-detail.component.ts +++ b/ogWebconsole/src/app/components/commands/main-commands/detail-command/command-detail.component.ts @@ -38,6 +38,7 @@ export class CommandDetailComponent implements OnInit { this.http.get('http://127.0.0.1:8001/clients?page=1&itemsPerPage=30').subscribe(response => { this.clients = response['hydra:member']; }); + } execute(): void { @@ -50,11 +51,9 @@ export class CommandDetailComponent implements OnInit { clients: this.form.value.selectedClients.map((uuid: any) => `/clients/${uuid}`) }; - const apiUrl = `${this.baseUrl}/commands/${this.data.command.uuid}/execute`; - + const apiUrl = `${this.baseUrl}/commands/${this.data.uuid}/execute`; this.http.post(apiUrl, payload).subscribe({ next: () => { - console.log('Command executed successfully'); this.dialogRef.close(); this.toastService.success('Command executed successfully'); }, @@ -95,14 +94,13 @@ export class CommandDetailComponent implements OnInit { dialogRef.afterClosed().subscribe(result => { if (result) { - console.log('Comando editado:', result); + this.toastService.success('Comando editado' ); this.data.command = result; } }); } cancel(): void { - console.log('Comando cancelado'); this.dialogRef.close(); } } diff --git a/ogWebconsole/src/app/components/groups/shared/organizational-units/create-organizational-unit/create-organizational-unit.component.html b/ogWebconsole/src/app/components/groups/shared/organizational-units/create-organizational-unit/create-organizational-unit.component.html index 19cce7f..3195b81 100644 --- a/ogWebconsole/src/app/components/groups/shared/organizational-units/create-organizational-unit/create-organizational-unit.component.html +++ b/ogWebconsole/src/app/components/groups/shared/organizational-units/create-organizational-unit/create-organizational-unit.component.html @@ -49,8 +49,6 @@ Aforo - - Calendario Asociado diff --git a/ogWebconsole/src/app/components/groups/shared/organizational-units/edit-organizational-unit/edit-organizational-unit.component.html b/ogWebconsole/src/app/components/groups/shared/organizational-units/edit-organizational-unit/edit-organizational-unit.component.html index f2ff39d..fdadaa5 100644 --- a/ogWebconsole/src/app/components/groups/shared/organizational-units/edit-organizational-unit/edit-organizational-unit.component.html +++ b/ogWebconsole/src/app/components/groups/shared/organizational-units/edit-organizational-unit/edit-organizational-unit.component.html @@ -45,12 +45,24 @@ Aforo + + + +
+ diff --git a/ogWebconsole/src/app/layout/sidebar/sidebar.component.html b/ogWebconsole/src/app/layout/sidebar/sidebar.component.html index 60cbd81..3f8021b 100644 --- a/ogWebconsole/src/app/layout/sidebar/sidebar.component.html +++ b/ogWebconsole/src/app/layout/sidebar/sidebar.component.html @@ -41,6 +41,12 @@ Tareas + + + notifications + Trazas + + diff --git a/ogWebconsole/src/app/shared/delete_modal/delete-modal/delete-modal.component.spec.ts b/ogWebconsole/src/app/shared/delete_modal/delete-modal/delete-modal.component.spec.ts index 30f4266..c304072 100644 --- a/ogWebconsole/src/app/shared/delete_modal/delete-modal/delete-modal.component.spec.ts +++ b/ogWebconsole/src/app/shared/delete_modal/delete-modal/delete-modal.component.spec.ts @@ -1,5 +1,5 @@ import { ComponentFixture, TestBed } from '@angular/core/testing'; - +import { MatDialogRef, MAT_DIALOG_DATA } from '@angular/material/dialog'; import { DeleteModalComponent } from './delete-modal.component'; describe('DeleteModalComponent', () => { @@ -8,16 +8,23 @@ describe('DeleteModalComponent', () => { beforeEach(async () => { await TestBed.configureTestingModule({ - declarations: [DeleteModalComponent] - }) - .compileComponents(); + declarations: [DeleteModalComponent], + providers: [ + { provide: MatDialogRef, useValue: {} }, + { provide: MAT_DIALOG_DATA, useValue: { name: 'Test Name' } } + ] + }).compileComponents(); + }); + beforeEach(() => { fixture = TestBed.createComponent(DeleteModalComponent); component = fixture.componentInstance; fixture.detectChanges(); }); - it('should create', () => { + it('should create the component', () => { expect(component).toBeTruthy(); }); + }); +