Skip to content

Commit 5780eae

Browse files
PR changes plus search function for devices in multicast
1 parent 5f88b68 commit 5780eae

20 files changed

+215
-266
lines changed
Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
21
export class Downlink {
3-
data: string;
4-
port: number = 0;
5-
confirmedDownlink? = false;
2+
data: string;
3+
port = 0;
4+
confirmedDownlink? = false;
65
}

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

Lines changed: 0 additions & 25 deletions
This file was deleted.

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

Lines changed: 17 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,11 @@ import { Location } from '@angular/common';
1010
import { MulticastService } from '../multicast.service';
1111
import { SnackService } from '@shared/services/snack.service';
1212
import { Downlink } from '@applications/iot-devices/downlink.model';
13-
import { DownlinkService } from '@shared/services/downlink.service';
1413
import { HttpErrorResponse } from '@angular/common/http';
1514
import { ErrorMessageService } from '@shared/error-message.service';
1615
import { MatDialog } from '@angular/material/dialog';
1716
import { 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-fA-F0-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-fA-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
}

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

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@
196196
</div> -->
197197
</div>
198198

199-
<div class="form-group mt-3">
199+
<div class="form-group mt-3 col-12">
200200
<label class="form-label" for="groupType">{{
201201
'QUESTION.GIVE-MULTICAST-IOTDEVICES' | translate
202202
}}</label>
@@ -211,7 +211,12 @@
211211
name="devices"
212212
[compareWith]="compare"
213213
[(ngModel)]="multicast.iotDevices"
214+
panelClass="overflow-x-hidden"
214215
>
216+
<mat-select-search
217+
[formControl]="deviceFilterCtrl"
218+
></mat-select-search>
219+
215220
<mat-option disabled="disabled" class="filter-option">
216221
<button
217222
mat-raised-button
@@ -227,10 +232,15 @@
227232
>
228233
{{ 'QUESTION.MULTICAST.DESELECTALLDEVICES' | translate }}
229234
</button>
235+
<label class="onlyLorawan">{{
236+
'QUESTION.MULTICAST.ONLY-LORAWAN' | translate
237+
}}</label>
230238
</mat-option>
231-
<mat-option *ngFor="let device of iotDevices" [value]="device">{{
232-
device.name
233-
}}</mat-option>
239+
<mat-option
240+
*ngFor="let device of filteredDevicesMulti | async | filterDevices"
241+
[value]="device"
242+
>{{ device.name }}</mat-option
243+
>
234244
</mat-select>
235245
</mat-form-field>
236246
</div>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
.onlyLorawan {
2+
font-weight: bold;
3+
font-size: 13px;
4+
margin-left: 10px;
5+
}

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

Lines changed: 0 additions & 25 deletions
This file was deleted.

0 commit comments

Comments
 (0)