Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/IoT_640 - downlink queue #169

Merged
merged 7 commits into from
Sep 17, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<h1 mat-dialog-title>{{ "IOTDEVICE.DOWNLINK.DIALOG-TITLE" | translate }}</h1>
<h1 mat-dialog-title>{{ "IOTDEVICE.DOWNLINK.FLUSH-QUEUE" | translate }}</h1>
<div mat-dialog-content>
{{ "IOTDEVICE.DOWNLINK.DIALOG-MESSAGE" | translate }}
</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Component, OnInit } from "@angular/core";
import { MatDialogRef } from "@angular/material/dialog";
import { TranslateService } from "@ngx-translate/core";
import { DownlinkComponent } from "../downlink.component";
import { DownlinkComponent } from "../downlinks/downlink.component";

@Component({
selector: "app-downlink-dialog",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export class DownlinkQueueDto {
fCntDown: number;
payload: string;
port: number;
sendAt: Date;
acknowledgedAt: Date;
acknowledged: boolean;
createdAt: Date;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
<div *ngIf="device.type === 'LORAWAN'" class="jumbotron jumbotron--full-width">
<h3 class="headerStyle">{{ "IOTDEVICE.DOWNLINK.DOWNLINKQUEUE" | translate }}</h3>
<div class="mat-elevation-z8">
<table mat-table [dataSource]="downlinkQueue">
<div class="loading-shade" *ngIf="isLoadingResults">
<mat-spinner *ngIf="isLoadingResults"></mat-spinner>
</div>
<!-- Created At Column -->
<ng-container matColumnDef="createdAt">
<th mat-header-cell *matHeaderCellDef>
{{ "IOTDEVICE.CREATED" | translate }}
</th>
<td mat-cell *matCellDef="let element">
{{ element.createdAt | dkTimeWithSeconds }}
</td>
</ng-container>

<!-- fCntDown Column -->
<ng-container matColumnDef="status">
<th mat-header-cell *matHeaderCellDef>{{ "USERS.STATUS" | translate }}</th>
<td mat-cell *matCellDef="let element">
{{ getStatus(element) }}
</td>
</ng-container>

<!-- Payload Column -->
<ng-container matColumnDef="payload">
<th mat-header-cell *matHeaderCellDef>{{ "IOTDEVICE.DOWNLINK.PAYLOADTITLE" | translate }}</th>
<td mat-cell *matCellDef="let element">
{{ element.payload }}
</td>
</ng-container>

<!-- Port Column -->
<ng-container matColumnDef="port">
<th mat-header-cell *matHeaderCellDef>{{ "IOTDEVICE.MQTT.PORT" | translate }}</th>
<td mat-cell *matCellDef="let element">
{{ element.port }}
</td>
</ng-container>

<tr mat-header-row *matHeaderRowDef="displayedColumns"></tr>
<tr mat-row *matRowDef="let row; columns: displayedColumns"></tr>
</table>
</div>
<div *ngIf="checkForLoRaWAN(device)" class="mt-5 buttons">
<button (click)="clickFlushQueue()" class="btn btn-secondary" type="button">
{{ "IOTDEVICE.DOWNLINK.FLUSH-QUEUE" | translate }}
</button>

<button (click)="clickReload()" class="btn btn-secondary" type="button">
{{ "IOTDEVICE.DOWNLINK.RELOAD" | translate }}
</button>
</div>
</div>

<div *ngIf="device.type === 'LORAWAN'" class="jumbotron jumbotron--full-width">
<h3 class="headerStyle">{{ "IOTDEVICE.DOWNLINK.HISTORICQUEUE" | translate }}</h3>
<div class="mat-elevation-z8">
<table mat-table [dataSource]="downlinkHistoryQueue">
<div class="loading-shade" *ngIf="isLoadingResults">
<mat-spinner *ngIf="isLoadingResults"></mat-spinner>
</div>
<!-- Created At Column -->
<ng-container matColumnDef="createdAt">
<th mat-header-cell *matHeaderCellDef>
{{ "IOTDEVICE.CREATED" | translate }}
</th>
<td mat-cell *matCellDef="let element">
{{ element.createdAt | dkTimeWithSeconds }}
</td>
</ng-container>

<!-- Send At Column -->
<ng-container matColumnDef="sendAt">
<th mat-header-cell *matHeaderCellDef>
{{ "IOTDEVICE.DOWNLINK.SENDAT" | translate }}
</th>
<td mat-cell *matCellDef="let element">
{{ element.sendAt | dkTimeWithSeconds }}
</td>
</ng-container>

<!-- AcknowlegdedAt Column -->
<ng-container matColumnDef="acknowledgedAt">
<th mat-header-cell *matHeaderCellDef>{{ "IOTDEVICE.DOWNLINK.RECEIVEDAT" | translate }}</th>
<td mat-cell *matCellDef="let element">
{{
element.acknowledgedAt
? (element.acknowledgedAt | dkTimeWithSeconds)
: ("IOTDEVICE.DOWNLINK.NOT-RECEIVED" | translate)
}}
</td>
</ng-container>

<!-- fCntDown Column -->
<ng-container matColumnDef="status">
<th mat-header-cell *matHeaderCellDef>{{ "USERS.STATUS" | translate }}</th>
<td mat-cell *matCellDef="let element">
{{ getStatus(element) }}
</td>
</ng-container>

<!-- fCntDown Column -->
<ng-container matColumnDef="fCntDown">
<th mat-header-cell *matHeaderCellDef>{{ "IOTDEVICE.DOWNLINK.FRAMECOUNTER" | translate }}</th>
<td mat-cell *matCellDef="let element">
{{ element.fCntDown }}
</td>
</ng-container>

<!-- Acknowlegded Column -->
<ng-container matColumnDef="acknowlegded">
<th mat-header-cell *matHeaderCellDef>{{ "IOTDEVICE.DOWNLINK.CONFIRMED" | translate }}</th>
<td mat-cell *matCellDef="let element">
{{ isAcknowledged(element) }}
</td>
</ng-container>

<!-- Payload Column -->
<ng-container matColumnDef="payload">
<th mat-header-cell *matHeaderCellDef>{{ "IOTDEVICE.DOWNLINK.PAYLOADTITLE" | translate }}</th>
<td mat-cell *matCellDef="let element">
{{ element.payload }}
</td>
</ng-container>

<!-- Port Column -->
<ng-container matColumnDef="port">
<th mat-header-cell *matHeaderCellDef>{{ "IOTDEVICE.MQTT.PORT" | translate }}</th>
<td mat-cell *matCellDef="let element">
{{ element.port }}
</td>
</ng-container>

<tr mat-header-row *matHeaderRowDef="displayedColumnsHistory"></tr>
<tr mat-row *matRowDef="let row; columns: displayedColumnsHistory"></tr>
</table>
</div>
<div *ngIf="checkForLoRaWAN(device)" class="mt-5 buttons">
<button (click)="clickReload()" class="btn btn-secondary" type="button">
{{ "IOTDEVICE.DOWNLINK.RELOAD" | translate }}
</button>
</div>
</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
.headerStyle {
margin-bottom: 50px !important;
}

.buttons {
gap: 10px;
display: flex;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
import { HttpErrorResponse } from "@angular/common/http";
import { Component, Input, OnInit } from "@angular/core";
import { MatDialog } from "@angular/material/dialog";
import { MatSnackBar } from "@angular/material/snack-bar";
import { IotDevice } from "@applications/iot-devices/iot-device.model";
import { TranslateService } from "@ngx-translate/core";
import { DeviceType } from "@shared/enums/device-type";
import { ErrorMessageService } from "@shared/error-message.service";
import { DownlinkService } from "@shared/services/downlink.service";
import { DownlinkDialogComponent } from "../downlink-dialog/downlink-dialog.component";
import { Downlink } from "../downlink.model";
import { DownlinkQueueDto } from "../downlink-queue-dto";

@Component({
selector: "app-downlink-tables",
templateUrl: "./downlink-tables.component.html",
styleUrls: ["./downlink-tables.component.scss"],
})
export class DownlinkTablesComponent implements OnInit {
@Input() device: IotDevice;
@Input() errorMessages: string[];
@Input() downlinkQueue: DownlinkQueueDto[];
public downlinkHistoryQueue: DownlinkQueueDto[];
public isLoadingResults = false;
public displayedColumns: string[] = ["createdAt", "status", "payload", "port"];
public displayedColumnsHistory: string[] = [
"createdAt",
"sendAt",
"acknowledgedAt",
"status",
"fCntDown",
"acknowlegded",
augusthjerrild marked this conversation as resolved.
Show resolved Hide resolved
"payload",
"port",
];

constructor(
private snackBar: MatSnackBar,
private translate: TranslateService,
private downlinkService: DownlinkService,
public dialog: MatDialog,
private errorMessageService: ErrorMessageService
) {}

ngOnInit(): void {
this.errorMessages = [];

this.getDownlinksQueue();
this.getHistoricalDownlinksQueue();
}

getDownlinksQueue() {
this.isLoadingResults = true;
this.downlinkService.getDownlinkQueue(this.device.id).subscribe(
(response: DownlinkQueueDto[]) => {
this.downlinkQueue = response;
this.isLoadingResults = false;
},
error => {
this.handleError(error);
this.isLoadingResults = false;
}
);
}

getHistoricalDownlinksQueue() {
this.isLoadingResults = true;
this.downlinkService.getHistoricalDownlinkQueue(this.device.id).subscribe(
(response: DownlinkQueueDto[]) => {
this.downlinkHistoryQueue = response;
this.isLoadingResults = false;
},
error => {
this.handleError(error);
this.isLoadingResults = false;
}
);
}

clickReload() {
augusthjerrild marked this conversation as resolved.
Show resolved Hide resolved
this.getDownlinksQueue();
this.getHistoricalDownlinksQueue();
}

clickFlushQueue() {
augusthjerrild marked this conversation as resolved.
Show resolved Hide resolved
this.openDownlinkDialog();
}

private handleError(error: HttpErrorResponse) {
this.errorMessages = this.errorMessageService.handleErrorMessage(error);
}

openDownlinkDialog() {
const dialog = this.dialog.open(DownlinkDialogComponent, {});

dialog.afterClosed().subscribe(result => {
if (result === true) {
this.downlinkService.flushQueue(this.device.id).subscribe(
response => {
this.snackBar.open("Kø ryddet", "OK", {
augusthjerrild marked this conversation as resolved.
Show resolved Hide resolved
duration: 10000,
});
this.getDownlinksQueue();
},
error => {
console.log(error);
augusthjerrild marked this conversation as resolved.
Show resolved Hide resolved
this.handleError(error);
}
);
}
});
}

checkForLoRaWAN(device: IotDevice) {
return device.type === DeviceType.LORAWAN;
augusthjerrild marked this conversation as resolved.
Show resolved Hide resolved
}

getStatus(downlink: DownlinkQueueDto) {
if (!downlink.acknowledgedAt && !downlink.sendAt) {
return this.translate.instant("IOTDEVICE.DOWNLINK.IN-QUEUE");
}
if (downlink.acknowledgedAt) {
return this.translate.instant("IOTDEVICE.DOWNLINK.RECEIVEDAT");
}

return this.translate.instant("IOTDEVICE.DOWNLINK.SENDAT");
}

isAcknowledged(downlink: DownlinkQueueDto) {
if (!downlink.acknowledged) {
augusthjerrild marked this conversation as resolved.
Show resolved Hide resolved
return this.translate.instant("false");
} else {
return this.translate.instant("true");
}
}
}

This file was deleted.

Loading
Loading