component.ts 3.4 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 18
import {PersistentVolume, PersistentVolumeList} from '@api/backendapi';
import {Observable} from 'rxjs/Observable';
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 {ResourceService} 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-list',
  templateUrl: './template.html',
30
  changeDetection: ChangeDetectionStrategy.OnPush,
31
})
M
Marcin Maciaszczyk 已提交
32
export class PersistentVolumeListComponent extends ResourceListWithStatuses<PersistentVolumeList, PersistentVolume> {
33
  @Input() endpoint = EndpointManager.resource(Resource.persistentVolume).list();
34 35

  constructor(
S
Shu Muto 已提交
36 37
    private readonly pv_: ResourceService<PersistentVolumeList>,
    notifications: NotificationsService,
38
    cdr: ChangeDetectorRef,
S
Shu Muto 已提交
39
  ) {
40
    super('persistentvolume', notifications, cdr);
41 42
    this.id = ListIdentifier.persistentVolume;
    this.groupId = ListGroupIdentifier.cluster;
43

44 45 46
    // Register action columns.
    this.registerActionColumn<MenuComponent>('menu', MenuComponent);

47
    // Register status icon handlers
48
    this.registerBinding(this.icon.checkCircle, 'kd-success', this.isInSuccessState);
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
    this.registerBinding(this.icon.help, 'kd-muted', this.isInPendingState);
    this.registerBinding(this.icon.error, 'kd-error', this.isInErrorState);
  }

  getResourceObservable(params?: HttpParams): Observable<PersistentVolumeList> {
    return this.pv_.get(this.endpoint, undefined, params);
  }

  map(persistentVolumeList: PersistentVolumeList): PersistentVolume[] {
    return persistentVolumeList.items;
  }

  isInErrorState(resource: PersistentVolume): boolean {
    return resource.status === 'Failed';
  }

  isInPendingState(resource: PersistentVolume): boolean {
    return resource.status === 'Pending' || resource.status === 'Released';
  }

  isInSuccessState(resource: PersistentVolume): boolean {
    return resource.status === 'Available' || resource.status === 'Bound';
  }

73 74 75 76 77
  getClaimHref(claimReference: string): string {
    let href = '';

    const splittedRef = claimReference.split('/');
    if (splittedRef.length === 2) {
78
      href = this.kdState_.href('persistentvolumeclaim', splittedRef[1], splittedRef[0]);
79 80 81 82 83
    }

    return href;
  }

84 85
  getDisplayColumns(): string[] {
    return [
S
Shu Muto 已提交
86 87 88 89 90 91 92 93 94
      'statusicon',
      'name',
      'capacity',
      'accmodes',
      'reclaimpol',
      'status',
      'claim',
      'storagecl',
      'reason',
95
      'created',
96 97 98
    ];
  }
}