component.ts 3.6 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.

S
Shu Muto 已提交
15 16 17 18 19
import { HttpParams } from '@angular/common/http';
import { Component, Input } from '@angular/core';
import { PersistentVolume, PersistentVolumeList } from '@api/backendapi';
import { StateService } from '@uirouter/core';
import { Observable } from 'rxjs/Observable';
20

S
Shu Muto 已提交
21 22 23 24 25 26 27 28
import { persistentVolumeState } from '../../../../resource/cluster/persistentvolume/state';
import { persistentVolumeClaimState } from '../../../../resource/config/persistentvolumeclaim/state';
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';
import { ListGroupIdentifiers, ListIdentifiers } from '../groupids';
29 30 31 32 33

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

  constructor(
S
Shu Muto 已提交
43 44 45 46
    state: StateService,
    private readonly pv_: ResourceService<PersistentVolumeList>,
    notifications: NotificationsService
  ) {
47 48 49 50
    super(persistentVolumeState.name, state, notifications);
    this.id = ListIdentifiers.persistentVolume;
    this.groupId = ListGroupIdentifiers.cluster;

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

54
    // Register status icon handlers
S
Shu Muto 已提交
55 56 57 58 59
    this.registerBinding(
      this.icon.checkCircle,
      'kd-success',
      this.isInSuccessState
    );
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83
    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';
  }

84 85 86 87 88
  getClaimHref(claimReference: string): string {
    let href = '';

    const splittedRef = claimReference.split('/');
    if (splittedRef.length === 2) {
S
Shu Muto 已提交
89 90 91 92 93
      href = this.kdState_.href(
        persistentVolumeClaimState.name,
        splittedRef[1],
        splittedRef[0]
      );
94 95 96 97 98
    }

    return href;
  }

99 100
  getDisplayColumns(): string[] {
    return [
S
Shu Muto 已提交
101 102 103 104 105 106 107 108 109 110
      'statusicon',
      'name',
      'capacity',
      'accmodes',
      'reclaimpol',
      'status',
      'claim',
      'storagecl',
      'reason',
      'age',
111 112 113
    ];
  }
}