component.ts 3.5 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14
// Copyright 2017 The Kubernetes Authors.
//
// 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
import {HttpParams} from '@angular/common/http';
16
import {ChangeDetectionStrategy, ChangeDetectorRef, Component, Input} from '@angular/core';
17
import {Observable} from 'rxjs';
S
Shu Muto 已提交
18
import {PersistentVolumeClaim, PersistentVolumeClaimList} from 'typings/backendapi';
19

20 21 22 23 24
import {ResourceListWithStatuses} from '../../../resources/list';
import {NotificationsService} from '../../../services/global/notifications';
import {EndpointManager, Resource} from '../../../services/resource/endpoint';
import {NamespacedResourceService} from '../../../services/resource/resource';
import {MenuComponent} from '../../list/column/menu/component';
25
import {ListGroupIdentifier, ListIdentifier} from '../groupids';
26 27 28 29

@Component({
  selector: 'kd-persistent-volume-claim-list',
  templateUrl: './template.html',
30
  changeDetection: ChangeDetectionStrategy.OnPush,
31
})
S
Shu Muto 已提交
32 33 34 35
export class PersistentVolumeClaimListComponent extends ResourceListWithStatuses<
  PersistentVolumeClaimList,
  PersistentVolumeClaim
> {
36
  @Input() endpoint = EndpointManager.resource(Resource.persistentVolumeClaim, true).list();
37 38

  constructor(
S
Shu Muto 已提交
39 40
    private readonly persistentVolumeClaim_: NamespacedResourceService<PersistentVolumeClaimList>,
    notifications: NotificationsService,
41
    cdr: ChangeDetectorRef
S
Shu Muto 已提交
42
  ) {
43
    super('persistentvolumeclaim', notifications, cdr);
44 45
    this.id = ListIdentifier.persistentVolumeClaim;
    this.groupId = ListGroupIdentifier.config;
46 47

    // Register status icon handlers
48 49
    this.registerBinding(this.icon.checkCircle, 'kd-success', this.isInBoundState);
    this.registerBinding(this.icon.timelapse, 'kd-muted', this.isInPendingState);
50
    this.registerBinding(this.icon.error, 'kd-error', this.isInLostState);
51

52 53 54
    // Register action columns.
    this.registerActionColumn<MenuComponent>('menu', MenuComponent);

55
    // Register dynamic columns.
56
    this.registerDynamicColumn('namespace', 'name', this.shouldShowNamespaceColumn_.bind(this));
57 58 59 60 61 62 63 64 65 66 67 68 69 70
  }

  isInBoundState(resource: PersistentVolumeClaim): boolean {
    return resource.status === 'Bound';
  }

  isInPendingState(resource: PersistentVolumeClaim): boolean {
    return resource.status === 'Pending';
  }

  isInLostState(resource: PersistentVolumeClaim): boolean {
    return resource.status === 'Lost';
  }

71 72
  getResourceObservable(params?: HttpParams): Observable<PersistentVolumeClaimList> {
    return this.persistentVolumeClaim_.get(this.endpoint, undefined, undefined, params);
73 74
  }

75
  map(persistentVolumeClaimList: PersistentVolumeClaimList): PersistentVolumeClaim[] {
76 77 78 79
    return persistentVolumeClaimList.items;
  }

  getDisplayColumns(): string[] {
M
Marcin Maciaszczyk 已提交
80
    return ['statusicon', 'name', 'labels', 'status', 'volume', 'capacity', 'accmodes', 'storagecl', 'created'];
81
  }
82

83
  getVolumeHref(persistentVolumeName: string): string {
84
    return this.kdState_.href('persistentvolume', persistentVolumeName);
85 86
  }

87 88 89
  private shouldShowNamespaceColumn_(): boolean {
    return this.namespaceService_.areMultipleNamespacesSelected();
  }
90
}