提交 3fc3fcbc 编写于 作者: A Ajat Prabha 提交者: Kubernetes Prow Robot

align actionbar actions with context actions (#3514)

上级 1f2007d1
......@@ -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',
......
......@@ -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',
......@@ -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;
......@@ -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);
......
......@@ -15,6 +15,15 @@ limitations under the License.
-->
<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
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册