Skip to content
This repository was archived by the owner on Jul 15, 2022. It is now read-only.

Commit aa8a70c

Browse files
author
Leonardo Chaia
committed
feat: force remove running containers
1 parent 92e63a0 commit aa8a70c

File tree

2 files changed

+34
-8
lines changed

2 files changed

+34
-8
lines changed

src/app/daemon-tools/container-menu.service.ts

+32-8
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { TimoneerTabs } from '../timoneer-tabs';
55
import { DockerContainerService } from './docker-container.service';
66
import { NotificationService } from '../shared/notification.service';
77
import { ContextMenuService, ContextMenuConstructor } from '../electron-tools/context-menu.service';
8+
import { TimDialogService } from '../tim-dialog/tim-dialog.service';
89

910
@Injectable({
1011
providedIn: 'root'
@@ -14,7 +15,8 @@ export class ContainerMenuService {
1415
constructor(private menu: ContextMenuService,
1516
private containerService: DockerContainerService,
1617
private notificationService: NotificationService,
17-
private tabService: TabService) { }
18+
private tabService: TabService,
19+
private timDialog: TimDialogService) { }
1820

1921
public open(container: ContainerInfo) {
2022

@@ -39,7 +41,9 @@ export class ContainerMenuService {
3941
}
4042
];
4143

42-
if (container.State === 'running') {
44+
const isRunning = container.State === 'running';
45+
46+
if (isRunning) {
4347
template.push({
4448
label: 'Stop',
4549
click: () => {
@@ -67,18 +71,38 @@ export class ContainerMenuService {
6771
});
6872
}
6973

70-
7174
template.push({
7275
label: 'Remove',
7376
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+
}
7993
}
8094
});
8195

8296
return this.menu.open(template);
8397
}
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+
}
84108
}

src/app/daemon-tools/daemon-tools.module.ts

+2
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ import { ContainerListContainerComponent } from './container-list-container/cont
4747
import { ContainerLauncherComponent } from './container-launcher/container-launcher.component';
4848
import { PullImageJobLogsComponent } from './pull-image-job-logs/pull-image-job-logs.component';
4949
import { JobsModule } from '../jobs/jobs.module';
50+
import { TimDialogModule } from '../tim-dialog/tim-dialog.module';
5051

5152
@NgModule({
5253
imports: [
@@ -73,6 +74,7 @@ import { JobsModule } from '../jobs/jobs.module';
7374
MatTooltipModule,
7475

7576
SharedModule,
77+
TimDialogModule,
7678
SettingsModule,
7779
JobsModule,
7880

0 commit comments

Comments
 (0)