service_config_layout_tab_view.js 6.9 KB

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