Skip to content

Commit 4b11b86

Browse files
PR Changes. Also made the check for sigfox devices in detail page, which i missed before.
1 parent 963f5d4 commit 4b11b86

File tree

2 files changed

+49
-48
lines changed

2 files changed

+49
-48
lines changed

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

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { Application } from '@applications/application.model';
55
import { ApplicationService } from '@applications/application.service';
66
import { TranslateService } from '@ngx-translate/core';
77
import { DeleteDialogService } from '@shared/components/delete-dialog/delete-dialog.service';
8+
import { DeviceType } from '@shared/enums/device-type';
89
import { BackButton } from '@shared/models/back-button.model';
910
import { DropdownButton } from '@shared/models/dropdown-button.model';
1011
import { MeService } from '@shared/services/me.service';
@@ -59,12 +60,22 @@ export class ApplicationDetailComponent implements OnInit, OnDestroy {
5960
}
6061

6162
onDeleteApplication() {
63+
6264
let message: string;
63-
if (this.applicationHasDevices()) {
64-
message = this.translate.instant('APPLICATION.DELETE-HAS-DEVICES-PROMPT');
65+
let showAccept: boolean = true;
66+
const hasSigfoxDevices: boolean = this.applicationHasSigFoxDevices();
67+
68+
if (hasSigfoxDevices) {
69+
message = this.translate.instant(
70+
'APPLICATION.DELETE-HAS-SIGFOX-DEVICES-PROMPT'
71+
);
72+
showAccept = false;
73+
74+
} else if (this.applicationHasDevices()) {
75+
message = this.translate.instant('APPLICATION.DELETE-HAS-DEVICES-PROMPT');
6576
}
6677

67-
this.deleteDialogSubscription = this.deleteDialogService.showSimpleDialog(message).subscribe(
78+
this.deleteDialogSubscription = this.deleteDialogService.showSimpleDialog(message, showAccept).subscribe(
6879
(response) => {
6980
if (response) {
7081
this.applicationService.deleteApplication(this.application.id).subscribe((response) => {
@@ -86,6 +97,13 @@ export class ApplicationDetailComponent implements OnInit, OnDestroy {
8697
return this.application.iotDevices?.length > 0;
8798
}
8899

100+
applicationHasSigFoxDevices(): boolean {
101+
const sigfoxDevice = this.application.iotDevices.find((device) => {
102+
return device.type === DeviceType.SIGFOX;
103+
});
104+
return sigfoxDevice !== undefined;
105+
}
106+
89107
bindApplication(id: number): void {
90108
this.applicationsSubscription = this.applicationService.getApplication(id).subscribe((application) => {
91109
this.application = application;

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

Lines changed: 28 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -95,30 +95,37 @@ export class ApplicationsTableComponent implements AfterViewInit, OnInit {
9595

9696
deleteApplication(id: number) {
9797
let message: string;
98+
let showAccept: boolean = true;
99+
const hasSigfoxDevices: boolean = this.applicationHasSigFoxDevices(id);
98100

99-
if (this.canBeDeleted(id)) {
100-
return;
101-
}
102-
103-
if (this.applicationHasDevices(id)) {
101+
if (hasSigfoxDevices) {
102+
message = this.translate.instant(
103+
'APPLICATION.DELETE-HAS-SIGFOX-DEVICES-PROMPT'
104+
);
105+
showAccept = false;
106+
} else if (this.applicationHasDevices(id)) {
104107
message = this.translate.instant('APPLICATION.DELETE-HAS-DEVICES-PROMPT');
105108
}
106109

107-
this.deleteDialogService.showSimpleDialog(message).subscribe((response) => {
108-
if (response) {
109-
this.applicationService.deleteApplication(id).subscribe((response) => {
110-
if (response.ok && response.body.affected > 0) {
111-
this.paginator.page.emit({
112-
pageIndex: this.paginator.pageIndex,
113-
pageSize: this.paginator.pageSize,
114-
length: this.resultsLength,
110+
this.deleteDialogService
111+
.showSimpleDialog(message, showAccept)
112+
.subscribe((response) => {
113+
if (response) {
114+
this.applicationService
115+
.deleteApplication(id)
116+
.subscribe((response) => {
117+
if (response.ok && response.body.affected > 0) {
118+
this.paginator.page.emit({
119+
pageIndex: this.paginator.pageIndex,
120+
pageSize: this.paginator.pageSize,
121+
length: this.resultsLength,
122+
});
123+
} else {
124+
this.errorMessage = response?.error?.message;
125+
}
115126
});
116-
} else {
117-
this.errorMessage = response?.error?.message;
118-
}
119-
});
120-
}
121-
});
127+
}
128+
});
122129
}
123130

124131
applicationHasDevices(id: number): boolean {
@@ -128,34 +135,10 @@ export class ApplicationsTableComponent implements AfterViewInit, OnInit {
128135

129136
applicationHasSigFoxDevices(id: number): boolean {
130137
const applicationToDelete = this.data?.find((app) => app.id === id);
131-
const checkForSigfox = applicationToDelete.iotDevices.find((device) => {
138+
const sigfoxDevice = applicationToDelete.iotDevices.find((device) => {
132139
return device.type === DeviceType.SIGFOX;
133140
});
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-
}
141+
return sigfoxDevice !== undefined;
159142
}
160143

161144
navigateToEditPage(applicationId: string) {

0 commit comments

Comments
 (0)