tasktracker_live.js 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  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.TextDashboardWidgetView.extend({
  20. title: Em.I18n.t('dashboard.widgets.TaskTrackerUp'),
  21. id: '8',
  22. model_type: 'mapreduce',
  23. hiddenInfo: function () {
  24. var svc = this.get('model');
  25. var liveCount = this.get('taskTrackersLive').length;
  26. var totalCount = svc.get('taskTrackers').get('length');
  27. var result = [];
  28. result.pushObject(liveCount + " live");
  29. result.pushObject(totalCount + " total");
  30. return result;
  31. }.property('model.taskTrackers.length', 'taskTrackersLive'),
  32. thresh1: 40,
  33. thresh2: 70,
  34. maxValue: 100,
  35. taskTrackersLive: function () {
  36. return this.get('model.taskTrackers').filterProperty("workStatus", "STARTED");
  37. }.property('model.taskTrackers.@each.workStatus'),
  38. data: function () {
  39. if (!this.get('model.taskTrackers.length')) {
  40. return -1;
  41. } else {
  42. return (this.get('taskTrackersLive').length / this.get('model.taskTrackers.length')).toFixed(2) * 100;
  43. }
  44. }.property('model.taskTrackers.length', 'taskTrackersLive'),
  45. content: function () {
  46. return this.get('taskTrackersLive').length + "/" + this.get('model.taskTrackers.length');
  47. }.property('model.taskTrackers.length', 'taskTrackersLive'),
  48. editWidget: function (event) {
  49. var parent = this;
  50. var max_tmp = parseFloat(parent.get('maxValue'));
  51. var configObj = Ember.Object.create({
  52. thresh1: parent.get('thresh1') + '',
  53. thresh2: parent.get('thresh2') + '',
  54. hintInfo: Em.I18n.t('dashboard.widgets.hintInfo.hint1').format(max_tmp),
  55. isThresh1Error: false,
  56. isThresh2Error: false,
  57. errorMessage1: "",
  58. errorMessage2: "",
  59. maxValue: max_tmp,
  60. observeNewThresholdValue: function () {
  61. var thresh1 = this.get('thresh1');
  62. var thresh2 = this.get('thresh2');
  63. if (thresh1.trim() != "") {
  64. if (isNaN(thresh1) || thresh1 > max_tmp || thresh1 < 0) {
  65. this.set('isThresh1Error', true);
  66. this.set('errorMessage1', 'Invalid! Enter a number between 0 - ' + max_tmp);
  67. } else if (this.get('isThresh2Error') === false && parseFloat(thresh2)<= parseFloat(thresh1)){
  68. this.set('isThresh1Error', true);
  69. this.set('errorMessage1', 'Threshold 1 should be smaller than threshold 2 !');
  70. } else {
  71. this.set('isThresh1Error', false);
  72. this.set('errorMessage1', '');
  73. }
  74. } else {
  75. this.set('isThresh1Error', true);
  76. this.set('errorMessage1', 'This is required');
  77. }
  78. if (thresh2.trim() != "") {
  79. if (isNaN(thresh2) || thresh2 > max_tmp || thresh2 < 0) {
  80. this.set('isThresh2Error', true);
  81. this.set('errorMessage2', 'Invalid! Enter a number between 0 - ' + max_tmp);
  82. } else {
  83. this.set('isThresh2Error', false);
  84. this.set('errorMessage2', '');
  85. }
  86. } else {
  87. this.set('isThresh2Error', true);
  88. this.set('errorMessage2', 'This is required');
  89. }
  90. // update the slider handles and color
  91. if (this.get('isThresh1Error') === false && this.get('isThresh2Error') === false) {
  92. $("#slider-range").slider('values', 0 , parseFloat(thresh1));
  93. $("#slider-range").slider('values', 1 , parseFloat(thresh2));
  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 persit
  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 handlers = [configObj.get('thresh1'), configObj.get('thresh2')];
  124. var colors = ['#B80000', '#FF8E00', '#95A800']; //color red, orange, green
  125. if (browserVerion == -1 || browserVerion > 9) {
  126. configObj.set('isIE9', false);
  127. configObj.set('isGreenOrangeRed', false);
  128. $("#slider-range").slider({
  129. range: true,
  130. min: 0,
  131. max: max_tmp,
  132. values: handlers,
  133. create: function (event, ui) {
  134. parent.updateColors(handlers, colors);
  135. },
  136. slide: function (event, ui) {
  137. parent.updateColors(ui.values, colors);
  138. configObj.set('thresh1', ui.values[0] + '');
  139. configObj.set('thresh2', ui.values[1] + '');
  140. },
  141. change: function (event, ui) {
  142. parent.updateColors(ui.values, colors);
  143. }
  144. });
  145. } else {
  146. configObj.set('isIE9', true);
  147. configObj.set('isGreenOrangeRed', false);
  148. }
  149. }
  150. });
  151. }
  152. });