From 975e77d5aa466a6d67971d5bc239fa70cfac3acf Mon Sep 17 00:00:00 2001 From: jmbardallo Date: Wed, 6 May 2026 12:38:54 +0200 Subject: [PATCH] Modificada vista para eliminar imagen de cache, se muestra la lista de ficheros de imagen contenida en la cache y se borra el fichero --- CHANGELOG.md | 4 + .../remove-cache-image.component.html | 157 ++++++++---------- .../remove-cache-image.component.ts | 81 +++++---- ogWebconsole/src/locale/cat.json | 2 +- ogWebconsole/src/locale/en.json | 2 +- ogWebconsole/src/locale/es.json | 2 +- 6 files changed, 131 insertions(+), 117 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 97f4414..57c323e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## [1.5.7] - 2026-05-05 +### Fixed +- Modificada vista para eliminar imagen de cache, se muestra la lista de ficheros de imagen contenida en la cache y se borra el fichero + ## [1.5.6] - 2026-05-05 ### Fixed - Corregida edicion de menus diff --git a/ogWebconsole/src/app/components/commands/main-commands/execute-command/remove-cache-image/remove-cache-image.component.html b/ogWebconsole/src/app/components/commands/main-commands/execute-command/remove-cache-image/remove-cache-image.component.html index 460fb65..b7643fa 100644 --- a/ogWebconsole/src/app/components/commands/main-commands/execute-command/remove-cache-image/remove-cache-image.component.html +++ b/ogWebconsole/src/app/components/commands/main-commands/execute-command/remove-cache-image/remove-cache-image.component.html @@ -1,103 +1,90 @@

{{ 'selectImageToDeleteFromCache' | translate }}

- + @if (loading) { + + } -
- - - {{ 'labelClients' | translate }} - - {{ 'clientListBootOs' | translate }}desktop_windows - - + @if (!loading) { +
+ + + {{ 'labelClients' | translate }} + + {{ 'clientListBootOs' | translate }}desktop_windows + + -
- -
- -
-
-
- - Client Icon - -
- {{ client.name | slice:0:20 }} - {{ client.ip }} - {{ client.mac }} -
- - - - - {{ 'labelModel' | translate }} - -
+
+
-
- -
+
+ @for (client of data.clients; track client['@id']) { +
+
- + Client Icon -
- - - - - +
+ {{ client.name | slice:0:20 }} + {{ client.ip }} + {{ client.mac }} +
+ - - - + +
{{ 'buttonSelectImage' | translate }} - - - - - {{ column.header | translate }} - - {{ column.cell(image) }} - - - -
- {{ image.size }} MB - {{ image.size / 1024 }} GB + + + {{ 'labelModel' | translate }} + +
+ } + + + + + + + +
+ + + + + + + @for (column of columns; track column.columnDef) { + + + + } - -
- {{ image.operativeSystem?.name }} - {{ image.image?.name}} -
-
- - - - - - -
{{ 'buttonSelectImage' | translate }} + + + + {{ column.header | translate }} + {{ column.cell(image) }} +
-
+
+
+ }
- +
diff --git a/ogWebconsole/src/app/components/commands/main-commands/execute-command/remove-cache-image/remove-cache-image.component.ts b/ogWebconsole/src/app/components/commands/main-commands/execute-command/remove-cache-image/remove-cache-image.component.ts index 782b7cd..390c235 100644 --- a/ogWebconsole/src/app/components/commands/main-commands/execute-command/remove-cache-image/remove-cache-image.component.ts +++ b/ogWebconsole/src/app/components/commands/main-commands/execute-command/remove-cache-image/remove-cache-image.component.ts @@ -15,7 +15,7 @@ import {ToastrService} from "ngx-toastr"; export class RemoveCacheImageComponent { public translate = inject(TranslateService); baseUrl: string; - selectedPartition: any = null; + selectedImage: any = null; dataSource = new MatTableDataSource(); clientId: string | null = null; selectedClients: any[] = []; @@ -26,34 +26,14 @@ export class RemoveCacheImageComponent { loading: boolean = false; columns = [ { - columnDef: 'diskNumber', - header: 'labelDisk', - cell: (partition: any) => partition.diskNumber - }, - { - columnDef: 'partitionNumber', - header: 'partition', - cell: (partition: any) => partition.partitionNumber + columnDef: 'name', + header: 'name', + cell: (image: any) => image.name }, { columnDef: 'size', - header: 'labelDiskSize', - cell: (partition: any) => `${partition.size} MB` - }, - { - columnDef: 'partitionCode', - header: 'partitionType', - cell: (partition: any) => partition.partitionCode - }, - { - columnDef: 'filesystem', - header: 'fileSystem', - cell: (partition: any) => partition.filesystem - }, - { - columnDef: 'operativeSystem', - header: 'sW', - cell: (partition: any) => partition.operativeSystem?.name + header: 'size', + cell: (image: any) => this.formatBytes(image.size) } ]; @@ -97,9 +77,43 @@ export class RemoveCacheImageComponent { this.http.get(url).subscribe( (response: any) => { if (response.partitions) { - this.dataSource.data = response.partitions.filter((partition: any) => { - return partition.partitionNumber !== 0 && partition.image; + const cachePartitions = response.partitions.filter((partition: any) => { + return partition.partitionNumber !== 0 && partition.filesystem === 'CACHE' && partition.cacheContent !== ""; }); + + let imagesMap: { [key: string]: number } = {}; + + cachePartitions.forEach((p: any) => { + if (p.cacheContent) { + const items = p.cacheContent.split(','); + items.forEach((item: string) => { + const parts = item.split(':'); + if (parts.length >= 2) { + const filename = parts[0]; + let size = 0; + + let baseName = filename; + if (baseName.endsWith('.img.full.sum')) baseName = baseName.replace('.img.full.sum', ''); + else if (baseName.endsWith('.img.sum')) baseName = baseName.replace('.img.sum', ''); + // El tamaño de la imagen que usamos es sólo del fichero .img + else if (baseName.endsWith('.img')) { + baseName = baseName.replace('.img', ''); + size = parseInt(parts[1], 10) || 0; + } + + if (!imagesMap[baseName]) { + imagesMap[baseName] = 0; + } + imagesMap[baseName] += size; + } + }); + } + }); + + this.dataSource.data = Object.keys(imagesMap).map(name => ({ + name: name, + size: imagesMap[name] + })); } }, (error) => { @@ -108,6 +122,15 @@ export class RemoveCacheImageComponent { ); } + formatBytes(bytes: number, decimals = 2) { + if (bytes === 0) return '0 Bytes'; + const k = 1024; + const dm = decimals < 0 ? 0 : decimals; + const sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB']; + const i = Math.floor(Math.log(bytes) / Math.log(k)); + return parseFloat((bytes / Math.pow(k, i)).toFixed(dm)) + ' ' + sizes[i]; + } + toggleClientSelection(client: any) { client.selected = !client.selected; this.updateSelectedClients(); @@ -141,7 +164,7 @@ export class RemoveCacheImageComponent { this.loading = true; this.http.post(`${this.baseUrl}/clients/server/remove-cache-image`, { clients: this.selectedClients.map((client: any) => client.uuid), - partition: this.selectedPartition['@id'] + imageName: this.selectedImage.name }).subscribe( response => { this.toastService.success(this.translate.instant('clientUpdatedSuccessfully')); diff --git a/ogWebconsole/src/locale/cat.json b/ogWebconsole/src/locale/cat.json index a69d3f6..0942b70 100644 --- a/ogWebconsole/src/locale/cat.json +++ b/ogWebconsole/src/locale/cat.json @@ -575,7 +575,7 @@ "login": "Iniciar sessió", "createImage": "Crear imatge", "deployImage": "Desplegar imatge", - "deleteImageCache": "Esborrar cache d'imatge", + "deleteImageCache": "Esborrar imatge de cache", "partition": "Particionar i formatar", "softwareInventory": "Inventari de software", "hardwareInventory": "Inventari de hardware", diff --git a/ogWebconsole/src/locale/en.json b/ogWebconsole/src/locale/en.json index 3857c4a..558716d 100644 --- a/ogWebconsole/src/locale/en.json +++ b/ogWebconsole/src/locale/en.json @@ -575,7 +575,7 @@ "login": "Login", "createImage": "Create Image", "deployImage": "Deploy Image", - "deleteImageCache": "Delete Image Cache", + "deleteImageCache": "Delete Image from Cache", "partition": "Partition and Format", "softwareInventory": "Software Inventory", "hardwareInventory": "Hardware Inventory", diff --git a/ogWebconsole/src/locale/es.json b/ogWebconsole/src/locale/es.json index c1dce8f..d14ecd4 100644 --- a/ogWebconsole/src/locale/es.json +++ b/ogWebconsole/src/locale/es.json @@ -575,7 +575,7 @@ "login": "Iniciar sesión", "createImage": "Crear imagen", "deployImage": "Desplegar imagen", - "deleteImageCache": "Borrar caché de imagen", + "deleteImageCache": "Borrar imagen de cache", "partition": "Particionar y formatear", "softwareInventory": "Inventario de software", "hardwareInventory": "Inventario de hardware",