refs #1884 Refactor command state handling to improve client status management and enable/disable commands based on client states
testing/ogGui-multibranch/pipeline/head This commit looks good
Details
testing/ogGui-multibranch/pipeline/head This commit looks good
Details
parent
6621f7a8fe
commit
a418d26615
|
@ -55,41 +55,49 @@ export class ExecuteCommandComponent implements OnInit {
|
||||||
|
|
||||||
private updateCommandStates(): void {
|
private updateCommandStates(): void {
|
||||||
let states: string[] = [];
|
let states: string[] = [];
|
||||||
|
|
||||||
|
// Obtener los estados de los clientes
|
||||||
if (this.clientData.length > 0) {
|
if (this.clientData.length > 0) {
|
||||||
states = this.clientData.map(client => client.status);
|
states = this.clientData.map(client => client.status);
|
||||||
} else if (this.clientState) {
|
} else if (this.clientState) {
|
||||||
states = [this.clientState];
|
states = [this.clientState];
|
||||||
}
|
}
|
||||||
|
|
||||||
const allOffOrDisconnected = states.every(state => state === 'off' || state === 'disconnected');
|
const allOffOrDisconnected = states.every(state => state === 'off' || state === 'disconnected');
|
||||||
const allSameState = states.every(state => state === states[0]);
|
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 => {
|
this.arrayCommands = this.arrayCommands.map(command => {
|
||||||
if (allOffOrDisconnected) {
|
if (allOffOrDisconnected) {
|
||||||
|
// Si todos los clientes están apagados o desconectados, solo habilitar "Encender"
|
||||||
command.disabled = command.slug !== 'power-on';
|
command.disabled = command.slug !== 'power-on';
|
||||||
} else if (allSameState) {
|
} else if (allSameState) {
|
||||||
|
// Si todos los clientes tienen el mismo estado
|
||||||
if (states[0] === 'off' || states[0] === 'disconnected') {
|
if (states[0] === 'off' || states[0] === 'disconnected') {
|
||||||
command.disabled = command.slug !== 'power-on';
|
command.disabled = command.slug !== 'power-on';
|
||||||
} else {
|
} 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 {
|
} else {
|
||||||
|
// Si los estados son distintos
|
||||||
if (command.slug === 'create-image') {
|
if (command.slug === 'create-image') {
|
||||||
|
// "Crear imagen" solo está habilitado para un único cliente
|
||||||
command.disabled = multipleClients;
|
command.disabled = multipleClients;
|
||||||
} else if (
|
} else if (
|
||||||
['power-on', 'power-off', 'reboot', 'login', 'deploy-image', 'partition', 'run-script'].includes(command.slug)
|
['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;
|
command.disabled = false;
|
||||||
} else {
|
} else {
|
||||||
|
// Deshabilitar otros comandos
|
||||||
command.disabled = true;
|
command.disabled = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return command;
|
return command;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
onCommandSelect(action: any): void {
|
onCommandSelect(action: any): void {
|
||||||
if (action === 'partition') {
|
if (action === 'partition') {
|
||||||
this.openPartitionAssistant();
|
this.openPartitionAssistant();
|
||||||
|
|
Loading…
Reference in New Issue