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.

S
Shu Muto 已提交
15
import { Component, Input } from '@angular/core';
16
import { Router } from '@angular/router';
S
Shu Muto 已提交
17 18 19 20 21 22
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 24

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

const scalableResources: string[] = [
S
Shu Muto 已提交
34 35 36 37
  Resource.deployment,
  Resource.replicaSet,
  Resource.replicationController,
  Resource.statefulSet,
38
];
B
bryk 已提交
39

40 41
const executableResources: string[] = [Resource.pod];

42 43
const triggerableResources: string[] = [Resource.cronJob];

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

52
  constructor(
S
Shu Muto 已提交
53
    private readonly verber_: VerberService,
54
    private readonly router_: Router,
S
Shu Muto 已提交
55 56
    private readonly kdState_: KdStateService
  ) {}
57

58 59
  setObjectMeta(objectMeta: ObjectMeta): void {
    this.objectMeta = objectMeta;
60 61
  }

62 63
  setTypeMeta(typeMeta: TypeMeta): void {
    this.typeMeta = typeMeta;
64
  }
65

66 67
  isLogsEnabled(): boolean {
    return loggableResources.includes(this.typeMeta.kind);
68 69 70
  }

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

79 80 81 82
  isExecEnabled(): boolean {
    return executableResources.includes(this.typeMeta.kind);
  }

83
  getExecHref(): string {
S
Shu Muto 已提交
84 85 86 87 88
    return this.kdState_.href(
      'shell',
      this.objectMeta.name,
      this.objectMeta.namespace
    );
89 90
  }

91 92 93 94 95
  isTriggerEnabled(): boolean {
    return triggerableResources.includes(this.typeMeta.kind);
  }

  onTrigger(): void {
S
Shu Muto 已提交
96 97 98 99 100
    this.verber_.showTriggerDialog(
      this.typeMeta.kind,
      this.typeMeta,
      this.objectMeta
    );
101 102
  }

103 104 105 106
  isScaleEnabled(): boolean {
    return scalableResources.includes(this.typeMeta.kind);
  }

107
  onScale(): void {
108 109 110
    this.verber_.onScale
      .pipe(first())
      .subscribe(() => this.router_.navigate([]));
S
Shu Muto 已提交
111 112 113 114 115
    this.verber_.showScaleDialog(
      this.typeMeta.kind,
      this.typeMeta,
      this.objectMeta
    );
116 117
  }

118
  onEdit(): void {
119 120 121
    this.verber_.onEdit
      .pipe(first())
      .subscribe(() => this.router_.navigate([]));
S
Shu Muto 已提交
122 123 124 125 126
    this.verber_.showEditDialog(
      this.typeMeta.kind,
      this.typeMeta,
      this.objectMeta
    );
127 128 129
  }

  onDelete(): void {
130 131 132
    this.verber_.onDelete
      .pipe(first())
      .subscribe(() => this.router_.navigate([]));
S
Shu Muto 已提交
133 134 135 136 137
    this.verber_.showDeleteDialog(
      this.typeMeta.kind,
      this.typeMeta,
      this.objectMeta
    );
138
  }
B
bryk 已提交
139
}