component.ts 2.1 KB
Newer Older
1
// Copyright 2017 The Kubernetes Authors.
B
bryk 已提交
2 3 4 5 6 7 8 9 10 11 12 13 14
//
// 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
import {HttpClient} from '@angular/common/http';
import {Component, OnInit} from '@angular/core';
import {Router} from '@angular/router';
B
bryk 已提交
18

19
import {AssetsService} from '../common/services/global/assets';
20

21 22 23 24 25
class SystemBanner {
  message: string;
  severity: string;
}

26 27 28 29 30
@Component({
  selector: 'kd-chrome',
  templateUrl: './template.html',
  styleUrls: ['./style.scss'],
})
31 32 33
export class ChromeComponent implements OnInit {
  private static readonly systemBannerEndpoint = 'api/v1/systembanner';
  private systemBanner_: SystemBanner;
34
  loading = false;
B
bryk 已提交
35

36
  constructor(
37 38
      public assets: AssetsService, private readonly http_: HttpClient,
      private readonly router_: Router) {}
39 40

  ngOnInit(): void {
41 42 43
    this.http_.get<SystemBanner>(ChromeComponent.systemBannerEndpoint).toPromise().then(sb => {
      this.systemBanner_ = sb;
    });
44
  }
B
bryk 已提交
45

46
  getOverviewStateName(): string {
47
    return 'overview';
B
bryk 已提交
48 49
  }

50
  isSystemBannerVisible(): boolean {
51
    return this.systemBanner_ && this.systemBanner_.message.length > 0;
B
bryk 已提交
52 53
  }

54
  getSystemBannerClass(): string {
55 56 57
    const severity = this.systemBanner_ && this.systemBanner_.severity ?
        this.systemBanner_.severity.toLowerCase() :
        '';
58 59 60 61 62 63 64 65
    switch (severity) {
      case 'warning':
        return 'kd-bg-warning-light';
      case 'error':
        return 'kd-bg-error-light';
      default:
        return 'kd-bg-success-light';
    }
66
  }
B
bryk 已提交
67

68
  getSystemBannerMessage(): string {
69
    return this.systemBanner_ ? this.systemBanner_.message : '';
70 71 72
  }

  goToCreateState(): void {
73
    this.router_.navigate(['create']);
74
  }
B
bryk 已提交
75
}