hbase_average_load.js 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  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. App.HBaseAverageLoadView = App.TextDashboardWidgetView.extend({
  20. title: Em.I18n.t('dashboard.widgets.HBaseAverageLoad'),
  21. id: '21',
  22. model_type: 'hbase',
  23. hiddenInfo: function () {
  24. var avgLoad = this.get('model.averageLoad');
  25. if (isNaN(avgLoad)) {
  26. avgLoad = Em.I18n.t('services.service.summary.notAvailable');
  27. }
  28. var result = [];
  29. result.pushObject(Em.I18n.t('dashboard.services.hbase.averageLoadPerServer').format(avgLoad));
  30. return result;
  31. }.property("model.averageLoad"),
  32. isGreen: function () {
  33. return this.get('data') <= this.get('thresh1');
  34. }.property('data','thresh1','thresh2'),
  35. isRed: function () {
  36. return this.get('data') > this.get('thresh2');
  37. }.property('data','thresh1','thresh2'),
  38. isNA: function (){
  39. return this.get('data') === null || isNaN(this.get('data'));
  40. }.property('data'),
  41. thresh1: 0.5,
  42. thresh2: 2,
  43. maxValue: 'infinity',
  44. data: function () {
  45. return this.get('model.averageLoad');
  46. }.property("model.averageLoad"),
  47. content: function (){
  48. if(this.get('data') || this.get('data') == 0){
  49. return this.get('data') + "";
  50. }else{
  51. return Em.I18n.t('services.service.summary.notAvailable');
  52. }
  53. }.property('model.averageLoad'),
  54. editWidget: function (event) {
  55. var parent = this;
  56. var configObj = Ember.Object.create({
  57. thresh1: parent.get('thresh1') + '',
  58. thresh2: parent.get('thresh2') + '',
  59. hintInfo: Em.I18n.t('dashboard.widgets.hintInfo.hint2'),
  60. isThresh1Error: false,
  61. isThresh2Error: false,
  62. errorMessage1: "",
  63. errorMessage2: "",
  64. maxValue: 'infinity',
  65. observeNewThresholdValue: function () {
  66. var thresh1 = this.get('thresh1');
  67. var thresh2 = this.get('thresh2');
  68. if (thresh1.trim() != "") {
  69. if (isNaN(thresh1) || thresh1 < 0) {
  70. this.set('isThresh1Error', true);
  71. this.set('errorMessage1', 'Invalid! Enter a number larger than 0');
  72. } else if ( this.get('isThresh2Error') === false && parseFloat(thresh2)<= parseFloat(thresh1)){
  73. this.set('isThresh1Error', true);
  74. this.set('errorMessage1', 'Threshold 1 should be smaller than threshold 2 !');
  75. } else {
  76. this.set('isThresh1Error', false);
  77. this.set('errorMessage1', '');
  78. }
  79. } else {
  80. this.set('isThresh1Error', true);
  81. this.set('errorMessage1', 'This is required');
  82. }
  83. if (thresh2.trim() != "") {
  84. if (isNaN(thresh2) || thresh2 < 0) {
  85. this.set('isThresh2Error', true);
  86. this.set('errorMessage2', 'Invalid! Enter a number larger than 0');
  87. } else {
  88. this.set('isThresh2Error', false);
  89. this.set('errorMessage2', '');
  90. }
  91. } else {
  92. this.set('isThresh2Error', true);
  93. this.set('errorMessage2', 'This is required');
  94. }
  95. }.observes('thresh1', 'thresh2')
  96. });
  97. var browserVerion = this.getInternetExplorerVersion();
  98. App.ModalPopup.show( {
  99. header: Em.I18n.t('dashboard.widgets.popupHeader'),
  100. classNames: [ 'sixty-percent-width-modal-edit-widget'],
  101. bodyClass: Ember.View.extend({
  102. templateName: require('templates/main/dashboard/edit_widget_popup'),
  103. configPropertyObj: configObj
  104. }),
  105. primary: Em.I18n.t('common.apply'),
  106. onPrimary: function () {
  107. configObj.observeNewThresholdValue();
  108. if (!configObj.isThresh1Error && !configObj.isThresh2Error) {
  109. parent.set('thresh1', parseFloat(configObj.get('thresh1')) );
  110. parent.set('thresh2', parseFloat(configObj.get('thresh2')) );
  111. if (!App.testMode) {
  112. //save to persist
  113. var big_parent = parent.get('parentView');
  114. big_parent.getUserPref(big_parent.get('persistKey'));
  115. var oldValue = big_parent.get('currentPrefObject');
  116. oldValue.threshold[parseInt(parent.id)] = [configObj.get('thresh1'), configObj.get('thresh2')];
  117. big_parent.postUserPref(big_parent.get('persistKey'),oldValue);
  118. }
  119. this.hide();
  120. }
  121. },
  122. didInsertElement: function () {
  123. var colors = ['#95A800', '#FF8E00', '#B80000']; //color green, orange ,red
  124. var handlers = [33, 66]; //fixed value
  125. if (browserVerion == -1 || browserVerion > 9) {
  126. configObj.set('isIE9', false);
  127. configObj.set('isGreenOrangeRed', true);
  128. $("#slider-range").slider({
  129. range:true,
  130. disabled:true, //handlers cannot move
  131. min: 0,
  132. max: 100,
  133. values: handlers,
  134. create: function (event, ui) {
  135. parent.updateColors(handlers, colors);
  136. }
  137. });
  138. } else {
  139. configObj.set('isIE9', true);
  140. configObj.set('isGreenOrangeRed', true);
  141. }
  142. }
  143. });
  144. }
  145. });