@@ -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