component.ts 3.5 KB
Newer Older
1
// Copyright 2017 The Kubernetes Authors.
B
bryk 已提交
2 3 4 5 6 7 8 9 10 11 12 13 14
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

15 16 17 18 19 20 21 22
import {Component, Input} from '@angular/core';
import {Router} from '@angular/router';
import {ObjectMeta, TypeMeta} from '@api/backendapi';
import {ActionColumn} from '@api/frontendapi';
import {first} from 'rxjs/operators';
import {KdStateService} from '../../../../services/global/state';
import {VerberService} from '../../../../services/global/verber';
import {Resource} from '../../../../services/resource/endpoint';
23
import {PinnerService} from '../../../../services/global/pinner';
24 25

const loggableResources: string[] = [
S
Shu Muto 已提交
26 27 28 29 30 31
  Resource.daemonSet,
  Resource.job,
  Resource.pod,
  Resource.replicaSet,
  Resource.replicationController,
  Resource.statefulSet,
32 33
];

34 35
const pinnableResources: string[] = [Resource.crdFull];

36 37
const executableResources: string[] = [Resource.pod];

38 39
const triggerableResources: string[] = [Resource.cronJob];

40
@Component({
41
  selector: 'kd-resource-context-menu',
42 43
  templateUrl: './template.html',
})
44
export class MenuComponent implements ActionColumn {
45 46
  @Input() objectMeta: ObjectMeta;
  @Input() typeMeta: TypeMeta;
47

48
  constructor(
S
Shu Muto 已提交
49 50 51
    private readonly verber_: VerberService,
    private readonly router_: Router,
    private readonly kdState_: KdStateService,
52
    private readonly pinner_: PinnerService,
S
Shu Muto 已提交
53
  ) {}
54

55 56
  setObjectMeta(objectMeta: ObjectMeta): void {
    this.objectMeta = objectMeta;
57 58
  }

59 60
  setTypeMeta(typeMeta: TypeMeta): void {
    this.typeMeta = typeMeta;
61
  }
62

63 64
  isLogsEnabled(): boolean {
    return loggableResources.includes(this.typeMeta.kind);
65 66 67
  }

  getLogsHref(): string {
68
    return this.kdState_.href(
S
Shu Muto 已提交
69 70 71 72 73
      'log',
      this.objectMeta.name,
      this.objectMeta.namespace,
      this.typeMeta.kind,
    );
74 75
  }

76 77 78 79
  isExecEnabled(): boolean {
    return executableResources.includes(this.typeMeta.kind);
  }

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

84 85 86 87 88
  isTriggerEnabled(): boolean {
    return triggerableResources.includes(this.typeMeta.kind);
  }

  onTrigger(): void {
89
    this.verber_.showTriggerDialog(this.typeMeta.kind, this.typeMeta, this.objectMeta);
90 91
  }

92
  isScaleEnabled(): boolean {
93
    return this.typeMeta.scalable;
94 95
  }

96
  onScale(): void {
97
    this.verber_.showScaleDialog(this.typeMeta.kind, this.typeMeta, this.objectMeta);
98 99
  }

100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119
  isPinEnabled(): boolean {
    return pinnableResources.includes(this.typeMeta.kind);
  }

  onPin(): void {
    this.pinner_.pin(this.typeMeta.kind, this.objectMeta.name, this.objectMeta.namespace);
  }

  onUnpin(): void {
    this.pinner_.unpin(this.typeMeta.kind, this.objectMeta.name, this.objectMeta.namespace);
  }

  isPinned(): boolean {
    return this.pinner_.isPinned(
      this.typeMeta.kind,
      this.objectMeta.name,
      this.objectMeta.namespace,
    );
  }

120
  onEdit(): void {
121
    this.verber_.showEditDialog(this.typeMeta.kind, this.typeMeta, this.objectMeta);
122 123 124
  }

  onDelete(): void {
125
    this.verber_.showDeleteDialog(this.typeMeta.kind, this.typeMeta, this.objectMeta);
126
  }
B
bryk 已提交
127
}