From 2bc17e8b568c0254df5a36a572449416c2f6756c Mon Sep 17 00:00:00 2001 From: Lucas Lara Date: Thu, 24 Apr 2025 14:09:54 +0200 Subject: [PATCH] Refactor updateCommandStates method in ExecuteCommandComponent: restore and optimize command state management logic for improved functionality --- .../execute-command.component.ts | 62 +++++++++---------- 1 file changed, 31 insertions(+), 31 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 cd63c1e..e459e66 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 @@ -55,40 +55,40 @@ export class ExecuteCommandComponent implements OnInit { } private updateCommandStates(): void { - // let states: string[] = []; + let states: string[] = []; - // if (this.clientData.length > 0) { - // states = this.clientData.map(client => client.status); - // } else if (this.clientState) { - // states = [this.clientState]; - // } + if (this.clientData.length > 0) { + states = this.clientData.map(client => client.status); + } else if (this.clientState) { + states = [this.clientState]; + } - // const allOffOrDisconnected = states.every(state => state === 'off' || state === 'disconnected'); - // const allSameState = states.every(state => state === states[0]); - // const multipleClients = this.clientData.length > 1; + const allOffOrDisconnected = states.every(state => state === 'off' || state === 'disconnected'); + const allSameState = states.every(state => state === states[0]); + const multipleClients = this.clientData.length > 1; - // this.arrayCommands = this.arrayCommands.map(command => { - // if (allOffOrDisconnected) { - // command.disabled = command.slug !== 'power-on'; - // } else if (allSameState) { - // if (states[0] === 'off' || states[0] === 'disconnected') { - // command.disabled = command.slug !== 'power-on'; - // } else { - // command.disabled = !['power-off', 'reboot', 'login', 'create-image', 'deploy-image', 'partition', 'run-script'].includes(command.slug); - // } - // } else { - // if (command.slug === 'create-image') { - // command.disabled = multipleClients; - // } else if ( - // ['power-on', 'power-off', 'reboot', 'login', 'deploy-image', 'partition', 'run-script'].includes(command.slug) - // ) { - // command.disabled = false; - // } else { - // command.disabled = true; - // } - // } - // return command; - // }); + this.arrayCommands = this.arrayCommands.map(command => { + if (allOffOrDisconnected) { + command.disabled = command.slug !== 'power-on'; + } else if (allSameState) { + if (states[0] === 'off' || states[0] === 'disconnected') { + command.disabled = command.slug !== 'power-on'; + } else { + command.disabled = !['power-off', 'reboot', 'login', 'create-image', 'deploy-image', 'partition', 'run-script'].includes(command.slug); + } + } else { + if (command.slug === 'create-image') { + command.disabled = multipleClients; + } else if ( + ['power-on', 'power-off', 'reboot', 'login', 'deploy-image', 'partition', 'run-script'].includes(command.slug) + ) { + command.disabled = false; + } else { + command.disabled = true; + } + } + return command; + }); } onCommandSelect(action: any): void {