deploymentcard_component.js 3.8 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14
// 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.

B
bryk 已提交
15
import {StateParams} from 'common/resource/resourcedetail';
16 17 18 19 20 21 22 23 24 25
import {stateName} from 'deploymentdetail/deploymentdetail_state';

/**
 * Controller for the replica set card.
 *
 * @final
 */
export default class DeploymentCardController {
  /**
   * @param {!ui.router.$state} $state
26
   * @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
    /**
     * Initialized from the scope.
     * @export {!backendApi.Deployment}
     */
    this.deployment;

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

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

43 44 45
    /** @private {!./../common/namespace/namespace_service.NamespaceService} */
    this.kdNamespaceService_ = kdNamespaceService;

46 47
    /** @export */
    this.i18n = i18n;
48 49
  }

50 51 52 53 54 55 56 57
  /**
   * @return {boolean}
   * @export
   */
  areMultipleNamespacesSelected() {
    return this.kdNamespaceService_.areMultipleNamespacesSelected();
  }

58 59 60 61 62
  /**
   * @return {string}
   * @export
   */
  getDeploymentDetailHref() {
63 64 65
    return this.state_.href(
        stateName,
        new StateParams(this.deployment.objectMeta.namespace, this.deployment.objectMeta.name));
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87
  }

  /**
   * Returns true if any of replica set pods has warning, false otherwise
   * @return {boolean}
   * @export
   */
  hasWarnings() { return this.deployment.pods.warnings.length > 0; }

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

  /**
   * @return {boolean}
   * @export
   */
  isSuccess() { return !this.isPending() && !this.hasWarnings(); }
88 89 90 91 92 93 94 95 96 97 98 99 100 101

  /**
   * @export
   * @param  {string} creationDate - creation date of the deployment
   * @return {string} localized tooltip with the formatted creation date
   */
  getCreatedAtTooltip(creationDate) {
    let filter = this.interpolate_(`{{date | date:'short'}}`);
    /** @type {string} @desc Tooltip 'Created at [some date]' showing the exact creation time of
     * a deployment. */
    let MSG_DEPLOYMENT_LIST_CREATED_AT_TOOLTIP =
        goog.getMsg('Created at {$creationDate}', {'creationDate': filter({'date': creationDate})});
    return MSG_DEPLOYMENT_LIST_CREATED_AT_TOOLTIP;
  }
102 103 104 105 106 107 108 109 110 111 112 113
}

/**
 * @return {!angular.Component}
 */
export const deploymentCardComponent = {
  bindings: {
    'deployment': '=',
  },
  controller: DeploymentCardController,
  templateUrl: 'deploymentlist/deploymentcard.html',
};
114 115 116 117 118 119 120 121 122 123

const i18n = {
  /** @export {string} @desc Tooltip saying that some pods in a deployment have errors. */
  MSG_DEPLOYMENT_LIST_PODS_ERRORS_TOOLTIP: goog.getMsg('One or more pods have errors'),
  /** @export {string} @desc Tooltip saying that some pods in a deployment are pending. */
  MSG_DEPLOYMENT_LIST_PODS_PENDING_TOOLTIP: goog.getMsg('One or more pods are in pending state'),
  /** @export {string} @desc Label 'Deployment' which will appear in the deployment
      delete dialog opened from a deployment card on the list page.*/
  MSG_DEPLOYMENT_LIST_DEPLOYMENT_LABEL: goog.getMsg('Deployment'),
};