Skip to content

Commit 44de7a5

Browse files
PR Changes
1 parent 144a650 commit 44de7a5

File tree

6 files changed

+34
-25
lines changed

6 files changed

+34
-25
lines changed

src/app/applications/multicast/multicast-detail/multicast-detail.component.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Component, Input, OnInit } from '@angular/core';
1+
import { Component, Input, OnDestroy, OnInit } from '@angular/core';
22
import { ActivatedRoute } from '@angular/router';
33
import { TranslateService } from '@ngx-translate/core';
44
import { DeleteDialogService } from '@shared/components/delete-dialog/delete-dialog.service';
@@ -15,18 +15,19 @@ import { ErrorMessageService } from '@shared/error-message.service';
1515
import { MatDialog } from '@angular/material/dialog';
1616
import { DownlinkDialogComponent } from '@applications/iot-devices/iot-device-detail/downlink/downlink-dialog/downlink-dialog.component';
1717
import { keyPressedHex } from '@shared/constants/regex-constants';
18+
import { DownlinkService } from '@shared/services/downlink.service';
1819

1920
@Component({
2021
selector: 'app-multicast-detail',
2122
templateUrl: './multicast-detail.component.html',
2223
styleUrls: ['./multicast-detail.component.scss'],
2324
})
24-
export class MulticastDetailComponent implements OnInit {
25+
export class MulticastDetailComponent implements OnInit, OnDestroy {
2526
public multicast: Multicast;
2627
public backButton: BackButton = { label: '', routerLink: '/multicast-list' };
2728
private deleteDialogSubscription: Subscription;
2829
public dropdownButton: DropdownButton;
29-
public formFailedSubmit: boolean = false;
30+
public formFailedSubmit = false;
3031
private applicationId: number;
3132
public downlink = new Downlink();
3233
@Input() errorMessages: string[];
@@ -39,7 +40,8 @@ export class MulticastDetailComponent implements OnInit {
3940
private multicastService: MulticastService,
4041
private translate: TranslateService,
4142
private snackService: SnackService,
42-
private errorMessageService: ErrorMessageService
43+
private errorMessageService: ErrorMessageService,
44+
private downlinkService: DownlinkService
4345
) {}
4446

4547
ngOnInit(): void {
@@ -75,7 +77,7 @@ export class MulticastDetailComponent implements OnInit {
7577
}
7678

7779
// Class-B:
78-
//only if classB can be used
80+
// only if classB can be used
7981
// canShowPeriodicity(): boolean {
8082
// if (this.multicast.groupType === MulticastType.ClassB) {
8183
// return true;
@@ -127,7 +129,7 @@ export class MulticastDetailComponent implements OnInit {
127129
});
128130
}
129131
} else {
130-
this.snackService.showSendDownlinkFailNoDevices();
132+
this.downlinkService.showSendDownlinkFailNoDevices();
131133
}
132134
}
133135
openDownlinkDialog() {

src/app/applications/multicast/multicast-edit/multicast-edit.component.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { HttpErrorResponse } from '@angular/common/http';
2-
import { Component, Input, OnInit } from '@angular/core';
2+
import { Component, Input, OnDestroy, OnInit } from '@angular/core';
33
import { ActivatedRoute, Router } from '@angular/router';
44
import { TranslateService } from '@ngx-translate/core';
55
import { MulticastType } from '@shared/enums/multicast-type';
@@ -20,10 +20,10 @@ import { takeUntil } from 'rxjs/operators';
2020
templateUrl: './multicast-edit.component.html',
2121
styleUrls: ['./multicast-edit.component.scss'],
2222
})
23-
export class MulticastEditComponent implements OnInit {
23+
export class MulticastEditComponent implements OnInit, OnDestroy {
2424
public title: string;
2525
public multicastId: number;
26-
public errorMessages: any;
26+
public errorMessages: unknown;
2727
private multicastSubscription: Subscription;
2828
public searchDevices: FormControl = new FormControl();
2929
public errorFields: string[];
@@ -32,7 +32,8 @@ export class MulticastEditComponent implements OnInit {
3232
public backButtonTitle: string;
3333
public multicast: Multicast = new Multicast();
3434
private applicationId: number;
35-
public formFailedSubmit: boolean = false;
35+
private onDestroy = new Subject<void>();
36+
public formFailedSubmit = false;
3637
public multicastTypes: string[] = Object.values(MulticastType);
3738
// Class-B: { public periodicities: number[] = [2, 4, 8, 16, 32, 64, 128]; // used for classB if it has to be used in the future }
3839
public deviceFilterCtrl: FormControl = new FormControl();
@@ -81,7 +82,7 @@ export class MulticastEditComponent implements OnInit {
8182
}
8283

8384
this.deviceFilterCtrl.valueChanges
84-
.pipe(takeUntil(this._onDestroy))
85+
.pipe(takeUntil(this.onDestroy))
8586
.subscribe(() => {
8687
this.filterDevicesMulti();
8788
});
@@ -130,7 +131,7 @@ export class MulticastEditComponent implements OnInit {
130131
});
131132
}
132133

133-
//only if classB can be used
134+
// only if classB can be used
134135
// showPeriodicity(): boolean {
135136
// if (this.multicast.groupType === MulticastType.ClassB) {
136137
// return true;
@@ -203,5 +204,4 @@ export class MulticastEditComponent implements OnInit {
203204
ngOnDestroy(): void {
204205
this.multicastSubscription?.unsubscribe();
205206
}
206-
private _onDestroy = new Subject<void>();
207207
}

src/app/applications/multicast/multicast-table/multicast-table.component.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ export class MulticastTableComponent
3232
multicasts: Multicast[] = [];
3333
resultsLength = 0;
3434
public canEdit = false;
35-
@Input() isLoadingResults: boolean = true;
35+
@Input() isLoadingResults = true;
3636
public pageSize = environment.tablePageSize;
3737
public pageOffset = 0;
3838
public applicationId: number;
@@ -127,10 +127,7 @@ export class MulticastTableComponent
127127
});
128128
}
129129
ngOnDestroy() {
130-
// prevent memory leak by unsubscribing
131-
132130
this.multicastSubscription?.unsubscribe();
133-
134131
this.deleteDialogSubscription?.unsubscribe();
135132
}
136133
}

src/app/applications/multicast/multicast.service.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ export class MulticastService {
8585
return model;
8686
}
8787

88-
public multicastGet(multicastId: number, params = {}): Observable<any> {
88+
public multicastGet(multicastId: number, params = {}): Observable<unknown> {
8989
const url =
9090
this.multicastDownlinkURL + multicastId + '/' + this.DOWNLINKMULTICASTURL;
9191
return this.restService.get(url, params);
@@ -94,7 +94,7 @@ export class MulticastService {
9494
downlink: Downlink,
9595
multicastId: number,
9696
params = {}
97-
): Observable<any> {
97+
): Observable<unknown> {
9898
const url =
9999
this.multicastDownlinkURL + multicastId + '/' + this.DOWNLINKMULTICASTURL;
100100
return this.restService.post(url, downlink, params);

src/app/shared/services/downlink.service.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import { Injectable } from '@angular/core';
22
import { RestService } from './rest.service';
33
import { Observable } from 'rxjs';
44
import { Downlink } from '@applications/iot-devices/downlink.model';
5+
import { MatSnackBar } from '@angular/material/snack-bar';
6+
import { TranslateService } from '@ngx-translate/core';
57

68
@Injectable({
79
providedIn: 'root',
@@ -10,7 +12,11 @@ export class DownlinkService {
1012
private IOTDEVICEURL = 'iot-device/';
1113
private DOWNLINKURL = 'downlink';
1214

13-
constructor(private restService: RestService) {}
15+
constructor(
16+
private restService: RestService,
17+
private snackBar: MatSnackBar,
18+
public translate: TranslateService
19+
) {}
1420

1521
public get(deviceId: number, params = {}): Observable<any> {
1622
const url = this.IOTDEVICEURL + deviceId + '/' + this.DOWNLINKURL;
@@ -25,4 +31,13 @@ export class DownlinkService {
2531
const url = this.IOTDEVICEURL + deviceId + '/' + this.DOWNLINKURL;
2632
return this.restService.post(url, downlink, params);
2733
}
34+
public showSendDownlinkFailNoDevices() {
35+
this.snackBar.open(
36+
this.translate.instant('SNACK.NODEVICES'),
37+
this.translate.instant('SNACK.CLOSE'),
38+
{
39+
duration: 10000,
40+
}
41+
);
42+
}
2843
}

src/app/shared/services/snack.service.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,4 @@ export class SnackService {
4141
duration: 10000,
4242
});
4343
}
44-
public showSendDownlinkFailNoDevices(){
45-
this.snackBar.open(this.translate.instant('SNACK.NODEVICES'), this.translate.instant('SNACK.CLOSE'), {
46-
duration: 10000,
47-
});
48-
}
4944
}

0 commit comments

Comments
 (0)