step2_controller.js 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  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.WidgetWizardStep2Controller = Em.Controller.extend({
  20. name: "widgetWizardStep2Controller",
  21. widgetProperties: [],
  22. widgetValues: {},
  23. //TODO: Following computed property needs to be implemented. Next button should be enabled when there is no validation error and all required fields are filled
  24. isSubmitDisabled: function () {
  25. return this.get('widgetProperties').someProperty('isValid', false);
  26. }.property('widgetProperties.@each.isValid'),
  27. filteredMetrics: function () {
  28. var type = this.get('content.widgetType');
  29. return this.get('content.widgetMetrics').filter(function (metric) {
  30. if (type === 'GRAPH') {
  31. return metric.temporal;
  32. } else {
  33. return metric.point_in_time;
  34. }
  35. }, this);
  36. }.property('content.widgetMetrics'),
  37. /*
  38. * Generate the thresholds, unit, time range.etc object based on the widget type selected in previous step.
  39. */
  40. renderProperties: function () {
  41. var widgetType = this.get('content.widgetType');
  42. this.set("widgetProperties", {});
  43. var widgetProperties = App.WidgetType.find().findProperty('name', widgetType).get('properties');
  44. var properties = [];
  45. switch (widgetType) {
  46. case 'GAUGE':
  47. properties = this.renderGaugeProperties(widgetProperties);
  48. break;
  49. case 'NUMBER':
  50. properties = this.renderNumberProperties(widgetProperties);
  51. break;
  52. case 'GRAPH':
  53. properties = this.renderGraphProperties(widgetProperties);
  54. break;
  55. case 'TEMPLATE':
  56. properties = this.renderTemplateProperties(widgetProperties);
  57. break;
  58. default:
  59. console.error('Incorrect Widget Type: ', widgetType);
  60. }
  61. this.set('widgetProperties', properties);
  62. },
  63. /**
  64. * Render properties for gauge-type widget
  65. * @method renderGaugeProperties
  66. * @returns {App.WidgetProperties[]}
  67. */
  68. renderGaugeProperties: function (widgetProperties) {
  69. var result = [];
  70. result = result.concat([
  71. App.WidgetProperties.Thresholds.PercentageThreshold.create({
  72. smallValue: '0.7',
  73. bigValue: '0.9',
  74. isRequired: true
  75. })
  76. ]);
  77. return result;
  78. },
  79. /**
  80. * Render properties for number-type widget
  81. * @method renderNumberProperties
  82. * @returns {App.WidgetProperties[]}
  83. */
  84. renderNumberProperties: function (widgetProperties) {
  85. var result = [];
  86. result = result.concat([
  87. App.WidgetProperties.Threshold.create({
  88. smallValue: '10',
  89. bigValue: '20',
  90. isRequired: false
  91. }),
  92. App.WidgetProperties.Unit.create({
  93. value: 'MB',
  94. isRequired: false
  95. })
  96. ]);
  97. return result;
  98. },
  99. /**
  100. * Render properties for template-type widget
  101. * @method renderTemplateProperties
  102. * @returns {App.WidgetProperties[]}
  103. */
  104. renderTemplateProperties: function (widgetProperties) {
  105. var result = [];
  106. result = result.concat([
  107. App.WidgetProperties.Unit.create({
  108. value: 'MB',
  109. isRequired: false
  110. })
  111. ]);
  112. return result;
  113. },
  114. /**
  115. * Render properties for graph-type widget
  116. * @method renderGraphProperties
  117. * @returns {App.WidgetProperties[]}
  118. */
  119. renderGraphProperties: function (widgetProperties) {
  120. var result = [];
  121. result = result.concat([
  122. App.WidgetProperties.GraphType.create({
  123. value: 'LINE',
  124. isRequired: true
  125. }),
  126. App.WidgetProperties.TimeRange.create({
  127. value: 'Last 1 hour',
  128. isRequired: true
  129. }),
  130. App.WidgetProperties.Unit.create({
  131. value: 'MB',
  132. isRequired: false
  133. })
  134. ]);
  135. return result;
  136. },
  137. next: function () {
  138. if (!this.get('isSubmitDisabled')) {
  139. App.router.send('next');
  140. }
  141. }
  142. });