From a418d2661511efb619213d609180785dc8065a07 Mon Sep 17 00:00:00 2001 From: Lucas Lara Date: Tue, 22 Apr 2025 13:19:22 +0200 Subject: [PATCH] refs #1884 Refactor command state handling to improve client status management and enable/disable commands based on client states --- .../execute-command.component.ts | 20 +++++++++++++------ 1 file changed, 14 insertions(+), 6 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 6ebe109..5824047 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,41 +55,49 @@ export class ExecuteCommandComponent implements OnInit { private updateCommandStates(): void { let states: string[] = []; - + + // Obtener los estados de los clientes 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 multipleClients = this.clientData.length > 1; + this.arrayCommands = this.arrayCommands.map(command => { if (allOffOrDisconnected) { + // Si todos los clientes están apagados o desconectados, solo habilitar "Encender" command.disabled = command.slug !== 'power-on'; } else if (allSameState) { + // Si todos los clientes tienen el mismo estado if (states[0] === 'off' || states[0] === 'disconnected') { command.disabled = command.slug !== 'power-on'; } else { - command.disabled = command.slug === 'power-on'; + // Habilitar comandos específicos para un cliente que no está apagado ni desconectado + command.disabled = !['reboot', 'login', 'deploy-image', 'partition', 'run-script'].includes(command.slug); } } else { + // Si los estados son distintos if (command.slug === 'create-image') { + // "Crear imagen" solo está habilitado para un único cliente command.disabled = multipleClients; } else if ( ['power-on', 'power-off', 'reboot', 'login', 'deploy-image', 'partition', 'run-script'].includes(command.slug) ) { + // Habilitar los comandos permitidos cuando los estados son distintos command.disabled = false; } else { + // Deshabilitar otros comandos command.disabled = true; } } return command; }); } - + onCommandSelect(action: any): void { if (action === 'partition') { this.openPartitionAssistant();