refs #1928 Add runScriptContext input to ExecuteCommandComponent and update related components for improved script execution context handling
testing/ogGui-multibranch/pipeline/head There was a failure building this commit
Details
testing/ogGui-multibranch/pipeline/head There was a failure building this commit
Details
parent
e8b713ea09
commit
9582ce338c
|
@ -16,6 +16,7 @@ export class ExecuteCommandComponent implements OnInit {
|
||||||
@Input() buttonText: string = 'Ejecutar Comandos';
|
@Input() buttonText: string = 'Ejecutar Comandos';
|
||||||
@Input() icon: string = 'terminal';
|
@Input() icon: string = 'terminal';
|
||||||
@Input() disabled: boolean = false;
|
@Input() disabled: boolean = false;
|
||||||
|
@Input() runScriptContext: string = '';
|
||||||
baseUrl: string;
|
baseUrl: string;
|
||||||
loading: boolean = true;
|
loading: boolean = true;
|
||||||
|
|
||||||
|
@ -54,40 +55,40 @@ export class ExecuteCommandComponent implements OnInit {
|
||||||
}
|
}
|
||||||
|
|
||||||
private updateCommandStates(): void {
|
private updateCommandStates(): void {
|
||||||
let states: string[] = [];
|
// let states: string[] = [];
|
||||||
|
|
||||||
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) {
|
||||||
command.disabled = command.slug !== 'power-on';
|
// command.disabled = command.slug !== 'power-on';
|
||||||
} else if (allSameState) {
|
// } else if (allSameState) {
|
||||||
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 = !['power-off', 'reboot', 'login', 'create-image', 'deploy-image', 'partition', 'run-script'].includes(command.slug);
|
// command.disabled = !['power-off', 'reboot', 'login', 'create-image', 'deploy-image', 'partition', 'run-script'].includes(command.slug);
|
||||||
}
|
// }
|
||||||
} else {
|
// } else {
|
||||||
if (command.slug === 'create-image') {
|
// if (command.slug === 'create-image') {
|
||||||
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)
|
||||||
) {
|
// ) {
|
||||||
command.disabled = false;
|
// command.disabled = false;
|
||||||
} else {
|
// } else {
|
||||||
command.disabled = true;
|
// command.disabled = true;
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
return command;
|
// return command;
|
||||||
});
|
// });
|
||||||
}
|
}
|
||||||
|
|
||||||
onCommandSelect(action: any): void {
|
onCommandSelect(action: any): void {
|
||||||
|
@ -228,9 +229,12 @@ export class ExecuteCommandComponent implements OnInit {
|
||||||
}));
|
}));
|
||||||
|
|
||||||
this.router.navigate(['/clients/run-script'], {
|
this.router.navigate(['/clients/run-script'], {
|
||||||
queryParams: { clientData: JSON.stringify(clientDataToSend) }
|
queryParams: {
|
||||||
|
clientData: JSON.stringify(clientDataToSend) ,
|
||||||
|
runScriptContext: this.runScriptContext
|
||||||
|
}
|
||||||
}).then(() => {
|
}).then(() => {
|
||||||
console.log('Navigated to run script with data:', clientDataToSend);
|
console.log('Navigated to run script with data:', clientDataToSend, 'runScriptContext:', this.runScriptContext);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
<div class="header-container">
|
<div class="header-container">
|
||||||
<div class="header-container-title">
|
<div class="header-container-title">
|
||||||
<h2>
|
<h2>
|
||||||
{{ 'runScript' | translate }}
|
{{ 'runScript' | translate }} {{this.runScriptContext}}
|
||||||
</h2>
|
</h2>
|
||||||
</div>
|
</div>
|
||||||
<div class="button-row">
|
<div class="button-row">
|
||||||
|
|
|
@ -32,6 +32,7 @@ export class RunScriptAssistantComponent {
|
||||||
newScript: string = '';
|
newScript: string = '';
|
||||||
selection = new SelectionModel(true, []);
|
selection = new SelectionModel(true, []);
|
||||||
parameterNames: string[] = Object.keys(this.parameters);
|
parameterNames: string[] = Object.keys(this.parameters);
|
||||||
|
runScriptContext: string = '';
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
private http: HttpClient,
|
private http: HttpClient,
|
||||||
|
@ -46,6 +47,9 @@ export class RunScriptAssistantComponent {
|
||||||
if (params['clientData']) {
|
if (params['clientData']) {
|
||||||
this.clientData = JSON.parse(params['clientData']);
|
this.clientData = JSON.parse(params['clientData']);
|
||||||
}
|
}
|
||||||
|
if (params['runScriptContext']) {
|
||||||
|
this.runScriptContext = params['runScriptContext'];
|
||||||
|
}
|
||||||
});
|
});
|
||||||
this.clientId = this.clientData?.length ? this.clientData[0]['@id'] : null;
|
this.clientId = this.clientData?.length ? this.clientData[0]['@id'] : null;
|
||||||
this.clientData.forEach((client: { selected: boolean; status: string}) => {
|
this.clientData.forEach((client: { selected: boolean; status: string}) => {
|
||||||
|
|
|
@ -199,7 +199,9 @@
|
||||||
<span>{{ 'delete' | translate }}</span>
|
<span>{{ 'delete' | translate }}</span>
|
||||||
</button>
|
</button>
|
||||||
<app-execute-command [clientData]="selectedNode?.clients || []" [buttonType]="'menu-item'"
|
<app-execute-command [clientData]="selectedNode?.clients || []" [buttonType]="'menu-item'"
|
||||||
[buttonText]="'Ejecutar comandos'" [icon]="'terminal'" [disabled]="!((selectedNode?.clients ?? []).length > 0)">
|
[buttonText]="'Ejecutar comandos'" [icon]="'terminal'"
|
||||||
|
[disabled]="!((selectedNode?.clients ?? []).length > 0)" [runScriptContext]="selectedNode?.name || ''"
|
||||||
|
[runScriptContext]="getRunScriptContext(selectedNode?.clients || [])">
|
||||||
</app-execute-command>
|
</app-execute-command>
|
||||||
</mat-menu>
|
</mat-menu>
|
||||||
</div>
|
</div>
|
||||||
|
@ -217,7 +219,8 @@
|
||||||
</span>
|
</span>
|
||||||
<div class="view-type-container">
|
<div class="view-type-container">
|
||||||
<app-execute-command [clientData]="selection.selected" [buttonType]="'text'"
|
<app-execute-command [clientData]="selection.selected" [buttonType]="'text'"
|
||||||
[buttonText]="'Ejecutar comandos'" [disabled]="selection.selected.length === 0"></app-execute-command>
|
[buttonText]="'Ejecutar comandos'" [disabled]="selection.selected.length === 0"
|
||||||
|
[runScriptContext]="getRunScriptContext(selection.selected)"></app-execute-command>
|
||||||
<mat-button-toggle-group name="viewType" aria-label="View Type" [hideSingleSelectionIndicator]="true"
|
<mat-button-toggle-group name="viewType" aria-label="View Type" [hideSingleSelectionIndicator]="true"
|
||||||
(change)="toggleView($event.value)">
|
(change)="toggleView($event.value)">
|
||||||
<mat-button-toggle value="list" [disabled]="currentView === 'list'">
|
<mat-button-toggle value="list" [disabled]="currentView === 'list'">
|
||||||
|
@ -259,8 +262,10 @@
|
||||||
<span class="client-ip">{{ client.mac }}</span>
|
<span class="client-ip">{{ client.mac }}</span>
|
||||||
<div class="action-icons">
|
<div class="action-icons">
|
||||||
|
|
||||||
<app-execute-command [clientState]="client.status" [clientData]="[client]" [buttonType]="'icon'" [icon]="'terminal'"
|
<app-execute-command [clientState]="client.status" [clientData]="[client]"
|
||||||
[disabled]="selection.selected.length > 1 || (selection.selected.length === 1 && !selection.isSelected(client))"></app-execute-command>
|
[buttonType]="'icon'" [icon]="'terminal'"
|
||||||
|
[disabled]="selection.selected.length > 1 || (selection.selected.length === 1 && !selection.isSelected(client))"
|
||||||
|
[runScriptContext]="getRunScriptContext([client])"></app-execute-command>
|
||||||
|
|
||||||
<button
|
<button
|
||||||
[disabled]="selection.selected.length > 1 || (selection.selected.length === 1 && !selection.isSelected(client))"
|
[disabled]="selection.selected.length > 1 || (selection.selected.length === 1 && !selection.isSelected(client))"
|
||||||
|
@ -394,8 +399,10 @@
|
||||||
mat-icon-button [matMenuTriggerFor]="clientMenu" color="primary">
|
mat-icon-button [matMenuTriggerFor]="clientMenu" color="primary">
|
||||||
<mat-icon>more_vert</mat-icon>
|
<mat-icon>more_vert</mat-icon>
|
||||||
</button>
|
</button>
|
||||||
<app-execute-command [clientState]="client.status" [clientData]="[client]" [buttonType]="'icon'" [icon]="'terminal'"
|
<app-execute-command [clientState]="client.status" [clientData]="[client]" [buttonType]="'icon'"
|
||||||
[disabled]="selection.selected.length > 1 || (selection.selected.length === 1 && !selection.isSelected(client))">
|
[icon]="'terminal'"
|
||||||
|
[disabled]="selection.selected.length > 1 || (selection.selected.length === 1 && !selection.isSelected(client))"
|
||||||
|
[runScriptContext]="getRunScriptContext([client])">
|
||||||
</app-execute-command>
|
</app-execute-command>
|
||||||
<mat-menu #clientMenu="matMenu">
|
<mat-menu #clientMenu="matMenu">
|
||||||
<button mat-menu-item (click)="onEditClick($event, client.type, client.uuid)">
|
<button mat-menu-item (click)="onEditClick($event, client.type, client.uuid)">
|
||||||
|
@ -441,4 +448,4 @@
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
</ng-template>
|
</ng-template>
|
||||||
</div>
|
</div>
|
|
@ -828,4 +828,22 @@ export class GroupsComponent implements OnInit, OnDestroy {
|
||||||
clientSearchStatusInput.value = null;
|
clientSearchStatusInput.value = null;
|
||||||
this.fetchClientsForNode(this.selectedNode);
|
this.fetchClientsForNode(this.selectedNode);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getRunScriptContext(clientData: any[]): string {
|
||||||
|
const selectedClientNames = clientData.map(client => client.name);
|
||||||
|
|
||||||
|
if (clientData.length === 1) {
|
||||||
|
return selectedClientNames[0];
|
||||||
|
} else if (
|
||||||
|
clientData.length === this.selectedClients.data.length &&
|
||||||
|
selectedClientNames.every(name => this.selectedClients.data.some(c => c.name === name))
|
||||||
|
) {
|
||||||
|
return this.selectedNode?.name || '';
|
||||||
|
} else if (clientData.length > 1) {
|
||||||
|
return selectedClientNames.join(', ');
|
||||||
|
} else if (this.selectedNode?.name && clientData.length === 0) {
|
||||||
|
return this.selectedNode.name;
|
||||||
|
}
|
||||||
|
return '';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue