step3_controller.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  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.WidgetWizardStep3Controller = Em.Controller.extend({
  20. name: "widgetWizardStep3Controller",
  21. /**
  22. * @type {Array}
  23. */
  24. scopes: [
  25. Em.Object.create({
  26. name: 'User',
  27. checked: true
  28. }),
  29. Em.Object.create({
  30. name: 'Cluster',
  31. checked: false
  32. })
  33. ],
  34. /**
  35. * @type {string}
  36. */
  37. widgetName: '',
  38. /**
  39. * @type {string}
  40. */
  41. widgetAuthor: '',
  42. /**
  43. * @type {string}
  44. */
  45. widgetScope: function () {
  46. return this.get('scopes').findProperty('checked');
  47. }.property('scopes.@each.checked'),
  48. /**
  49. * @type {string}
  50. */
  51. widgetDescription: '',
  52. /**
  53. * actual values of properties in API format
  54. * @type {object}
  55. */
  56. widgetProperties: {},
  57. /**
  58. * @type {Array}
  59. */
  60. widgetValues: [],
  61. /**
  62. * @type {Array}
  63. */
  64. widgetMetrics: [],
  65. /**
  66. * restore widget data set on 2nd step
  67. */
  68. initPreviewData: function () {
  69. this.set('widgetProperties', this.get('content.widgetProperties'));
  70. this.set('widgetValues', this.get('content.widgetValues'));
  71. this.set('widgetMetrics', this.get('content.widgetMetrics'));
  72. this.set('widgetAuthor', App.router.get('loginName'));
  73. this.set('widgetName', '');
  74. this.set('widgetDescription', '');
  75. },
  76. //TODO: Following computed propert needs to be implemented. Next button should be enabled when there is no validation error and all required fields are filled
  77. isSubmitDisabled: function () {
  78. return !this.get('widgetName');
  79. }.property('widgetName'),
  80. /**
  81. * collect all needed data to create new widget
  82. * @returns {{WidgetInfo: {cluster_name: *, widget_name: *, display_name: *, widget_type: *, description: *, scope: string, metrics: *, values: *, properties: *}}}
  83. */
  84. collectWidgetData: function () {
  85. return {
  86. WidgetInfo: {
  87. widget_name: this.get('widgetName'),
  88. display_name: this.get('widgetName'),
  89. widget_type: this.get('content.widgetType'),
  90. description: this.get('widgetDescription'),
  91. scope: this.get('widgetScope.name').toUpperCase(),
  92. "metrics": this.get('widgetMetrics').map(function (metric) {
  93. return {
  94. "name": metric.name,
  95. "service_name": metric.serviceName,
  96. "component_name": metric.componentName
  97. }
  98. }),
  99. values: this.get('widgetValues'),
  100. properties: this.get('widgetProperties')
  101. }
  102. };
  103. },
  104. /**
  105. * post widget definition to server
  106. * @returns {$.ajax}
  107. */
  108. postWidgetDefinition: function () {
  109. return App.ajax.send({
  110. name: 'widgets.wizard.add',
  111. sender: this,
  112. data: {
  113. data: this.collectWidgetData()
  114. },
  115. success: 'postWidgetDefinitionSuccessCallback'
  116. });
  117. },
  118. postWidgetDefinitionSuccessCallback: function() {
  119. },
  120. complete: function () {
  121. this.postWidgetDefinition();
  122. App.router.send('complete');
  123. }
  124. });