Skip to content

Commit 144a650

Browse files
Minor snack changes and check if devices is included before sending downlink
1 parent e859ab1 commit 144a650

File tree

5 files changed

+31
-38
lines changed

5 files changed

+31
-38
lines changed

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

Lines changed: 17 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -91,27 +91,17 @@ export class MulticastDetailComponent implements OnInit {
9191
.delete(this.multicast.id)
9292
.subscribe((response) => {
9393
if (response.status !== 0) {
94-
this.showDeletedSnack();
94+
this.snackService.showDeletedSnack();
9595
this.location.back();
9696
} else {
97-
this.showFailSnack();
97+
this.snackService.showFailSnack();
9898
}
9999
});
100100
} else {
101101
}
102102
});
103103
}
104104

105-
showDeletedSnack(): void {
106-
this.snackService.showDeletedSnack();
107-
}
108-
109-
showFailSnack(): void {
110-
this.snackService.showFailSnack();
111-
}
112-
showQueueSnack(): void {
113-
this.snackService.showInQueueSnack();
114-
}
115105
keyPressHexadecimal(event) {
116106
// make sure only hexadecimal can be typed in input with adresses.
117107
keyPressedHex(event);
@@ -124,16 +114,20 @@ export class MulticastDetailComponent implements OnInit {
124114
}
125115

126116
clickDownlink() {
127-
if (this.validateHex(this.downlink.data)) {
128-
this.multicastService
129-
.multicastGet(this.multicast.id)
130-
.subscribe((response: any) => {
131-
if (response.totalCount > 0) {
132-
this.openDownlinkDialog();
133-
} else {
134-
this.startDownlink();
135-
}
136-
});
117+
if (this.multicast.iotDevices.length > 0) {
118+
if (this.validateHex(this.downlink.data)) {
119+
this.multicastService
120+
.multicastGet(this.multicast.id)
121+
.subscribe((response: any) => {
122+
if (response.totalCount > 0) {
123+
this.openDownlinkDialog();
124+
} else {
125+
this.startDownlink();
126+
}
127+
});
128+
}
129+
} else {
130+
this.snackService.showSendDownlinkFailNoDevices();
137131
}
138132
}
139133
openDownlinkDialog() {
@@ -152,7 +146,7 @@ export class MulticastDetailComponent implements OnInit {
152146
.multicastPost(this.downlink, this.multicast.id)
153147
.subscribe(
154148
() => {
155-
this.showQueueSnack();
149+
this.snackService.showInQueueSnack();
156150
},
157151
(error) => {
158152
this.handleError(error);

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

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -143,11 +143,11 @@ export class MulticastEditComponent implements OnInit {
143143

144144
this.multicastService.update(this.multicast).subscribe(
145145
() => {
146-
this.showUpdatedSnack();
146+
this.snackService.showUpdatedSnack();
147147
this.routeBack();
148148
},
149149
(error: HttpErrorResponse) => {
150-
this.showFailSnack();
150+
this.snackService.showFailSnack();
151151
this.handleError(error);
152152
this.formFailedSubmit = true;
153153
}
@@ -159,11 +159,11 @@ export class MulticastEditComponent implements OnInit {
159159

160160
this.multicastService.create(this.multicast).subscribe(
161161
() => {
162-
this.showSavedSnack();
162+
this.snackService.showSavedSnack();
163163
this.routeBack();
164164
},
165165
(error: HttpErrorResponse) => {
166-
this.showFailSnack();
166+
this.snackService.showFailSnack();
167167
this.handleError(error);
168168
this.formFailedSubmit = true;
169169
}
@@ -186,15 +186,6 @@ export class MulticastEditComponent implements OnInit {
186186
routeBack(): void {
187187
this.router.navigate(['applications', this.applicationId.toString()]);
188188
}
189-
showSavedSnack() {
190-
this.snackService.showSavedSnack();
191-
}
192-
showFailSnack() {
193-
this.snackService.showFailSnack();
194-
}
195-
showUpdatedSnack() {
196-
this.snackService.showUpdatedSnack();
197-
}
198189
keyPressHexadecimal(event) {
199190
keyPressedHex(event);
200191
}

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,13 @@ export class MulticastTableComponent
6969
this.sort.active,
7070
this.sort.direction
7171
);
72-
//TODO::: Snack here
7372
return multicasts;
7473
}),
7574
map((data) => {
7675
// Flip flag to show that loading has finished.
76+
if (data.ok === false) {
77+
this.snackService.showLoadFailSnack();
78+
}
7779
this.isLoadingResults = false;
7880
this.resultsLength = data.count;
7981

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,9 @@ 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+
}
4449
}

src/assets/i18n/da.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@
5353
"FAIL": "Fejl - aktion ikke fuldført",
5454
"LOADFAIL": "Fejl - kunne ikke loade",
5555
"QUEUE": "Element sat i kø",
56-
"CLOSE": "Luk"
56+
"CLOSE": "Luk",
57+
"NODEVICES": "Kan ikke sende downlink - der er ingen devices!"
5758
},
5859
"SEARCH": {
5960
"ICON": "",

0 commit comments

Comments
 (0)