hbase_regions_in_transition.js 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  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.DashboardWidgetView.extend({
  20. title: Em.I18n.t('dashboard.widgets.HBaseRegionsInTransition'),
  21. id: '22',
  22. isPieChart: false,
  23. isText: true,
  24. isProgressBar: false,
  25. model_type: 'hbase',
  26. hiddenInfo: function () {
  27. var result = [];
  28. result.pushObject(this.get("model.regionsInTransition") + " regions");
  29. result.pushObject("in transition");
  30. return result;
  31. }.property("model.regionsInTransition"),
  32. classNameBindings: ['isRed', 'isOrange', 'isGreen', 'isNA'],
  33. isGreen: function () {
  34. var thresh1 = this.get('thresh1');
  35. var thresh2 = this.get('thresh2');
  36. return this.get('data') <= thresh1? true: false;
  37. }.property('data','thresh1','thresh2'),
  38. isOrange: function () {
  39. var thresh1 = this.get('thresh1');
  40. var thresh2 = this.get('thresh2');
  41. return (this.get('data') <= thresh2 && this.get('data') > thresh1 )? true: false;
  42. }.property('data','thresh1','thresh2'),
  43. isRed: function () {
  44. var thresh1 = this.get('thresh1');
  45. var thresh2 = this.get('thresh2');
  46. return this.get('data') > thresh2? true: false;
  47. }.property('data','thresh1','thresh2'),
  48. isNA: function () {
  49. return this.get('data') === null;
  50. }.property('data'),
  51. thresh1: 0.5,
  52. thresh2: 2,
  53. maxValue: 'infinity',
  54. data: function () {
  55. return this.get('model.regionsInTransition');
  56. }.property("model.regionsInTransition"),
  57. content: function (){
  58. return this.get('data') + "";
  59. }.property('model.regionsInTransition'),
  60. editWidget: function (event) {
  61. var parent = this;
  62. var configObj = Ember.Object.create({
  63. thresh1: parent.get('thresh1') + '',
  64. thresh2: parent.get('thresh2') + '',
  65. hintInfo: 'Edit the thresholds to change the color of current widget. ' +
  66. ' So enter two numbers larger than 0. ',
  67. isThresh1Error: false,
  68. isThresh2Error: false,
  69. errorMessage1: "",
  70. errorMessage2: "",
  71. maxValue: 'infinity',
  72. observeNewThresholdValue: function () {
  73. var thresh1 = this.get('thresh1');
  74. var thresh2 = this.get('thresh2');
  75. if (thresh1.trim() != "") {
  76. if (isNaN(thresh1) || thresh1 < 0) {
  77. this.set('isThresh1Error', true);
  78. this.set('errorMessage1', 'Invalid! Enter a number larger than 0');
  79. } else if ( this.get('isThresh2Error') === false && parseFloat(thresh2)<= parseFloat(thresh1)){
  80. this.set('isThresh1Error', true);
  81. this.set('errorMessage1', 'Threshold 1 should be smaller than threshold 2 !');
  82. } else {
  83. this.set('isThresh1Error', false);
  84. this.set('errorMessage1', '');
  85. }
  86. } else {
  87. this.set('isThresh1Error', true);
  88. this.set('errorMessage1', 'This is required');
  89. }
  90. if (thresh2.trim() != "") {
  91. if (isNaN(thresh2) || thresh2 < 0) {
  92. this.set('isThresh2Error', true);
  93. this.set('errorMessage2', 'Invalid! Enter a number larger than 0');
  94. } else {
  95. this.set('isThresh2Error', false);
  96. this.set('errorMessage2', '');
  97. }
  98. } else {
  99. this.set('isThresh2Error', true);
  100. this.set('errorMessage2', 'This is required');
  101. }
  102. }.observes('thresh1', 'thresh2')
  103. });
  104. var browserVerion = this.getInternetExplorerVersion();
  105. App.ModalPopup.show({
  106. header: 'Customize Widget',
  107. classNames: [ 'sixty-percent-width-modal-edit-widget'],
  108. bodyClass: Ember.View.extend({
  109. templateName: require('templates/main/dashboard/edit_widget_popup'),
  110. configPropertyObj: configObj
  111. }),
  112. primary: Em.I18n.t('common.apply'),
  113. onPrimary: function () {
  114. configObj.observeNewThresholdValue();
  115. if (!configObj.isThresh1Error && !configObj.isThresh2Error) {
  116. parent.set('thresh1', parseFloat(configObj.get('thresh1')) );
  117. parent.set('thresh2', parseFloat(configObj.get('thresh2')) );
  118. if (!App.testMode) {
  119. //save to persist
  120. var big_parent = parent.get('parentView');
  121. big_parent.getUserPref(big_parent.get('persistKey'));
  122. var oldValue = big_parent.get('currentPrefObject');
  123. oldValue.threshold[parseInt(parent.id)] = [configObj.get('thresh1'), configObj.get('thresh2')];
  124. big_parent.postUserPref(big_parent.get('persistKey'),oldValue);
  125. }
  126. this.hide();
  127. }
  128. },
  129. secondary : Em.I18n.t('common.cancel'),
  130. onSecondary: function () {
  131. this.hide();
  132. },
  133. didInsertElement: function () {
  134. var colors = ['#95A800', '#FF8E00', '#B80000']; //color green, orange ,red
  135. var handlers = [33, 66]; //fixed value
  136. if (browserVerion == -1 || browserVerion > 9) {
  137. configObj.set('isIE9', false);
  138. configObj.set('isGreenOrangeRed', true);
  139. $("#slider-range").slider({
  140. range:true,
  141. disabled:true, //handlers cannot move
  142. min: 0,
  143. max: 100,
  144. values: handlers,
  145. create: function (event, ui) {
  146. updateColors(handlers);
  147. }
  148. });
  149. function updateColors (handlers) {
  150. var colorstops = colors[0] + ", "; // start with the first color
  151. for (var i = 0; i < handlers.length; i++) {
  152. colorstops += colors[i] + " " + handlers[i] + "%,";
  153. colorstops += colors[i+1] + " " + handlers[i] + "%,";
  154. }
  155. // end with the last color
  156. colorstops += colors[colors.length - 1];
  157. var css1 = '-webkit-linear-gradient(left,' + colorstops + ')'; // chrome & safari
  158. $('#slider-range').css('background-image', css1);
  159. var css2 = '-ms-linear-gradient(left,' + colorstops + ')'; // IE 10+
  160. $('#slider-range').css('background-image', css2);
  161. //$('#slider-range').css('filter', 'progid:DXImageTransform.Microsoft.gradient( startColorStr= ' + colors[0] + ', endColorStr= ' + colors[2] +', GradientType=1 )' ); // IE 10-
  162. var css3 = '-moz-linear-gradient(left,' + colorstops + ')'; // Firefox
  163. $('#slider-range').css('background-image', css3);
  164. $('#slider-range .ui-widget-header').css({'background-color': '#FF8E00', 'background-image': 'none'}); // change the original ranger color
  165. }
  166. } else {
  167. configObj.set('isIE9', true);
  168. configObj.set('isGreenOrangeRed', true);
  169. }
  170. }
  171. });
  172. }
  173. })