This repository has been archived by the owner on Jul 15, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: improved container action buttons
- Loading branch information
Leonardo Chaia
committed
Oct 24, 2018
1 parent
69c4bb8
commit 631771c
Showing
6 changed files
with
222 additions
and
161 deletions.
There are no files selected for viewing
73 changes: 73 additions & 0 deletions
73
src/app/daemon-tools/container-action-buttons/container-action-buttons.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
<ng-template #loadingTemplate> | ||
<tim-loading></tim-loading> | ||
</ng-template> | ||
<div *ngIf="!loading; else loadingTemplate" | ||
fxLayout="row"> | ||
|
||
<div fxFlex="grow" | ||
fxLayout="row" | ||
fxLayoutAlign="start center" | ||
fxLayoutGap="4px"> | ||
|
||
<ng-container *ngIf="containerState === 'running'; else notRunningTemplate"> | ||
<button type="button" | ||
*ngIf="isButtonVisible('attach')" | ||
(click)="attach()" | ||
mat-raised-button | ||
color="accent"> | ||
<mat-icon>code</mat-icon> | ||
Attach | ||
</button> | ||
|
||
<button type="button" | ||
*ngIf="isButtonVisible('exec')" | ||
(click)="exec()" | ||
mat-raised-button> | ||
<mat-icon>settings_ethernet</mat-icon> | ||
Exec | ||
</button> | ||
|
||
</ng-container> | ||
|
||
<ng-template #notRunningTemplate> | ||
<button type="button" | ||
*ngIf="isButtonVisible('start')" | ||
(click)="start()" | ||
color="accent" | ||
mat-raised-button> | ||
<mat-icon>play_arrow</mat-icon> | ||
Start | ||
</button> | ||
</ng-template> | ||
|
||
<button type="button" | ||
*ngIf="isButtonVisible('logs')" | ||
(click)="logs()" | ||
mat-raised-button> | ||
<mat-icon>subject</mat-icon> | ||
Logs | ||
</button> | ||
|
||
<ng-container *ngIf="containerState === 'running'"> | ||
<button type="button" | ||
*ngIf="isButtonVisible('stop')" | ||
(click)="stop()" | ||
mat-raised-button> | ||
<mat-icon>stop</mat-icon> | ||
Stop | ||
</button> | ||
</ng-container> | ||
|
||
</div> | ||
|
||
<div> | ||
<button type="button" | ||
*ngIf="isButtonVisible('delete')" | ||
(click)="remove()" | ||
mat-raised-button> | ||
<mat-icon>delete</mat-icon> | ||
Delete | ||
</button> | ||
</div> | ||
|
||
</div> |
Empty file.
98 changes: 98 additions & 0 deletions
98
src/app/daemon-tools/container-action-buttons/container-action-buttons.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
import { Component, Input } from '@angular/core'; | ||
import { TabService } from '../../tabs/tab.service'; | ||
import { TimoneerTabs } from '../../timoneer-tabs'; | ||
import { Observable, throwError } from 'rxjs'; | ||
import { catchError, map } from 'rxjs/operators'; | ||
import { DockerContainerService } from '../docker-container.service'; | ||
import { NotificationService } from '../../shared/notification.service'; | ||
|
||
@Component({ | ||
selector: 'tim-container-action-buttons', | ||
templateUrl: './container-action-buttons.component.html', | ||
styleUrls: ['./container-action-buttons.component.scss'] | ||
}) | ||
export class ContainerActionButtonsComponent { | ||
|
||
@Input() | ||
public containerId: string; | ||
|
||
@Input() | ||
public containerState: string; | ||
|
||
@Input() | ||
public containerName: string; | ||
|
||
@Input() | ||
public hiddenButtons: string[] = []; | ||
|
||
public loading: boolean; | ||
|
||
constructor( | ||
private readonly tabService: TabService, | ||
private readonly containerService: DockerContainerService, | ||
private readonly notificationService: NotificationService) { } | ||
|
||
public attach() { | ||
this.tabService.add(TimoneerTabs.DOCKER_ATTACH, { | ||
title: `Attached to ${this.containerName}`, | ||
params: this.containerId, | ||
}); | ||
} | ||
|
||
public logs() { | ||
this.tabService.add(TimoneerTabs.DOCKER_LOGS, { | ||
title: `Logs from ${this.containerName}`, | ||
params: this.containerId, | ||
}); | ||
} | ||
|
||
public exec() { | ||
this.tabService.add(TimoneerTabs.DOCKER_EXEC, { | ||
title: `Exec into ${this.containerName}`, | ||
params: this.containerId, | ||
}); | ||
} | ||
|
||
public start() { | ||
this.bindLoading(this.containerService.start(this.containerId)) | ||
.subscribe(() => { | ||
this.notificationService.open(`${this.containerName} started`); | ||
this.attach(); | ||
}); | ||
} | ||
|
||
public stop() { | ||
this.bindLoading(this.containerService.stop(this.containerId)) | ||
.subscribe(() => { | ||
this.notificationService.open(`${this.containerName} stopped`); | ||
}); | ||
} | ||
|
||
public remove() { | ||
this.bindLoading(this.containerService.remove(this.containerId)) | ||
.subscribe(() => { | ||
this.notificationService.open(`${this.containerName} removed`); | ||
}); | ||
} | ||
|
||
public isButtonVisible(key: string) { | ||
return !this.hiddenButtons.includes(key); | ||
} | ||
|
||
private bindLoading(obs: Observable<any>) { | ||
this.loading = true; | ||
return obs.pipe( | ||
catchError((e) => { | ||
this.loading = false; | ||
this.notificationService.open(e.message, null, { | ||
panelClass: 'tim-bg-warn', | ||
}); | ||
return throwError(e); | ||
}), | ||
map(r => { | ||
this.loading = false; | ||
return r; | ||
}) | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.