service_config_view.js 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  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.ServiceConfigView = Em.View.extend({
  20. templateName: require('templates/common/configs/service_config'),
  21. isRestartMessageCollapsed: false,
  22. filter: '', //from template
  23. columns: [], //from template
  24. propertyFilterPopover: [Em.I18n.t('services.service.config.propertyFilterPopover.title'), Em.I18n.t('services.service.config.propertyFilterPopover.content')],
  25. canEdit: true, // View is editable or read-only?
  26. supportsHostOverrides: function () {
  27. switch (this.get('controller.name')) {
  28. case 'wizardStep7Controller':
  29. return this.get('controller.selectedService.serviceName') !== 'MISC';
  30. case 'mainServiceInfoConfigsController':
  31. case 'mainHostServiceConfigsController':
  32. return true;
  33. default:
  34. return false;
  35. }
  36. }.property('controller.name', 'controller.selectedService'),
  37. /**
  38. * Check for layout config supports.
  39. * @returns {Boolean}
  40. */
  41. supportsConfigLayout: function() {
  42. var supportedControllers = ['wizardStep7Controller', 'mainServiceInfoConfigsController', 'mainHostServiceConfigsController'];
  43. if (!App.get('isClusterSupportsEnhancedConfigs')) {
  44. return false;
  45. }
  46. if (App.Tab.find().someProperty('serviceName', this.get('controller.selectedService.serviceName')) && supportedControllers.contains(this.get('controller.name'))) {
  47. return !Em.isEmpty(App.Tab.find().filterProperty('serviceName', this.get('controller.selectedService.serviceName')).filterProperty('isAdvanced', false));
  48. } else {
  49. return false;
  50. }
  51. }.property('controller.name', 'controller.selectedService'),
  52. showConfigHistoryFeature: false,
  53. toggleRestartMessageView: function () {
  54. this.$('.service-body').toggle('blind', 200);
  55. this.set('isRestartMessageCollapsed', !this.get('isRestartMessageCollapsed'));
  56. },
  57. didInsertElement: function () {
  58. if (this.get('isNotEditable') === true) {
  59. this.set('canEdit', false);
  60. }
  61. if (this.$('.service-body')) {
  62. this.$('.service-body').hide();
  63. }
  64. App.tooltip($(".restart-required-property"), {html: true});
  65. App.tooltip($(".icon-lock"), {placement: 'right'});
  66. this.checkCanEdit();
  67. },
  68. /**
  69. * Check if we should show Custom Property category
  70. */
  71. checkCanEdit: function () {
  72. var controller = this.get('controller');
  73. if (!controller.get('selectedService.configCategories')) {
  74. return;
  75. }
  76. if (controller.get('selectedConfigGroup')) {
  77. controller.get('selectedService.configCategories').filterProperty('siteFileName').forEach(function (config) {
  78. config.set('customCanAddProperty', config.get('canAddProperty'));
  79. });
  80. }
  81. }.observes(
  82. 'App.router.mainServiceInfoConfigsController.selectedConfigGroup.name',
  83. 'App.router.wizardStep7Controller.selectedConfigGroup.name'
  84. ),
  85. setActiveTab: function (event) {
  86. if (event.context.get('isHiddenByFilter')) return false;
  87. this.get('tabs').forEach(function (tab) {
  88. tab.set('isActive', false);
  89. });
  90. var currentTab = event.context;
  91. currentTab.set('isActive', true);
  92. },
  93. /**
  94. * Object that used for Twitter Bootstrap tabs markup.
  95. *
  96. * @returns {Ember.A}
  97. */
  98. tabs: function() {
  99. if (!App.get('isClusterSupportsEnhancedConfigs')) {
  100. return Em.A([]);
  101. }
  102. var tabs = App.Tab.find().filterProperty('serviceName', this.get('controller.selectedService.serviceName'));
  103. this.processTabs(tabs);
  104. this.pickActiveTab(tabs);
  105. return tabs;
  106. }.property('controller.selectedService.serviceName'),
  107. /**
  108. * Pick the first non hidden tab and make it active when there is no active tab
  109. * @method pickActiveTab
  110. */
  111. pickActiveTab: function (tabs) {
  112. if (!tabs) return;
  113. var activeTab = tabs.findProperty('isActive', true);
  114. if (activeTab) {
  115. if (activeTab.get('isHiddenByFilter')) {
  116. activeTab.set('isActive', false);
  117. this.pickActiveTab(tabs);
  118. }
  119. }
  120. else {
  121. var firstHotHiddenTab = tabs.filterProperty('isHiddenByFilter', false).get('firstObject');
  122. if(firstHotHiddenTab) {
  123. firstHotHiddenTab.set('isActive', true);
  124. }
  125. }
  126. },
  127. /**
  128. * Data reordering before rendering.
  129. * Reorder all sections/subsections into rows based on their rowIndex
  130. * @param tabs
  131. */
  132. processTabs: function (tabs) {
  133. for (var i = 0; i < tabs.length; i++) {
  134. var tab = tabs[i];
  135. // process sections
  136. var sectionRows = [];
  137. var sections = tab.get('sections');
  138. for (var j = 0; j < sections.get('length'); j++) {
  139. var section = sections.objectAt(j);
  140. var sectionRow = sectionRows[section.get('rowIndex')];
  141. if (!sectionRow) { sectionRow = sectionRows[section.get('rowIndex')] = []; }
  142. sectionRow.push(section);
  143. //process subsections
  144. var subsections = section.get('subSections');
  145. var subsectionRows = [];
  146. for (var k = 0; k < subsections.get('length'); k++) {
  147. var subsection = subsections.objectAt(k);
  148. var subsectionRow = subsectionRows[subsection.get('rowIndex')];
  149. if (!subsectionRow) { subsectionRow = subsectionRows[subsection.get('rowIndex')] = []; }
  150. subsectionRow.push(subsection);
  151. }
  152. section.set('subsectionRows', subsectionRows);
  153. }
  154. tab.set('sectionRows', sectionRows);
  155. }
  156. },
  157. /**
  158. * Mark isHiddenByFilter flag for configs, sub-sections, and tab
  159. * @method filterEnhancedConfigs
  160. */
  161. filterEnhancedConfigs: function () {
  162. var self = this;
  163. Em.run.next(function () {
  164. self.pickActiveTab(self.get('tabs'));
  165. });
  166. }.observes('filter', 'columns.@each.selected', 'tabs.@each.isHiddenByFilter')
  167. });