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 19 20 21 22 23 24
import {HttpParams} from '@angular/common/http';
import {Component, ComponentFactoryResolver, Input} from '@angular/core';
import {DaemonSet, DaemonSetList, Event} from '@api/backendapi';
import {Observable} from 'rxjs/Observable';

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 30

@Component({
  selector: 'kd-daemon-set-list',
  templateUrl: './template.html',
})
31
export class DaemonSetListComponent extends ResourceListWithStatuses<DaemonSetList, DaemonSet> {
32 33 34
  @Input() endpoint = EndpointManager.resource(Resource.daemonSet, true).list();

  constructor(
S
Shu Muto 已提交
35 36 37 38
    private readonly daemonSet_: NamespacedResourceService<DaemonSetList>,
    resolver: ComponentFactoryResolver,
    notifications: NotificationsService,
  ) {
39
    super('daemonset', notifications, resolver);
40 41
    this.id = ListIdentifier.daemonSet;
    this.groupId = ListGroupIdentifier.workloads;
42 43

    // Register status icon handlers
44 45
    this.registerBinding(this.icon.checkCircle, 'kd-success', this.isInSuccessState);
    this.registerBinding(this.icon.timelapse, 'kd-muted', this.isInPendingState);
46
    this.registerBinding(this.icon.error, 'kd-error', this.isInErrorState);
47

48 49 50
    // Register action columns.
    this.registerActionColumn<MenuComponent>('menu', MenuComponent);

51
    // Register dynamic columns.
52
    this.registerDynamicColumn('namespace', 'name', this.shouldShowNamespaceColumn_.bind(this));
53 54 55
  }

  getResourceObservable(params?: HttpParams): Observable<DaemonSetList> {
56
    return this.daemonSet_.get(this.endpoint, undefined, undefined, params);
57 58 59 60 61 62 63
  }

  map(daemonSetList: DaemonSetList): DaemonSet[] {
    return daemonSetList.daemonSets;
  }

  isInErrorState(resource: DaemonSet): boolean {
64
    return resource.podInfo.warnings.length > 0;
65 66 67
  }

  isInPendingState(resource: DaemonSet): boolean {
S
Shu Muto 已提交
68
    return resource.podInfo.warnings.length === 0 && resource.podInfo.pending > 0;
69 70 71
  }

  isInSuccessState(resource: DaemonSet): boolean {
S
Shu Muto 已提交
72
    return resource.podInfo.warnings.length === 0 && resource.podInfo.pending === 0;
73 74 75
  }

  hasErrors(daemonSet: DaemonSet): boolean {
76
    return daemonSet.podInfo.warnings.length > 0;
77 78 79
  }

  getEvents(daemonSet: DaemonSet): Event[] {
80
    return daemonSet.podInfo.warnings;
81 82 83 84 85
  }

  getDisplayColumns(): string[] {
    return ['statusicon', 'name', 'labels', 'pods', 'age', 'images'];
  }
86 87 88 89

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