component.ts 3.3 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 16 17 18
import {HttpParams} from '@angular/common/http';
import {Component, Input} from '@angular/core';
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 30

@Component({
  selector: 'kd-persistent-volume-list',
  templateUrl: './template.html',
})
S
Shu Muto 已提交
31 32 33 34
export class PersistentVolumeListComponent extends ResourceListWithStatuses<
  PersistentVolumeList,
  PersistentVolume
> {
35
  @Input() endpoint = EndpointManager.resource(Resource.persistentVolume).list();
36 37

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

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

48
    // Register status icon handlers
49
    this.registerBinding(this.icon.checkCircle, 'kd-success', this.isInSuccessState);
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
    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';
  }

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

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

    return href;
  }

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