Skip to content

Commit 76fa5c1

Browse files
author
Jeppe Elkjær Jørgensen
committed
IOT-34 add statistics to gateway
1 parent c03320a commit 76fa5c1

File tree

6 files changed

+58
-11
lines changed

6 files changed

+58
-11
lines changed

src/app/gateway/gateway-detail/gateway-detail.component.html

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<app-top-bar-single [data]="gateway" [backButton]="backButton"></app-top-bar-single>
22
<div class="application-component">
3-
<div class="col-12 mb-4 py-3 bottom-separator">
4-
<div class="col-12 col-sm-12">
5-
<div class="col-12 col-sm-12">
3+
<div class="bottom-separator">
4+
<div class="col-12 py-4">
5+
<div class="col-12 col-sm-4">
66
<h4>{{ 'GATEWAY.NAME' | translate }}</h4>
77
</div>
88
<div class="col-12 pt-2 col-sm-8">
@@ -56,5 +56,30 @@ <h4>{{ 'GATEWAY.TAGS' | translate }}</h4>
5656
<p>{{gateway.tagsString}}</p>
5757
</div>
5858
</div>
59+
<div class="col-12 col-sm-4">
60+
<h4>{{ 'GATEWAY.STATS' | translate }}</h4>
61+
</div>
62+
<div class="mat-elevation-z8 col-12 pt-2 col-sm-8">
63+
<table mat-table [dataSource]="dataSource">
64+
<ng-container matColumnDef="rxPacketsReceived">
65+
<th mat-header-cell *matHeaderCellDef>{{ 'GATEWAY.STATS-RXPACKETSRECEIVED' | translate }}</th>
66+
<td mat-cell *matCellDef="let element">{{element.rxPacketsReceived}}</td>
67+
</ng-container>
68+
69+
<ng-container matColumnDef="txPacketsEmitted">
70+
<th mat-header-cell *matHeaderCellDef>{{ 'GATEWAY.STATS-TXPACKETSEMITTED' | translate }}</th>
71+
<td mat-cell *matCellDef="let element">{{element.txPacketsEmitted}}</td>
72+
</ng-container>
73+
74+
<ng-container matColumnDef="txPacketsReceived">
75+
<th mat-header-cell *matHeaderCellDef>{{ 'GATEWAY.STATS-TIMESTAMP' | translate }}</th>
76+
<td mat-cell *matCellDef="let element">{{element.timestamp | date}}</td>
77+
</ng-container>
78+
79+
<tr mat-header-row *matHeaderRowDef="displayedColumns"></tr>
80+
<tr mat-row *matRowDef="let row; columns: displayedColumns;"></tr>
81+
</table>
82+
<mat-paginator [pageSizeOptions]="[5, 10, 20]" showFirstLastButtons></mat-paginator>
83+
</div>
5984
</div>
60-
</div>
85+
</div>
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
table {
2+
width: 100%;
3+
}

src/app/gateway/gateway-detail/gateway-detail.component.ts

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,29 @@
1-
import { Component, OnDestroy, OnInit } from '@angular/core';
2-
import { Gateway } from 'src/app/models/gateway';
1+
import { AfterViewInit, Component, OnDestroy, OnInit, ViewChild } from '@angular/core';
2+
import { Gateway, GatewayStats } from 'src/app/models/gateway';
33
import { Subscription } from 'rxjs';
44
import { ChirpstackGatewayService } from 'src/app/shared/services/chirpstack-gateway.service';
55
import { ActivatedRoute } from '@angular/router';
66
import { TranslateService } from '@ngx-translate/core';
77
import { BackButton } from 'src/app/models/back-button';
8+
import { MatTableDataSource } from '@angular/material/table';
9+
import { MatPaginator } from '@angular/material/paginator';
810

911
@Component({
1012
selector: 'app-gateway-detail',
1113
templateUrl: './gateway-detail.component.html',
1214
styleUrls: ['./gateway-detail.component.scss']
1315
})
14-
export class GatewayDetailComponent implements OnInit, OnDestroy {
16+
export class GatewayDetailComponent implements OnInit, OnDestroy, AfterViewInit {
1517

1618
public gatewaySubscription: Subscription;
1719
public gateway: Gateway;
1820
public backButton: BackButton = { label: '', routerLink: '/gateways' };
1921
private id: string;
22+
private gatewayStats: GatewayStats[];
23+
displayedColumns: string[] = ['rxPacketsReceived', 'txPacketsEmitted', 'txPacketsReceived'];
24+
public dataSource = new MatTableDataSource<GatewayStats>();
25+
@ViewChild(MatPaginator) paginator: MatPaginator;
26+
2027
constructor(
2128
private gatewayService: ChirpstackGatewayService,
2229
private route: ActivatedRoute,
@@ -35,10 +42,16 @@ export class GatewayDetailComponent implements OnInit, OnDestroy {
3542
});
3643
}
3744

45+
ngAfterViewInit() {
46+
this.dataSource.paginator = this.paginator;
47+
}
48+
3849
bindGateway(id: string): void {
3950
this.gatewayService.get(id).subscribe((result: any) => {
4051
result.gateway.tagsString = JSON.stringify(result.gateway.tags);
4152
this.gateway = result.gateway;
53+
this.gatewayStats = result.stats;
54+
this.dataSource = new MatTableDataSource<GatewayStats>(this.gatewayStats);
4255
console.log('gateway', this.gateway);
4356
});
4457
}

src/app/gateway/gateway.module.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { GatewayEditComponent } from './gateway-edit/gateway-edit.component';
1212
import { FormsModule } from '@angular/forms';
1313
import { GatewayDetailComponent } from './gateway-detail/gateway-detail.component';
1414
import { FontAwesomeModule } from '@fortawesome/angular-fontawesome';
15+
import { NGMaterialModule } from '@shared/Modules/materiale.module';
1516

1617
@NgModule({
1718
declarations: [
@@ -29,14 +30,15 @@ import { FontAwesomeModule } from '@fortawesome/angular-fontawesome';
2930
TranslateModule,
3031
FormModule,
3132
FormsModule,
32-
FontAwesomeModule
33+
FontAwesomeModule,
34+
NGMaterialModule
3335
],
3436
exports: [
3537
GatewayTableComponent,
3638
GatewayTableRowComponent,
3739
GatewaysComponent,
3840
GatewayListComponent,
39-
GatewayEditComponent,
41+
GatewayEditComponent
4042
]
4143
})
4244
export class GatewayModule { }

src/app/models/gateway.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ export class GatewayResponse {
3232
}
3333

3434
export interface GatewayStats {
35-
timestamp: string;
35+
timestamp: Date;
3636
rxPacketsReceived: number;
3737
rxPacketsReceivedOK: number;
3838
txPacketsReceived: number;

src/assets/i18n/da.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,11 @@
4141
"ID": "Gateway ID",
4242
"LOCATION": "Placering",
4343
"TAGS": "Tags",
44-
"NAME": "Gatewayens navn"
44+
"NAME": "Gatewayens navn",
45+
"STATS": "Statistik",
46+
"STATS-RXPACKETSRECEIVED": "Pakker modtaget",
47+
"STATS-TXPACKETSEMITTED": "Pakker Sendt",
48+
"STATS-TIMESTAMP": "Tidspunkt"
4549
},
4650
"IOT-DEVICE": {
4751
"CREATE": "Gem IoT enhed",

0 commit comments

Comments
 (0)