refs #1941 Refactor partition type organizer: enhance data structure and improve client grouping logic
testing/ogGui-multibranch/pipeline/head This commit looks good Details

pull/22/head
Lucas Lara García 2025-05-02 13:24:06 +02:00
parent 35512ce65f
commit f6dbd6dad9
4 changed files with 113 additions and 30 deletions

View File

@ -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<any>(`${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();

View File

@ -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;
}

View File

@ -1,42 +1,47 @@
<mat-dialog-content class="modal-content">
<div *ngFor="let client of simplifiedData" class="client-section">
<h3 class="client-title">{{ client.name }}</h3>
<div *ngFor="let group of groupedPartitions" class="client-section">
<h3 class="client-title">
{{ group.clientNames.length === 1 ? group.clientNames[0] : 'Clientes (' + group.clientNames.length + '): ' +
group.clientNames.join(', ') }}
</h3>
<table mat-table [dataSource]="client.partitions" class="mat-elevation-z1 partition-table">
<table mat-table [dataSource]="group.partitions" class="mat-elevation-z2 partition-table">
<!-- Disco -->
<ng-container matColumnDef="diskNumber">
<th mat-header-cell *matHeaderCellDef>Disco</th>
<td mat-cell *matCellDef="let element">{{ element.diskNumber }}</td>
</ng-container>
<!-- Partición -->
<ng-container matColumnDef="partitionNumber">
<th mat-header-cell *matHeaderCellDef>Partición</th>
<td mat-cell *matCellDef="let element">{{ element.partitionNumber }}</td>
</ng-container>
<!-- Tipo -->
<ng-container matColumnDef="partitionCode">
<th mat-header-cell *matHeaderCellDef>Tipo</th>
<td mat-cell *matCellDef="let element">{{ element.partitionCode }}</td>
</ng-container>
<!-- Tamaño -->
<ng-container matColumnDef="size">
<th mat-header-cell *matHeaderCellDef>Tamaño</th>
<td mat-cell *matCellDef="let element">{{ element.size }}</td>
<th mat-header-cell *matHeaderCellDef>Tamaño (MB)</th>
<td mat-cell *matCellDef="let element">{{ element.size | number }}</td>
</ng-container>
<!-- File System -->
<ng-container matColumnDef="filesystem">
<th mat-header-cell *matHeaderCellDef>Fyle System</th>
<td mat-cell *matCellDef="let element">{{ element.filesystem }}</td>
</ng-container>
<ng-container matColumnDef="memoryUsage">
<th mat-header-cell *matHeaderCellDef>Memoria</th>
<td mat-cell *matCellDef="let element">{{ element.memoryUsage }}</td>
<th mat-header-cell *matHeaderCellDef>File System</th>
<td mat-cell *matCellDef="let element">
<span *ngIf="!element.isSummary; else summaryFs">{{ element.filesystem || '-' }}</span>
<ng-template #summaryFs><em class="summary-label">Resumen</em></ng-template>
</td>
</ng-container>
<tr mat-header-row *matHeaderRowDef="displayedColumns"></tr>
<tr mat-row *matRowDef="let row; columns: displayedColumns;"></tr>
<tr mat-row *matRowDef="let row; columns: displayedColumns;" [ngClass]="{ 'summary-row': row.isSummary }"></tr>
</table>
</div>
</mat-dialog-content>

View File

@ -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);
}
}