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

Commit

Permalink
feat: improved container action buttons
Browse files Browse the repository at this point in the history
  • Loading branch information
Leonardo Chaia committed Oct 24, 2018
1 parent 69c4bb8 commit 631771c
Show file tree
Hide file tree
Showing 6 changed files with 222 additions and 161 deletions.
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>
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;
})
);
}
}
150 changes: 49 additions & 101 deletions src/app/daemon-tools/container-list/container-list.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,112 +12,60 @@

<ng-template #defaultTemplate
let-container>
<mat-card fxLayout="row"
fxLayoutAlign="start center"
fxLayoutGap="16px">
<mat-icon class="tim-text-primary tim-icon-48">computer</mat-icon>
<div fxFlex="grow">
<h2 style="margin-bottom: 0">
{{container.Names[0]}}
<small [ngClass]="container.State === 'running' ? 'tim-text-primary' : 'tim-text-accent'">
{{container.State}}
</small>
<br>
<code title="Container Id">{{container.Id | slice:0:12}}</code>
<code title="Image"> {{getImageName(container)}}</code>
</h2>
<tim-loading *ngIf="loadingMap.get(container.Id)"></tim-loading>
</div>

<div style="text-align: right">

<span [title]="'Port Mappings:\n' + getPortMappings(container)"
class="text-nowrap">
<mat-icon>network_wifi</mat-icon>
<b>
{{container.Ports.length}}
</b>
</span>
<span title="Volume Mappings"
class="text-nowrap">
<mat-icon>storage</mat-icon>
<b>
{{container.Mounts.length}}
</b>
</span>

<div class="text-nowrap">
{{container.Status}}
</div>
</div>

<div fxLayout="column"
fxLayoutGap="4px">

<div fxLayout="row"
fxLayoutAlign="start center"
fxLayoutGap="4px">

<ng-container *ngIf="container.State === 'running'">
<button type="button"
matTooltip="Attach"
(click)="attach(container)"
mat-raised-button
color="accent">
<mat-icon>code</mat-icon>
</button>

<button type="button"
matTooltip="Exec"
(click)="exec(container)"
mat-raised-button
color="accent">
<mat-icon>settings_ethernet</mat-icon>
</button>

</ng-container>

<button type="button"
matTooltip="Logs"
(click)="logs(container)"
mat-raised-button
color="accent">
<mat-icon>subject</mat-icon>
</button>
<mat-card>
<div fxLayout="row"
fxLayoutAlign="start center"
fxLayoutGap="16px">

<mat-icon class="tim-text-primary tim-icon-48">computer</mat-icon>
<div fxFlex="grow">
<h2 style="margin-bottom: 0">
<span title="Name">
{{container.Names[0]}}
</span>

<small>
<code title="Id">{{container.Id | slice:0:12}}</code>
</small>

<small title="State"
[ngClass]="container.State === 'running' ? 'tim-text-primary' : 'tim-text-accent'">
{{container.State}}
</small>
<br>
<code title="Image"> {{getImageName(container)}}</code>
</h2>
<tim-loading *ngIf="loadingMap.get(container.Id)"></tim-loading>
</div>

<div fxLayout="row"
fxLayoutAlign="start center"
fxLayoutGap="4px">

<ng-container *ngIf="container.State === 'running'">
<button type="button"
matTooltip="Stop"
(click)="stop(container)"
mat-raised-button>
<mat-icon>stop</mat-icon>
</button>
</ng-container>

<ng-container *ngIf="container.State !== 'running'">
<button type="button"
matTooltip="Start"
(click)="start(container)"
color="accent"
mat-raised-button>
<mat-icon>play_arrow</mat-icon>
</button>
</ng-container>

<button type="button"
matTooltip="Delete"
(click)="remove(container)"
mat-raised-button>
<mat-icon>delete</mat-icon>
</button>
<div style="text-align: right">

<span [title]="'Port Mappings:\n' + getPortMappings(container)"
class="text-nowrap">
<mat-icon>network_wifi</mat-icon>
<b>
{{container.Ports.length}}
</b>
</span>
<span title="Volume Mappings"
class="text-nowrap">
<mat-icon>storage</mat-icon>
<b>
{{container.Mounts.length}}
</b>
</span>

<div class="text-nowrap">
{{container.Status}}
</div>
</div>
</div>

<div>
<tim-container-action-buttons [containerId]="container.Id"
[containerName]="container.Names[0]"
[containerState]="container.State"></tim-container-action-buttons>
</div>
</mat-card>
</ng-template>

Expand Down
Loading

0 comments on commit 631771c

Please sign in to comment.