feat: persist deploy post-actions in localStorage
testing/ogGui-multibranch/pipeline/head There was a failure building this commit Details
oggui-debian-package/pipeline/head This commit looks good Details

main
Juan Manuel Bardallo 2026-09-23 13:57:04 +02:00
parent d7d2f9c7be
commit 744e721598
1 changed files with 101 additions and 4 deletions

View File

@ -62,6 +62,11 @@ export class DeployImageComponent implements OnInit {
selectedClients: any[] = [];
selectedModelClient: any = null;
filteredPartitions: any[] = [];
postDeployAction: string = 'none';
selectedPxeTemplate: any = null;
pxePermanent: boolean = false;
pxeTemplates: any[] = [];
allImageRepositories: any[] = [];
loadingAllRepositories: boolean = false;
@ -147,7 +152,37 @@ export class DeployImageComponent implements OnInit {
this.route.queryParams.subscribe(params => {
this.runScriptContext = params['runScriptContext'] ? JSON.parse(params['runScriptContext']) : null;
});
const savedAction = localStorage.getItem('deploy_postDeployAction');
if (savedAction) {
this.postDeployAction = savedAction;
}
const savedPxePermanent = localStorage.getItem('deploy_pxePermanent');
if (savedPxePermanent !== null) {
this.pxePermanent = savedPxePermanent === 'true';
}
this.loadAllRepositories();
this.loadPxeTemplates();
}
loadPxeTemplates() {
this.http.get<any>(`${this.baseUrl}/pxe-templates?page=1&itemsPerPage=10000`).subscribe(
(response: any) => {
this.pxeTemplates = response?.['hydra:member'] || [];
const savedTemplateUuid = localStorage.getItem('deploy_selectedPxeTemplateUuid');
if (savedTemplateUuid && this.postDeployAction === 'pxeTemplate') {
const match = this.pxeTemplates.find(t => t.uuid === savedTemplateUuid);
if (match) {
this.selectedPxeTemplate = match;
}
}
},
(error) => {
console.error('Error loading PXE templates:', error);
}
);
}
loadAllRepositories() {
@ -486,12 +521,10 @@ export class DeployImageComponent implements OnInit {
this.http.post(url, payload)
.subscribe({
next: (response) => {
this.toastService.success(this.translate.instant('deployRequestSentCorrectly'));
this.loading = false;
this.router.navigate(['/commands-logs']);
this.enqueuePostDeployActions();
},
error: (error) => {
this.toastService.error(error.error['hydra:description'], 'Se ha detectado un error en el despliegue de imágenes.', {
this.toastService.error(error.error['hydra:description'] || error.message, 'Se ha detectado un error en el despliegue de imágenes.', {
"closeButton": true,
"newestOnTop": false,
"progressBar": false,
@ -507,12 +540,76 @@ export class DeployImageComponent implements OnInit {
});
}
private enqueuePostDeployActions() {
localStorage.setItem('deploy_postDeployAction', this.postDeployAction);
localStorage.setItem('deploy_pxePermanent', String(this.pxePermanent));
if (this.selectedPxeTemplate?.uuid) {
localStorage.setItem('deploy_selectedPxeTemplateUuid', this.selectedPxeTemplate.uuid);
}
if (this.postDeployAction === 'none') {
this.toastService.success(this.translate.instant('deployRequestSentCorrectly'));
this.loading = false;
this.router.navigate(['/commands-logs']);
return;
}
const clientIds = this.selectedClients.map((c: any) => c.uuid);
if (this.postDeployAction === 'bootOs') {
const disk = this.selectedPartition?.diskNumber || 1;
const part = this.selectedPartition?.partitionNumber || 1;
const payload = {
clients: clientIds,
script: `bootOs ${disk} ${part}`,
queue: true,
runAsAdmin: true
};
this.http.post(`${this.baseUrl}/commands/run-script`, payload).subscribe({
next: () => this.finishPostDeploy(),
error: () => this.finishPostDeployWithError()
});
} else if (this.postDeployAction === 'pxeTemplate' && this.selectedPxeTemplate) {
const mode = this.pxePermanent ? 1 : 0;
const combinedScript = `setBootMode ${this.selectedPxeTemplate.name} ${mode}\nreboot`;
const setBootModePayload = {
clients: clientIds,
script: combinedScript,
queue: true,
runAsAdmin: true
};
this.http.post(`${this.baseUrl}/commands/run-script`, setBootModePayload).subscribe({
next: () => this.finishPostDeploy(),
error: () => this.finishPostDeployWithError()
});
} else {
this.finishPostDeploy();
}
}
private finishPostDeploy() {
this.toastService.success(this.translate.instant('deployRequestSentCorrectly') + ' y post-acciones encoladas.');
this.loading = false;
this.router.navigate(['/commands-logs']);
}
private finishPostDeployWithError() {
this.toastService.error('Se programó el despliegue pero falló al encolar las acciones post-despliegue.');
this.loading = false;
this.router.navigate(['/commands-logs']);
}
isFormValid(): boolean {
const needsPartition = this.deployMode !== 'update-cache';
if (!this.allSelected || !this.selectedModelClient || (needsPartition && !this.selectedPartition)) {
return false;
}
if (this.postDeployAction === 'pxeTemplate' && !this.selectedPxeTemplate) {
return false;
}
if (this.imageType === 'git') {
if (!this.selectedCommit || this.filteredCommits.length === 0) {
return false;