@@ -10,12 +10,11 @@ import { Location } from '@angular/common';
1010import { MulticastService } from '../multicast.service' ;
1111import { SnackService } from '@shared/services/snack.service' ;
1212import { Downlink } from '@applications/iot-devices/downlink.model' ;
13- import { DownlinkService } from '@shared/services/downlink.service' ;
1413import { HttpErrorResponse } from '@angular/common/http' ;
1514import { ErrorMessageService } from '@shared/error-message.service' ;
1615import { MatDialog } from '@angular/material/dialog' ;
1716import { DownlinkDialogComponent } from '@applications/iot-devices/iot-device-detail/downlink/downlink-dialog/downlink-dialog.component' ;
18- import { MatSnackBar } from '@angular/material/snack-bar ' ;
17+ import { keyPressedHex } from '@shared/constants/regex-constants ' ;
1918
2019@Component ( {
2120 selector : 'app-multicast-detail' ,
@@ -27,22 +26,19 @@ export class MulticastDetailComponent implements OnInit {
2726 public backButton : BackButton = { label : '' , routerLink : '/multicast-list' } ;
2827 private deleteDialogSubscription : Subscription ;
2928 public dropdownButton : DropdownButton ;
30-
3129 public formFailedSubmit : boolean = false ;
3230 private applicationId : number ;
3331 public downlink = new Downlink ( ) ;
3432 @Input ( ) errorMessages : string [ ] ;
3533
3634 constructor (
3735 private route : ActivatedRoute ,
38- private snackBar : MatSnackBar ,
39- public dialog : MatDialog ,
36+ private dialog : MatDialog ,
4037 private deleteDialogService : DeleteDialogService ,
4138 private location : Location ,
4239 private multicastService : MulticastService ,
43- public translate : TranslateService ,
44- public snackService : SnackService ,
45- public downlinkService : DownlinkService ,
40+ private translate : TranslateService ,
41+ private snackService : SnackService ,
4642 private errorMessageService : ErrorMessageService
4743 ) { }
4844
@@ -78,6 +74,7 @@ export class MulticastDetailComponent implements OnInit {
7874 this . backButton . routerLink = [ 'applications' , applicationId . toString ( ) ] ;
7975 }
8076
77+ // Class-B:
8178 //only if classB can be used
8279 // canShowPeriodicity(): boolean {
8380 // if (this.multicast.groupType === MulticastType.ClassB) {
@@ -101,7 +98,6 @@ export class MulticastDetailComponent implements OnInit {
10198 }
10299 } ) ;
103100 } else {
104- console . log ( response ) ;
105101 }
106102 } ) ;
107103 }
@@ -118,15 +114,9 @@ export class MulticastDetailComponent implements OnInit {
118114 }
119115 keyPressHexadecimal ( event ) {
120116 // make sure only hexadecimal can be typed in input with adresses.
121- var inp = String . fromCharCode ( event . keyCode ) ;
122-
123- if ( / [ a - f A - F 0 - 9 ] / . test ( inp ) ) {
124- return true ;
125- } else {
126- event . preventDefault ( ) ;
127- return false ;
128- }
117+ keyPressedHex ( event ) ;
129118 }
119+
130120 private handleError ( error : HttpErrorResponse ) {
131121 const errors = this . errorMessageService . handleErrorMessageWithFields ( error ) ;
132122 this . errorMessages = errors . errorFields ;
@@ -135,20 +125,15 @@ export class MulticastDetailComponent implements OnInit {
135125
136126 clickDownlink ( ) {
137127 if ( this . validateHex ( this . downlink . data ) ) {
138- this . downlinkService . multicastGet ( this . multicast . id ) . subscribe (
139- ( response : any ) => {
140- console . log ( response )
128+ this . multicastService
129+ . multicastGet ( this . multicast . id )
130+ . subscribe ( ( response : any ) => {
141131 if ( response . totalCount > 0 ) {
142132 this . openDownlinkDialog ( ) ;
143133 } else {
144134 this . startDownlink ( ) ;
145135 }
146- } ,
147- ( error ) => {
148- this . handleError ( error ) ;
149- console . log ( error ) ;
150- }
151- ) ;
136+ } ) ;
152137 }
153138 }
154139 openDownlinkDialog ( ) {
@@ -157,17 +142,16 @@ export class MulticastDetailComponent implements OnInit {
157142 dialog . afterClosed ( ) . subscribe ( ( result ) => {
158143 if ( result === true ) {
159144 this . startDownlink ( ) ;
160- console . log ( `Dialog result: ${ result } ` ) ;
161145 }
162146 } ) ;
163147 }
164148
165149 private startDownlink ( ) {
166150 this . errorMessages = [ ] ;
167- this . downlinkService
151+ this . multicastService
168152 . multicastPost ( this . downlink , this . multicast . id )
169153 . subscribe (
170- ( response ) => {
154+ ( ) => {
171155 this . showQueueSnack ( ) ;
172156 } ,
173157 ( error ) => {
@@ -178,15 +162,13 @@ export class MulticastDetailComponent implements OnInit {
178162
179163 private validateHex ( input : string ) : boolean {
180164 const isHexinput = / ^ [ a - f A - F \d ] + $ / . test ( input ) ;
181- let validator = false ;
165+
182166 if ( isHexinput ) {
183- validator = true ;
167+ return true ;
184168 } else {
185- console . log ( 'test' ) ;
186169 this . addToErrorMessage ( 'MULTICAST.DOWNLINK.NO-PORT-OR-PAYLOAD' ) ;
187- validator = false ;
170+ return false ;
188171 }
189- return validator ;
190172 }
191173
192174 addToErrorMessage ( text : string ) {
@@ -196,8 +178,6 @@ export class MulticastDetailComponent implements OnInit {
196178 }
197179
198180 ngOnDestroy ( ) : void {
199- if ( this . deleteDialogSubscription ) {
200- this . deleteDialogSubscription . unsubscribe ( ) ;
201- }
181+ this . deleteDialogSubscription ?. unsubscribe ( ) ;
202182 }
203183}
0 commit comments