@@ -5,6 +5,7 @@ import { TimoneerTabs } from '../timoneer-tabs';
5
5
import { DockerContainerService } from './docker-container.service' ;
6
6
import { NotificationService } from '../shared/notification.service' ;
7
7
import { ContextMenuService , ContextMenuConstructor } from '../electron-tools/context-menu.service' ;
8
+ import { TimDialogService } from '../tim-dialog/tim-dialog.service' ;
8
9
9
10
@Injectable ( {
10
11
providedIn : 'root'
@@ -14,7 +15,8 @@ export class ContainerMenuService {
14
15
constructor ( private menu : ContextMenuService ,
15
16
private containerService : DockerContainerService ,
16
17
private notificationService : NotificationService ,
17
- private tabService : TabService ) { }
18
+ private tabService : TabService ,
19
+ private timDialog : TimDialogService ) { }
18
20
19
21
public open ( container : ContainerInfo ) {
20
22
@@ -39,7 +41,9 @@ export class ContainerMenuService {
39
41
}
40
42
] ;
41
43
42
- if ( container . State === 'running' ) {
44
+ const isRunning = container . State === 'running' ;
45
+
46
+ if ( isRunning ) {
43
47
template . push ( {
44
48
label : 'Stop' ,
45
49
click : ( ) => {
@@ -67,18 +71,38 @@ export class ContainerMenuService {
67
71
} ) ;
68
72
}
69
73
70
-
71
74
template . push ( {
72
75
label : 'Remove' ,
73
76
click : ( ) => {
74
- const obs = this . containerService . remove ( container . Id ) ;
75
- obs . subscribe ( ( ) => {
76
- this . notificationService . open ( `${ container . Names [ 0 ] } has been removed` ) ;
77
- } ) ;
78
- return obs ;
77
+ if ( isRunning ) {
78
+ this . timDialog . openMessageModal ( {
79
+ title : `Force remove ${ container . Names [ 0 ] } ` ,
80
+ message : 'The container is running and must be forced to be removed.' ,
81
+ confirmButton : {
82
+ color : 'warn' ,
83
+ icon : 'delete' ,
84
+ text : 'Force Removal' ,
85
+ action : ( ) => {
86
+ this . deleteContainer ( container , true ) ;
87
+ }
88
+ }
89
+ } ) ;
90
+ } else {
91
+ this . deleteContainer ( container ) ;
92
+ }
79
93
}
80
94
} ) ;
81
95
82
96
return this . menu . open ( template ) ;
83
97
}
98
+
99
+ protected deleteContainer ( container : ContainerInfo , force = false ) {
100
+ const obs = this . containerService . remove ( container . Id , {
101
+ force : force
102
+ } ) ;
103
+ obs . subscribe ( ( ) => {
104
+ this . notificationService . open ( `${ container . Names [ 0 ] } has been removed` ) ;
105
+ } ) ;
106
+ return obs ;
107
+ }
84
108
}
0 commit comments