tasktracker_live.js 8.3 KB

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