From f6dbd6dad99b75d0ec0f53fac8ecd75ff5137a73 Mon Sep 17 00:00:00 2001 From: Lucas Lara Date: Fri, 2 May 2025 13:24:06 +0200 Subject: [PATCH] refs #1941 Refactor partition type organizer: enhance data structure and improve client grouping logic --- .../app/components/groups/groups.component.ts | 10 +-- .../partition-type-organizator.component.css | 13 ++- .../partition-type-organizator.component.html | 33 ++++--- .../partition-type-organizator.component.ts | 87 +++++++++++++++++-- 4 files changed, 113 insertions(+), 30 deletions(-) diff --git a/ogWebconsole/src/app/components/groups/groups.component.ts b/ogWebconsole/src/app/components/groups/groups.component.ts index 16a8dc7..3e07050 100644 --- a/ogWebconsole/src/app/components/groups/groups.component.ts +++ b/ogWebconsole/src/app/components/groups/groups.component.ts @@ -583,11 +583,11 @@ export class GroupsComponent implements OnInit, OnDestroy { onRoomMap(room: TreeNode | null): void { if (!room || !room['@id']) return; this.subscriptions.add( - this.http.get(`${this.baseUrl}/clients?organizationalUnit.id=${room.id}`, { }).subscribe( + this.http.get<{ clients: Client[] }>(`${this.baseUrl}${room['@id']}`).subscribe( (response) => { this.dialog.open(ClassroomViewDialogComponent, { width: '90vw', - data: { clients: response['hydra:member'] }, + data: { clients: response.clients }, }); }, (error) => { @@ -612,7 +612,7 @@ export class GroupsComponent implements OnInit, OnDestroy { onShowClientDetail(event: MouseEvent, client: Client): void { event.stopPropagation(); this.dialog.open(ClientDetailsComponent, { - width: '1300px', + width: '1200px', data: { clientData: client }, }) } @@ -832,7 +832,7 @@ export class GroupsComponent implements OnInit, OnDestroy { getRunScriptContext(clientData: any[]): any { const selectedClientNames = clientData.map(client => client.name); - + if (clientData.length === 1) { return clientData[0]; // devuelve el objeto cliente completo } else if ( @@ -847,7 +847,7 @@ export class GroupsComponent implements OnInit, OnDestroy { } return null; } - + openPartitionTypeModal(event: MouseEvent, node: TreeNode | null = null): void { event.stopPropagation(); diff --git a/ogWebconsole/src/app/components/groups/shared/partition-type-organizator/partition-type-organizator.component.css b/ogWebconsole/src/app/components/groups/shared/partition-type-organizator/partition-type-organizator.component.css index aa2921c..8172cde 100644 --- a/ogWebconsole/src/app/components/groups/shared/partition-type-organizator/partition-type-organizator.component.css +++ b/ogWebconsole/src/app/components/groups/shared/partition-type-organizator/partition-type-organizator.component.css @@ -36,11 +36,20 @@ } .partition-table th { - background-color: #f5f5f5; + background-color: #ebebeb; font-weight: 500; - color: #444; + color: #252525; } .partition-table tr:hover td { background-color: #f9f9f9; +} + +.summary-row { + font-weight: 500; + background-color: #ebebeb; +} + +.partition-table tr:hover td { + background-color: unset; } \ No newline at end of file diff --git a/ogWebconsole/src/app/components/groups/shared/partition-type-organizator/partition-type-organizator.component.html b/ogWebconsole/src/app/components/groups/shared/partition-type-organizator/partition-type-organizator.component.html index 6f25123..8c66c0a 100644 --- a/ogWebconsole/src/app/components/groups/shared/partition-type-organizator/partition-type-organizator.component.html +++ b/ogWebconsole/src/app/components/groups/shared/partition-type-organizator/partition-type-organizator.component.html @@ -1,42 +1,47 @@ -
-

{{ client.name }}

+
+

+ {{ group.clientNames.length === 1 ? group.clientNames[0] : 'Clientes (' + group.clientNames.length + '): ' + + group.clientNames.join(', ') }} +

- +
+ + + + - - + + + - - - - - - - + + - - +
Disco {{ element.diskNumber }} Partición {{ element.partitionNumber }} Tipo {{ element.partitionCode }} Tamaño{{ element.size }}Tamaño (MB){{ element.size | number }} Fyle System{{ element.filesystem }}Memoria{{ element.memoryUsage }}File System + {{ element.filesystem || '-' }} + Resumen +
\ No newline at end of file diff --git a/ogWebconsole/src/app/components/groups/shared/partition-type-organizator/partition-type-organizator.component.ts b/ogWebconsole/src/app/components/groups/shared/partition-type-organizator/partition-type-organizator.component.ts index b9eb8f5..99337c6 100644 --- a/ogWebconsole/src/app/components/groups/shared/partition-type-organizator/partition-type-organizator.component.ts +++ b/ogWebconsole/src/app/components/groups/shared/partition-type-organizator/partition-type-organizator.component.ts @@ -1,28 +1,97 @@ import { Component, Inject, OnInit } from '@angular/core'; import { MAT_DIALOG_DATA } from '@angular/material/dialog'; +interface Partition { + diskNumber: number; + partitionNumber: number; + partitionCode: string; + size: number; + filesystem: string | null; + isSummary?: boolean; +} + +interface SimplifiedClient { + name: string; + partitions: Partition[]; +} + +interface GroupedClientPartitions { + clientNames: string[]; + partitions: Partition[]; +} + @Component({ selector: 'app-partition-type-organizator', templateUrl: './partition-type-organizator.component.html', styleUrl: './partition-type-organizator.component.css' }) export class PartitionTypeOrganizatorComponent implements OnInit { - constructor(@Inject(MAT_DIALOG_DATA) public data: any) { } + displayedColumns: string[] = ['diskNumber', 'partitionNumber', 'partitionCode', 'size', 'filesystem']; + groupedPartitions: GroupedClientPartitions[] = []; - public simplifiedData: any[] = []; - displayedColumns: string[] = ['diskNumber', 'partitionNumber', 'partitionCode', 'size', 'filesystem', 'memoryUsage']; + constructor(@Inject(MAT_DIALOG_DATA) public data: SimplifiedClient[]) { } ngOnInit(): void { - this.simplifiedData = this.data.map((client: any) => ({ - name: client.name, - partitions: client.partitions.map((p: any) => ({ + const simplifiedClients = this.simplifyClients(this.data); + this.groupedPartitions = this.groupClientsByPartitions(simplifiedClients); + } + + private simplifyClients(clients: SimplifiedClient[]): SimplifiedClient[] { + return clients.map(client => { + const partitionZero = client.partitions.find(p => p.partitionNumber === 0); + const otherPartitions = client.partitions.filter(p => p.partitionNumber !== 0); + + const simplifiedPartitions: Partition[] = otherPartitions.map(p => ({ diskNumber: p.diskNumber, partitionNumber: p.partitionNumber, partitionCode: p.partitionCode, size: p.size, filesystem: p.filesystem, - memoryUsage: p.memoryUsage - })) - })); + isSummary: false + })); + + if (partitionZero) { + simplifiedPartitions.push({ + diskNumber: partitionZero.diskNumber, + partitionNumber: partitionZero.partitionNumber, + partitionCode: partitionZero.partitionCode, + size: partitionZero.size, + filesystem: null, + isSummary: true + }); + } + + return { + name: client.name, + partitions: simplifiedPartitions + }; + }); + } + + private groupClientsByPartitions(clients: SimplifiedClient[]): GroupedClientPartitions[] { + const groups: GroupedClientPartitions[] = []; + + clients.forEach(client => { + const normalizedPartitions = this.normalizePartitions(client.partitions); + + const existingGroup = groups.find(group => + JSON.stringify(this.normalizePartitions(group.partitions)) === JSON.stringify(normalizedPartitions) + ); + + if (existingGroup) { + existingGroup.clientNames.push(client.name); + } else { + groups.push({ + clientNames: [client.name], + partitions: client.partitions + }); + } + }); + + return groups; + } + + private normalizePartitions(partitions: Partition[]): Partition[] { + return [...partitions].sort((a, b) => a.partitionNumber - b.partitionNumber); } }