From 558a3205ab06d98224adfba9e44f7ad89be64f22 Mon Sep 17 00:00:00 2001 From: Lucas Lara Date: Mon, 21 Apr 2025 14:56:09 +0200 Subject: [PATCH] refs #1884 Add clientState input to execute-command component for dynamic state handling --- .../execute-command.component.ts | 42 ++++++++++++++++--- .../components/groups/groups.component.html | 4 +- 2 files changed, 39 insertions(+), 7 deletions(-) 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 90af7b0..721a97f 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 @@ -10,6 +10,7 @@ import { ConfigService } from '@services/config.service'; styleUrls: ['./execute-command.component.css'] }) export class ExecuteCommandComponent implements OnInit { + @Input() clientState: string = 'off'; @Input() clientData: any[] = []; @Input() buttonType: 'icon' | 'text' | 'menu-item' = 'icon'; @Input() buttonText: string = 'Ejecutar Comandos'; @@ -45,6 +46,39 @@ export class ExecuteCommandComponent implements OnInit { ngOnInit(): void { this.clientData = this.clientData || []; + this.updateCommandStates(); + } + + ngOnChanges(): void { + this.updateCommandStates(); + } + + private updateCommandStates(): void { + let states: string[] = []; + + if (this.clientData.length > 0) { + states = this.clientData.map(client => client.status); + } else if (this.clientState) { + states = [this.clientState]; + } + + const allOff = states.every(state => state === 'off'); + const allSameState = states.every(state => state === states[0]); + + this.arrayCommands = this.arrayCommands.map(command => { + if (allOff) { + command.disabled = command.slug !== 'power-on'; + } else if (allSameState) { + if (states[0] === 'off') { + command.disabled = command.slug !== 'power-on'; + } else { + command.disabled = command.slug === 'power-on'; + } + } else { + command.disabled = true; + } + return command; + }); } onCommandSelect(action: any): void { @@ -137,7 +171,7 @@ export class ExecuteCommandComponent implements OnInit { const clientDataToSend = this.clientData.map(client => ({ name: client.name, mac: client.mac, - uuid: '/clients/'+client.uuid, + uuid: '/clients/' + client.uuid, status: client.status, partitions: client.partitions, firmwareType: client.firmwareType, @@ -161,7 +195,7 @@ export class ExecuteCommandComponent implements OnInit { const clientDataToSend = this.clientData.map(client => ({ name: client.name, mac: client.mac, - uuid: '/clients/'+client.uuid, + uuid: '/clients/' + client.uuid, status: client.status, partitions: client.partitions, ip: client.ip @@ -178,7 +212,7 @@ export class ExecuteCommandComponent implements OnInit { const clientDataToSend = this.clientData.map(client => ({ name: client.name, mac: client.mac, - uuid: '/clients/'+client.uuid, + uuid: '/clients/' + client.uuid, status: client.status, partitions: client.partitions, ip: client.ip @@ -190,6 +224,4 @@ export class ExecuteCommandComponent implements OnInit { console.log('Navigated to run script with data:', clientDataToSend); }); } - - } diff --git a/ogWebconsole/src/app/components/groups/groups.component.html b/ogWebconsole/src/app/components/groups/groups.component.html index 116dbc3..95db6c5 100644 --- a/ogWebconsole/src/app/components/groups/groups.component.html +++ b/ogWebconsole/src/app/components/groups/groups.component.html @@ -260,7 +260,7 @@ {{ client.mac }}
- -