daemonsetcard_component.js 3.7 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
// Copyright 2015 Google Inc. All Rights Reserved.
//
// 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.

import {StateParams} from 'common/resource/resourcedetail';
import {stateName} from 'daemonsetdetail/daemonsetdetail_state';

/**
 * Controller for daemon set card.
 *
 * @final
 */
export class DaemonSetCardController {
  /**
   * @param {!ui.router.$state} $state
   * @param {!angular.$interpolate} $interpolate
27
   * @param {!./../common/namespace/namespace_service.NamespaceService} kdNamespaceService
28 29
   * @ngInject
   */
30
  constructor($state, $interpolate, kdNamespaceService) {
31 32 33 34 35 36 37 38 39
    /** @export {!backendApi.DaemonSet} - Initialized from binding. */
    this.daemonSet;

    /** @private {!ui.router.$state} */
    this.state_ = $state;

    /** @private {!angular.$interpolate} */
    this.interpolate_ = $interpolate;

40 41 42
    /** @private {!./../common/namespace/namespace_service.NamespaceService} */
    this.kdNamespaceService_ = kdNamespaceService;

43 44 45 46
    /** @export */
    this.i18n = i18n;
  }

47 48 49 50 51 52 53 54
  /**
   * @return {boolean}
   * @export
   */
  areMultipleNamespacesSelected() {
    return this.kdNamespaceService_.areMultipleNamespacesSelected();
  }

55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120
  /**
   * @return {string}
   * @export
   */
  getDaemonSetDetailHref() {
    return this.state_.href(
        stateName,
        new StateParams(this.daemonSet.objectMeta.namespace, this.daemonSet.objectMeta.name));
  }

  /**
   * Returns true if any of the object's pods have warning, false otherwise
   * @return {boolean}
   * @export
   */
  hasWarnings() { return this.daemonSet.pods.failed > 0; }

  /**
   * Returns true if the object's pods have no warnings and there is at least one pod
   * in pending state, false otherwise
   * @return {boolean}
   * @export
   */
  isPending() { return !this.hasWarnings() && this.daemonSet.pods.pending > 0; }

  /**
   * @return {boolean}
   * @export
   */
  isSuccess() { return !this.isPending() && !this.hasWarnings(); }

  /**
   * @export
   * @return {string} localized tooltip with the formatted creation date
   */
  getCreatedAtTooltip() {
    let filter = this.interpolate_(`{{date | date:'short'}}`);
    /** @type {string} @desc Tooltip 'Created at [some date]' showing the exact creation time of
     * the daemon set.*/
    let MSG_DAEMON_SET_LIST_CREATED_AT_TOOLTIP = goog.getMsg(
        'Created at {$creationDate}',
        {'creationDate': filter({'date': this.daemonSet.objectMeta.creationTimestamp})});
    return MSG_DAEMON_SET_LIST_CREATED_AT_TOOLTIP;
  }
}

/**
 * @type {!angular.Component}
 */
export const daemonSetCardComponent = {
  bindings: {
    'daemonSet': '=',
  },
  controller: DaemonSetCardController,
  templateUrl: 'daemonsetlist/daemonsetcard.html',
};

const i18n = {
  /** @export {string} @desc tooltip for failed pod card icon */
  MSG_PODS_ARE_FAILED_TOOLTIP: goog.getMsg('One or more pods have errors.'),
  /** @export {string} @desc tooltip for pending pod card icon */
  MSG_PODS_ARE_PENDING_TOOLTIP: goog.getMsg('One or more pods are in pending state.'),
  /** @export {string} @desc Title 'Daemon set' which is used as a title for the delete/update
   dialogs (that can be opened on the daemon set list view.) */
  MSG_DAEMON_SET_LIST_DAEMON_SET_TITLE: goog.getMsg('Daemon Set'),
};