78 lines
2.2 KiB
TypeScript
78 lines
2.2 KiB
TypeScript
// componente
|
|
import { Component, Inject } from '@angular/core';
|
|
import { MatDialogRef, MAT_DIALOG_DATA, MatDialog } from '@angular/material/dialog';
|
|
import { ToastrService } from 'ngx-toastr';
|
|
import { CreatePxeBootFileComponent } from '../../ogboot/pxe-boot-files/create-pxeBootFile/create-pxe-boot-file/create-pxe-boot-file.component';
|
|
import { HttpClient } from '@angular/common/http';
|
|
import { CommandDetailComponent } from '../../commands/command-detail/command-detail/command-detail.component';
|
|
@Component({
|
|
selector: 'app-acctions-modal',
|
|
templateUrl: './acctions-modal.component.html',
|
|
styleUrls: ['./acctions-modal.component.css']
|
|
})
|
|
export class AcctionsModalComponent {
|
|
selectedElements: any;
|
|
commands: any[] = [];
|
|
displayedColumns: string[] = ['name', 'createdBy', 'createdAt'];
|
|
private apiUrl = 'http://127.0.0.1:8001/commands?page=1&itemsPerPage=30';
|
|
|
|
ngOnInit(): void {
|
|
this.loadCommands();
|
|
}
|
|
|
|
loadCommands(): void {
|
|
this.http.get<any>(this.apiUrl).subscribe(
|
|
(data) => {
|
|
this.commands = data['hydra:member'];
|
|
},
|
|
(error) => {
|
|
console.error('Error fetching commands', error);
|
|
}
|
|
);
|
|
}
|
|
|
|
constructor(
|
|
private toastService: ToastrService,
|
|
public dialog: MatDialog,
|
|
private http: HttpClient,
|
|
@Inject(MAT_DIALOG_DATA) public data: any
|
|
) {
|
|
this.selectedElements = data?.selectedElements || [];
|
|
}
|
|
|
|
onSend(): void {
|
|
this.toastService.success('Acción enviada a: ' + this.selectedElements);
|
|
}
|
|
|
|
onPxeBootFile(): void {
|
|
const dialog = this.dialog.open(CreatePxeBootFileComponent, { data: this.selectedElements, width: '400px' });
|
|
dialog.afterClosed().subscribe(() => {
|
|
this.dialog.closeAll();
|
|
});
|
|
}
|
|
|
|
onCommandClick(command: any): void {
|
|
const dialogRef = this.dialog.open(CommandDetailComponent, {
|
|
width: '600px',
|
|
data: {
|
|
command: command,
|
|
importedClients: this.selectedElements
|
|
}
|
|
});
|
|
|
|
dialogRef.afterClosed().subscribe(result => {
|
|
if (result) {
|
|
console.log('Modal cerrado. Resultado:', result);
|
|
}
|
|
});
|
|
}
|
|
|
|
chunkArray(arr: any[], chunkSize: number): any[] {
|
|
const chunks = [];
|
|
for (let i = 0; i < arr.length; i += chunkSize) {
|
|
chunks.push(arr.slice(i, i + chunkSize));
|
|
}
|
|
return chunks;
|
|
}
|
|
}
|