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 {
display: flex;
align-items: center;
@ -43,6 +40,10 @@
.info-section {
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 {
@ -78,14 +79,6 @@
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 {
font-size: 1.4rem;
margin-bottom: 10px;
@ -97,17 +90,43 @@
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 {
display: flex;
align-items: center;
justify-content: center;
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 {
width: 150px;
height: 150px;
margin-bottom: 10px;
margin-bottom: 15px;
}
.circular-chart {
@ -119,7 +138,7 @@
.circle-bg {
fill: none;
stroke: #eee;
stroke: #f0f0f0;
stroke-width: 3.8;
}
@ -133,10 +152,22 @@
.percentage {
fill: #333;
font-size: 0.5rem;
font-size: 0.7rem;
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 {
background-color: #fff;
margin-top: 10px;
@ -144,15 +175,3 @@
border-radius: 12px;
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-group>
</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">
<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">
<svg viewBox="0 0 36 36" class="circular-chart green">
<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" />
<path class="circle"
stroke-dasharray="75, 100"
[attr.stroke-dasharray]="disk.percentage + ', 100'"
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" />
<text x="18" y="20.35" class="percentage">75%</text>
<text x="18" y="20.35" class="percentage">{{ disk.percentage }}%</text>
</svg>
</div>
<p>Usado: 75% (375GB)</p>
<p>Total: 500GB</p>
<p>Usado: {{ disk.used }} GB ({{ disk.percentage }}%)</p>
<p>Total: {{ disk.total }} GB</p>
</div>
</ng-container>
</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 class="assistants-container" *ngIf="isPartitionAssistantVisible">
<app-partition-assistant [data]="clientData"></app-partition-assistant>

View File

@ -16,14 +16,12 @@ export class ClientMainViewComponent implements OnInit {
clientData: any = {};
isPartitionAssistantVisible: boolean = false;
isBootImageVisible: boolean = false;
isGeneralInfoVisible: boolean = true;
isDiskUsageVisible: boolean = true;
displayedColumns: string[] = ['property', 'value'];
generalData: ClientInfo[] = [];
networkData: ClientInfo[] = [];
classroomData: ClientInfo[] = [];
diskUsageData: any[] = [];
constructor(private http: HttpClient) {
const url = window.location.href;
@ -32,10 +30,11 @@ export class ClientMainViewComponent implements OnInit {
}
ngOnInit() {
this.clientData = history.state.clientData
this.clientData = history.state.clientData;
this.updateGeneralData();
this.updateNetworkData();
this.updateClassroomData();
this.calculateDiskUsage();
}
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() {
this.isPartitionAssistantVisible = !this.isPartitionAssistantVisible;
this.isBootImageVisible = false;