hawqsegment_live.js 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /**
  2. * Licensed to the Apache Software Foundation (ASF) under one
  3. * or more contributor license agreements. See the NOTICE file
  4. * distributed with this work for additional information
  5. * regarding copyright ownership. The ASF licenses this file
  6. * to you under the Apache License, Version 2.0 (the
  7. * "License"); you may not use this file except in compliance
  8. * with the License. You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing, software
  13. * distributed under the License is distributed on an "AS IS" BASIS,
  14. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. * See the License for the specific language governing permissions and
  16. * limitations under the License.
  17. */
  18. var App = require('app');
  19. function counterOrNA(key) {
  20. var _key = 'model.{0}'.format(key);
  21. return Em.computed(_key, function () {
  22. var value = this.get(_key);
  23. if (Em.isNone(value)) {
  24. return Em.I18n.t('services.service.summary.notAvailable');
  25. }
  26. return value;
  27. });
  28. }
  29. App.HawqSegmentUpView = App.TextDashboardWidgetView.extend(App.EditableWithLimitWidgetMixin, {
  30. title: Em.I18n.t('dashboard.widgets.HawqSegmentUp'),
  31. id: '24',
  32. model_type: 'hawq',
  33. hiddenInfo: function () {
  34. return [
  35. this.get('hawqSegmentsStarted') + ' ' + Em.I18n.t('dashboard.services.components.started'),
  36. this.get('hawqSegmentsInstalled') + ' ' + Em.I18n.t('dashboard.services.components.stopped'),
  37. this.get('hawqSegmentsTotal')+ ' ' + Em.I18n.t('dashboard.services.components.total')
  38. ];
  39. }.property('hawqSegmentsStarted', 'hawqSegmentsInstalled', 'hawqSegmentsTotal'),
  40. hiddenInfoClass: "hidden-info-three-line",
  41. thresh1: 75,
  42. thresh2: 90,
  43. maxValue: 100,
  44. hawqSegmentsStarted: counterOrNA('hawqSegmentsStarted'),
  45. hawqSegmentsInstalled: counterOrNA('hawqSegmentsInstalled'),
  46. hawqSegmentsTotal: counterOrNA('hawqSegmentsTotal'),
  47. /**
  48. * @type {?number}
  49. */
  50. data: function () {
  51. if (this.get('someMetricsNA')) {
  52. return null;
  53. }
  54. return (this.get('hawqSegmentsStarted') / this.get('model.hawqSegmentsTotal')).toFixed(2) * 100;
  55. }.property('model.hawqSegmentsTotal', 'hawqSegmentsStarted', 'someMetricsNA'),
  56. /**
  57. * @type {string}
  58. */
  59. content: function () {
  60. if (this.get('someMetricsNA')) {
  61. return Em.I18n.t('services.service.summary.notAvailable');
  62. }
  63. return this.get('hawqSegmentsStarted') + "/" + this.get('model.hawqSegmentsTotal');
  64. }.property('model.hawqSegmentsTotal', 'hawqSegmentsStarted', 'someMetricsNA'),
  65. hintInfo: function () {
  66. var maxTmp = parseFloat(this.get('maxValue'));
  67. return Em.I18n.t('dashboard.widgets.hintInfo.hint1').format(maxTmp);
  68. }.property('maxValue'),
  69. /**
  70. * @type {boolean}
  71. */
  72. someMetricsNA: function() {
  73. return Em.isNone(this.get('model.hawqSegmentsStarted')) || Em.isNone(this.get('model.hawqSegmentsTotal'));
  74. }.property('model.hawqSegmentsStarted', 'model.hawqSegmentsTotal')
  75. });