Skip to content

Commit

Permalink
align actionbar actions with context actions
Browse files Browse the repository at this point in the history
  • Loading branch information
ajatprabha committed Jan 28, 2019
1 parent bcda2b0 commit 96be014
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

import {Component, Input} from '@angular/core';
import {ObjectMeta, TypeMeta} from '@api/backendapi';
import {ResourceMeta} from '../../../services/global/actionbar';

@Component({
selector: 'kd-actionbar-detail-actions',
Expand Down
41 changes: 40 additions & 1 deletion src/app/frontend/common/components/list/column/menu/component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,21 @@ import {ObjectMeta, TypeMeta} from '@api/backendapi';
import {ActionColumn} from '@api/frontendapi';
import {StateService} from '@uirouter/core';
import {Subscription} from 'rxjs/Subscription';

import {logsState} from '../../../../../logs/state';
import {LogsStateParams} from '../../../../params/params';
import {KdStateService} from '../../../../services/global/state';
import {VerberService} from '../../../../services/global/verber';
import {Resource} from '../../../../services/resource/endpoint';

const loggableResources: string[] = [
Resource.daemonSet, Resource.job, Resource.pod, Resource.replicaSet,
Resource.replicationController, Resource.statefulSet
];

const scalableResources: string[] = [
Resource.deployment, Resource.replicaSet, Resource.replicationController, Resource.statefulSet
];

@Component({
selector: 'kd-resource-context-menu',
Expand All @@ -27,10 +41,13 @@ export class MenuComponent implements ActionColumn, OnDestroy {
@Input() objectMeta: ObjectMeta;
@Input() typeMeta: TypeMeta;

private onScaleSubscription_: Subscription;
private onEditSubscription_: Subscription;
private onDeleteSubscription_: Subscription;

constructor(private readonly verber_: VerberService, private readonly state_: StateService) {}
constructor(
private readonly verber_: VerberService, private readonly state_: StateService,
private readonly kdState_: KdStateService) {}

setObjectMeta(objectMeta: ObjectMeta): void {
this.objectMeta = objectMeta;
Expand All @@ -41,10 +58,32 @@ export class MenuComponent implements ActionColumn, OnDestroy {
}

ngOnDestroy(): void {
if (this.onScaleSubscription_) this.onScaleSubscription_.unsubscribe();
if (this.onEditSubscription_) this.onEditSubscription_.unsubscribe();
if (this.onDeleteSubscription_) this.onDeleteSubscription_.unsubscribe();
}

showOption(optionName: string): boolean {
return (optionName === 'logs' && loggableResources.includes(this.typeMeta.kind)) ||
(optionName === 'scale' && scalableResources.includes(this.typeMeta.kind)) ||
(optionName === 'exec' && this.typeMeta.kind === Resource.pod);
}

getLogsHref(): string {
return this.state_.href(
logsState.name,
new LogsStateParams(this.objectMeta.namespace, this.objectMeta.name, this.typeMeta.kind));
}

getExecHref(): string {
return this.kdState_.href('shell', this.objectMeta.name, this.objectMeta.namespace);
}

onScale() {
this.onScaleSubscription_ = this.verber_.onScale.subscribe(this.onSuccess_.bind(this));
this.verber_.showScaleDialog(this.typeMeta.kind, this.typeMeta, this.objectMeta);
}

onEdit(): void {
this.onEditSubscription_ = this.verber_.onEdit.subscribe(this.onSuccess_.bind(this));
this.verber_.showEditDialog(this.typeMeta.kind, this.typeMeta, this.objectMeta);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,15 @@
-->

<mat-menu #actions="matMenu">
<a mat-menu-item
*ngIf="showOption('logs')"
[href]="getLogsHref()">Logs</a>
<a mat-menu-item
*ngIf="showOption('exec')"
[href]="getExecHref()">Exec</a>
<button mat-menu-item
*ngIf="showOption('scale')"
(click)="onScale()">Scale</button>
<button mat-menu-item
(click)="onEdit()">Edit</button>
<button mat-menu-item
Expand Down

0 comments on commit 96be014

Please sign in to comment.