refs #917 Refactor disk usage calculation and display

develop-jenkins
Alvaro Puente Mella 2024-10-17 11:44:55 +02:00
parent a4e1f44218
commit 9de990edf2
3 changed files with 229 additions and 182 deletions

View File

@ -1,6 +1,3 @@
.client-header { .client-header {
display: flex; display: flex;
align-items: center; align-items: center;
@ -43,6 +40,10 @@
.info-section { .info-section {
margin-bottom: 30px; margin-bottom: 30px;
background-color: #fff;
padding: 20px;
border-radius: 12px;
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
} }
.two-column-table { .two-column-table {
@ -78,14 +79,6 @@
min-height: inherit; min-height: inherit;
} }
.info-section {
background-color: #fff;
padding: 20px;
border-radius: 12px;
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
height: auto;
}
.info-section h2 { .info-section h2 {
font-size: 1.4rem; font-size: 1.4rem;
margin-bottom: 10px; margin-bottom: 10px;
@ -97,17 +90,43 @@
margin: 5px 0; margin: 5px 0;
} }
.second-section {
display: grid;
grid-template-columns: 1fr 3fr;
gap: 20px;
}
.buttons-row {
display: flex;
flex-direction: column;
background-color: #fff;
padding: 20px;
border-radius: 12px;
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
justify-content: flex-start;
}
.buttons-row button {
margin-bottom: 10px;
width: 100%;
}
.disk-usage { .disk-usage {
display: flex; display: flex;
align-items: center; align-items: center;
justify-content: center; justify-content: center;
flex-direction: column; flex-direction: column;
margin-bottom: 20px;
background-color: #fff;
padding: 20px;
border-radius: 12px;
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
} }
.chart-container { .chart-container {
width: 150px; width: 150px;
height: 150px; height: 150px;
margin-bottom: 10px; margin-bottom: 15px;
} }
.circular-chart { .circular-chart {
@ -119,7 +138,7 @@
.circle-bg { .circle-bg {
fill: none; fill: none;
stroke: #eee; stroke: #f0f0f0;
stroke-width: 3.8; stroke-width: 3.8;
} }
@ -133,10 +152,22 @@
.percentage { .percentage {
fill: #333; fill: #333;
font-size: 0.5rem; font-size: 0.7rem;
text-anchor: middle; text-anchor: middle;
} }
.disk-usage h3 {
margin: 0 0 10px 0;
font-size: 1.2rem;
color: #333;
}
@keyframes progress {
0% {
stroke-dasharray: 0, 100;
}
}
.assistants-container { .assistants-container {
background-color: #fff; background-color: #fff;
margin-top: 10px; margin-top: 10px;
@ -144,15 +175,3 @@
border-radius: 12px; border-radius: 12px;
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1); box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
} }
.buttons-row{
display: flex;
justify-content: space-between;
padding: 20px;
}
@keyframes progress {
0% {
stroke-dasharray: 0, 100;
}
}

View File

@ -27,9 +27,18 @@
</mat-tab> </mat-tab>
</mat-tab-group> </mat-tab-group>
</div> </div>
<div class="second-section">
<div class="buttons-row">
<button mat-flat-button color="primary" (click)="togglePartitionAssistant()">Asistente a particionado</button>
<button mat-flat-button color="primary" (click)="showBootImage()">Restaurar imagen</button>
</div>
<div class="info-section"> <div class="info-section">
<h2 *ngIf="isDiskUsageVisible">Disco</h2> <h2 *ngIf="isDiskUsageVisible">Disco</h2>
<div class="disk-usage" *ngIf="isDiskUsageVisible"> <ng-container *ngIf="diskUsageData && diskUsageData.length > 0">
<div *ngFor="let disk of diskUsageData" class="disk-usage">
<h3>Disco {{ disk.diskNumber }}</h3>
<div class="chart-container"> <div class="chart-container">
<svg viewBox="0 0 36 36" class="circular-chart green"> <svg viewBox="0 0 36 36" class="circular-chart green">
<path class="circle-bg" <path class="circle-bg"
@ -37,24 +46,21 @@
a 15.9155 15.9155 0 0 1 0 31.831 a 15.9155 15.9155 0 0 1 0 31.831
a 15.9155 15.9155 0 0 1 0 -31.831" /> a 15.9155 15.9155 0 0 1 0 -31.831" />
<path class="circle" <path class="circle"
stroke-dasharray="75, 100" [attr.stroke-dasharray]="disk.percentage + ', 100'"
d="M18 2.0845 d="M18 2.0845
a 15.9155 15.9155 0 0 1 0 31.831 a 15.9155 15.9155 0 0 1 0 31.831
a 15.9155 15.9155 0 0 1 0 -31.831" /> a 15.9155 15.9155 0 0 1 0 -31.831" />
<text x="18" y="20.35" class="percentage">75%</text> <text x="18" y="20.35" class="percentage">{{ disk.percentage }}%</text>
</svg> </svg>
</div> </div>
<p>Usado: 75% (375GB)</p> <p>Usado: {{ disk.used }} GB ({{ disk.percentage }}%)</p>
<p>Total: 500GB</p> <p>Total: {{ disk.total }} GB</p>
</div>
</ng-container>
</div> </div>
<div class="buttons-row">
<button mat-flat-button color="primary" (click)="togglePartitionAssistant()">Asistente a particionado</button>
<button mat-flat-button color="primary" (click)="showBootImage()">Restaurar imagen</button>
</div> </div>
</div> </div>
</div>
<div class="assistants-container" *ngIf="isPartitionAssistantVisible"> <div class="assistants-container" *ngIf="isPartitionAssistantVisible">
<app-partition-assistant [data]="clientData"></app-partition-assistant> <app-partition-assistant [data]="clientData"></app-partition-assistant>

View File

@ -16,14 +16,12 @@ export class ClientMainViewComponent implements OnInit {
clientData: any = {}; clientData: any = {};
isPartitionAssistantVisible: boolean = false; isPartitionAssistantVisible: boolean = false;
isBootImageVisible: boolean = false; isBootImageVisible: boolean = false;
isGeneralInfoVisible: boolean = true;
isDiskUsageVisible: boolean = true; isDiskUsageVisible: boolean = true;
displayedColumns: string[] = ['property', 'value'];
generalData: ClientInfo[] = []; generalData: ClientInfo[] = [];
networkData: ClientInfo[] = []; networkData: ClientInfo[] = [];
classroomData: ClientInfo[] = []; classroomData: ClientInfo[] = [];
diskUsageData: any[] = [];
constructor(private http: HttpClient) { constructor(private http: HttpClient) {
const url = window.location.href; const url = window.location.href;
@ -32,10 +30,11 @@ export class ClientMainViewComponent implements OnInit {
} }
ngOnInit() { ngOnInit() {
this.clientData = history.state.clientData this.clientData = history.state.clientData;
this.updateGeneralData(); this.updateGeneralData();
this.updateNetworkData(); this.updateNetworkData();
this.updateClassroomData(); this.updateClassroomData();
this.calculateDiskUsage();
} }
updateGeneralData() { updateGeneralData() {
@ -82,6 +81,29 @@ export class ClientMainViewComponent implements OnInit {
]; ];
} }
calculateDiskUsage() {
const diskUsageMap = new Map<number, { total: number, used: number }>();
this.clientData.partitions.forEach((partition: any) => {
const diskNumber = partition.diskNumber;
if (!diskUsageMap.has(diskNumber)) {
diskUsageMap.set(diskNumber, { total: 0, used: 0 });
}
const diskData = diskUsageMap.get(diskNumber);
if (partition.partitionNumber === 0) {
diskData!.total = partition.size / (1024 * 1024);
} else {
diskData!.used += partition.size / (1024 * 1024);
}
});
this.diskUsageData = Array.from(diskUsageMap.entries()).map(([diskNumber, { total, used }]) => {
const percentage = total > 0 ? Math.round((used / total) * 100) : 0;
return { diskNumber, total, used, percentage };
});
}
togglePartitionAssistant() { togglePartitionAssistant() {
this.isPartitionAssistantVisible = !this.isPartitionAssistantVisible; this.isPartitionAssistantVisible = !this.isPartitionAssistantVisible;
this.isBootImageVisible = false; this.isBootImageVisible = false;