141 lines
5.0 KiB
TypeScript
141 lines
5.0 KiB
TypeScript
import { inject } from '@angular/core';
|
|
import { TranslateService } from '@ngx-translate/core';
|
|
import { Component, Inject, OnInit } from '@angular/core';
|
|
import { MatTableDataSource } from "@angular/material/table";
|
|
import { ToastrService } from "ngx-toastr";
|
|
import { HttpClient } from "@angular/common/http";
|
|
import { MAT_DIALOG_DATA, MatDialog, MatDialogRef } from "@angular/material/dialog";
|
|
import { ConfigService } from "@services/config.service";
|
|
import { CreateTaskScheduleComponent } from "../create-task-schedule/create-task-schedule.component";
|
|
import { CreateTaskScriptComponent } from "../create-task-script/create-task-script.component";
|
|
import { DeleteModalComponent } from "../../../../shared/delete_modal/delete-modal/delete-modal.component";
|
|
import { ViewParametersModalComponent } from "./view-parameters-modal/view-parameters-modal.component";
|
|
|
|
@Component({
|
|
selector: 'app-show-task-script',
|
|
templateUrl: './show-task-script.component.html',
|
|
styleUrl: './show-task-script.component.css'
|
|
})
|
|
export class ShowTaskScriptComponent implements OnInit {
|
|
public translate = inject(TranslateService);
|
|
baseUrl: string;
|
|
dataSource = new MatTableDataSource<any>([]);
|
|
length = 0;
|
|
itemsPerPage: number = 10;
|
|
pageSizeOptions: number[] = [5, 10, 20];
|
|
page = 0;
|
|
loading: boolean = false;
|
|
filters: { [key: string]: string } = {};
|
|
|
|
columns = [
|
|
{ columnDef: 'id', header: 'labelId', cell: (item: any) => item.id },
|
|
{ columnDef: 'order', header: 'labelOrder', cell: (item: any) => item.order },
|
|
{ columnDef: 'type', header: 'labelType', cell: (item: any) => item.type },
|
|
{ columnDef: 'parameters', header: 'labelParameters', cell: (item: any) => item.parameters },
|
|
{ columnDef: 'content', header: 'labelContent', cell: (item: any) => item.content },
|
|
];
|
|
|
|
displayedColumns: string[] = ['order', 'type', 'content', 'parameters', 'actions'];
|
|
|
|
typeLabels: { [key: string]: { label: string, icon: string } } = {
|
|
'partition-and-format': { label: this.translate.instant('partitionAndFormat'), icon: 'storage' },
|
|
'partition-assistant': { label: this.translate.instant('partitionTitle'), icon: 'storage' },
|
|
'deploy-image': { label: this.translate.instant('displayImage'), icon: 'cloud_download' },
|
|
'create-image': { label: this.translate.instant('createImage'), icon: 'cloud_upload' },
|
|
'run-script': { label: this.translate.instant('runScript'), icon: 'code' },
|
|
'reboot': { label: 'Reiniciar', icon: 'restart_alt' },
|
|
'shutdown': { label: 'Apagar', icon: 'power_off' },
|
|
'poweron': { label: 'Encender', icon: 'power' },
|
|
'power-on': { label: 'Encender', icon: 'power' },
|
|
'login': { label: this.translate.instant('login'), icon: 'login' },
|
|
};
|
|
|
|
getTypeDisplay(type: string): { label: string, icon: string } {
|
|
return this.typeLabels[type] || { label: type, icon: 'play_arrow' };
|
|
}
|
|
|
|
constructor(
|
|
private toastService: ToastrService,
|
|
private http: HttpClient,
|
|
public dialogRef: MatDialogRef<ShowTaskScriptComponent>,
|
|
public dialog: MatDialog,
|
|
private configService: ConfigService,
|
|
@Inject(MAT_DIALOG_DATA) public data: any
|
|
) {
|
|
this.baseUrl = this.configService.apiUrl;
|
|
}
|
|
|
|
ngOnInit(): void {
|
|
if (this.data) {
|
|
this.loadData();
|
|
}
|
|
}
|
|
|
|
loadData() {
|
|
this.loading = true;
|
|
this.http.get<any>(`${this.baseUrl}/command-task-scripts?page=${this.page + 1}&itemsPerPage=${this.itemsPerPage}&commandTask.id=${this.data.commandTask?.id}&order[order]=ASC`, { params: this.filters }).subscribe(
|
|
(data) => {
|
|
const items = data['hydra:member'];
|
|
items.sort((a: any, b: any) => (a.order ?? 0) - (b.order ?? 0));
|
|
this.dataSource.data = items;
|
|
this.length = data['hydra:totalItems'];
|
|
this.loading = false;
|
|
},
|
|
(error) => {
|
|
this.loading = false;
|
|
}
|
|
);
|
|
}
|
|
|
|
deleteTaskScript(schedule: any): void {
|
|
const dialogRef = this.dialog.open(DeleteModalComponent, {
|
|
width: '300px',
|
|
data: { name: 'script de una tarea' }
|
|
});
|
|
|
|
dialogRef.afterClosed().subscribe(result => {
|
|
if (result) {
|
|
this.http.delete(`${this.baseUrl}${schedule['@id']}`).subscribe(
|
|
() => {
|
|
this.toastService.success(this.translate.instant('removedSuccessfully'));
|
|
this.loadData();
|
|
},
|
|
(error) => {
|
|
this.toastService.error(error.error['hydra:description']);
|
|
}
|
|
);
|
|
}
|
|
})
|
|
}
|
|
|
|
onNoClick(): void {
|
|
this.dialogRef.close(false);
|
|
}
|
|
|
|
openParametersModal(parameters: any): void {
|
|
this.dialog.open(ViewParametersModalComponent, {
|
|
width: '900px',
|
|
data: parameters
|
|
});
|
|
}
|
|
|
|
createNewScript(): void {
|
|
const dialogRef = this.dialog.open(CreateTaskScriptComponent, {
|
|
width: '800px',
|
|
data: { commandTask: this.data.commandTask }
|
|
});
|
|
|
|
dialogRef.afterClosed().subscribe(result => {
|
|
if (result) {
|
|
this.loadData();
|
|
}
|
|
});
|
|
}
|
|
|
|
onPageChange(event: any) {
|
|
this.page = event.pageIndex;
|
|
this.itemsPerPage = event.pageSize;
|
|
this.loadData()
|
|
}
|
|
}
|