diff --git a/ogWebconsole/src/app/app.module.ts b/ogWebconsole/src/app/app.module.ts index 4a0ed99..7a944c5 100644 --- a/ogWebconsole/src/app/app.module.ts +++ b/ogWebconsole/src/app/app.module.ts @@ -102,7 +102,7 @@ import { OperativeSystemComponent } from './components/operative-system/operativ import { CreateOperativeSystemComponent } from './components/operative-system/create-operative-system/create-operative-system.component'; import { ShowTemplateContentComponent } from './components/ogboot/pxe/show-template-content/show-template-content.component'; import { RepositoriesComponent } from './components/repositories/repositories.component'; -import { CreateRepositoryComponent } from './components/repositories/create-repository/create-repository.component'; +import { ManageRepositoryComponent } from './components/repositories/manage-repository/manage-repository.component'; import { ExecuteCommandComponent } from './components/commands/main-commands/execute-command/execute-command.component'; import { DeployImageComponent } from './components/groups/components/client-main-view/deploy-image/deploy-image.component'; import { MainRepositoryViewComponent } from './components/repositories/main-repository-view/main-repository-view.component'; @@ -134,6 +134,7 @@ import { ConvertImageComponent } from './components/repositories/convert-image/c import { registerLocaleData } from '@angular/common'; import localeEs from '@angular/common/locales/es'; import { GlobalStatusComponent } from './components/global-status/global-status.component'; +import { ShowImagesComponent } from './components/repositories/show-images/show-images.component'; export function HttpLoaderFactory(http: HttpClient) { return new TranslateHttpLoader(http, './locale/', '.json'); @@ -207,7 +208,7 @@ registerLocaleData(localeEs, 'es-ES'); CreateOperativeSystemComponent, ShowTemplateContentComponent, RepositoriesComponent, - CreateRepositoryComponent, + ManageRepositoryComponent, ExecuteCommandComponent, ExecuteCommandOuComponent, DeployImageComponent, @@ -227,7 +228,8 @@ registerLocaleData(localeEs, 'es-ES'); ShowClientsComponent, OperationResultDialogComponent, ConvertImageComponent, - GlobalStatusComponent + GlobalStatusComponent, + ShowImagesComponent ], bootstrap: [AppComponent], imports: [BrowserModule, diff --git a/ogWebconsole/src/app/components/groups/groups.component.css b/ogWebconsole/src/app/components/groups/groups.component.css index 50c1127..cc550ac 100644 --- a/ogWebconsole/src/app/components/groups/groups.component.css +++ b/ogWebconsole/src/app/components/groups/groups.component.css @@ -456,4 +456,4 @@ mat-button-toggle-group { padding: 0.5rem 1rem 1rem 1rem; width: 100%; box-sizing: border-box; -} \ No newline at end of file +} diff --git a/ogWebconsole/src/app/components/groups/groups.component.ts b/ogWebconsole/src/app/components/groups/groups.component.ts index 56393b4..c5b7c46 100644 --- a/ogWebconsole/src/app/components/groups/groups.component.ts +++ b/ogWebconsole/src/app/components/groups/groups.component.ts @@ -172,6 +172,7 @@ export class GroupsComponent implements OnInit, OnDestroy { }; this.selectedClients.data = updatedClients; + this.arrayClients = updatedClients; console.log(`Estado actualizado para el cliente ${clientUuid}: ${newStatus}`); } else { diff --git a/ogWebconsole/src/app/components/ogdhcp/add-clients-to-subnet/add-clients-to-subnet.component.ts b/ogWebconsole/src/app/components/ogdhcp/add-clients-to-subnet/add-clients-to-subnet.component.ts index 867f0f8..aaa8e8e 100644 --- a/ogWebconsole/src/app/components/ogdhcp/add-clients-to-subnet/add-clients-to-subnet.component.ts +++ b/ogWebconsole/src/app/components/ogdhcp/add-clients-to-subnet/add-clients-to-subnet.component.ts @@ -38,7 +38,7 @@ export class AddClientsToSubnetComponent implements OnInit { } loadUnits() { - this.http.get(`${this.baseUrl}/organizational-units?type=classroom&page=1&itemsPerPage=50`).subscribe( + this.http.get(`${this.baseUrl}/organizational-units?page=1&itemsPerPage=500`).subscribe( response => { this.units = response['hydra:member']; this.loading = false; diff --git a/ogWebconsole/src/app/components/ogdhcp/show-clients/show-clients.component.html b/ogWebconsole/src/app/components/ogdhcp/show-clients/show-clients.component.html index 9167cb1..2fba37e 100644 --- a/ogWebconsole/src/app/components/ogdhcp/show-clients/show-clients.component.html +++ b/ogWebconsole/src/app/components/ogdhcp/show-clients/show-clients.component.html @@ -97,5 +97,5 @@ - + diff --git a/ogWebconsole/src/app/components/ogdhcp/show-clients/show-clients.component.ts b/ogWebconsole/src/app/components/ogdhcp/show-clients/show-clients.component.ts index 0a8a836..322c90a 100644 --- a/ogWebconsole/src/app/components/ogdhcp/show-clients/show-clients.component.ts +++ b/ogWebconsole/src/app/components/ogdhcp/show-clients/show-clients.component.ts @@ -73,7 +73,6 @@ export class ShowClientsComponent implements OnInit { this.loading = false; } ); - console.log(this.dataSource.data) } deleteClient(client: any): void { diff --git a/ogWebconsole/src/app/components/repositories/convert-image/convert-image.component.html b/ogWebconsole/src/app/components/repositories/convert-image/convert-image.component.html index 3924407..331ecec 100644 --- a/ogWebconsole/src/app/components/repositories/convert-image/convert-image.component.html +++ b/ogWebconsole/src/app/components/repositories/convert-image/convert-image.component.html @@ -10,7 +10,7 @@ El nombre de la imagen tiene que ir con la extensión. - Filesystem + Sistema de archivos diff --git a/ogWebconsole/src/app/components/repositories/create-repository/create-repository.component.css b/ogWebconsole/src/app/components/repositories/manage-repository/manage-repository.component.css similarity index 100% rename from ogWebconsole/src/app/components/repositories/create-repository/create-repository.component.css rename to ogWebconsole/src/app/components/repositories/manage-repository/manage-repository.component.css diff --git a/ogWebconsole/src/app/components/repositories/create-repository/create-repository.component.html b/ogWebconsole/src/app/components/repositories/manage-repository/manage-repository.component.html similarity index 100% rename from ogWebconsole/src/app/components/repositories/create-repository/create-repository.component.html rename to ogWebconsole/src/app/components/repositories/manage-repository/manage-repository.component.html diff --git a/ogWebconsole/src/app/components/repositories/create-repository/create-repository.component.spec.ts b/ogWebconsole/src/app/components/repositories/manage-repository/manage-repository.component.spec.ts similarity index 97% rename from ogWebconsole/src/app/components/repositories/create-repository/create-repository.component.spec.ts rename to ogWebconsole/src/app/components/repositories/manage-repository/manage-repository.component.spec.ts index 6e01178..335f14d 100644 --- a/ogWebconsole/src/app/components/repositories/create-repository/create-repository.component.spec.ts +++ b/ogWebconsole/src/app/components/repositories/manage-repository/manage-repository.component.spec.ts @@ -1,5 +1,5 @@ import { ComponentFixture, TestBed } from '@angular/core/testing'; -import { CreateRepositoryComponent } from './create-repository.component'; +import { CreateRepositoryComponent } from './manage-repository.component'; import { provideHttpClient } from '@angular/common/http'; import { provideHttpClientTesting } from '@angular/common/http/testing'; import { ReactiveFormsModule, FormBuilder } from '@angular/forms'; diff --git a/ogWebconsole/src/app/components/repositories/create-repository/create-repository.component.ts b/ogWebconsole/src/app/components/repositories/manage-repository/manage-repository.component.ts similarity index 77% rename from ogWebconsole/src/app/components/repositories/create-repository/create-repository.component.ts rename to ogWebconsole/src/app/components/repositories/manage-repository/manage-repository.component.ts index 104c692..d570f90 100644 --- a/ogWebconsole/src/app/components/repositories/create-repository/create-repository.component.ts +++ b/ogWebconsole/src/app/components/repositories/manage-repository/manage-repository.component.ts @@ -1,4 +1,4 @@ -import { Component, Inject } from '@angular/core'; +import {Component, Inject, OnInit} from '@angular/core'; import { FormBuilder, FormGroup, Validators } from "@angular/forms"; import { HttpClient } from "@angular/common/http"; import { MAT_DIALOG_DATA, MatDialogRef } from "@angular/material/dialog"; @@ -7,11 +7,11 @@ import { DataService } from "../../images/data.service"; import { ConfigService } from "@services/config.service"; @Component({ - selector: 'app-create-repository', - templateUrl: './create-repository.component.html', - styleUrl: './create-repository.component.css' + selector: 'app-manage-repository', + templateUrl: './manage-repository.component.html', + styleUrl: './manage-repository.component.css' }) -export class CreateRepositoryComponent { +export class ManageRepositoryComponent implements OnInit { baseUrl: string; imageForm: FormGroup; repositoryId: string | null = null; @@ -20,7 +20,7 @@ export class CreateRepositoryComponent { constructor( private fb: FormBuilder, private http: HttpClient, - public dialogRef: MatDialogRef, + public dialogRef: MatDialogRef, private toastService: ToastrService, private dataService: DataService, private configService: ConfigService, @@ -28,9 +28,9 @@ export class CreateRepositoryComponent { ) { this.baseUrl = this.configService.apiUrl; this.imageForm = this.fb.group({ - name: ['', Validators.required], - ip: [''], - comments: [''], + name: [null, Validators.required], + ip: [null], + comments: [null], }); } @@ -66,23 +66,21 @@ export class CreateRepositoryComponent { if (this.repositoryId) { this.http.put(`${this.baseUrl}${this.repositoryId}`, payload).subscribe( (response) => { - this.toastService.success('Imagen editada correctamente'); + this.toastService.success('Repositorio editada correctamente'); this.dialogRef.close(); }, (error) => { this.toastService.error(error['error']['hydra:description']); - console.error('Error al editar la imagen', error); } ); } else { this.http.post(`${this.baseUrl}/image-repositories`, payload).subscribe( (response) => { - this.toastService.success('Imagen añadida correctamente'); + this.toastService.success('Repositorio añadido correctamente'); this.dialogRef.close(); }, (error) => { this.toastService.error(error['error']['hydra:description']); - console.error('Error al añadir la imagen', error); } ); } diff --git a/ogWebconsole/src/app/components/repositories/repositories.component.html b/ogWebconsole/src/app/components/repositories/repositories.component.html index 6ad69e6..2f33a45 100644 --- a/ogWebconsole/src/app/components/repositories/repositories.component.html +++ b/ogWebconsole/src/app/components/repositories/repositories.component.html @@ -37,19 +37,12 @@ {{ column.header }} - - - - {{ repository.status === true ? 'Conectado' : 'Fallido' }} - - - - + {{ column.cell(repository) }} - + + + + diff --git a/ogWebconsole/src/app/components/repositories/repositories.component.ts b/ogWebconsole/src/app/components/repositories/repositories.component.ts index d8defe5..6443e59 100644 --- a/ogWebconsole/src/app/components/repositories/repositories.component.ts +++ b/ogWebconsole/src/app/components/repositories/repositories.component.ts @@ -6,9 +6,11 @@ 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 { ConfigService } from '@services/config.service'; +import {Subnet} from "../ogdhcp/og-dhcp-subnets.component"; +import {ShowImagesComponent} from "./show-images/show-images.component"; +import {ManageRepositoryComponent} from "./manage-repository/manage-repository.component"; @Component({ selector: 'app-repositories', @@ -42,9 +44,9 @@ export class RepositoriesComponent implements OnInit { cell: (repository: any) => `${repository.ip}` }, { - columnDef: 'status', - header: 'Estado', - cell: (repository: any) => `${repository.status}` + columnDef: 'images', + header: 'Imágenes', + cell: (repository: any) => `${repository.images}` }, { columnDef: 'createdAt', @@ -52,7 +54,7 @@ export class RepositoriesComponent implements OnInit { cell: (repository: any) => `${this.datePipe.transform(repository.createdAt, 'dd/MM/yyyy hh:mm:ss')}` } ]; - displayedColumns = [...this.columns.map(column => column.columnDef), 'actions']; + displayedColumns: string[] = ['id', 'name', 'ip', 'images', 'createdAt', 'actions']; constructor( public dialog: MatDialog, @@ -71,7 +73,7 @@ export class RepositoriesComponent implements OnInit { } addImage(): void { - const dialogRef = this.dialog.open(CreateRepositoryComponent, { + const dialogRef = this.dialog.open(ManageRepositoryComponent, { width: '600px' }); @@ -97,7 +99,10 @@ export class RepositoriesComponent implements OnInit { editRepository(event: MouseEvent, repository: any): void { event.stopPropagation(); - this.router.navigate(['repository', repository.uuid]); + this.dialog.open(ManageRepositoryComponent, { + width: '600px', + data: repository['@id'] + }).afterClosed().subscribe(() => this.search()); } deleteRepository(event: MouseEvent,command: any): void { @@ -120,6 +125,21 @@ export class RepositoriesComponent implements OnInit { }); } + openShowImagesDialog(repository: Subnet) { + const dialogRef = this.dialog.open(ShowImagesComponent, { + width: '100vw', + height: '100vh', + maxWidth: '100vw', + maxHeight: '100vh', + data: { repositoryId: repository.id, repositoryName: repository.name, repositoryUuid: repository.uuid } + }); + + dialogRef.afterClosed().subscribe(result => { + this.search(); + }); + } + + onPageChange(event: any): void { this.page = event.pageIndex; this.itemsPerPage = event.pageSize; diff --git a/ogWebconsole/src/app/components/repositories/show-images/show-images.component.css b/ogWebconsole/src/app/components/repositories/show-images/show-images.component.css new file mode 100644 index 0000000..01712ec --- /dev/null +++ b/ogWebconsole/src/app/components/repositories/show-images/show-images.component.css @@ -0,0 +1,202 @@ + +table { + width: 100%; +} + +.search-container { + display: flex; + justify-content: space-between; + align-items: center; + width: 100%; + margin: 1.5rem 0rem 1.5rem 0rem; + box-sizing: border-box; +} + +.search-string { + flex: 2; + padding: 5px; +} + +.search-boolean { + flex: 1; + padding: 5px; +} + +.header-container { + display: flex; + justify-content: space-between; + align-items: center; + padding: 10px 10px; + border-bottom: 1px solid #ddd; +} + +.mat-elevation-z8 { + box-shadow: 0px 0px 0px rgba(0,0,0,0.2); +} + +.paginator-container { + display: flex; + justify-content: end; + margin-bottom: 30px; +} + +.example-headers-align .mat-expansion-panel-header-description { + justify-content: space-between; + align-items: center; +} + +.example-headers-align .mat-mdc-form-field + .mat-mdc-form-field { + margin-left: 8px; +} + +.button-row { + display: table-cell; + max-width: 600px; +} + +.button-row .mat-mdc-button-base { + margin: 8px 8px 8px 0; +} + +.chip-failed { + background-color: #e87979 !important; + color: white; +} + +.chip-success { + background-color: #46c446 !important; + color: white; +} + +.chip-pending { + background-color: lightgrey !important; + color: black; +} + +.chip-in-progress { + background-color: #f5a623 !important; + color: white; +} + +.chip-transferring { + background-color: #f5a623 !important; + color: white; +} + +.header-container-title { + flex-grow: 1; + text-align: left; + margin-left: 1em; +} + +.images-button-row { + display: flex; + gap: 15px; + padding: 5px; +} + + +table { + width: 100%; +} + +.search-container { + display: flex; + justify-content: space-between; + align-items: center; + width: 100%; + margin: 1.5rem 0rem 1.5rem 0rem; + box-sizing: border-box; +} + +.search-string { + flex: 2; + padding: 5px; +} + +.search-boolean { + flex: 1; + padding: 5px; +} + +.header-container { + display: flex; + justify-content: space-between; + align-items: center; + padding: 10px 10px; + border-bottom: 1px solid #ddd; +} + +.mat-elevation-z8 { + box-shadow: 0px 0px 0px rgba(0,0,0,0.2); +} + +.paginator-container { + display: flex; + justify-content: end; + margin-bottom: 30px; +} + +.example-headers-align .mat-expansion-panel-header-description { + justify-content: space-between; + align-items: center; +} + +.example-headers-align .mat-mdc-form-field + .mat-mdc-form-field { + margin-left: 8px; +} + +.button-row { + display: table-cell; + max-width: 600px; +} + +.button-row .mat-mdc-button-base { + margin: 8px 8px 8px 0; +} + +.chip-failed { + background-color: #e87979 !important; + color: white; +} + +.chip-success { + background-color: #46c446 !important; + color: white; +} + +.chip-pending { + background-color: lightgrey !important; + color: black; +} + +.chip-in-progress { + background-color: #f5a623 !important; + color: white; +} + +.chip-transferring { + background-color: #f5a623 !important; + color: white; +} + +.action-container { + display: flex; + justify-content: flex-end; + gap: 1em; + padding: 1.5em; +} + +.header-container-title { + flex-grow: 1; + text-align: left; + margin-left: 1em; +} + +.images-button-row { + display: flex; + gap: 15px; + padding: 5px; +} + + diff --git a/ogWebconsole/src/app/components/repositories/show-images/show-images.component.html b/ogWebconsole/src/app/components/repositories/show-images/show-images.component.html new file mode 100644 index 0000000..bd1f040 --- /dev/null +++ b/ogWebconsole/src/app/components/repositories/show-images/show-images.component.html @@ -0,0 +1,116 @@ + + +

Gestionar imágenes en {{data.repositoryName}}

+ + +
+ +
+
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+ + {{ 'searchLabel' | translate }} + + search + {{ 'searchHint' | translate }} + + + Estado + + Fallido + Pendiente + Transfiriendo + Creado con éxito + En progreso + Papelera + Creando archivos auxiliares + + +
+ + + + + + + + + + + + + +
{{ column.header }} + + + {{ image.image[column.columnDef] ? 'check_circle' : 'cancel' }} + + + + + {{ getStatusLabel(image[column.columnDef]) }} + + + + {{ column.cell(image) }} + + Acciones + + + + + + + + + + + + +
+ +
+ + +
+ +
+ + + + + diff --git a/ogWebconsole/src/app/components/repositories/show-images/show-images.component.spec.ts b/ogWebconsole/src/app/components/repositories/show-images/show-images.component.spec.ts new file mode 100644 index 0000000..52a6cd9 --- /dev/null +++ b/ogWebconsole/src/app/components/repositories/show-images/show-images.component.spec.ts @@ -0,0 +1,23 @@ +import { ComponentFixture, TestBed } from '@angular/core/testing'; + +import { ShowImagesComponent } from './show-images.component'; + +describe('ShowImagesComponent', () => { + let component: ShowImagesComponent; + let fixture: ComponentFixture; + + beforeEach(async () => { + await TestBed.configureTestingModule({ + declarations: [ShowImagesComponent] + }) + .compileComponents(); + + fixture = TestBed.createComponent(ShowImagesComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/ogWebconsole/src/app/components/repositories/show-images/show-images.component.ts b/ogWebconsole/src/app/components/repositories/show-images/show-images.component.ts new file mode 100644 index 0000000..8d89edb --- /dev/null +++ b/ogWebconsole/src/app/components/repositories/show-images/show-images.component.ts @@ -0,0 +1,384 @@ +import {Component, Inject, Input, isDevMode, OnInit} from '@angular/core'; +import {MatTableDataSource} from "@angular/material/table"; +import {DatePipe} from "@angular/common"; +import {MAT_DIALOG_DATA, MatDialog, MatDialogRef} from "@angular/material/dialog"; +import {HttpClient} from "@angular/common/http"; +import {ToastrService} from "ngx-toastr"; +import {JoyrideService} from "ngx-joyride"; +import {ConfigService} from "@services/config.service"; +import {Router} from "@angular/router"; +import {Observable} from "rxjs"; +import {ServerInfoDialogComponent} from "../../ogdhcp/server-info-dialog/server-info-dialog.component"; +import {ImportImageComponent} from "../import-image/import-image.component"; +import {ConvertImageComponent} from "../convert-image/convert-image.component"; +import {DeleteModalComponent} from "../../../shared/delete_modal/delete-modal/delete-modal.component"; +import {ExportImageComponent} from "../../images/export-image/export-image.component"; +import {BackupImageComponent} from "../backup-image/backup-image.component"; + +@Component({ + selector: 'app-show-images', + templateUrl: './show-images.component.html', + styleUrl: './show-images.component.css' +}) +export class ShowImagesComponent implements OnInit { + baseUrl: string; + private apiUrl: string; + dataSource = new MatTableDataSource(); + length: number = 0; + itemsPerPage: number = 10; + page: number = 0; + loading: boolean = false; + filters: { [key: string]: string } = {}; + alertMessage: string | null = null; + repository: any = {}; + datePipe: DatePipe = new DatePipe('es-ES'); + columns = [ + { + columnDef: 'id', + header: 'Id', + cell: (image: any) => `${image.id}` + }, + { + columnDef: 'name', + header: 'Nombre de imagen', + cell: (image: any) => `${image.image.name}` + }, + { + columnDef: 'remotePc', + header: 'Remote Pc', + cell: (image: any) => `${image.image?.remotePc}` + }, + { + columnDef: 'isGlobal', + header: 'Imagen global', + cell: (image: any) => `${image.image?.isGlobal}` + }, + { + columnDef: 'status', + header: 'Estado', + cell: (image: any) => `${image.status}` + }, + { + columnDef: 'imageFullsum', + header: 'Fullsum', + cell: (image: any) => `${image.imageFullsum}` + }, + { + columnDef: 'createdAt', + header: 'Fecha de creación', + cell: (image: any) => `${this.datePipe.transform(image.createdAt, 'dd/MM/yyyy hh:mm:ss')}` + } + ]; + displayedColumns = [...this.columns.map(column => column.columnDef), 'actions']; + + constructor( + public dialog: MatDialog, + private http: HttpClient, + private toastService: ToastrService, + private joyrideService: JoyrideService, + private configService: ConfigService, + private router: Router, + public dialogRef: MatDialogRef, + @Inject(MAT_DIALOG_DATA) public data: any + ) { + this.baseUrl = this.configService.apiUrl; + this.apiUrl = `${this.baseUrl}/image-image-repositories`; + } + + ngOnInit(): void { + console.error() + if (this.data) { + this.loadData(); + } + } + + loadData(): void { + this.loading = true; + this.http.get(`${this.apiUrl}?page=${this.page + 1}&itemsPerPage=${this.itemsPerPage}&repository.id=${this.data.repositoryId}`, { params: this.filters }).subscribe( + data => { + this.dataSource.data = data['hydra:member']; + this.length = data['hydra:totalItems']; + this.loading = false; + }, + error => { + console.error('Error fetching image repositories', error); + } + ) + } + + getStatusLabel(status: string): string { + switch (status) { + case 'pending': + return 'Pendiente'; + case 'in-progress': + return 'En progreso'; + case 'aux-files-pending': + return 'Archivos auxiliares pendientes'; + case 'success': + return 'Creado con éxito'; + case 'trash': + return 'Papelera temporal'; + case 'failed': + return 'Fallido'; + case 'transferring': + return 'Transfiriendo'; + default: + return 'Estado desconocido'; + } + } + + onPageChange(event: any): void { + this.page = event.pageIndex; + this.itemsPerPage = event.pageSize; + this.length = event.length; + this.loadData(); + } + + loadImageAlert(image: any): Observable { + return this.http.get(`${this.apiUrl}/server/${image.uuid}/get`, {}); + } + + showImageInfo(event: MouseEvent, image:any) { + event.stopPropagation(); + this.loading = true; + this.loadImageAlert(image).subscribe( + response => { + this.alertMessage = response; + + this.dialog.open(ServerInfoDialogComponent, { + width: '800px', + data: { + message: this.alertMessage + } + }); + this.loading = false; + }, + error => { + this.toastService.error(error.error['hydra:description']); + this.loading = false; + } + ); + } + + importImage(): void { + this.dialog.open(ImportImageComponent, { + width: '600px', + data: { + repositoryUuid: this.data.repositoryUuid, + name: this.repository.name + } + }).afterClosed().subscribe((result) => { + if (result) { + this.loadData(); + } + }); + } + + convertImage(): void { + this.dialog.open(ConvertImageComponent, { + width: '600px', + data: { + repositoryUuid: this.data.repositoryUuid, + name: this.repository.name + } + }).afterClosed().subscribe((result) => { + if (result) { + this.loadData(); + } + }); + } + + toggleAction(image: any, action:string): void { + switch (action) { + case 'get-aux': + this.http.post(`${this.baseUrl}/image-image-repositories/server/${image.uuid}/create-aux-files`, {}).subscribe({ + next: (message) => { + this.toastService.success('Petición de creación de archivos auxiliares enviada'); + this.loadData() + }, + error: (error) => { + this.toastService.error(error.error['hydra:description']); + } + }); + break; + case 'delete-trash': + if (!image.imageFullsum) { + const dialogRef = this.dialog.open(DeleteModalComponent, { + width: '400px', + data: { name: image.name }, + }); + + dialogRef.afterClosed().subscribe((result) => { + this.http.delete(`${this.baseUrl}${image['@id']}`).subscribe({ + next: () => { + this.toastService.success('Image deleted successfully'); + this.loadData() + }, + error: (error) => { + this.toastService.error('Error deleting image'); + } + }); + }); + } else { + this.http.post(`${this.baseUrl}/image-image-repositories/server/${image.uuid}/delete-trash`, + { repository: `/image-repositories/${this.data.repositoryUuid}` }) + .subscribe({ + next: () => { + this.toastService.success('Petición de eliminación de la papelera temporal enviada'); + this.loadData() + }, + error: (error) => { + this.toastService.error(error.error['hydra:description']); + } + }); + } + + break; + case 'delete-permanent': + this.dialog.open(DeleteModalComponent, { + width: '300px', + data: { name: image.name }, + }).afterClosed().subscribe((result) => { + if (result) { + this.http.post(`${this.baseUrl}/image-image-repositories/server/${image.uuid}/delete-permanent`, {}).subscribe({ + next: () => { + this.toastService.success('Petición de eliminación de la papelera temporal enviada'); + this.loadData() + }, + error: (error) => { + this.toastService.error(error.error['hydra:description']); + } + }); + } + }); + break; + case 'recover': + this.http.post(`${this.baseUrl}/image-image-repositories/server/${image.uuid}/recover`, {}).subscribe({ + next: () => { + this.toastService.success('Petición de recuperación de la imagen enviada'); + this.loadData() + }, + error: (error) => { + this.toastService.error(error.error['hydra:description']); + } + }); + break; + case 'status': + this.http.post(`${this.baseUrl}/image-image-repositories/server/${image.uuid}/status`, {}).subscribe({ + next: (response: any) => { + this.toastService.info(response?.output); + this.loadData() + }, + error: (error) => { + this.toastService.error(error.error['hydra:description']); + } + }); + break; + case 'transfer': + this.http.get(`${this.baseUrl}${image.image['@id']}`).subscribe({ + next: (response) => { + this.dialog.open(ExportImageComponent, { + width: '600px', + data: { + image: response, + imageImageRepository: image + } + }); + }, + error: (error) => { + this.toastService.error(error.error['hydra:description']); + } + }); + break; + case 'transfer-global': + this.http.post(`${this.baseUrl}/image-image-repositories/server/${image.uuid}/transfer-global`, { + }).subscribe({ + next: (response) => { + this.toastService.success('Petición de exportación de imagen realizada correctamente'); + this.loading = false; + this.router.navigate(['/commands-logs']); + }, + error: error => { + this.loading = false; + this.toastService.error('Error en la petición de exportación de imagen'); + } + }); + break; + case 'backup': + this.http.get(`${this.baseUrl}${image.image['@id']}`).subscribe({ + next: (response) => { + this.dialog.open(BackupImageComponent, { + width: '600px', + data: { + image: response, + imageImageRepository: image + } + }); + }, + error: (error) => { + this.toastService.error(error.error['hydra:description']); + } + }); + break; + default: + console.error('Acción no soportada:', action); + break; + } + } + + iniciarTour(): void { + this.joyrideService.startTour({ + steps: [ + 'imagesTitleStep', + 'addImageButton', + 'searchImagesField', + 'imagesTable', + 'actionsHeader', + 'editImageButton', + 'deleteImageButton', + 'imagesPagination' + ], + showPrevButton: true, + themeColor: '#3f51b5' + }); + } + + loadAlert(): Observable { + return this.http.post(`${this.baseUrl}/image-repositories/server/${this.data.repositoryUuid}/get-collection`, {}); + } + + syncRepository() { + this.http.post(`${this.baseUrl}/image-repositories/server/${this.data.repositoryUuid}/sync`, {}) + .subscribe(response => { + this.toastService.success('Sincronización completada'); + this.loadData() + }, error => { + console.error('Error al sincronizar', error); + this.toastService.error('Error al sincronizar'); + }); + } + + openImageInfoDialog() { + this.loadAlert().subscribe( + response => { + this.alertMessage = response.output; + + this.dialog.open(ServerInfoDialogComponent, { + width: '800px', + data: { + message: this.alertMessage + } + }); + }, + error => { + console.error('Error al cargar la información del alert', error); + } + ); + } + + onNoClick(): void { + this.dialogRef.close(); + } + + protected readonly isDevMode = isDevMode; +}