refs #1725 Use tab status component for dchp status in global component
testing/ogGui-multibranch/pipeline/head There was a failure building this commit Details

pull/18/head
Lucas Lara García 2025-03-19 13:02:25 +01:00
parent 50755bd1d5
commit 6c8ad465ea
3 changed files with 66 additions and 170 deletions

View File

@ -1,80 +1,7 @@
.dashboard {
display: flex;
flex-direction: column;
}
mat-dialog-content { mat-dialog-content {
padding-top: 0.5em !important; padding-top: 0.5em !important;
} }
.disk-usage-container {
display: flex;
flex-direction: column;
}
.disk-usage {
flex: 1;
display: flex;
flex-direction: row;
align-items: center;
justify-content: center;
}
.service-list {
margin-top: 0em;
margin-bottom: 0.5em;
}
.services-status {
display: flex;
flex-direction: column;
}
.services-status li {
margin: 5px 0;
display: flex;
align-items: center;
}
.status-led {
width: 10px;
height: 10px;
border-radius: 50%;
display: inline-block;
margin-right: 10px;
}
.status-led.active {
background-color: green;
}
.status-led.inactive {
background-color: red;
}
.disk-title {
margin-bottom: 0px;
}
.service-title {
margin-top: 0px;
}
table {
width: 100%;
border-collapse: collapse;
}
th,
td {
border: 1px solid #ddd;
padding: 8px;
}
th {
background-color: #f4f4f4;
}
.action-container { .action-container {
display: flex; display: flex;
justify-content: flex-end; justify-content: flex-end;

View File

@ -1,68 +1,39 @@
<header> <header>
<h1 mat-dialog-title>Estado global de la aplicación</h1> <h1 mat-dialog-title>Estado global de la aplicación</h1>
</header> </header>
<mat-dialog-content> <mat-dialog-content>
<mat-tab-group (selectedTabChange)="onTabChange($event)"> <mat-tab-group (selectedTabChange)="onTabChange($event)">
<mat-tab label="OgBoot"> <mat-tab label="OgBoot">
<app-loading [isLoading]="loading"></app-loading> <app-status-tab
<div *ngIf="!loading" class="dashboard"> [loading]="loading"
<!-- Disk Usage Section --> [diskUsage]="ogBootDiskUsage"
<div class="disk-usage-container"> [servicesStatus]="ogBootServicesStatus"
<h3 class="disk-title">{{ 'diskUsageTitle' | translate }}</h3> [installedOgLives]="installedOgLives"
<div class="disk-usage" joyrideStep="diskUsageStep" text="{{ 'diskUsageDescription' | translate }}"> [diskUsageChartData]="ogBootDiskUsageChartData"
<ngx-charts-pie-chart [view]="view" [scheme]="colorScheme" [results]="diskUsageChartData" [view]="view"
[doughnut]="isDoughnut" [labels]="showLabels"> [colorScheme]="colorScheme"
</ngx-charts-pie-chart> [isDoughnut]="isDoughnut"
<div class="disk-usage-info"> [showLabels]="showLabels">
<p>{{ 'totalLabel' | translate }}: <strong>{{ formatBytes(ogBootDiskUsage.total) }}</strong></p> </app-status-tab>
<p>{{ 'usedLabel' | translate }}: <strong>{{ formatBytes(ogBootDiskUsage.used) }}</strong></p> </mat-tab>
<p>{{ 'availableLabel' | translate }}: <strong>{{ formatBytes(ogBootDiskUsage.available) }}</strong></p>
<p>{{ 'freeLabel' | translate }}: <strong>{{ ogBootDiskUsage.percentage }}</strong></p>
</div>
</div>
</div>
<!-- Services Status Section --> <mat-tab label="Dhcp">
<div class="services-status" joyrideStep="servicesStatusStep" <app-status-tab
text="{{ 'servicesStatusDescription' | translate }}"> [loading]="loading"
<h3 class="service-title">{{ 'servicesTitle' | translate }}</h3> [diskUsage]="dhcpDiskUsage"
<ul class="service-list"> [servicesStatus]="dhcpServicesStatus"
<li *ngFor="let service of getServices()"> [installedOgLives]="installedOgLives"
<span class="status-led" [diskUsageChartData]="dhcpDiskUsageChartData"
[ngClass]="{ 'active': service.status === 'active', 'inactive': service.status !== 'active' }"></span> [view]="view"
{{ service.name }}: {{ service.status | translate }} [colorScheme]="colorScheme"
</li> [isDoughnut]="isDoughnut"
</ul> [showLabels]="showLabels">
</div> </app-status-tab>
</mat-tab>
<!-- Installed OgLives Section --> <mat-tab label="Pxe"> Content 3 </mat-tab>
<div class="installed-oglives" joyrideStep="oglivesStep" text="{{ 'oglivesDescription' | translate }}"> </mat-tab-group>
<h3>{{ 'installedOglivesTitle' | translate }}</h3>
<table>
<thead>
<tr>
<th>{{ 'idLabel' | translate }}</th>
<th>{{ 'kernelLabel' | translate }}</th>
<th>{{ 'architectureLabel' | translate }}</th>
<th>{{ 'revisionLabel' | translate }}</th>
</tr>
</thead>
<tbody>
<tr *ngFor="let oglive of installedOgLives">
<td>{{ oglive.id }}</td>
<td>{{ oglive.kernel }}</td>
<td>{{ oglive.architecture }}</td>
<td>{{ oglive.revision }}</td>
</tr>
</tbody>
</table>
</div>
</div>
</mat-tab>
<mat-tab label="Dhcp"> Content 2 </mat-tab>
<mat-tab label="Pxe"> Content 3 </mat-tab>
</mat-tab-group>
</mat-dialog-content> </mat-dialog-content>
<mat-dialog-actions class="action-container"> <mat-dialog-actions class="action-container">
<button class="ordinary-button" [mat-dialog-close]="true">{{ 'closeButton' | translate }}</button> <button class="ordinary-button" [mat-dialog-close]="true">{{ 'closeButton' | translate }}</button>
</mat-dialog-actions> </mat-dialog-actions>

View File

@ -11,14 +11,8 @@ import { MatTabChangeEvent } from '@angular/material/tabs';
}) })
export class GlobalStatusComponent implements OnInit { export class GlobalStatusComponent implements OnInit {
baseUrl: string; baseUrl: string;
ogBootApiUrl: string;
loading: boolean = false; loading: boolean = false;
ogBootDiskUsage: any = {};
ogBootSubnets: any[] = [];
ogBootServicesStatus: any = {};
installedOgLives: any[] = []; installedOgLives: any[] = [];
diskUsageChartData: any[] = [];
gradient: boolean = true;
showLabels: boolean = true; showLabels: boolean = true;
isDoughnut: boolean = true; isDoughnut: boolean = true;
colorScheme: any = { colorScheme: any = {
@ -26,6 +20,16 @@ export class GlobalStatusComponent implements OnInit {
}; };
view: [number, number] = [400, 220]; view: [number, number] = [400, 220];
ogBootApiUrl: string;
ogBootDiskUsage: any = {};
ogBootServicesStatus: any = {};
ogBootDiskUsageChartData: any[] = [];
dhcpApiUrl: string;
dhcpDiskUsage: any = {};
dhcpServicesStatus: any = {};
dhcpDiskUsageChartData: any[] = [];
constructor( constructor(
private configService: ConfigService, private configService: ConfigService,
private http: HttpClient, private http: HttpClient,
@ -33,60 +37,54 @@ export class GlobalStatusComponent implements OnInit {
) { ) {
this.baseUrl = this.configService.apiUrl; this.baseUrl = this.configService.apiUrl;
this.ogBootApiUrl = `${this.baseUrl}/og-boot/status`; this.ogBootApiUrl = `${this.baseUrl}/og-boot/status`;
this.dhcpApiUrl = `${this.baseUrl}/og-dhcp/status`;
} }
ngOnInit(): void { ngOnInit(): void {
this.loadOgBootStatus(); this.loadOgBootStatus();
} }
loadOgBootStatus(): void { loadStatus(apiUrl: string, diskUsage: any, servicesStatus: any, diskUsageChartData: any[]): void {
this.loading = true; this.loading = true;
this.http.get<any>(this.ogBootApiUrl).subscribe({ const timeoutId = setTimeout(() => {
this.loading = false;
this.toastService.error('Error al sincronizar: Tiempo de espera excedido')
}, 5000);
this.http.get<any>(apiUrl).subscribe({
next: data => { next: data => {
this.ogBootDiskUsage = data.message.disk_usage; diskUsage = data.message.disk_usage;
this.ogBootSubnets = data.message.subnets; servicesStatus = data.message.services_status;
this.ogBootServicesStatus = data.message.services_status;
this.installedOgLives = data.message.installed_oglives; this.installedOgLives = data.message.installed_oglives;
this.diskUsageChartData = [ diskUsageChartData = [
{ name: 'Usado', value: parseFloat(this.ogBootDiskUsage.used) }, { name: 'Usado', value: parseFloat(diskUsage.used) },
{ name: 'Disponible', value: parseFloat(this.ogBootDiskUsage.available) } { name: 'Disponible', value: parseFloat(diskUsage.available) }
]; ];
this.loading = false; this.loading = false;
clearTimeout(timeoutId);
}, },
error: error => { error: error => {
this.toastService.error('Error al sincronizar ogBoot'); this.toastService.error('Error al sincronizar');
console.log(error); console.log(error);
this.loading = false; this.loading = false;
clearTimeout(timeoutId);
} }
}); });
} }
loadOgBootStatus(): void {
this.loadStatus(this.ogBootApiUrl, this.ogBootDiskUsage, this.ogBootServicesStatus, this.ogBootDiskUsageChartData)
}
loadDhcpStatus(): void {
this.loadStatus(this.dhcpApiUrl, this.dhcpDiskUsage, this.dhcpServicesStatus, this.dhcpDiskUsageChartData)
}
onTabChange(event: MatTabChangeEvent): void { onTabChange(event: MatTabChangeEvent): void {
if (event.tab.textLabel === 'OgBoot') { if (event.tab.textLabel === 'OgBoot') {
this.loadOgBootStatus(); this.loadOgBootStatus();
} }
} else if (event.tab.textLabel === 'Dhcp') {
this.loadDhcpStatus();
getServices(): { name: string, status: string }[] {
if (!this.ogBootServicesStatus) {
return [];
}
const services = Object.keys(this.ogBootServicesStatus).map(key => ({
name: key,
status: this.ogBootServicesStatus[key]
}))
return services;
}
formatBytes(bytes: number): string {
if (bytes >= 1e9) {
return (bytes / 1e9).toFixed(2) + ' GB';
} else if (bytes >= 1e6) {
return (bytes / 1e6).toFixed(2) + ' MB';
} else if (bytes >= 1e3) {
return (bytes / 1e3).toFixed(2) + ' KB';
} else {
return bytes + ' B';
} }
} }
} }