component.ts 2.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, OnInit} from '@angular/core';
17
import {Event, EventList} from '@api/backendapi';
18
import {Observable} from 'rxjs';
19

20 21 22
import {ResourceListWithStatuses} from '../../../resources/list';
import {NotificationsService} from '../../../services/global/notifications';
import {NamespacedResourceService} from '../../../services/resource/resource';
23
import {ListGroupIdentifier, ListIdentifier} from '../groupids';
24 25 26

const EVENT_TYPE_WARNING = 'Warning';

27 28 29 30 31
@Component({
  selector: 'kd-event-list',
  templateUrl: './template.html',
  changeDetection: ChangeDetectionStrategy.OnPush,
})
M
Marcin Maciaszczyk 已提交
32
export class EventListComponent extends ResourceListWithStatuses<EventList, Event> implements OnInit {
33 34 35
  @Input() endpoint: string;

  constructor(
S
Shu Muto 已提交
36 37
    private readonly eventList: NamespacedResourceService<EventList>,
    notifications: NotificationsService,
38
    cdr: ChangeDetectorRef
S
Shu Muto 已提交
39
  ) {
40
    super('', notifications, cdr);
41 42
    this.id = ListIdentifier.event;
    this.groupId = ListGroupIdentifier.none;
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65

    // Register status icon handler
    this.registerBinding(this.icon.warning, 'kd-warning', this.isWarning);
    this.registerBinding(this.icon.none, '', this.isNormal.bind(this));
  }

  ngOnInit(): void {
    if (this.endpoint === undefined) {
      throw Error('Endpoint is a required parameter of event list.');
    }

    super.ngOnInit();
  }

  isWarning(event: Event): boolean {
    return event.type === EVENT_TYPE_WARNING;
  }

  isNormal(event: Event): boolean {
    return !this.isWarning(event);
  }

  getResourceObservable(params?: HttpParams): Observable<EventList> {
66
    return this.eventList.get(this.endpoint, undefined, undefined, params);
67 68 69 70 71 72 73
  }

  map(eventList: EventList): Event[] {
    return eventList.events;
  }

  getDisplayColumns(): string[] {
S
Shu Muto 已提交
74
    return ['statusicon', 'message', 'source', 'subobject', 'count', 'firstseen', 'lastseen'];
75 76
  }
}