From 75357b82c8178855a65ec2ae4f10b9783faacf10 Mon Sep 17 00:00:00 2001 From: Manuel Aranda Date: Mon, 10 Feb 2025 13:59:14 +0100 Subject: [PATCH] refs #1472. Changes in images and imageRepo --- .../export-image/export-image.component.html | 4 +- .../export-image.component.spec.ts | 5 ++- .../export-image/export-image.component.ts | 41 +++++++++++++------ .../app/components/images/images.component.ts | 40 +++++++++++++----- .../ogboot-status/ogboot-status.component.ts | 13 ++++-- .../status/status.component.ts | 3 +- .../main-repository-view.component.ts | 2 +- .../repositories/repositories.component.html | 3 +- .../repositories.component.spec.ts | 5 ++- .../repositories/repositories.component.ts | 10 ----- 10 files changed, 84 insertions(+), 42 deletions(-) diff --git a/ogWebconsole/src/app/components/images/export-image/export-image.component.html b/ogWebconsole/src/app/components/images/export-image/export-image.component.html index 231151f..0837588 100644 --- a/ogWebconsole/src/app/components/images/export-image/export-image.component.html +++ b/ogWebconsole/src/app/components/images/export-image/export-image.component.html @@ -1,9 +1,11 @@ + +

Transferir imagen {{data.image?.name}}

Seleccione nuevo repositorio destino - + {{ repository.name }} diff --git a/ogWebconsole/src/app/components/images/export-image/export-image.component.spec.ts b/ogWebconsole/src/app/components/images/export-image/export-image.component.spec.ts index e45ee65..e573706 100644 --- a/ogWebconsole/src/app/components/images/export-image/export-image.component.spec.ts +++ b/ogWebconsole/src/app/components/images/export-image/export-image.component.spec.ts @@ -12,6 +12,8 @@ import {MatButtonModule} from "@angular/material/button"; import {MatSelectModule} from "@angular/material/select"; import {BrowserAnimationsModule} from "@angular/platform-browser/animations"; import {TranslateModule} from "@ngx-translate/core"; +import {LoadingComponent} from "../../../shared/loading/loading.component"; +import {MatProgressSpinner} from "@angular/material/progress-spinner"; describe('ExportImageComponent', () => { let component: ExportImageComponent; @@ -19,7 +21,7 @@ describe('ExportImageComponent', () => { beforeEach(async () => { await TestBed.configureTestingModule({ - declarations: [ExportImageComponent], + declarations: [ExportImageComponent, LoadingComponent], imports: [ ReactiveFormsModule, MatDialogModule, @@ -27,6 +29,7 @@ describe('ExportImageComponent', () => { MatInputModule, MatButtonModule, MatSelectModule, + MatProgressSpinner, BrowserAnimationsModule, ToastrModule.forRoot(), TranslateModule.forRoot() diff --git a/ogWebconsole/src/app/components/images/export-image/export-image.component.ts b/ogWebconsole/src/app/components/images/export-image/export-image.component.ts index c115134..e6cf530 100644 --- a/ogWebconsole/src/app/components/images/export-image/export-image.component.ts +++ b/ogWebconsole/src/app/components/images/export-image/export-image.component.ts @@ -13,7 +13,7 @@ export class ExportImageComponent implements OnInit { baseUrl: string = import.meta.env.NG_APP_BASE_API_URL; loading: boolean = true; repositories: any[] = []; - selectedRepository: string = ''; + selectedRepositories: any[] = []; constructor( private http: HttpClient, @@ -31,27 +31,42 @@ export class ExportImageComponent implements OnInit { } loadRepositories() { - this.http.get(`${this.baseUrl}/image-repositories?id[neq]=1&page=1&itemsPerPage=50`).subscribe( - response => { - this.repositories = response['hydra:member']; - this.loading = false; - }, - error => console.error('Error fetching organizational units:', error) - ); + const excludedIds = this.data?.image?.imageRepositories?.map((repository: any) => repository.id) || null; + + let url = `${this.baseUrl}/image-repositories?page=1&itemsPerPage=50`; + + if (excludedIds) { + url += `&id[neq]=${excludedIds.join(',')}`; + } + + this.http.get(url) + .subscribe( + response => { + this.repositories = response['hydra:member']; + this.loading = false; + }, + error => { + console.error('Error fetching repositories:', error); + this.loading = false; + } + ); } + save() { - this.http.post(`${this.baseUrl}${this.selectedRepository}/transfer-image`, { - images: [this.data.image['@id']] + this.loading = true; + this.http.post(`${this.baseUrl}${this.data.image['@id']}/transfer-image`, { + repositories: this.selectedRepositories }).subscribe({ next: (response) => { - this.toastService.success('Imagen exportada correctamente'); + this.toastService.success('Petición de exportación de imagen realizada correctamente'); this.dialogRef.close(); + this.loading = false; this.router.navigate(['/commands-logs']); }, error: error => { - console.error('Error al exportar imagen:', error); - this.toastService.error('Error al exportar imagen'); + this.loading = false; + this.toastService.error('Error en la petición de exportación de imagen'); } }); } diff --git a/ogWebconsole/src/app/components/images/images.component.ts b/ogWebconsole/src/app/components/images/images.component.ts index dfef3e1..6380e6c 100644 --- a/ogWebconsole/src/app/components/images/images.component.ts +++ b/ogWebconsole/src/app/components/images/images.component.ts @@ -129,7 +129,7 @@ export class ImagesComponent implements OnInit { search(): void { this.loading = true; - this.http.get(`${this.apiUrl}?page=${this.page +1 }&itemsPerPage=${this.itemsPerPage}&repository.id=${this.repositoryId}`, { params: this.filters }).subscribe( + this.http.get(`${this.apiUrl}?page=${this.page +1 }&itemsPerPage=${this.itemsPerPage}&repositoryId=${this.repositoryId}`, { params: this.filters }).subscribe( data => { this.dataSource.data = data['hydra:member']; this.length = data['hydra:totalItems']; @@ -197,15 +197,35 @@ export class ImagesComponent implements OnInit { }); break; case 'delete-trash': - this.http.post(`${this.baseUrl}/images/server/${image.uuid}/delete-trash`, {}).subscribe({ - next: () => { - this.toastService.success('Petición de eliminación de la papelera temporal enviada'); - this.search() - }, - error: (error) => { - this.toastService.error(error.error['hydra:description']); - } - }); + 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.search() + }, + error: (error) => { + this.toastService.error('Error deleting image'); + } + }); + }); + } else { + this.http.post(`${this.baseUrl}/images/server/${image.uuid}/delete-trash`, {}).subscribe({ + next: () => { + this.toastService.success('Petición de eliminación de la papelera temporal enviada'); + this.search() + }, + error: (error) => { + this.toastService.error(error.error['hydra:description']); + } + }); + } + break; case 'delete-permanent': this.http.post(`${this.baseUrl}/images/server/${image.uuid}/delete-permanent`, {}).subscribe({ diff --git a/ogWebconsole/src/app/components/ogboot/ogboot-status/ogboot-status.component.ts b/ogWebconsole/src/app/components/ogboot/ogboot-status/ogboot-status.component.ts index 2b72056..42634f5 100644 --- a/ogWebconsole/src/app/components/ogboot/ogboot-status/ogboot-status.component.ts +++ b/ogWebconsole/src/app/components/ogboot/ogboot-status/ogboot-status.component.ts @@ -1,6 +1,7 @@ import { Component, OnInit } from '@angular/core'; import { HttpClient } from '@angular/common/http'; import { JoyrideService } from 'ngx-joyride'; +import {ToastrService} from "ngx-toastr"; @Component({ selector: 'app-ogboot-status', @@ -25,7 +26,11 @@ export class OgbootStatusComponent implements OnInit { domain: ['#FF6384', '#3f51b5'] }; - constructor(private http: HttpClient, private joyrideService: JoyrideService) {} + constructor( + private http: HttpClient, + private joyrideService: JoyrideService, + private toastService: ToastrService, + ) {} ngOnInit(): void { this.loadStatus(); @@ -48,10 +53,12 @@ export class OgbootStatusComponent implements OnInit { value: parseFloat(this.diskUsage.available) } ]; + this.loading = false; + }, error => { - console.error('Error fetching status', error); + this.toastService.error('Error al sincronizar con el el servicio de og-boot'); + this.loading = false; }); - this.loading = false; } getServices(): { name: string, status: string }[] { diff --git a/ogWebconsole/src/app/components/ogdhcp/og-dhcp-subnets/status/status.component.ts b/ogWebconsole/src/app/components/ogdhcp/og-dhcp-subnets/status/status.component.ts index a320e7e..db2630d 100644 --- a/ogWebconsole/src/app/components/ogdhcp/og-dhcp-subnets/status/status.component.ts +++ b/ogWebconsole/src/app/components/ogdhcp/og-dhcp-subnets/status/status.component.ts @@ -48,10 +48,11 @@ export class StatusComponent { value: parseFloat(this.diskUsage.available) } ]; + this.loading = false; }, error => { + this.loading = false; console.error('Error fetching status', error); }); - this.loading = false; } getServices(): { name: string, status: string }[] { diff --git a/ogWebconsole/src/app/components/repositories/main-repository-view/main-repository-view.component.ts b/ogWebconsole/src/app/components/repositories/main-repository-view/main-repository-view.component.ts index 3b77099..15f3c75 100644 --- a/ogWebconsole/src/app/components/repositories/main-repository-view/main-repository-view.component.ts +++ b/ogWebconsole/src/app/components/repositories/main-repository-view/main-repository-view.component.ts @@ -209,7 +209,7 @@ export class MainRepositoryViewComponent implements OnInit { searchImages(): void { this.loading = true; - this.http.get(`${this.apiUrl}?repository.id=${this.repositoryData.id}&page=${this.page +1 }&itemsPerPage=${this.itemsPerPage}`, { params: this.filters }).subscribe( + this.http.get(`${this.apiUrl}?repositoryId=${this.repositoryData.id}&page=${this.page +1 }&itemsPerPage=${this.itemsPerPage}`, { params: this.filters }).subscribe( data => { this.dataSource.data = data['hydra:member']; this.length = data['hydra:totalItems']; diff --git a/ogWebconsole/src/app/components/repositories/repositories.component.html b/ogWebconsole/src/app/components/repositories/repositories.component.html index 204a119..9e776a5 100644 --- a/ogWebconsole/src/app/components/repositories/repositories.component.html +++ b/ogWebconsole/src/app/components/repositories/repositories.component.html @@ -1,3 +1,5 @@ + +