Skip to content

Commit 963f5d4

Browse files
Added message to prompt when attempting to delete application with SigFox device
* Added message and functionality to check and to prompt when attempting to delete application with SigFox device
1 parent 93e1889 commit 963f5d4

File tree

2 files changed

+48
-3
lines changed

2 files changed

+48
-3
lines changed

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

Lines changed: 47 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
1-
import { Component, ViewChild, AfterViewInit, Input, OnInit } from '@angular/core';
1+
import {
2+
Component,
3+
ViewChild,
4+
AfterViewInit,
5+
Input,
6+
OnInit,
7+
} from '@angular/core';
28
import { MatPaginator } from '@angular/material/paginator';
39
import { MatSort } from '@angular/material/sort';
410
import { Router } from '@angular/router';
@@ -10,6 +16,7 @@ import { DeleteDialogService } from '@shared/components/delete-dialog/delete-dia
1016
import { MeService } from '@shared/services/me.service';
1117
import { merge, Observable, of as observableOf } from 'rxjs';
1218
import { catchError, map, startWith, switchMap } from 'rxjs/operators';
19+
import { DeviceType } from '@shared/enums/device-type';
1320

1421
/**
1522
* @title Table retrieving data through HTTP
@@ -40,7 +47,7 @@ export class ApplicationsTableComponent implements AfterViewInit, OnInit {
4047
private router: Router,
4148
private meService: MeService,
4249
private deleteDialogService: DeleteDialogService
43-
) { }
50+
) {}
4451

4552
ngOnInit() {
4653
this.canEdit = this.meService.canWriteInTargetOrganization();
@@ -88,6 +95,11 @@ export class ApplicationsTableComponent implements AfterViewInit, OnInit {
8895

8996
deleteApplication(id: number) {
9097
let message: string;
98+
99+
if (this.canBeDeleted(id)) {
100+
return;
101+
}
102+
91103
if (this.applicationHasDevices(id)) {
92104
message = this.translate.instant('APPLICATION.DELETE-HAS-DEVICES-PROMPT');
93105
}
@@ -110,10 +122,42 @@ export class ApplicationsTableComponent implements AfterViewInit, OnInit {
110122
}
111123

112124
applicationHasDevices(id: number): boolean {
113-
const applicationToDelete = this.data?.find(app => app.id === id);
125+
const applicationToDelete = this.data?.find((app) => app.id === id);
114126
return applicationToDelete && applicationToDelete.iotDevices.length > 0;
115127
}
116128

129+
applicationHasSigFoxDevices(id: number): boolean {
130+
const applicationToDelete = this.data?.find((app) => app.id === id);
131+
const checkForSigfox = applicationToDelete.iotDevices.find((device) => {
132+
return device.type === DeviceType.SIGFOX;
133+
});
134+
if (checkForSigfox) {
135+
return true;
136+
} else return false;
137+
}
138+
139+
canBeDeleted(id: number): boolean {
140+
let message: string;
141+
142+
if (this.applicationHasSigFoxDevices(id)) {
143+
message = this.translate.instant(
144+
'APPLICATION.DELETE-HAS-SIGFOX-DEVICES-PROMPT'
145+
);
146+
this.deleteDialogService
147+
.showSimpleDialog(
148+
message,
149+
false,
150+
true,
151+
false,
152+
this.translate.instant('APPLICATION.DELETE')
153+
)
154+
.subscribe();
155+
return true;
156+
} else {
157+
return false;
158+
}
159+
}
160+
117161
navigateToEditPage(applicationId: string) {
118162
this.router.navigate(['applications', 'edit-application', applicationId]);
119163
}

src/assets/i18n/da.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@
8181
"SAVE": "Gem applikation",
8282
"DELETE": "Slet applikation",
8383
"DELETE-HAS-DEVICES-PROMPT": "Der er knyttet IoT-enheder til denne applikation. Disse vil også blive slettet. Slet alligevel?",
84+
"DELETE-HAS-SIGFOX-DEVICES-PROMPT": "Applikationen kan ikke slettes, da der er knyttet Sigfox enheder til den",
8485
"NAME": "Applikationens navn",
8586
"DESCRIPTION": "Applikationens beskrivelse",
8687
"ATTACHED-IOT": "Tilknyttede IoT enheder",

0 commit comments

Comments
 (0)