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' ;
28import { MatPaginator } from '@angular/material/paginator' ;
39import { MatSort } from '@angular/material/sort' ;
410import { Router } from '@angular/router' ;
@@ -10,6 +16,7 @@ import { DeleteDialogService } from '@shared/components/delete-dialog/delete-dia
1016import { MeService } from '@shared/services/me.service' ;
1117import { merge , Observable , of as observableOf } from 'rxjs' ;
1218import { 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 }
0 commit comments