step3_controller.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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. widgetDisplayName: '',
  42. /**
  43. * @type {string}
  44. */
  45. widgetAuthor: '',
  46. /**
  47. * @type {string}
  48. */
  49. widgetScope: function () {
  50. return this.get('scopes').findProperty('checked');
  51. }.property('scopes.@each.checked'),
  52. /**
  53. * @type {string}
  54. */
  55. widgetDescription: '',
  56. /**
  57. * actual values of properties in API format
  58. * @type {object}
  59. */
  60. widgetProperties: {},
  61. /**
  62. * @type {Array}
  63. */
  64. widgetValues: [],
  65. /**
  66. * @type {Array}
  67. */
  68. widgetMetrics: [],
  69. /**
  70. * restore widget data set on 2nd step
  71. */
  72. initPreviewData: function () {
  73. this.set('widgetProperties', this.get('content.widgetProperties'));
  74. this.set('widgetValues', this.get('content.widgetValues'));
  75. this.set('widgetMetrics', this.get('content.widgetMetrics'));
  76. this.set('widgetAuthor', App.router.get('loginName'));
  77. this.set('widgetName', this.get('content.widgetDisplayName'));
  78. this.set('widgetDisplayName', this.get('content.widgetDisplayName'));
  79. this.set('widgetDescription', this.get('content.widgetDescription'));
  80. },
  81. //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
  82. isSubmitDisabled: function () {
  83. return !this.get('widgetDisplayName');
  84. }.property('widgetDisplayName'),
  85. /**
  86. * collect all needed data to create new widget
  87. * @returns {{WidgetInfo: {cluster_name: *, widget_name: *, display_name: *, widget_type: *, description: *, scope: string, metrics: *, values: *, properties: *}}}
  88. */
  89. collectWidgetData: function () {
  90. return {
  91. WidgetInfo: {
  92. widget_name: this.get('widgetName'),
  93. display_name: this.get('widgetDisplayName'),
  94. widget_type: this.get('content.widgetType'),
  95. description: this.get('widgetDescription'),
  96. scope: this.get('widgetScope.name').toUpperCase(),
  97. "metrics": this.get('widgetMetrics').map(function (metric) {
  98. return {
  99. "name": metric.name,
  100. "service_name": metric.serviceName,
  101. "component_name": metric.componentName
  102. }
  103. }),
  104. values: this.get('widgetValues'),
  105. properties: this.get('widgetProperties')
  106. }
  107. };
  108. },
  109. complete: function () {
  110. App.router.send('complete', this.collectWidgetData());
  111. }
  112. });