diff --git a/ogWebconsole/src/app/components/commands/main-commands/commands.component.html b/ogWebconsole/src/app/components/commands/main-commands/commands.component.html index d529f48..74d1e2b 100644 --- a/ogWebconsole/src/app/components/commands/main-commands/commands.component.html +++ b/ogWebconsole/src/app/components/commands/main-commands/commands.component.html @@ -31,9 +31,11 @@ {{ column.cell(command) }} + - check - close + + {{ command[column.columnDef] ? 'check_circle' : 'cancel' }} + @@ -41,7 +43,6 @@ {{ 'columnActions' | translate }} - 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 903b606..a2ca53b 100644 --- a/ogWebconsole/src/app/components/commands/main-commands/commands.component.ts +++ b/ogWebconsole/src/app/components/commands/main-commands/commands.component.ts @@ -50,7 +50,7 @@ export class CommandsComponent implements OnInit { displayedColumns = [...this.columns.map(column => column.columnDef), 'actions']; private apiUrl = `${this.baseUrl}/commands`; - constructor(private http: HttpClient, private dialog: MatDialog, private toastService: ToastrService, + constructor(private http: HttpClient, private dialog: MatDialog, private toastService: ToastrService, private joyrideService: JoyrideService) {} ngOnInit(): void { @@ -114,19 +114,6 @@ export class CommandsComponent implements OnInit { }); } - executeCommand(event: MouseEvent, command: any): void { - this.dialog.open(ExecuteCommandComponent, { - width: '50%', - data: { commandData: command } - }).afterClosed().subscribe((result) => { - if (result) { - console.log('Comando ejecutado con éxito'); - } else { - console.log('Ejecución de comando cancelada'); - } - }); - } - onPageChange(event: any): void { this.page = event.pageIndex; this.itemsPerPage = event.pageSize; @@ -147,5 +134,5 @@ export class CommandsComponent implements OnInit { themeColor: '#3f51b5' }); } - + } diff --git a/ogWebconsole/src/app/components/commands/main-commands/execute-command/execute-command.component.html b/ogWebconsole/src/app/components/commands/main-commands/execute-command/execute-command.component.html index 5aada00..cabc939 100644 --- a/ogWebconsole/src/app/components/commands/main-commands/execute-command/execute-command.component.html +++ b/ogWebconsole/src/app/components/commands/main-commands/execute-command/execute-command.component.html @@ -1,40 +1,10 @@ -

{{ 'executeCommandTitle' | translate }}

+ - -
- - - {{ 'organizationalUnitLabel' | translate }} - - {{ unit.name }} - - + + + - - {{ 'subOrganizationalUnitLabel' | translate }} - - {{ child.name }} - - - -
- -
- - {{ client.name }} - -
-
-

{{ 'noClientsAvailable' | translate }}

-
-
- -
-
- - - - - diff --git a/ogWebconsole/src/app/components/commands/main-commands/execute-command/execute-command.component.ts b/ogWebconsole/src/app/components/commands/main-commands/execute-command/execute-command.component.ts index ceeaf2c..59cbabc 100644 --- a/ogWebconsole/src/app/components/commands/main-commands/execute-command/execute-command.component.ts +++ b/ogWebconsole/src/app/components/commands/main-commands/execute-command/execute-command.component.ts @@ -1,7 +1,9 @@ -import { Component, Inject, OnInit } from '@angular/core'; -import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material/dialog'; +import {Component, Inject, Input, OnInit} from '@angular/core'; +import {MAT_DIALOG_DATA, MatDialog, MatDialogRef} from '@angular/material/dialog'; import { HttpClient } from '@angular/common/http'; import { FormBuilder, FormGroup } from '@angular/forms'; +import {Router} from "@angular/router"; +import {ToastrService} from "ngx-toastr"; @Component({ selector: 'app-execute-command', @@ -9,92 +11,129 @@ import { FormBuilder, FormGroup } from '@angular/forms'; styleUrls: ['./execute-command.component.css'] }) export class ExecuteCommandComponent implements OnInit { - form: FormGroup; - units: any[] = []; - childUnits: any[] = []; - clients: any[] = []; - selectedClients: any[] = []; + @Input() clientData: any = {}; baseUrl: string = import.meta.env.NG_APP_BASE_API_URL; + loading: boolean = true; + + arrayCommands: any[] = [ + {name: 'Enceder', slug: 'power-on', disabled: false}, + {name: 'Apagar', slug: 'power-off', disabled: false}, + {name: 'Reiniciar', slug: 'reboot', disabled: false}, + {name: 'Iniciar Sesión', slug: 'login', disabled: true}, + {name: 'Crear Image', slug: 'create-image', disabled: false}, + {name: 'Deploy Image', slug: 'deploy-image', disabled: false}, + {name: 'Eliminar Imagen Cache', slug: 'delete-image-cache', disabled: true}, + {name: 'Particionar y Formatear', slug: 'partition', disabled: false}, + {name: 'Inventario Software', slug: 'software-inventory', disabled: true}, + {name: 'Inventario Hardware', slug: 'hardware-inventory', disabled: true}, + {name: 'Ejecutar script', slug: 'run-script', disabled: true}, + ]; constructor( - private dialogRef: MatDialogRef, - @Inject(MAT_DIALOG_DATA) public data: any, + private dialog: MatDialog, private http: HttpClient, - private fb: FormBuilder + private fb: FormBuilder, + private router: Router, + private toastService: ToastrService ) { - this.form = this.fb.group({ - unit: [null], - childUnit: [null], - clientSelection: [[]] - }); } ngOnInit(): void { - this.loadUnits(); - this.form.get('unit')?.valueChanges.subscribe(value => this.onUnitChange(value)); - this.form.get('childUnit')?.valueChanges.subscribe(value => this.onChildUnitChange(value)); + this.clientData = this.clientData || {}; + this.loadClient(this.clientData) } - loadUnits(): void { - this.http.get(`${this.baseUrl}/organizational-units?page=1&itemsPerPage=30`).subscribe( - response => { - this.units = response['hydra:member'].filter((unit: { type: string; }) => unit.type === 'organizational-unit'); + loadClient = (uuid: string) => { + this.http.get(`${this.baseUrl}${uuid}`).subscribe({ + next: data => { + this.clientData = data; + this.loading = false; }, - error => console.error('Error fetching organizational units:', error) + error: error => { + console.error('Error al obtener el cliente:', error); + } + }); + } + + onCommandSelect(action: any): void { + if (action === 'partition') { + this.openPartitionAssistant(); + } + + if (action === 'create-image') { + this.openCreateImageAssistant(); + } + + if (action === 'deploy-image') { + this.openDeployImageAssistant(); + } + + if (action === 'reboot') { + this.rebootClient(); + } + + if (action === 'power-off') { + this.powerOffClient(); + } + + if (action === 'power-on') { + this.powerOnClient(); + } + } + + rebootClient(): void { + this.http.post(`${this.baseUrl}/clients/server/${this.clientData.uuid}/reboot`, {}).subscribe( + response => { + this.toastService.success('Cliente actualizado correctamente'); + }, + error => { + this.toastService.error('Error de conexión con el cliente'); + } ); } - onUnitChange(unitId: string): void { - const unit = this.units.find(unit => unit.uuid === unitId); - this.childUnits = unit ? this.getAllChildren(unit) : []; - this.clients = []; - this.form.patchValue({ childUnit: null, clientSelection: [] }); - } - - getAllChildren(unit: any): any[] { - let allChildren = []; - if (unit.children && unit.children.length > 0) { - for (const child of unit.children) { - allChildren.push(child); - allChildren = allChildren.concat(this.getAllChildren(child)); - } - } - return allChildren; - } - - onChildUnitChange(childUnitId: string): void { - const childUnit = this.childUnits.find(unit => unit.uuid === childUnitId); - this.clients = childUnit && childUnit.clients ? childUnit.clients : []; - this.form.patchValue({ clientSelection: [] }); - } - - executeCommand(): void { + powerOnClient(): void { const payload = { - clients: ['/clients/'+this.form.get('clientSelection')?.value] - }; - - this.http.post(`${this.baseUrl}/commands/${this.data.commandData.uuid}/execute`, payload) - .subscribe({ - next: () => { - console.log('Comando ejecutado con éxito'); - this.dialogRef.close(true); - }, - error: (error) => { - console.error('Error al ejecutar el comando:', error); - } - }); - } - - closeModal(): void { - this.dialogRef.close(false); - } - - toggleClientSelection(clientId: string): void { - const selectedClients = this.form.get('clientSelection')?.value; - if (selectedClients.includes(clientId)) { - this.form.get('clientSelection')?.setValue(selectedClients.filter((id: string) => id !== clientId)); - } else { - this.form.get('clientSelection')?.setValue([...selectedClients, clientId]); + client: this.clientData['@id'] } + + this.http.post(`${this.baseUrl}${this.clientData.repository['@id']}/wol`, payload).subscribe( + response => { + this.toastService.success('Cliente actualizado correctamente'); + }, + error => { + this.toastService.error('Error de conexión con el cliente'); + } + ); } + + powerOffClient(): void { + this.http.post(`${this.baseUrl}/clients/server/${this.clientData.uuid}/power-off`, {}).subscribe( + response => { + this.toastService.success('Cliente actualizado correctamente'); + }, + error => { + this.toastService.error('Error de conexión con el cliente'); + } + ); + } + + openPartitionAssistant(): void { + this.router.navigate([`/clients/${this.clientData.uuid}/partition-assistant`]).then(r => { + console.log('navigated', r); + }); + } + + openCreateImageAssistant(): void { + this.router.navigate([`/clients/${this.clientData.uuid}/create-image`]).then(r => { + console.log('navigated', r); + }); + } + + openDeployImageAssistant(): void { + this.router.navigate([`/clients/${this.clientData.uuid}/deploy-image`]).then(r => { + console.log('navigated', r); + }); + } + } diff --git a/ogWebconsole/src/app/components/groups/components/client-main-view/client-main-view.component.ts b/ogWebconsole/src/app/components/groups/components/client-main-view/client-main-view.component.ts index 7599633..29db234 100644 --- a/ogWebconsole/src/app/components/groups/components/client-main-view/client-main-view.component.ts +++ b/ogWebconsole/src/app/components/groups/components/client-main-view/client-main-view.component.ts @@ -122,6 +122,7 @@ export class ClientMainViewComponent implements OnInit { } }); } + updateGeneralData() { this.generalData = [ { property: 'Nombre', value: this.clientData?.name || '' }, diff --git a/ogWebconsole/src/app/components/groups/components/client-main-view/deploy-image/deploy-image.component.ts b/ogWebconsole/src/app/components/groups/components/client-main-view/deploy-image/deploy-image.component.ts index 17404a7..e5dc0c5 100644 --- a/ogWebconsole/src/app/components/groups/components/client-main-view/deploy-image/deploy-image.component.ts +++ b/ogWebconsole/src/app/components/groups/components/client-main-view/deploy-image/deploy-image.component.ts @@ -187,7 +187,6 @@ export class DeployImageComponent { .subscribe({ next: (response) => { this.toastService.success('Petición de despliegue enviada correctamente'); - this.router.navigate(['/commands-logs']) }, error: (error) => { console.error('Error:', error); diff --git a/ogWebconsole/src/app/components/groups/groups.component.html b/ogWebconsole/src/app/components/groups/groups.component.html index a697a88..960dff5 100644 --- a/ogWebconsole/src/app/components/groups/groups.component.html +++ b/ogWebconsole/src/app/components/groups/groups.component.html @@ -166,10 +166,6 @@ - - + @@ -245,7 +239,6 @@ [src]="'assets/images/ordenador_' + client.status + '.png'" alt="Client Icon" class="client-image" /> -
@@ -299,25 +292,14 @@ {{ client.parentName }} - + {{ 'actions' | translate }} + - - - - - - -