hbase_regions_in_transition.js 5.4 KB

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