183 lines
5.2 KiB
TypeScript
183 lines
5.2 KiB
TypeScript
import { Component } from '@angular/core';
|
|
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";
|
|
|
|
@Component({
|
|
selector: 'app-pxe-boot-files',
|
|
templateUrl: './pxe-boot-files.component.html',
|
|
styleUrl: './pxe-boot-files.component.css'
|
|
})
|
|
export class PxeBootFilesComponent {
|
|
pxeTemplates: any[] = []; // Inicializa el array de plantillas
|
|
currentPage: number = 1;
|
|
dataSource = new MatTableDataSource<any>();
|
|
length: number = 0;
|
|
alertMessage: string | null = null;
|
|
itemsPerPage: number = 10;
|
|
page: number = 1;
|
|
pageSizeOptions: number[] = [5, 10, 20, 40, 100];
|
|
datePipe: DatePipe = new DatePipe('es-ES');
|
|
selectedElements: string[] = [];
|
|
columns = [
|
|
{
|
|
columnDef: 'id',
|
|
header: 'ID',
|
|
cell: (user: any) => `${user.id}`
|
|
},
|
|
{
|
|
columnDef: 'templateName',
|
|
header: 'Nombre de la plantilla',
|
|
cell: (user: any) => `${user.template.name}`
|
|
},
|
|
{
|
|
columnDef: 'clients',
|
|
header: 'Clientes',
|
|
cell: (user: any) => user.clients
|
|
},
|
|
{
|
|
columnDef: 'createdAt',
|
|
header: 'Fecha de creación',
|
|
cell: (user: any) => `${this.datePipe.transform(user.createdAt, 'dd/MM/yyyy hh:mm:ss')}`
|
|
}
|
|
];
|
|
displayedColumns = [...this.columns.map(column => column.columnDef), 'actions'];
|
|
|
|
private apiUrl = 'http://127.0.0.1:8080/pxe-boot-files';
|
|
|
|
constructor(
|
|
public dialog: MatDialog,
|
|
private http: HttpClient,
|
|
private toastService: ToastrService
|
|
)
|
|
{ }
|
|
|
|
ngOnInit(): void {
|
|
this.loadPxeBootFiles();
|
|
this.loadAlert();
|
|
}
|
|
|
|
loadPxeBootFiles(): void {
|
|
this.http.get<any>(`${this.apiUrl}?page=1&itemsPerPage=${this.itemsPerPage}`).subscribe({
|
|
next: (response) => {
|
|
this.dataSource.data = response['hydra:member'];
|
|
this.length = response['hydra:totalItems'];
|
|
console.log('Plantillas PXE cargadas:', this.pxeTemplates);
|
|
},
|
|
error: error => {
|
|
console.error('Error al cargar plantillas PXE:', error);
|
|
}
|
|
});
|
|
}
|
|
|
|
addPxeTemplate() {
|
|
const dialogRef = this.dialog.open(CreatePxeTemplateComponent, {
|
|
});
|
|
|
|
dialogRef.afterClosed().subscribe(() => {
|
|
this.loadPxeBootFiles();
|
|
});
|
|
}
|
|
|
|
showPxeInfo(template: any) {
|
|
|
|
}
|
|
|
|
toggleAction(image: any, action:string): void {
|
|
switch (action) {
|
|
case 'create':
|
|
this.http.post(`${this.apiUrl}/server/${image.uuid}/post`, {}).subscribe({
|
|
next: () => {
|
|
console.log('Plantilla cambiada');
|
|
this.loadPxeBootFiles();
|
|
},
|
|
error: (error) => {
|
|
console.error('Error al cambiar la imagen:', error);
|
|
}
|
|
});
|
|
break;
|
|
case 'delete':
|
|
this.http.post(`${this.apiUrl}/server/${image.uuid}/delete`, {}).subscribe({
|
|
next: () => {
|
|
console.log('Plantilla cambiada');
|
|
this.loadPxeBootFiles();
|
|
},
|
|
error: (error) => {
|
|
console.error('Error al cambiar la imagen:', error);
|
|
}
|
|
});
|
|
break;
|
|
default:
|
|
console.error('Acción no soportada:', action);
|
|
break;
|
|
}
|
|
}
|
|
|
|
deletePxeTemplate(uuid: string) {
|
|
// Lógica para eliminar una plantilla
|
|
}
|
|
|
|
editPxeTemplate(template: any) {
|
|
const dialogRef = this.dialog.open(EditPxeTemplateComponent, {
|
|
data: template
|
|
});
|
|
|
|
dialogRef.afterClosed().subscribe(() => {
|
|
this.loadPxeBootFiles();
|
|
});
|
|
}
|
|
|
|
applyFilter() {
|
|
this.http.get<any>(`${this.apiUrl}?page=${this.page}&itemsPerPage=${this.itemsPerPage}`).subscribe({
|
|
next: (response) => {
|
|
this.dataSource.data = response['hydra:member'];
|
|
this.length = response['hydra:totalItems'];
|
|
},
|
|
error: (error) => {
|
|
console.error('Error al cargar las imágenes:', error);
|
|
}
|
|
});
|
|
}
|
|
|
|
onPageChange(event: PageEvent) {
|
|
this.page = event.pageIndex;
|
|
this.itemsPerPage = event.pageSize;
|
|
this.applyFilter();
|
|
}
|
|
|
|
loadAlert() {
|
|
this.http.get(`${this.apiUrl}/server/get-collection`)
|
|
.subscribe(response => {
|
|
// @ts-ignore
|
|
this.alertMessage = response.templates.length
|
|
}, error => {
|
|
console.error('Error al cargar la información del alert', error);
|
|
});
|
|
}
|
|
|
|
getIcon(): { name: string, color: string } {
|
|
if (Number(this.alertMessage) === this.length) {
|
|
return { name: 'check_circle', color: 'green' }; // Icono de check verde
|
|
} else {
|
|
return { name: 'cancel', color: 'red' }; // Icono de cruz roja
|
|
}
|
|
}
|
|
|
|
syncOgCore(): void {
|
|
this.http.post(`${this.apiUrl}/sync`, {})
|
|
.subscribe(response => {
|
|
this.toastService.success('Sincronización completada');
|
|
this.loadPxeBootFiles()
|
|
}, error => {
|
|
console.error('Error al sincronizar', error);
|
|
this.toastService.error('Error al sincronizar');
|
|
});
|
|
}
|
|
|
|
}
|