From b646cd44777382bb1d513d8ffb34aedcfa4984e5 Mon Sep 17 00:00:00 2001 From: Albrecht Lohofener Date: Wed, 26 Mar 2025 17:29:31 +0100 Subject: [PATCH] Improve showing of IP adresses --- .../src/app/backend-communication.service.ts | 27 ++++++++-- .../app/dashboard/dashboard.component.html | 54 ++++++++++--------- .../src/app/dashboard/dashboard.component.ts | 2 +- 3 files changed, 54 insertions(+), 29 deletions(-) diff --git a/web-frontend/src/app/backend-communication.service.ts b/web-frontend/src/app/backend-communication.service.ts index 1ed1821..9afdffc 100644 --- a/web-frontend/src/app/backend-communication.service.ts +++ b/web-frontend/src/app/backend-communication.service.ts @@ -18,8 +18,8 @@ interface AttachedHardware { providedIn: 'root' }) export class BackendCommunicationService { - urlPrefix: string = 'http://localhost:8006'; // Just for development - //urlPrefix: string = ''; + //urlPrefix: string = 'http://localhost:8006'; // Just for development + urlPrefix: string = ''; constructor(private http: HttpClient) { } @@ -114,7 +114,7 @@ export class BackendCommunicationService { return this.http.get(this.urlPrefix + '/api/get_openwrt_ip_addresses').pipe( tap(response => console.log('Fetched OpenWrt IP addresses: ', response)), map(response => { - let tmpEthernetInterfaces= ''; + let tmpEthernetInterfaces= 'Unknown'; if (response['combined_output'] !== '\n') { try { response['combined_output'] = JSON.parse(response['combined_output']); @@ -129,4 +129,25 @@ export class BackendCommunicationService { }) ); } + + pollOpenWrtIpAddresses(intervalMs: number = 1000): Observable { + return new Observable(observer => { + const poll = () => { + this.getOpenWrtIpAddresses().subscribe({ + next: (response) => { + if (response.ethernetInterfaces !== 'Unknown') { + observer.next(response); + observer.complete(); + } else { + setTimeout(poll, intervalMs); + } + }, + error: (error) => { + observer.error(error); + } + }); + }; + poll(); + }); + } } diff --git a/web-frontend/src/app/dashboard/dashboard.component.html b/web-frontend/src/app/dashboard/dashboard.component.html index a4d4f4d..4b305bd 100644 --- a/web-frontend/src/app/dashboard/dashboard.component.html +++ b/web-frontend/src/app/dashboard/dashboard.component.html @@ -1,5 +1,5 @@
- + @@ -7,18 +7,18 @@ @if (openwrtVersion) { - - - router - {{ openwrtVersion }} - - - info - Linux kernel {{ openWrtKernel }} - - + + + router + {{ openwrtVersion }} + + + info + Linux kernel {{ openWrtKernel }} + + } @else { - + } @@ -40,16 +40,16 @@ LAN: {{ lan }} @for (usbDevice of usb; track usbDevice) { - - usb - USB: {{ usbDevice }} - + + usb + USB: {{ usbDevice }} + } @for (pciDevice of pci; track pciDevice) { - - memory - PCI: {{ pciDevice }} - + + memory + PCI: {{ pciDevice }} + } @@ -60,16 +60,20 @@ - Ethernet interfaces + IP addresses @if (ethernetInterfaces) { @for (ethernetInterface of ethernetInterfaces; track ethernetInterface) { - - settings_ethernet - {{ ethernetInterface.ifname }}: {{ ethernetInterface.address }} - + + @if (ethernetInterface.ifname !=='lo' && ethernetInterface.addr_info.length !== 0) { + + settings_ethernet + {{ ethernetInterface.ifname }} ({{ ethernetInterface.address }}) + @for (ipAddress of ethernetInterface.addr_info; track $index) {{{ ipAddress.local }} } + + } } } @else { diff --git a/web-frontend/src/app/dashboard/dashboard.component.ts b/web-frontend/src/app/dashboard/dashboard.component.ts index c9863ef..b904023 100644 --- a/web-frontend/src/app/dashboard/dashboard.component.ts +++ b/web-frontend/src/app/dashboard/dashboard.component.ts @@ -48,7 +48,7 @@ export class DashboardComponent { this.pci = response.pci; }); - this.service.getOpenWrtIpAddresses().subscribe(response => { + this.service.pollOpenWrtIpAddresses().subscribe(response => { this.ethernetInterfaces = response.ethernetInterfaces; }); }