143 lines
4.0 KiB
TypeScript
143 lines
4.0 KiB
TypeScript
import { Component } from '@angular/core';
|
|
import {MatTableDataSource} from "@angular/material/table";
|
|
import {DatePipe} from "@angular/common";
|
|
import {MatDialog} from "@angular/material/dialog";
|
|
import {HttpClient} from "@angular/common/http";
|
|
import {ToastrService} from "ngx-toastr";
|
|
import {DeleteModalComponent} from "../../shared/delete_modal/delete-modal/delete-modal.component";
|
|
import { JoyrideService } from 'ngx-joyride';
|
|
import {CreateRepositoryComponent} from "./create-repository/create-repository.component";
|
|
import { Router } from '@angular/router';
|
|
import {ImportImageComponent} from "./import-image/import-image.component";
|
|
|
|
@Component({
|
|
selector: 'app-repositories',
|
|
templateUrl: './repositories.component.html',
|
|
styleUrl: './repositories.component.css'
|
|
})
|
|
export class RepositoriesComponent {
|
|
baseUrl: string = import.meta.env.NG_APP_BASE_API_URL;
|
|
dataSource = new MatTableDataSource<any>();
|
|
length: number = 0;
|
|
itemsPerPage: number = 10;
|
|
page: number = 0;
|
|
loading: boolean = false;
|
|
filters: { [key: string]: string } = {};
|
|
datePipe: DatePipe = new DatePipe('es-ES');
|
|
columns = [
|
|
{
|
|
columnDef: 'id',
|
|
header: 'Id',
|
|
cell: (repository: any) => `${repository.id}`
|
|
},
|
|
{
|
|
columnDef: 'name',
|
|
header: 'Nombre de repositorio',
|
|
cell: (repository: any) => `${repository.name}`
|
|
},
|
|
{
|
|
columnDef: 'ip',
|
|
header: 'Ip',
|
|
cell: (repository: any) => `${repository.ip}`
|
|
},
|
|
{
|
|
columnDef: 'createdAt',
|
|
header: 'Fecha de creación',
|
|
cell: (repository: any) => `${this.datePipe.transform(repository.createdAt, 'dd/MM/yyyy hh:mm:ss')}`
|
|
}
|
|
];
|
|
displayedColumns = [...this.columns.map(column => column.columnDef), 'actions'];
|
|
|
|
private apiUrl = `${this.baseUrl}/image-repositories`;
|
|
|
|
constructor(
|
|
public dialog: MatDialog,
|
|
private http: HttpClient,
|
|
private toastService: ToastrService,
|
|
private joyrideService: JoyrideService,
|
|
private router: Router
|
|
) {}
|
|
|
|
ngOnInit(): void {
|
|
this.search();
|
|
}
|
|
|
|
addImage(): void {
|
|
const dialogRef = this.dialog.open(CreateRepositoryComponent, {
|
|
width: '600px'
|
|
});
|
|
|
|
dialogRef.afterClosed().subscribe(() => {
|
|
this.search();
|
|
});
|
|
}
|
|
|
|
search(): void {
|
|
this.loading = true;
|
|
this.http.get<any>(`${this.apiUrl}?page=${this.page +1 }&itemsPerPage=${this.itemsPerPage}`, { params: this.filters }).subscribe(
|
|
data => {
|
|
this.dataSource.data = data['hydra:member'];
|
|
this.length = data['hydra:totalItems'];
|
|
this.loading = false;
|
|
},
|
|
error => {
|
|
console.error('Error fetching images', error);
|
|
this.loading = false;
|
|
}
|
|
);
|
|
}
|
|
|
|
editRepository(event: MouseEvent, repository: any): void {
|
|
event.stopPropagation();
|
|
this.router.navigate(['repository', repository.uuid]);
|
|
}
|
|
|
|
importImage(event: MouseEvent, repository: any): void {
|
|
event.stopPropagation();
|
|
this.dialog.open(ImportImageComponent, {
|
|
width: '600px',
|
|
data: { repository }
|
|
}).afterClosed().subscribe(() => {
|
|
this.search();
|
|
});
|
|
}
|
|
|
|
deleteRepository(event: MouseEvent,command: any): void {
|
|
event.stopPropagation();
|
|
this.dialog.open(DeleteModalComponent, {
|
|
width: '300px',
|
|
data: { name: command.name },
|
|
}).afterClosed().subscribe((result) => {
|
|
if (result) {
|
|
this.http.delete(`${this.apiUrl}/${command.uuid}`).subscribe({
|
|
next: () => {
|
|
this.toastService.success('Imagen eliminada con éxito');
|
|
this.search();
|
|
},
|
|
error: (error) => {
|
|
console.error('Error al eliminar la imagen:', error);
|
|
}
|
|
});
|
|
}
|
|
});
|
|
}
|
|
|
|
onPageChange(event: any): void {
|
|
this.page = event.pageIndex;
|
|
this.itemsPerPage = event.pageSize;
|
|
this.length = event.length;
|
|
this.search();
|
|
}
|
|
|
|
iniciarTour(): void {
|
|
this.joyrideService.startTour({
|
|
steps: [
|
|
'titleStep',
|
|
'addStep',
|
|
],
|
|
showPrevButton: true,
|
|
themeColor: '#3f51b5'
|
|
});
|
|
}
|
|
}
|