From 1d28e443a3996bb7c361c830ebcf3c733925eec2 Mon Sep 17 00:00:00 2001 From: Lucas Lara Date: Tue, 25 Mar 2025 15:30:26 +0100 Subject: [PATCH] Refactor Global Status component to support individual error handling for repositories --- .../global-status.component.html | 4 +-- .../global-status/global-status.component.ts | 29 ++++++++++++------- 2 files changed, 20 insertions(+), 13 deletions(-) diff --git a/ogWebconsole/src/app/components/global-status/global-status.component.html b/ogWebconsole/src/app/components/global-status/global-status.component.html index 6add399..ae4d259 100644 --- a/ogWebconsole/src/app/components/global-status/global-status.component.html +++ b/ogWebconsole/src/app/components/global-status/global-status.component.html @@ -55,7 +55,7 @@ -
+
- +

{{ 'errorLoadingData' | translate }}

diff --git a/ogWebconsole/src/app/components/global-status/global-status.component.ts b/ogWebconsole/src/app/components/global-status/global-status.component.ts index 4eb996a..9991495 100644 --- a/ogWebconsole/src/app/components/global-status/global-status.component.ts +++ b/ogWebconsole/src/app/components/global-status/global-status.component.ts @@ -1,7 +1,6 @@ import { HttpClient } from '@angular/common/http'; import { Component, OnInit } from '@angular/core'; import { ConfigService } from '@services/config.service'; -import { ToastrService } from 'ngx-toastr'; import { MatTabChangeEvent } from '@angular/material/tabs'; @Component({ @@ -14,7 +13,7 @@ export class GlobalStatusComponent implements OnInit { loading: boolean = false; errorOgBoot: boolean = false; errorDhcp: boolean = false; - errorRepositories: boolean = false; + errorRepositories: { [key: string]: boolean } = {}; installedOgLives: any[] = []; subnets: any[] = []; showLabels: boolean = true; @@ -41,8 +40,7 @@ export class GlobalStatusComponent implements OnInit { constructor( private configService: ConfigService, - private http: HttpClient, - private toastService: ToastrService + private http: HttpClient ) { this.baseUrl = this.configService.apiUrl; this.ogBootApiUrl = `${this.baseUrl}/og-boot/status`; @@ -69,9 +67,9 @@ export class GlobalStatusComponent implements OnInit { diskUsage.available = data.message.disk_usage.available; diskUsage.total = data.message.disk_usage.total; diskUsage.percentage = data.message.disk_usage.percentage; - + Object.assign(servicesStatus, data.message.services_status); - + if (isDhcp) { this.subnets.length = 0; if (data.message.subnets) { @@ -83,13 +81,13 @@ export class GlobalStatusComponent implements OnInit { installedOgLives.push(...data.message.installed_oglives); } } - + diskUsageChartData.length = 0; diskUsageChartData.push( { name: 'Usado', value: parseFloat(diskUsage.used) }, { name: 'Disponible', value: parseFloat(diskUsage.available) } ); - + this.loading = false; clearTimeout(timeoutId); }, @@ -104,10 +102,12 @@ export class GlobalStatusComponent implements OnInit { loadRepositories(): void { this.loading = true; - this.errorRepositories = false; + this.errorRepositories = {}; const timeoutId = setTimeout(() => { this.loading = false; - this.errorRepositories = true; + this.repositories.forEach(repository => { + this.errorRepositories[repository.uuid] = true; + }); }, 5000); this.http.get(`${this.repositoriesUrl}?page=1&itemsPerPage=10`).subscribe( data => { @@ -120,13 +120,20 @@ export class GlobalStatusComponent implements OnInit { this.loading = false; clearTimeout(timeoutId); } + if (errorOccurred) { + this.errorRepositories[repository.uuid] = true; + } else { + this.errorRepositories[repository.uuid] = false; + } }); }); }, error => { console.error('Error fetching repositories', error); this.loading = false; - this.errorRepositories = true; + this.repositories.forEach(repository => { + this.errorRepositories[repository.uuid] = true; + }); clearTimeout(timeoutId); } );