Refactor updateCommandStates method in ExecuteCommandComponent: restore and optimize command state management logic for improved functionality
testing/ogGui-multibranch/pipeline/head There was a failure building this commit Details

develop
Lucas Lara García 2025-04-24 14:09:54 +02:00
parent 9582ce338c
commit 2bc17e8b56
1 changed files with 31 additions and 31 deletions

View File

@ -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 {