edit_controller.js 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  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. expressions: [],
  69. dataSets: [],
  70. templateValue: null,
  71. widgetName: null,
  72. widgetDisplayName: null,
  73. widgetDescription: null,
  74. widgetScope: null,
  75. widgetId: null
  76. }),
  77. loadMap: {
  78. '1': [
  79. {
  80. type: 'sync',
  81. callback: function () {
  82. this.load('widgetType');
  83. this.load('widgetProperties');
  84. this.load('widgetValues');
  85. this.load('widgetMetrics');
  86. this.load('expressions');
  87. this.load('dataSets');
  88. this.load('templateValue');
  89. }
  90. },
  91. {
  92. type: 'async',
  93. callback: function () {
  94. return this.loadAllMetrics();
  95. }
  96. }
  97. ],
  98. '2': [
  99. {
  100. type: 'sync',
  101. callback: function () {
  102. this.load('widgetName');
  103. this.load('widgetDescription');
  104. this.load('widgetDisplayName');
  105. }
  106. }
  107. ]
  108. },
  109. /**
  110. * set current step
  111. * @param {string} currentStep
  112. * @param {boolean} completed
  113. * @param {boolean} skipStateSave
  114. */
  115. setCurrentStep: function (currentStep, completed, skipStateSave) {
  116. this._super(currentStep, completed);
  117. if (App.get('testMode') || skipStateSave) {
  118. return;
  119. }
  120. },
  121. /**
  122. * post widget definition to server
  123. * @returns {$.ajax}
  124. */
  125. putWidgetDefinition: function (data) {
  126. return App.ajax.send({
  127. name: 'widgets.wizard.edit',
  128. sender: this,
  129. data: {
  130. data: data,
  131. widgetId: this.get('content.widgetId')
  132. },
  133. success: 'putWidgetDefinitionSuccessCallback'
  134. });
  135. },
  136. putWidgetDefinitionSuccessCallback: function() {
  137. },
  138. /**
  139. * Clear all temporary data
  140. */
  141. finish: function () {
  142. this.setCurrentStep('1', false, true);
  143. this.save('widgetType', '');
  144. this.save('widgetService', '');
  145. this.save('widgetProperties', null);
  146. this.save('widgetMetrics', []);
  147. this.save('widgetValues', []);
  148. this.save('widgetName', '');
  149. this.save('widgetDescription', '');
  150. this.save('widgetDisplayName', '');
  151. this.save('widgetScope', '');
  152. this.save('allMetrics', []);
  153. this.save('expressions', []);
  154. this.save('dataSets', []);
  155. this.save('templateValue', '');
  156. this.resetDbNamespace();
  157. }
  158. });