diff --git a/ogWebconsole/src/app/components/pxe/pxe/edit-pxe-template/edit-pxe-template.component.html b/ogWebconsole/src/app/components/pxe/pxe/edit-pxe-template/edit-pxe-template.component.html
index 30f1ce4..7f8d038 100644
--- a/ogWebconsole/src/app/components/pxe/pxe/edit-pxe-template/edit-pxe-template.component.html
+++ b/ogWebconsole/src/app/components/pxe/pxe/edit-pxe-template/edit-pxe-template.component.html
@@ -1,51 +1,24 @@
-
Editar Plantilla PXE
-
-
-
-
-
-
-
-
- Vista previa y guardar
- {{ previewContent }}
-
-
-
-
-
-
+
diff --git a/ogWebconsole/src/app/components/pxe/pxe/edit-pxe-template/edit-pxe-template.component.ts b/ogWebconsole/src/app/components/pxe/pxe/edit-pxe-template/edit-pxe-template.component.ts
index 343aaa5..d53b03b 100644
--- a/ogWebconsole/src/app/components/pxe/pxe/edit-pxe-template/edit-pxe-template.component.ts
+++ b/ogWebconsole/src/app/components/pxe/pxe/edit-pxe-template/edit-pxe-template.component.ts
@@ -1,112 +1,53 @@
import { HttpClient } from '@angular/common/http';
-import { Component, Inject } from '@angular/core';
+import { Component, Inject, OnInit } from '@angular/core';
import { FormGroup, FormBuilder, Validators } from '@angular/forms';
import { MatDialogRef, MAT_DIALOG_DATA } from '@angular/material/dialog';
@Component({
selector: 'app-edit-pxe-template',
templateUrl: './edit-pxe-template.component.html',
- styleUrl: './edit-pxe-template.component.css'
+ styleUrls: ['./edit-pxe-template.component.css'] // Corregido para 'styleUrls' plural
})
-export class EditPxeTemplateComponent {
- firstFormGroup!: FormGroup;
- secondFormGroup!: FormGroup;
- previewContent: string = '';
+export class EditPxeTemplateComponent implements OnInit {
+ templateForm!: FormGroup;
constructor(
private fb: FormBuilder,
private http: HttpClient,
public dialogRef: MatDialogRef,
@Inject(MAT_DIALOG_DATA) public data: any
- ) { }
+ ) {}
ngOnInit(): void {
- this.firstFormGroup = this.fb.group({
- name: [this.data.name, Validators.required],
- });
-
- const parsedContent = this.parseTemplateContent(this.data.templateContent);
- this.secondFormGroup = this.fb.group({
- timeout: [parsedContent.timeout, Validators.required],
- timeoutStyle: [parsedContent.timeoutStyle, Validators.required],
- isoDir: [parsedContent.isoDir, Validators.required],
- kernelArgs: [parsedContent.kernelArgs, Validators.required],
- });
-
- this.updatePreviewContent();
- this.secondFormGroup.valueChanges.subscribe(() => {
- this.updatePreviewContent();
+ // Configuración del formulario con los campos requeridos
+ console.log(this.data);
+ this.templateForm = this.fb.group({
+ name: [this.data.name || '', Validators.required], // Utilizar datos existentes o cadena vacía
+ templateContent: [this.data.templateContent || '', Validators.required]
});
}
- parseTemplateContent(templateContent: string): any {
- const lines = templateContent.split('\n');
- let timeout = '';
- let timeoutStyle = '';
- let isoDir = '';
- let kernelArgs = '';
-
- lines.forEach(line => {
- if (line.startsWith('set timeout ')) {
- timeout = line.replace('set timeout ', '').trim();
- } else if (line.startsWith('set timeout-style ')) {
- timeoutStyle = line.replace('set timeout-style ', '').trim();
- } else if (line.startsWith('set ISODIR ')) {
- isoDir = line.replace('set ISODIR ', '').trim();
- } else if (line.startsWith('set kernelargs ')) {
- kernelArgs = line.replace('set kernelargs ', '').trim();
- }
- });
-
- return { timeout, timeoutStyle, isoDir, kernelArgs };
- }
-
- updatePreviewContent(): void {
- const { timeout, timeoutStyle, isoDir, kernelArgs } = this.secondFormGroup.value;
- this.previewContent = `
-#!ipxe
-set timeout ${timeout}
-set timeout-style ${timeoutStyle}
-
-set ISODIR ${isoDir}
-set kernelargs ${kernelArgs}
-# Menú de entrada para seleccionar OgLive
-
-:try_iso
-kernel http://SERVERIP/tftpboot/\${ISODIR}/ogvmlinuz \${kernelargs} || goto fallback
-initrd http://SERVERIP/tftpboot/\${ISODIR}/oginitrd.img
-boot
-
-:fallback
-echo "OgLive default"
-set ISODIR ogLive
-kernel http://SERVERIP/tftpboot/\${ISODIR}/ogvmlinuz \${kernelargs}
-initrd http://SERVERIP/tftpboot/\${ISODIR}/oginitrd.img
-boot
- `;
- }
-
- onEdit(): void {
- if (this.firstFormGroup.valid && this.secondFormGroup.valid) {
+ onCreate(): void {
+ if (this.templateForm.valid) {
const updatedTemplate = {
- name: this.firstFormGroup.value.name,
- templateContent: "this.previewContent.trim()",
+ name: this.templateForm.value.name,
+ templateContent: this.templateForm.value.templateContent
};
this.http.patch(`http://127.0.0.1:8080/pxe-templates/${this.data.uuid}`, updatedTemplate)
.subscribe({
next: () => {
console.log('Plantilla actualizada correctamente');
- this.dialogRef.close(true);
+ this.dialogRef.close(true); // Cerrar el diálogo con éxito
},
error: (error) => {
- console.error('Error al actualizar la plantilla:', error);
+ console.error('Error al actualizar la plantilla:', error); // Manejo de errores
}
});
}
}
onCancel(): void {
- this.dialogRef.close();
+ this.dialogRef.close(); // Cerrar el diálogo sin cambios
}
}