Skip to content

Commit c03320a

Browse files
author
Jeppe Elkjær Jørgensen
committed
IOT-34 add status to gateway table
1 parent 7faffbc commit c03320a

File tree

7 files changed

+68
-7
lines changed

7 files changed

+68
-7
lines changed

src/app/gateway/gateway-table-row/gateway-table-row.component.html

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,23 @@
33
{{ gateway.name }}
44
</a>
55
</td>
6-
76
<td class=" pr-3">
87
{{ gateway.id }}
98
</td>
10-
119
<td class=" pr-3">
1210
{{ gateway.location.longitude }}, {{ gateway.location.latitude }}
13-
11+
</td>
12+
<td class=" pr-3">
13+
{{lastActive()}}
14+
</td>
15+
<td class=" pr-3">
16+
<ng-container *ngIf="gatewayStatus(); then statusOk else statusError"></ng-container>
17+
<ng-template #statusOk>
18+
<fa-icon [icon]="faCheckCircle" class="fa-ok"></fa-icon>
19+
</ng-template>
20+
<ng-template #statusError>
21+
<fa-icon [icon]="faExclamationTriangle" class="fa-error"></fa-icon>
22+
</ng-template>
1423
</td>
1524
<td>
1625
<div class="dropdown">
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
.fa-error {
2+
color: red !important;
3+
}
4+
5+
.fa-ok {
6+
color: green !important;
7+
}

src/app/gateway/gateway-table-row/gateway-table-row.component.ts

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ import { Component, OnInit, Input, Output, EventEmitter } from '@angular/core';
22
import { TranslateService } from '@ngx-translate/core';
33
import { Router } from '@angular/router';
44
import { Gateway } from 'src/app/models/gateway';
5+
import { faCheckCircle, faExclamationTriangle } from '@fortawesome/free-solid-svg-icons';
6+
import * as moment from 'moment';
7+
import 'moment/locale/da';
58

69
@Component({
710
selector: 'tr[app-gateway-table-row]',
@@ -11,19 +14,46 @@ import { Gateway } from 'src/app/models/gateway';
1114
export class GatewayTableRowComponent implements OnInit {
1215

1316
@Input() gateway: Gateway;
14-
1517
@Output() deleteGateway = new EventEmitter();
16-
18+
faExclamationTriangle = faExclamationTriangle;
19+
faCheckCircle = faCheckCircle;
1720
private alertMessage: string;
1821

1922
constructor(
2023
public translate: TranslateService,
2124
private router: Router
2225
) {
26+
moment.locale('da');
2327
translate.use('da');
2428
}
2529

2630
ngOnInit(): void {
31+
/*
32+
*****Use for testting*****
33+
34+
const time = new Date();
35+
const addRandomTime = Math.floor(Math.random() * 200) + 1;
36+
time.setSeconds(time.getSeconds() - addRandomTime);
37+
this.gateway.lastSeenAt = time; */
38+
}
39+
40+
gatewayStatus(): boolean {
41+
const errorTime = new Date();
42+
// 150 seconds is the define error interval: 30 sec heartbeat * 5.
43+
errorTime.setSeconds(errorTime.getSeconds() - 150);
44+
if (this.gateway?.lastSeenAt && (errorTime.getTime() < this.gateway?.lastSeenAt.getTime())) {
45+
return true;
46+
} else {
47+
return false;
48+
}
49+
}
50+
51+
lastActive(): string {
52+
if (this.gateway?.lastSeenAt) {
53+
return moment(this.gateway.lastSeenAt).fromNow();
54+
} else {
55+
return this.translate.instant("ACTIVITY.NEVER");
56+
}
2757
}
2858

2959
clickDelete() {

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
<th>{{ 'LORA-GATEWAY-TABLE.NAME' | translate }}</th>
66
<th>{{ 'LORA-GATEWAY-TABLE.GATEWAYID' | translate }}</th>
77
<th>{{ 'LORA-GATEWAY-TABLE.LOCATION' | translate }}</th>
8+
<th>{{ 'LORA-GATEWAY-TABLE.LAST-SEEN-AT' | translate }}</th>
9+
<th>{{ 'LORA-GATEWAY-TABLE.STATUS' | translate }}</th>
810
<th></th>
911
</tr>
1012
</thead>

src/app/gateway/gateway.module.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { GatewayListComponent } from './gateway-list/gateway-list.component';
1111
import { GatewayEditComponent } from './gateway-edit/gateway-edit.component';
1212
import { FormsModule } from '@angular/forms';
1313
import { GatewayDetailComponent } from './gateway-detail/gateway-detail.component';
14+
import { FontAwesomeModule } from '@fortawesome/angular-fontawesome';
1415

1516
@NgModule({
1617
declarations: [
@@ -28,6 +29,7 @@ import { GatewayDetailComponent } from './gateway-detail/gateway-detail.componen
2829
TranslateModule,
2930
FormModule,
3031
FormsModule,
32+
FontAwesomeModule
3133
],
3234
exports: [
3335
GatewayTableComponent,

src/app/models/gateway.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ export class Gateway {
99
gatewayProfileID: string = null;
1010
tagsString = '{}';
1111
tags?: JSON;
12+
lastSeenAt: Date;
1213
}
1314

1415
export class GatewayData {
@@ -26,6 +27,14 @@ export class GatewayResponse {
2627
updatedAt: string;
2728
firstSeenAt: string;
2829
lastSeenAt: string;
29-
3030
gateway: Gateway;
31+
stats: GatewayStats[];
32+
}
33+
34+
export interface GatewayStats {
35+
timestamp: string;
36+
rxPacketsReceived: number;
37+
rxPacketsReceivedOK: number;
38+
txPacketsReceived: number;
39+
txPacketsEmitted: number;
3140
}

src/assets/i18n/da.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,9 @@
7878
"LORA-GATEWAY-TABLE": {
7979
"NAME": "Navn",
8080
"GATEWAYID": "Gateway ID",
81-
"LOCATION": "Placering"
81+
"LOCATION": "Placering",
82+
"LAST-SEEN-AT": "Seneste aktivitet",
83+
"STATUS": "Status"
8284
},
8385
"LORA-GATEWAY-TABLE-ROW": {
8486
"DELETE": "Slet Gateway",

0 commit comments

Comments
 (0)