service_config_layout_tab_view.js 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  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.ServiceConfigLayoutTabView = Em.View.extend(App.ConfigOverridable, {
  20. /**
  21. * Determines if view is editable
  22. * It true - show all control-elements (undo, override, finalize etc) for each widget
  23. * If false - no widgets control-elements will be shown
  24. * Bound from template
  25. * @type {boolean}
  26. */
  27. canEdit: true,
  28. /**
  29. * view need some time to prepare data to display it correct
  30. * before that it's better not to show anything
  31. * @type {boolean}
  32. */
  33. dataIsReady: false,
  34. /**
  35. * @type {App.Service}
  36. */
  37. service: function () {
  38. return this.get('controller.selectedService');
  39. }.property('controller.selectedService'),
  40. templateName: require('templates/common/configs/service_config_layout_tab'),
  41. classNames: ['enhanced-config-tab-content'],
  42. /**
  43. * ConfigType-Widget map
  44. * key - widget type
  45. * value - widget view
  46. * @type {object}
  47. */
  48. widgetTypeMap: {
  49. checkbox: App.CheckboxConfigWidgetView,
  50. combo: App.ComboConfigWidgetView,
  51. directory: App.DirectoryConfigWidgetView,
  52. directories: App.DirectoryConfigWidgetView,
  53. list: App.ListConfigWidgetView,
  54. password: App.PasswordConfigWidgetView,
  55. 'radio-buttons': App.RadioButtonConfigWidgetView,
  56. slider: App.SliderConfigWidgetView,
  57. 'text-field': App.TextFieldConfigWidgetView,
  58. 'time-interval-spinner': App.TimeIntervalSpinnerView,
  59. toggle: App.ToggleConfigWidgetView,
  60. 'text-area': App.StringConfigWidgetView,
  61. 'test-db-connection': App.TestDbConnectionWidgetView
  62. },
  63. /**
  64. * Prepare configs for render
  65. * <code>subsection.configs</code> is an array of App.StackConfigProperty, but not App.ConfigProperty,
  66. * so proper config-properties should be linked to the subsections.
  67. * @method prepareConfigProperties
  68. */
  69. prepareConfigProperties: function () {
  70. var self = this;
  71. this.get('content.sectionRows').forEach(function (row) {
  72. row.forEach(function (section) {
  73. section.get('subsectionRows').forEach(function (subRow) {
  74. subRow.forEach(function (subsection) {
  75. var uiOnlyConfigs = App.uiOnlyConfigDerivedFromTheme.filterProperty('subSection.name', subsection.get('name'));
  76. self.setConfigsToContainer(subsection, uiOnlyConfigs);
  77. subsection.get('subSectionTabs').forEach(function (subSectionTab) {
  78. self.setConfigsToContainer(subSectionTab);
  79. });
  80. });
  81. });
  82. });
  83. });
  84. },
  85. /**
  86. * set {code} configs {code} array of subsection or subsection tab.
  87. * Also correct widget should be used for each config (it's selected according to <code>widget.type</code> and
  88. * <code>widgetTypeMap</code>). It may throw an error if needed widget can't be found in the <code>widgetTypeMap</code>
  89. * @param containerObject
  90. * @param [uiOnlyConfigs]
  91. */
  92. setConfigsToContainer: function(containerObject, uiOnlyConfigs) {
  93. var self = this;
  94. var service = this.get('controller.stepConfigs').findProperty('serviceName', this.get('controller.selectedService.serviceName'));
  95. if (!service) return;
  96. containerObject.set('configs', []);
  97. containerObject.get('configProperties').toArray().concat(uiOnlyConfigs || []).forEach(function (config) {
  98. var configProperty = service.get('configs').findProperty('name', config.get('name'));
  99. if (!configProperty) return;
  100. containerObject.get('configs').pushObject(configProperty);
  101. var configWidgetType = config.get('widgetType');
  102. var widgetView = self.get('widgetTypeMap')[configWidgetType];
  103. Em.assert('Unknown config widget view for config ' + configProperty.get('id') + ' with type ' + configWidgetType, widgetView);
  104. var additionalProperties = {
  105. widget: widgetView,
  106. stackConfigProperty: config
  107. };
  108. var configConditions = App.ThemeCondition.find().filter(function (_configCondition) {
  109. // Filter config condition depending on the value of another config
  110. var conditionalConfigs = (_configCondition.get('configs')||[]).filterProperty('fileName', config.get('filename')).filterProperty('configName', config.get('name'));
  111. // Filter config condition depending on the service existence or service state
  112. var serviceConfigConditionFlag = ((_configCondition.get('configName') === config.get('name')) && (_configCondition.get('fileName') === config.get('filename')) && (_configCondition.get('resource') === 'service'));
  113. var conditions;
  114. if (serviceConfigConditionFlag) {
  115. var configCondition = {
  116. configName: _configCondition.get('configName'),
  117. fileName: _configCondition.get('fileName')
  118. };
  119. conditions = conditionalConfigs.concat(configCondition)
  120. } else {
  121. conditions = conditionalConfigs;
  122. }
  123. return (conditions && conditions.length);
  124. }, this);
  125. if (configConditions && configConditions.length) {
  126. additionalProperties.configConditions = configConditions;
  127. }
  128. configProperty.setProperties(additionalProperties);
  129. if (configProperty.get('overrides')) {
  130. configProperty.get('overrides').setEach('stackConfigProperty', config);
  131. }
  132. if (configProperty.get('compareConfigs')) {
  133. configProperty.get('compareConfigs').invoke('setProperties', {
  134. isComparison: false,
  135. stackConfigProperty: config
  136. });
  137. }
  138. });
  139. },
  140. /**
  141. * changes active subsection tab
  142. * @param event
  143. */
  144. setActiveSubTab: function(event) {
  145. if (!event.context) return;
  146. try {
  147. event.context.get('subSection.subSectionTabs').setEach('isActive', false);
  148. event.context.set('isActive', true);
  149. } catch (e) {
  150. console.error('Can\'t update active subsection tab');
  151. }
  152. },
  153. didInsertElement: function () {
  154. this.set('dataIsReady', false);
  155. this.set('content.isConfigsPrepared', false);
  156. this._super();
  157. this.prepareConfigProperties();
  158. if (this.get('controller.isCompareMode')) {
  159. this.get('parentView').filterEnhancedConfigs();
  160. }
  161. this.set('content.isConfigsPrepared', true);
  162. this.set('dataIsReady', true);
  163. }
  164. });