edit_controller.js 5.2 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.WidgetEditController = App.WidgetWizardController.extend({
  20. name: 'widgetEditController',
  21. totalSteps: 2,
  22. content: Em.Object.create({
  23. controllerName: 'widgetEditController',
  24. widgetService: null,
  25. widgetType: '',
  26. /**
  27. * Example:
  28. * {
  29. * "display_unit": "%",
  30. * "warning_threshold": 70,
  31. * "error_threshold": 90
  32. * }
  33. */
  34. widgetProperties: {},
  35. /**
  36. * Example:
  37. * [{
  38. * widget_id: "metrics/rpc/closeRegion_num_ops",
  39. * name: "rpc.rpc.closeRegion_num_ops",
  40. * pointInTime: true,
  41. * temporal: true,
  42. * category: "default"
  43. * serviceName: "HBASE"
  44. * componentName: "HBASE_CLIENT"
  45. * type: "GANGLIA"//or JMX
  46. * level: "COMPONENT"//or HOSTCOMPONENT
  47. * }]
  48. * @type {Array}
  49. */
  50. allMetrics: [],
  51. /**
  52. * Example:
  53. * [{
  54. * "name": "regionserver.Server.percentFilesLocal",
  55. * "serviceName": "HBASE",
  56. * "componentName": "HBASE_REGIONSERVER"
  57. * }]
  58. */
  59. widgetMetrics: [],
  60. /**
  61. * Example:
  62. * [{
  63. * "name": "Files Local",
  64. * "value": "${regionserver.Server.percentFilesLocal}"
  65. * }]
  66. */
  67. widgetValues: [],
  68. widgetName: null,
  69. widgetDescription: null,
  70. widgetScope: null,
  71. widgetAuthor: null,
  72. widgetId: null
  73. }),
  74. loadMap: {
  75. '1': [
  76. {
  77. type: 'sync',
  78. callback: function () {
  79. this.load('widgetType');
  80. this.load('widgetProperties', true);
  81. this.load('widgetValues', true);
  82. this.load('widgetMetrics', true);
  83. }
  84. },
  85. {
  86. type: 'async',
  87. callback: function () {
  88. return this.loadAllMetrics();
  89. }
  90. }
  91. ],
  92. '2': [
  93. {
  94. type: 'sync',
  95. callback: function () {
  96. this.load('widgetName');
  97. this.load('widgetDescription');
  98. this.load('widgetAuthor');
  99. }
  100. }
  101. ]
  102. },
  103. /**
  104. * set current step
  105. * @param {string} currentStep
  106. * @param {boolean} completed
  107. * @param {boolean} skipStateSave
  108. */
  109. setCurrentStep: function (currentStep, completed, skipStateSave) {
  110. this._super(currentStep, completed);
  111. if (App.get('testMode') || skipStateSave) {
  112. return;
  113. }
  114. },
  115. /**
  116. * post widget definition to server
  117. * @returns {$.ajax}
  118. */
  119. putWidgetDefinition: function (data) {
  120. return App.ajax.send({
  121. name: 'widgets.wizard.edit',
  122. sender: this,
  123. data: {
  124. data: data,
  125. widgetId: this.get('content.widgetId')
  126. },
  127. success: 'putWidgetDefinitionSuccessCallback'
  128. });
  129. },
  130. putWidgetDefinitionSuccessCallback: function() {
  131. },
  132. cancel: function () {
  133. var self = this;
  134. var step3Controller = App.router.get('widgetWizardStep3Controller');
  135. return App.ModalPopup.show({
  136. header: Em.I18n.t('common.warning'),
  137. bodyClass: Em.View.extend({
  138. template: Ember.Handlebars.compile('{{t alerts.saveChanges}}')
  139. }),
  140. primary: Em.I18n.t('common.save'),
  141. secondary: Em.I18n.t('common.discard'),
  142. third: Em.I18n.t('common.cancel'),
  143. disablePrimary: function () {
  144. if (self.get('currentStep') == 2 && !step3Controller.get('isSubmitDisabled')) {
  145. return false;
  146. } else {
  147. return true;
  148. }
  149. }.property(''),
  150. onPrimary: function () {
  151. if (self.get('currentStep') == 2) {
  152. App.router.send('complete', step3Controller.collectWidgetData());
  153. }
  154. this.onSecondary();
  155. },
  156. onSecondary: function () {
  157. this.hide();
  158. self.finish();
  159. self.get('popup').hide();
  160. var serviceName = self.get('content.widgetService');
  161. var service = App.Service.find().findProperty('serviceName', serviceName);
  162. App.router.transitionTo('main.services.service', service);
  163. },
  164. onThird: function () {
  165. this.hide();
  166. }
  167. });
  168. },
  169. /**
  170. * Clear all temporary data
  171. */
  172. finish: function () {
  173. this.setCurrentStep('1', false, true);
  174. this.save('widgetType', '');
  175. this.save('widgetService', '');
  176. this.save('widgetProperties', null);
  177. this.save('widgetMetrics', []);
  178. this.save('widgetValues', []);
  179. this.save('widgetName', '');
  180. this.save('widgetDescription', '');
  181. this.save('widgetAuthor', '');
  182. this.save('widgetScope', '');
  183. this.save('allMetrics', []);
  184. this.save('expressions', []);
  185. this.save('dataSets', []);
  186. this.save('templateValue', '');
  187. this.resetDbNamespace();
  188. }
  189. });