diff --git a/ogWebconsole/src/app/app.module.ts b/ogWebconsole/src/app/app.module.ts
index 9d6c5ea..9e965d8 100644
--- a/ogWebconsole/src/app/app.module.ts
+++ b/ogWebconsole/src/app/app.module.ts
@@ -71,11 +71,9 @@ import { SaveFiltersDialogComponent } from './components/groups/save-filters-dia
import { AcctionsModalComponent } from './components/groups/acctions-modal/acctions-modal.component';
import { ImagesComponent } from './components/ogboot/images/images.component';
import { CreateImageComponent } from './components/ogboot/images/create-image/create-image/create-image.component';
-import { EditImageComponent } from './components/ogboot/images/edit-image/edit-image/edit-image.component';
import { InfoImageComponent } from './components/ogboot/images/info-image/info-image/info-image.component';
import { PxeComponent } from './components/ogboot/pxe/pxe.component';
import { CreatePxeTemplateComponent } from './components/ogboot/pxe/create-pxeTemplate/create-pxe-template.component';
-import { EditPxeTemplateComponent } from './components/ogboot/pxe/edit-pxe-template/edit-pxe-template.component';
import { PxeBootFilesComponent } from './components/ogboot/pxe-boot-files/pxe-boot-files.component';
import {MatExpansionPanel, MatExpansionPanelDescription, MatExpansionPanelTitle} from "@angular/material/expansion";
import { OgbootStatusComponent } from './components/ogboot/ogboot-status/ogboot-status.component';
@@ -117,11 +115,9 @@ import { CreateSubnetComponent } from './components/ogdhcp/og-dhcp-subnets/creat
AcctionsModalComponent,
ImagesComponent,
CreateImageComponent,
- EditImageComponent,
InfoImageComponent,
PxeComponent,
CreatePxeTemplateComponent,
- EditPxeTemplateComponent,
PxeBootFilesComponent,
OgbootStatusComponent,
CreatePxeBootFileComponent,
diff --git a/ogWebconsole/src/app/components/ogboot/images/create-image/create-image/create-image.component.html b/ogWebconsole/src/app/components/ogboot/images/create-image/create-image/create-image.component.html
index e875b4e..6ea7556 100644
--- a/ogWebconsole/src/app/components/ogboot/images/create-image/create-image/create-image.component.html
+++ b/ogWebconsole/src/app/components/ogboot/images/create-image/create-image/create-image.component.html
@@ -1,4 +1,4 @@
-
Añadir imagen ogLive
+{{ isEditMode ? 'Editar' : 'Añadir' }} imagen ogLive
Nombre
@@ -14,6 +14,6 @@
-
-
+
+
diff --git a/ogWebconsole/src/app/components/ogboot/images/create-image/create-image/create-image.component.ts b/ogWebconsole/src/app/components/ogboot/images/create-image/create-image/create-image.component.ts
index e7ca971..0726926 100644
--- a/ogWebconsole/src/app/components/ogboot/images/create-image/create-image/create-image.component.ts
+++ b/ogWebconsole/src/app/components/ogboot/images/create-image/create-image/create-image.component.ts
@@ -12,6 +12,8 @@ export class CreateImageComponent implements OnInit {
name: string = '';
downloads: any[] = [];
selectedDownload: any;
+ isEditMode: boolean = false;
+ imageId: string | null = null;
constructor(
private toastService: ToastrService,
@@ -22,6 +24,12 @@ export class CreateImageComponent implements OnInit {
ngOnInit(): void {
this.fetchDownloads();
+ if (this.data) {
+ this.isEditMode = true;
+ this.name = this.data.name;
+ this.selectedDownload = this.data.downloadUrl;
+ this.imageId = this.data.uuid; // Assuming UUID is used for edit
+ }
}
fetchDownloads(): void {
@@ -35,30 +43,42 @@ export class CreateImageComponent implements OnInit {
this.toastService.error('Error fetching iso files');
}
});
-
}
onNoClick(): void {
this.dialogRef.close();
}
- addOgLive(): void {
+ submitForm(): void {
const payload = {
name: this.name,
downloadUrl: this.selectedDownload.URL
};
- this.http.post('http://127.0.0.1:8080/og-lives', payload)
- .subscribe({
- next: (response) => {
- console.log('Success:', response);
- this.toastService.success('Image created successfully');
- this.dialogRef.close();
- },
- error: (error) => {
- console.error('Error:', error);
- this.toastService.error('Error creating image');
- }
- });
+ if (this.isEditMode && this.imageId) {
+ this.http.patch(`http://127.0.0.1:8080/og-lives/${this.imageId}`, payload)
+ .subscribe({
+ next: (response) => {
+ this.toastService.success('Image updated successfully');
+ this.dialogRef.close(true);
+ },
+ error: (error) => {
+ console.error('Error:', error);
+ this.toastService.error('Error updating image');
+ }
+ });
+ } else {
+ this.http.post('http://127.0.0.1:8080/og-lives', payload)
+ .subscribe({
+ next: (response) => {
+ this.toastService.success('Image created successfully');
+ this.dialogRef.close(true);
+ },
+ error: (error) => {
+ console.error('Error:', error);
+ this.toastService.error('Error creating image');
+ }
+ });
+ }
}
}
diff --git a/ogWebconsole/src/app/components/ogboot/images/edit-image/edit-image/edit-image.component.css b/ogWebconsole/src/app/components/ogboot/images/edit-image/edit-image/edit-image.component.css
deleted file mode 100644
index 16289b6..0000000
--- a/ogWebconsole/src/app/components/ogboot/images/edit-image/edit-image/edit-image.component.css
+++ /dev/null
@@ -1,16 +0,0 @@
-.form-container {
- display: flex;
- flex-direction: column;
- gap: 16px; /* Espacio entre los campos */
-}
-
-.form-field {
- width: 100%; /* Para que cada campo ocupe todo el ancho disponible */
-}
-
-.actions-container {
- display: flex;
- justify-content: flex-end;
- gap: 8px; /* Espacio entre los botones */
- margin-top: 16px; /* Separación superior para los botones */
-}
diff --git a/ogWebconsole/src/app/components/ogboot/images/edit-image/edit-image/edit-image.component.html b/ogWebconsole/src/app/components/ogboot/images/edit-image/edit-image/edit-image.component.html
deleted file mode 100644
index d19e0df..0000000
--- a/ogWebconsole/src/app/components/ogboot/images/edit-image/edit-image/edit-image.component.html
+++ /dev/null
@@ -1,15 +0,0 @@
-Editar Imagen
-
-
- Nombre
-
-
-
- URL de descarga
-
-
-
-
-
-
-
diff --git a/ogWebconsole/src/app/components/ogboot/images/edit-image/edit-image/edit-image.component.spec.ts b/ogWebconsole/src/app/components/ogboot/images/edit-image/edit-image/edit-image.component.spec.ts
deleted file mode 100644
index b8e13f2..0000000
--- a/ogWebconsole/src/app/components/ogboot/images/edit-image/edit-image/edit-image.component.spec.ts
+++ /dev/null
@@ -1,23 +0,0 @@
-import { ComponentFixture, TestBed } from '@angular/core/testing';
-
-import { EditImageComponent } from './edit-image.component';
-
-describe('EditImageComponent', () => {
- let component: EditImageComponent;
- let fixture: ComponentFixture;
-
- beforeEach(async () => {
- await TestBed.configureTestingModule({
- declarations: [EditImageComponent]
- })
- .compileComponents();
-
- fixture = TestBed.createComponent(EditImageComponent);
- component = fixture.componentInstance;
- fixture.detectChanges();
- });
-
- it('should create', () => {
- expect(component).toBeTruthy();
- });
-});
diff --git a/ogWebconsole/src/app/components/ogboot/images/edit-image/edit-image/edit-image.component.ts b/ogWebconsole/src/app/components/ogboot/images/edit-image/edit-image/edit-image.component.ts
deleted file mode 100644
index ae63460..0000000
--- a/ogWebconsole/src/app/components/ogboot/images/edit-image/edit-image/edit-image.component.ts
+++ /dev/null
@@ -1,52 +0,0 @@
-import { HttpClient } from '@angular/common/http';
-import { Component, Inject } from '@angular/core';
-import { MatDialogRef, MAT_DIALOG_DATA } from '@angular/material/dialog';
-import { ToastrService } from 'ngx-toastr';
-
-@Component({
- selector: 'app-edit-image',
- templateUrl: './edit-image.component.html',
- styleUrls: ['./edit-image.component.css']
-})
-export class EditImageComponent {
- name: string = '';
- downloadUrl: string = '';
-
- constructor(
- private toastService: ToastrService,
- private http: HttpClient,
- public dialogRef: MatDialogRef,
- @Inject(MAT_DIALOG_DATA) public data: any
- ) {
- // Rellenar los campos con los datos recibidos
- if (data) {
- this.name = data.name;
- this.downloadUrl = data.downloadUrl;
- }
- }
-
- onNoClick(): void {
- this.dialogRef.close();
- }
-
- editOgLive(): void {
- const payload = {
- name: this.name,
- downloadUrl: this.downloadUrl
- };
-
- // Realizar PATCH para editar la imagen
- this.http.patch(`http://127.0.0.1:8080/og-lives/${this.data.uuid}`, payload)
- .subscribe({
- next: (response) => {
- console.log('Success:', response);
- this.toastService.success('Image updated successfully');
- this.dialogRef.close();
- },
- error: (error) => {
- console.error('Error:', error);
- this.toastService.error('Error updating image');
- }
- });
- }
-}
diff --git a/ogWebconsole/src/app/components/ogboot/images/images.component.ts b/ogWebconsole/src/app/components/ogboot/images/images.component.ts
index 1ce2ab0..500b619 100644
--- a/ogWebconsole/src/app/components/ogboot/images/images.component.ts
+++ b/ogWebconsole/src/app/components/ogboot/images/images.component.ts
@@ -2,7 +2,6 @@ import {Component, OnInit, signal} from '@angular/core';
import { MatDialog } from '@angular/material/dialog';
import { HttpClient } from '@angular/common/http';
import { CreateImageComponent } from './create-image/create-image/create-image.component';
-import { EditImageComponent } from './edit-image/edit-image/edit-image.component';
import { InfoImageComponent } from './info-image/info-image/info-image.component';
import { MatTableDataSource } from "@angular/material/table";
import {PageEvent} from "@angular/material/paginator";
@@ -158,17 +157,18 @@ export class ImagesComponent implements OnInit {
}
editImage(image: any): void {
- const dialogRef = this.dialog.open(EditImageComponent, {
+ const dialogRef = this.dialog.open(CreateImageComponent, {
width: '700px',
data: image
});
-
+
dialogRef.afterClosed().subscribe(result => {
if (result) {
this.search();
}
});
}
+
applyFilter() {
this.http.get(`${this.apiUrl}?page=${this.page}&itemsPerPage=${this.itemsPerPage}`).subscribe({
diff --git a/ogWebconsole/src/app/components/ogboot/pxe-boot-files/create-pxeBootFile/create-pxe-boot-file/create-pxe-boot-file.component.html b/ogWebconsole/src/app/components/ogboot/pxe-boot-files/create-pxeBootFile/create-pxe-boot-file/create-pxe-boot-file.component.html
index bd58857..6c1fbc2 100644
--- a/ogWebconsole/src/app/components/ogboot/pxe-boot-files/create-pxeBootFile/create-pxe-boot-file/create-pxe-boot-file.component.html
+++ b/ogWebconsole/src/app/components/ogboot/pxe-boot-files/create-pxeBootFile/create-pxe-boot-file/create-pxe-boot-file.component.html
@@ -1,21 +1,20 @@
-
Añadir Cliente
-
-
- Seleccione una plantilla PXE
-
-
- {{ template.name }}
-
-
-
-
-
- Clientes: {{ getClientesNames() }}
-
-
-
-
-
+
{{ isEditMode ? 'Editar Cliente' : 'Añadir Cliente' }}
+
+
+ Seleccione una plantilla PXE
+
+
+ {{ template.name }}
+
+
+
-
\ No newline at end of file
+
+ Clientes: {{ getClientesNames() }}
+
+
+
+
+
+
diff --git a/ogWebconsole/src/app/components/ogboot/pxe-boot-files/create-pxeBootFile/create-pxe-boot-file/create-pxe-boot-file.component.ts b/ogWebconsole/src/app/components/ogboot/pxe-boot-files/create-pxeBootFile/create-pxe-boot-file/create-pxe-boot-file.component.ts
index 0419b69..ae04295 100644
--- a/ogWebconsole/src/app/components/ogboot/pxe-boot-files/create-pxeBootFile/create-pxe-boot-file/create-pxe-boot-file.component.ts
+++ b/ogWebconsole/src/app/components/ogboot/pxe-boot-files/create-pxeBootFile/create-pxe-boot-file/create-pxe-boot-file.component.ts
@@ -1,6 +1,5 @@
import { HttpClient } from '@angular/common/http';
-import { Component, Inject } from '@angular/core';
-
+import { Component, Inject, OnInit } from '@angular/core';
import { ToastrService } from 'ngx-toastr';
import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material/dialog';
@@ -9,27 +8,34 @@ import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material/dialog';
templateUrl: './create-pxe-boot-file.component.html',
styleUrls: ['./create-pxe-boot-file.component.css']
})
-export class CreatePxeBootFileComponent {
+export class CreatePxeBootFileComponent implements OnInit {
pxeTemplates: any[] = [];
selectedPxeTemplate: string | undefined;
clientes: string[] = [];
selectedElements: any;
+ isEditMode: boolean = false;
constructor(
private toastService: ToastrService,
private http: HttpClient,
private dialogRef: MatDialogRef,
- @Inject(MAT_DIALOG_DATA) public data: string[]
+ @Inject(MAT_DIALOG_DATA) public data: { clients: any[], bootFile?: any }
) {}
ngOnInit(): void {
- this.selectedElements = this.data;
- this.clientes = this.selectedElements.map((client: { uuid: any; }) => `/clients/${client.uuid}`);
+ this.selectedElements = this.data.clients;
+ this.clientes = this.selectedElements.map((client: { uuid: any }) => `/clients/${client.uuid}`);
this.loadPxeTemplates();
+
+ // Configura el modo de edición si se proporciona bootFile
+ if (this.data.bootFile) {
+ this.isEditMode = true;
+ this.selectedPxeTemplate = this.data.bootFile.template.uuid;
+ }
}
getClientesNames(): string {
- return this.selectedElements.map((client: { name: any; }) => client.name).join(', ');
+ return this.selectedElements.map((client: { name: any }) => client.name).join(', ');
}
loadPxeTemplates(): void {
@@ -45,25 +51,39 @@ export class CreatePxeBootFileComponent {
this.dialogRef.close();
}
- onAdd(): void {
+ onSave(): void {
if (this.selectedPxeTemplate) {
const payload = {
template: `/pxe-templates/${this.selectedPxeTemplate}`,
clients: this.clientes
};
- console.log('Payload FINAAAL:', payload);
- this.http.post('http://127.0.0.1:8080/pxe-boot-files', payload)
- .subscribe({
- next: response => {
- this.toastService.success('PXE asignado con éxito');
- this.dialogRef.close();
- },
- error: error => {
- this.toastService.error('Error enviando el payload', error);
- }
- });
+
+ if (this.isEditMode && this.data.bootFile) {
+ // Edit mode: Actualizar boot file existente
+ this.http.put(`http://127.0.0.1:8080/pxe-boot-files/${this.data.bootFile.uuid}`, payload)
+ .subscribe({
+ next: response => {
+ this.toastService.success('PXE actualizado con éxito');
+ this.dialogRef.close(true);
+ },
+ error: error => {
+ this.toastService.error('Error al actualizar el PXE', error);
+ }
+ });
+ } else {
+ // Create mode: Crear nuevo boot file
+ this.http.post('http://127.0.0.1:8080/pxe-boot-files', payload)
+ .subscribe({
+ next: response => {
+ this.toastService.success('PXE asignado con éxito');
+ this.dialogRef.close(true);
+ },
+ error: error => {
+ this.toastService.error('Error enviando el payload', error);
+ }
+ });
+ }
} else {
- console.error('No se ha seleccionado ninguna plantilla PXE');
this.toastService.error('No se ha seleccionado ninguna plantilla PXE');
}
}
diff --git a/ogWebconsole/src/app/components/ogboot/pxe-boot-files/pxe-boot-files.component.ts b/ogWebconsole/src/app/components/ogboot/pxe-boot-files/pxe-boot-files.component.ts
index b4350b1..ac7d13b 100644
--- a/ogWebconsole/src/app/components/ogboot/pxe-boot-files/pxe-boot-files.component.ts
+++ b/ogWebconsole/src/app/components/ogboot/pxe-boot-files/pxe-boot-files.component.ts
@@ -3,7 +3,6 @@ import {MatTableDataSource} from "@angular/material/table";
import {MatDialog} from "@angular/material/dialog";
import {HttpClient} from "@angular/common/http";
import { CreatePxeTemplateComponent } from '../pxe/create-pxeTemplate/create-pxe-template.component';
-import { EditPxeTemplateComponent } from '../pxe/edit-pxe-template/edit-pxe-template.component';
import {PageEvent} from "@angular/material/paginator";
import {ToastrService} from "ngx-toastr";
import {DatePipe} from "@angular/common";
@@ -123,7 +122,7 @@ export class PxeBootFilesComponent {
}
editPxeTemplate(template: any) {
- const dialogRef = this.dialog.open(EditPxeTemplateComponent, {
+ const dialogRef = this.dialog.open(CreatePxeTemplateComponent, {
data: template
});
@@ -132,6 +131,21 @@ export class PxeBootFilesComponent {
});
}
+ /* editPxeBootFile(bootFile: any) {
+ const dialogRef = this.dialog.open(CreatePxeBootFileComponent, {
+ data: {
+ clients: bootFile.clients,
+ bootFile: bootFile
+ }
+ });
+
+ dialogRef.afterClosed().subscribe(result => {
+ if (result) {
+ this.loadPxeBootFiles(); // Refrescar la lista después de la edición
+ }
+ });
+ } */
+
applyFilter() {
this.http.get(`${this.apiUrl}?page=${this.page}&itemsPerPage=${this.itemsPerPage}`).subscribe({
next: (response) => {
diff --git a/ogWebconsole/src/app/components/ogboot/pxe/create-pxeTemplate/create-pxe-template.component.html b/ogWebconsole/src/app/components/ogboot/pxe/create-pxeTemplate/create-pxe-template.component.html
index 43c9137..757ea95 100644
--- a/ogWebconsole/src/app/components/ogboot/pxe/create-pxeTemplate/create-pxe-template.component.html
+++ b/ogWebconsole/src/app/components/ogboot/pxe/create-pxeTemplate/create-pxe-template.component.html
@@ -1,5 +1,6 @@
-
diff --git a/ogWebconsole/src/app/components/ogboot/pxe/create-pxeTemplate/create-pxe-template.component.ts b/ogWebconsole/src/app/components/ogboot/pxe/create-pxeTemplate/create-pxe-template.component.ts
index 05a5927..708b190 100644
--- a/ogWebconsole/src/app/components/ogboot/pxe/create-pxeTemplate/create-pxe-template.component.ts
+++ b/ogWebconsole/src/app/components/ogboot/pxe/create-pxeTemplate/create-pxe-template.component.ts
@@ -1,44 +1,81 @@
import { HttpClient } from '@angular/common/http';
-import { Component } from '@angular/core';
+import { Component, Inject, OnInit } from '@angular/core';
import { FormGroup, FormBuilder, Validators } from '@angular/forms';
-import { MatDialogRef } from '@angular/material/dialog';
+import { MatDialogRef, MAT_DIALOG_DATA } from '@angular/material/dialog';
+import { ToastrService } from 'ngx-toastr';
@Component({
selector: 'app-create-pxe-template',
templateUrl: './create-pxe-template.component.html',
styleUrls: ['./create-pxe-template.component.css']
})
-export class CreatePxeTemplateComponent {
+export class CreatePxeTemplateComponent implements OnInit {
templateForm!: FormGroup;
previewContent: string = '';
+ isEditMode: boolean = false;
constructor(
public dialogRef: MatDialogRef,
private http: HttpClient,
- private fb: FormBuilder
+ private fb: FormBuilder,
+ private toastService: ToastrService,
+ @Inject(MAT_DIALOG_DATA) public data: any
) {}
ngOnInit() {
+ this.isEditMode = !!this.data; // Verifica si hay datos inyectados (modo edición)
+
this.templateForm = this.fb.group({
- name: ['', Validators.required],
- templateContent: ['', Validators.required]
+ name: [this.data?.name || '', Validators.required],
+ templateContent: [this.data?.templateContent || '', Validators.required]
});
}
- onCreate(): void {
+ onSave(): void {
+ if (this.isEditMode) {
+ this.updatePxeTemplate();
+ } else {
+ this.createPxeTemplate();
+ }
+ }
+
+ createPxeTemplate(): void {
const formValues = this.templateForm.value;
const payload = {
name: formValues.name,
templateContent: formValues.templateContent
};
- console.log(payload);
+
this.http.post('http://127.0.0.1:8080/pxe-templates', payload).subscribe({
next: data => {
console.log('Plantilla PXE creada:', data);
+ this.toastService.success('Plantilla PXE creada exitosamente');
this.dialogRef.close(true);
},
error: error => {
console.error('Error al crear la plantilla PXE:', error);
+ this.toastService.error('Error al crear la plantilla PXE');
+ this.dialogRef.close(false);
+ }
+ });
+ }
+
+ updatePxeTemplate(): void {
+ const formValues = this.templateForm.value;
+ const payload = {
+ name: formValues.name,
+ templateContent: formValues.templateContent
+ };
+
+ this.http.patch(`http://127.0.0.1:8080/pxe-templates/${this.data.uuid}`, payload).subscribe({
+ next: data => {
+ console.log('Plantilla PXE actualizada:', data);
+ this.toastService.success('Plantilla PXE actualizada exitosamente');
+ this.dialogRef.close(true);
+ },
+ error: error => {
+ console.error('Error al actualizar la plantilla PXE:', error);
+ this.toastService.error('Error al actualizar la plantilla PXE');
this.dialogRef.close(false);
}
});
diff --git a/ogWebconsole/src/app/components/ogboot/pxe/edit-pxe-template/edit-pxe-template.component.css b/ogWebconsole/src/app/components/ogboot/pxe/edit-pxe-template/edit-pxe-template.component.css
deleted file mode 100644
index d56d90c..0000000
--- a/ogWebconsole/src/app/components/ogboot/pxe/edit-pxe-template/edit-pxe-template.component.css
+++ /dev/null
@@ -1,52 +0,0 @@
-form {
- max-width: 600px;
- margin: 20px auto;
- padding: 20px;
-}
-
-mat-form-field {
- width: 100%;
- margin-bottom: 20px;
-}
-
-pre {
- background-color: #eceff1;
- padding: 15px;
- border-radius: 4px;
- white-space: pre-wrap;
- word-wrap: break-word;
- font-size: 0.9rem;
- color: #333;
-}
-
-mat-dialog-actions {
- margin-top: 20px;
- display: flex;
- justify-content: flex-end;
-}
-
-button {
- margin-left: 10px;
-}
-
-button[type="submit"] {
- background-color: #3f51b5;
- color: #fff;
-}
-
-button[type="submit"]:disabled {
- background-color: #c5cae9;
-}
-
-h2 {
- margin-bottom: 20px;
- font-size: 1.5rem;
- color: #000000;
- text-align: center;
-}
-
-h3 {
- margin-top: 30px;
- font-size: 1.2rem;
- color: #000000;
-}
diff --git a/ogWebconsole/src/app/components/ogboot/pxe/edit-pxe-template/edit-pxe-template.component.html b/ogWebconsole/src/app/components/ogboot/pxe/edit-pxe-template/edit-pxe-template.component.html
deleted file mode 100644
index 7f8d038..0000000
--- a/ogWebconsole/src/app/components/ogboot/pxe/edit-pxe-template/edit-pxe-template.component.html
+++ /dev/null
@@ -1,24 +0,0 @@
-
diff --git a/ogWebconsole/src/app/components/ogboot/pxe/edit-pxe-template/edit-pxe-template.component.spec.ts b/ogWebconsole/src/app/components/ogboot/pxe/edit-pxe-template/edit-pxe-template.component.spec.ts
deleted file mode 100644
index 64f507e..0000000
--- a/ogWebconsole/src/app/components/ogboot/pxe/edit-pxe-template/edit-pxe-template.component.spec.ts
+++ /dev/null
@@ -1,23 +0,0 @@
-import { ComponentFixture, TestBed } from '@angular/core/testing';
-
-import { EditPxeTemplateComponent } from './edit-pxe-template.component';
-
-describe('EditPxeTemplateComponent', () => {
- let component: EditPxeTemplateComponent;
- let fixture: ComponentFixture;
-
- beforeEach(async () => {
- await TestBed.configureTestingModule({
- declarations: [EditPxeTemplateComponent]
- })
- .compileComponents();
-
- fixture = TestBed.createComponent(EditPxeTemplateComponent);
- component = fixture.componentInstance;
- fixture.detectChanges();
- });
-
- it('should create', () => {
- expect(component).toBeTruthy();
- });
-});
diff --git a/ogWebconsole/src/app/components/ogboot/pxe/edit-pxe-template/edit-pxe-template.component.ts b/ogWebconsole/src/app/components/ogboot/pxe/edit-pxe-template/edit-pxe-template.component.ts
deleted file mode 100644
index f13c4e7..0000000
--- a/ogWebconsole/src/app/components/ogboot/pxe/edit-pxe-template/edit-pxe-template.component.ts
+++ /dev/null
@@ -1,52 +0,0 @@
-import { HttpClient } from '@angular/common/http';
-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',
- styleUrls: ['./edit-pxe-template.component.css']
-})
-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 {
- console.log(this.data);
- this.templateForm = this.fb.group({
- name: [this.data.name || '', Validators.required],
- templateContent: [this.data.templateContent || '', Validators.required]
- });
- }
-
- onCreate(): void {
- if (this.templateForm.valid) {
- const updatedTemplate = {
- 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);
- },
- error: (error) => {
- console.error('Error al actualizar la plantilla:', error);
- }
- });
- }
- }
-
- onCancel(): void {
- this.dialogRef.close();
- }
-}
diff --git a/ogWebconsole/src/app/components/ogboot/pxe/pxe.component.ts b/ogWebconsole/src/app/components/ogboot/pxe/pxe.component.ts
index ee6e2ec..86ead24 100644
--- a/ogWebconsole/src/app/components/ogboot/pxe/pxe.component.ts
+++ b/ogWebconsole/src/app/components/ogboot/pxe/pxe.component.ts
@@ -1,19 +1,18 @@
import { HttpClient } from '@angular/common/http';
import { Component } from '@angular/core';
-import { CreatePxeTemplateComponent } from './create-pxeTemplate/create-pxe-template.component';
+import { CreatePxeTemplateComponent } from './create-pxeTemplate/create-pxe-template.component'; // Asegúrate de que el path sea correcto
import { MatDialog } from '@angular/material/dialog';
-import { EditPxeTemplateComponent } from './edit-pxe-template/edit-pxe-template.component';
-import {MatTableDataSource} from "@angular/material/table";
-import {PageEvent} from "@angular/material/paginator";
-import {ToastrService} from "ngx-toastr";
-import {DatePipe} from "@angular/common";
+import { MatTableDataSource } from '@angular/material/table';
+import { PageEvent } from '@angular/material/paginator';
+import { ToastrService } from 'ngx-toastr';
+import { DatePipe } from '@angular/common';
import { DeleteModalComponent } from '../../../shared/delete_modal/delete-modal/delete-modal.component';
-import {DataService} from "./data.service";
+import { DataService } from './data.service';
@Component({
selector: 'app-pxe',
templateUrl: './pxe.component.html',
- styleUrl: './pxe.component.css'
+ styleUrls: ['./pxe.component.css']
})
export class PxeComponent {
pxeTemplates: any[] = [];
@@ -24,8 +23,8 @@ export class PxeComponent {
page: number = 1;
pageSizeOptions: number[] = [5, 10, 20, 40, 100];
selectedElements: string[] = [];
- loading:boolean = false;
- searchTerm: string = ''
+ loading: boolean = false;
+ searchTerm: string = '';
alertMessage: string | null = null;
datePipe: DatePipe = new DatePipe('es-ES');
selectedItem: any = null;
@@ -64,7 +63,7 @@ export class PxeComponent {
) { }
ngOnInit(): void {
- this.search()
+ this.search();
this.loadAlert();
}
@@ -92,13 +91,23 @@ export class PxeComponent {
});
}
+ editPxeTemplate(template: any) {
+ const dialogRef = this.dialog.open(CreatePxeTemplateComponent, {
+ data: template, // Pasa los datos del template para edición
+ width: '600px'
+ });
+
+ dialogRef.afterClosed().subscribe(() => {
+ this.search();
+ });
+ }
+
showPxeInfo(template: any) {
this.selectedItem = template;
-
this.previewContent = template.templateContent;
}
- toggleAction(image: any, action:string): void {
+ toggleAction(image: any, action: string): void {
switch (action) {
case 'create':
this.http.post(`${this.apiUrl}/server/${image.uuid}/post`, {}).subscribe({
@@ -129,17 +138,6 @@ export class PxeComponent {
}
}
- editPxeTemplate(template: any) {
- const dialogRef = this.dialog.open(EditPxeTemplateComponent, {
- data: template,
- width: '600px'
- });
-
- dialogRef.afterClosed().subscribe(() => {
- this.search();
- });
- }
-
applyFilter() {
this.http.get(`${this.apiUrl}?page=${this.page}&itemsPerPage=${this.itemsPerPage}`).subscribe({
next: (response) => {
@@ -180,7 +178,7 @@ export class PxeComponent {
this.http.post(`${this.apiUrl}/sync`, {})
.subscribe(response => {
this.toastService.success('Sincronización completada');
- this.search()
+ this.search();
}, error => {
console.error('Error al sincronizar', error);
this.toastService.error('Error al sincronizar');
diff --git a/ogWebconsole/src/app/components/ogdhcp/og-dhcp-subnets/create-subnet/create-subnet/create-subnet.component.html b/ogWebconsole/src/app/components/ogdhcp/og-dhcp-subnets/create-subnet/create-subnet/create-subnet.component.html
index c3ff12a..a99f009 100644
--- a/ogWebconsole/src/app/components/ogdhcp/og-dhcp-subnets/create-subnet/create-subnet/create-subnet.component.html
+++ b/ogWebconsole/src/app/components/ogdhcp/og-dhcp-subnets/create-subnet/create-subnet/create-subnet.component.html
@@ -1,4 +1,4 @@
-Añadir configuración de red
+{{ isEditMode ? 'Editar' : 'Añadir' }} configuración de red
Nombre
@@ -23,5 +23,5 @@
-
+
diff --git a/ogWebconsole/src/app/components/ogdhcp/og-dhcp-subnets/create-subnet/create-subnet/create-subnet.component.ts b/ogWebconsole/src/app/components/ogdhcp/og-dhcp-subnets/create-subnet/create-subnet/create-subnet.component.ts
index 8853c6f..9980986 100644
--- a/ogWebconsole/src/app/components/ogdhcp/og-dhcp-subnets/create-subnet/create-subnet/create-subnet.component.ts
+++ b/ogWebconsole/src/app/components/ogdhcp/og-dhcp-subnets/create-subnet/create-subnet/create-subnet.component.ts
@@ -1,3 +1,4 @@
+// create-subnet.component.ts
import { HttpClient } from '@angular/common/http';
import { Component, Inject, OnInit } from '@angular/core';
import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material/dialog';
@@ -14,23 +15,31 @@ export class CreateSubnetComponent implements OnInit {
ipAddress: string = '';
nextServer: string = '';
bootFileName: string = '';
+ isEditMode: boolean = false;
constructor(
private toastService: ToastrService,
private http: HttpClient,
public dialogRef: MatDialogRef,
- @Inject(MAT_DIALOG_DATA) public data: any
+ @Inject(MAT_DIALOG_DATA) public data: any
) { }
ngOnInit(): void {
-
+ if (this.data && this.data.subnet) {
+ this.isEditMode = true;
+ this.name = this.data.subnet.name;
+ this.netmask = this.data.subnet.netmask;
+ this.ipAddress = this.data.subnet.ipAddress;
+ this.nextServer = this.data.subnet.nextServer;
+ this.bootFileName = this.data.subnet.bootFileName;
+ }
}
onNoClick(): void {
this.dialogRef.close();
}
- addNetworkConfig(): void {
+ submitForm(): void {
const payload = {
name: this.name,
netmask: this.netmask,
@@ -39,17 +48,32 @@ export class CreateSubnetComponent implements OnInit {
bootFileName: this.bootFileName
};
- this.http.post('http://127.0.0.1:8080/subnets', payload)
- .subscribe({
- next: (response) => {
- console.log('Success:', response);
- this.toastService.success('Configuración de red añadida exitosamente');
- this.dialogRef.close();
- },
- error: (error) => {
- console.error('Error:', error);
- this.toastService.error('Error al añadir la configuración de red');
- }
- });
+ if (this.isEditMode) {
+ this.http.patch(`http://127.0.0.1:8080/subnets/${this.data.subnet.uuid}`, payload)
+ .subscribe({
+ next: (response) => {
+ console.log('Success:', response);
+ this.toastService.success('Configuración de red actualizada exitosamente');
+ this.dialogRef.close();
+ },
+ error: (error) => {
+ console.error('Error:', error);
+ this.toastService.error('Error al actualizar la configuración de red');
+ }
+ });
+ } else {
+ this.http.post('http://127.0.0.1:8080/subnets', payload)
+ .subscribe({
+ next: (response) => {
+ console.log('Success:', response);
+ this.toastService.success('Configuración de red añadida exitosamente');
+ this.dialogRef.close();
+ },
+ error: (error) => {
+ console.error('Error:', error);
+ this.toastService.error('Error al añadir la configuración de red');
+ }
+ });
+ }
}
}