hawqsegment_live.js 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  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.HawqSegmentUpView = App.TextDashboardWidgetView.extend({
  20. title: Em.I18n.t('dashboard.widgets.HawqSegmentUp'),
  21. id: '24',
  22. isPieChart: false,
  23. isText: true,
  24. isProgressBar: false,
  25. model_type: 'hawq',
  26. hiddenInfo: function () {
  27. var result = [];
  28. result.pushObject(this.get('hawqSegmentsStarted') + ' ' + Em.I18n.t('dashboard.services.hawq.segments.started'));
  29. result.pushObject(this.get('hawqSegmentsInstalled') + ' ' + Em.I18n.t('dashboard.services.hawq.segments.stopped'));
  30. result.pushObject(this.get('hawqSegmentsTotal')+ ' ' + Em.I18n.t('dashboard.services.hawq.segments.total'));
  31. return result;
  32. }.property('hawqSegmentsStarted', 'hawqSegmentsInstalled', 'hawqSegmentsTotal'),
  33. hiddenInfoClass: "hidden-info-three-line",
  34. thresh1: 40,
  35. thresh2: 70,
  36. maxValue: 100,
  37. hawqSegmentsStarted: function () {
  38. if (Em.isNone(this.get('model.hawqSegmentsStarted'))) {
  39. return Em.I18n.t('services.service.summary.notAvailable');
  40. }
  41. return this.get('model.hawqSegmentsStarted');
  42. }.property('model.hawqSegmentsStarted'),
  43. hawqSegmentsInstalled: function () {
  44. if (Em.isNone(this.get('model.hawqSegmentsInstalled'))) {
  45. return Em.I18n.t('services.service.summary.notAvailable');
  46. }
  47. return this.get('model.hawqSegmentsInstalled');
  48. }.property('model.hawqSegmentsInstalled'),
  49. hawqSegmentsTotal: function () {
  50. if (Em.isNone(this.get('model.hawqSegmentsTotal'))) {
  51. return Em.I18n.t('services.service.summary.notAvailable');
  52. }
  53. return this.get('model.hawqSegmentsTotal');
  54. }.property('model.hawqSegmentsTotal'),
  55. data: function () {
  56. if (Em.isNone(this.get('model.hawqSegmentsStarted')) || Em.isNone(this.get('model.hawqSegmentsTotal'))) {
  57. return null;
  58. } else {
  59. return ((this.get('hawqSegmentsStarted') / this.get('model.hawqSegmentsTotal')).toFixed(2)) * 100;
  60. }
  61. }.property('model.hawqSegmentsTotal', 'hawqSegmentsStarted'),
  62. content: function () {
  63. if (Em.isNone(this.get('model.hawqSegmentsStarted')) || Em.isNone(this.get('model.hawqSegmentsTotal'))) {
  64. return Em.I18n.t('services.service.summary.notAvailable');
  65. } else {
  66. return this.get('hawqSegmentsStarted') + "/" + this.get('model.hawqSegmentsTotal');
  67. }
  68. }.property('model.hawqSegmentsTotal', 'hawqSegmentsStarted'),
  69. editWidget: function (event) {
  70. var parent = this;
  71. var max_tmp = parseFloat(parent.get('maxValue'));
  72. var configObj = Ember.Object.create({
  73. thresh1: parent.get('thresh1') + '',
  74. thresh2: parent.get('thresh2') + '',
  75. hintInfo: Em.I18n.t('dashboard.widgets.hintInfo.hint1').format(max_tmp),
  76. isThresh1Error: false,
  77. isThresh2Error: false,
  78. errorMessage1: "",
  79. errorMessage2: "",
  80. maxValue: max_tmp,
  81. observeNewThresholdValue: function () {
  82. var thresh1 = this.get('thresh1');
  83. var thresh2 = this.get('thresh2');
  84. if (thresh1.trim() != "") {
  85. if (isNaN(thresh1) || thresh1 > max_tmp || thresh1 < 0){
  86. this.set('isThresh1Error', true);
  87. this.set('errorMessage1', 'Invalid! Enter a number between 0 - ' + max_tmp);
  88. } else if ( this.get('isThresh2Error') === false && parseFloat(thresh2)<= parseFloat(thresh1)) {
  89. this.set('isThresh1Error', true);
  90. this.set('errorMessage1', 'Threshold 1 should be smaller than threshold 2 !');
  91. } else {
  92. this.set('isThresh1Error', false);
  93. this.set('errorMessage1', '');
  94. }
  95. } else {
  96. this.set('isThresh1Error', true);
  97. this.set('errorMessage1', 'This is required');
  98. }
  99. if (thresh2.trim() != "") {
  100. if (isNaN(thresh2) || thresh2 > max_tmp || thresh2 < 0) {
  101. this.set('isThresh2Error', true);
  102. this.set('errorMessage2', 'Invalid! Enter a number between 0 - ' + max_tmp);
  103. } else {
  104. this.set('isThresh2Error', false);
  105. this.set('errorMessage2', '');
  106. }
  107. } else {
  108. this.set('isThresh2Error', true);
  109. this.set('errorMessage2', 'This is required');
  110. }
  111. // update the slider handles and color
  112. if (this.get('isThresh1Error') === false && this.get('isThresh2Error') === false) {
  113. $("#slider-range").slider('values', 0 , parseFloat(thresh1));
  114. $("#slider-range").slider('values', 1 , parseFloat(thresh2));
  115. }
  116. }.observes('thresh1', 'thresh2')
  117. });
  118. var browserVerion = this.getInternetExplorerVersion();
  119. App.ModalPopup.show({
  120. header: Em.I18n.t('dashboard.widgets.popupHeader'),
  121. classNames: [ 'sixty-percent-width-modal-edit-widget'],
  122. bodyClass: Ember.View.extend({
  123. templateName: require('templates/main/dashboard/edit_widget_popup'),
  124. configPropertyObj: configObj
  125. }),
  126. primary: Em.I18n.t('common.apply'),
  127. onPrimary: function () {
  128. configObj.observeNewThresholdValue();
  129. if (!configObj.isThresh1Error && !configObj.isThresh2Error) {
  130. parent.set('thresh1', parseFloat(configObj.get('thresh1')) );
  131. parent.set('thresh2', parseFloat(configObj.get('thresh2')) );
  132. if (!App.get('testMode')) {
  133. var big_parent = parent.get('parentView');
  134. big_parent.getUserPref(big_parent.get('persistKey'));
  135. var oldValue = big_parent.get('currentPrefObject');
  136. oldValue.threshold[parseInt(parent.id)] = [configObj.get('thresh1'), configObj.get('thresh2')];
  137. big_parent.postUserPref(big_parent.get('persistKey'),oldValue);
  138. }
  139. this.hide();
  140. }
  141. },
  142. didInsertElement: function () {
  143. var handlers = [configObj.get('thresh1'), configObj.get('thresh2')];
  144. var colors = [App.healthStatusRed, App.healthStatusOrange, App.healthStatusGreen]; //color red, orange, green
  145. if (browserVerion == -1 || browserVerion > 9) {
  146. configObj.set('isIE9', false);
  147. configObj.set('isGreenOrangeRed', false);
  148. $("#slider-range").slider({
  149. range: true,
  150. min: 0,
  151. max: max_tmp,
  152. values: handlers,
  153. create: function (event, ui) {
  154. parent.updateColors(handlers, colors);
  155. },
  156. slide: function (event, ui) {
  157. parent.updateColors(ui.values, colors);
  158. configObj.set('thresh1', ui.values[0] + '');
  159. configObj.set('thresh2', ui.values[1] + '');
  160. },
  161. change: function (event, ui) {
  162. parent.updateColors(ui.values, colors);
  163. }
  164. });
  165. } else {
  166. configObj.set('isIE9', true);
  167. configObj.set('isGreenOrangeRed', false);
  168. }
  169. }
  170. });
  171. }
  172. });