service_config_view.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302
  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. /**
  23. * Bound from parent view in the template
  24. * @type {string}
  25. */
  26. filter: '',
  27. /**
  28. * Determines that active tab is set during view initialize.
  29. * @type {boolean}
  30. */
  31. initialActiveTabIsSet: false,
  32. /**
  33. * Bound from parent view in the template
  34. * @type {object[]}
  35. */
  36. columns: [],
  37. propertyFilterPopover: [Em.I18n.t('services.service.config.propertyFilterPopover.title'), Em.I18n.t('services.service.config.propertyFilterPopover.content')],
  38. canEdit: true, // View is editable or read-only?
  39. supportsHostOverrides: function () {
  40. switch (this.get('controller.name')) {
  41. case 'wizardStep7Controller':
  42. return this.get('controller.selectedService.serviceName') !== 'MISC';
  43. case 'mainServiceInfoConfigsController':
  44. case 'mainHostServiceConfigsController':
  45. return true;
  46. default:
  47. return false;
  48. }
  49. }.property('controller.name', 'controller.selectedService'),
  50. /**
  51. * Determines if user is on the service configs page
  52. * @type {boolean}
  53. */
  54. isOnTheServicePage: Em.computed.equal('controller.name', 'mainServiceInfoConfigsController'),
  55. classNameBindings: ['isOnTheServicePage:serviceConfigs'],
  56. /**
  57. * flag defines if any config match filter
  58. * true if all configs should be hidden
  59. * @type {boolean}
  60. */
  61. isAllConfigsHidden: false,
  62. /**
  63. * method that runs <code>updateFilterCounters<code> to
  64. * update filter counters for advanced tab
  65. * @method showHideAdvancedByFilter
  66. */
  67. showHideAdvancedByFilter: function () {
  68. Em.run.once(this, 'updateFilterCounters');
  69. }.observes('controller.selectedService.configs.@each.isHiddenByFilter'),
  70. /**
  71. * updates filter counters for advanced tab
  72. * @method updateFilterCounters
  73. */
  74. updateFilterCounters: function() {
  75. if (this.get('controller.selectedService.configs')) {
  76. var categories = this.get('controller.selectedService.configCategories').mapProperty('name');
  77. var configsToShow = this.get('controller.selectedService.configs').filter(function(config) {
  78. return config.get('isHiddenByFilter') == false && categories.contains(config.get('category')) && config.get('isVisible');
  79. });
  80. var isAllConfigsHidden = configsToShow.get('length') == 0;
  81. var isAdvancedHidden = isAllConfigsHidden || configsToShow.filter(function (config) {
  82. return Em.isNone(config.get('widget'));
  83. }).get('length') == 0;
  84. this.set('isAllConfigsHidden', isAllConfigsHidden);
  85. var advancedTab = App.Tab.find().filterProperty('serviceName', this.get('controller.selectedService.serviceName')).findProperty('isAdvanced');
  86. advancedTab && advancedTab.set('isAdvancedHidden', isAdvancedHidden);
  87. }
  88. },
  89. /**
  90. * Check for layout config supports.
  91. * @returns {Boolean}
  92. */
  93. supportsConfigLayout: function() {
  94. var supportedControllers = ['wizardStep7Controller', 'mainServiceInfoConfigsController', 'mainHostServiceConfigsController'];
  95. if (App.Tab.find().someProperty('serviceName', this.get('controller.selectedService.serviceName')) && supportedControllers.contains(this.get('controller.name'))) {
  96. return !Em.isEmpty(App.Tab.find().filterProperty('serviceName', this.get('controller.selectedService.serviceName')).filterProperty('isAdvanced', false));
  97. } else {
  98. return false;
  99. }
  100. }.property('controller.name', 'controller.selectedService'),
  101. toggleRestartMessageView: function () {
  102. this.$('.service-body').toggle('blind', 200);
  103. this.set('isRestartMessageCollapsed', !this.get('isRestartMessageCollapsed'));
  104. },
  105. didInsertElement: function () {
  106. if (this.get('isNotEditable') === true) {
  107. this.set('canEdit', false);
  108. }
  109. if (this.$('.service-body')) {
  110. this.$('.service-body').hide();
  111. }
  112. App.tooltip($(".restart-required-property"), {html: true});
  113. App.tooltip($(".icon-lock"), {placement: 'right'});
  114. App.tooltip($("[rel=tooltip]"));
  115. this.checkCanEdit();
  116. },
  117. /**
  118. * Check if we should show Custom Property category
  119. * @method checkCanEdit
  120. */
  121. checkCanEdit: function () {
  122. var controller = this.get('controller');
  123. if (!controller.get('selectedService.configCategories')) {
  124. return;
  125. }
  126. if (controller.get('selectedConfigGroup')) {
  127. controller.get('selectedService.configCategories').filterProperty('siteFileName').forEach(function (config) {
  128. var supportsAddingForbidden = App.config.shouldSupportAddingForbidden(controller.get('selectedService').serviceName, config.siteFileName); //true if the UI should not display the Custom ... section
  129. config.set('customCanAddProperty', !supportsAddingForbidden);
  130. });
  131. }
  132. }.observes('controller.selectedConfigGroup.name'),
  133. setActiveTab: function (event) {
  134. if (event.context.get('isHiddenByFilter')) return false;
  135. this.set('initialActiveTabIsSet', true);
  136. this.get('tabs').forEach(function (tab) {
  137. tab.set('isActive', false);
  138. });
  139. var currentTab = event.context;
  140. currentTab.set('isActive', true);
  141. currentTab.set('isRendered', true);
  142. },
  143. /**
  144. * Object that used for Twitter Bootstrap tabs markup.
  145. *
  146. * @returns {Ember.A}
  147. */
  148. tabs: function() {
  149. var tabs = App.Tab.find().filterProperty('serviceName', this.get('controller.selectedService.serviceName'));
  150. var advancedTab = tabs.findProperty('isAdvanced', true);
  151. if (advancedTab) {
  152. advancedTab.set('isRendered', advancedTab.get('isActive'));
  153. }
  154. this.processTabs(tabs);
  155. return tabs;
  156. }.property('controller.selectedService.serviceName'),
  157. /**
  158. * Set active tab when view attached and configs are linked to tabs.
  159. */
  160. initialActiveTabObserver: function() {
  161. var tabs = this.get('tabs').filterProperty('isAdvanced', false);
  162. if (tabs.everyProperty('isConfigsPrepared', true) && !this.get('initialActiveTabIsSet')) {
  163. this.pickActiveTab(this.get('tabs'));
  164. this.set('initialActiveTabIsSet', true);
  165. }
  166. }.observes('tabs.@each.isConfigsPrepared'),
  167. /**
  168. * Pick the first non hidden tab and make it active when there is no active tab
  169. * @method pickActiveTab
  170. */
  171. pickActiveTab: function (tabs) {
  172. if (!tabs) return;
  173. var activeTab = tabs.findProperty('isActive', true);
  174. if (activeTab) {
  175. if (activeTab.get('isHiddenByFilter')) {
  176. activeTab.set('isActive', false);
  177. this.pickActiveTab(tabs);
  178. }
  179. }
  180. else {
  181. var firstHotHiddenTab = tabs.filterProperty('isHiddenByFilter', false).get('firstObject');
  182. if(firstHotHiddenTab) {
  183. firstHotHiddenTab.set('isActive', true);
  184. if (firstHotHiddenTab.get('isAdvanced') && !firstHotHiddenTab.get('isRendered')) {
  185. firstHotHiddenTab.set('isRendered', true);
  186. }
  187. }
  188. }
  189. },
  190. /**
  191. * Data reordering before rendering.
  192. * Reorder all sections/subsections into rows based on their rowIndex
  193. * @param tabs
  194. */
  195. processTabs: function (tabs) {
  196. for (var i = 0; i < tabs.length; i++) {
  197. var tab = tabs[i];
  198. // process sections
  199. var sectionRows = [];
  200. var sections = tab.get('sections');
  201. for (var j = 0; j < sections.get('length'); j++) {
  202. var section = sections.objectAt(j);
  203. var sectionRow = sectionRows[section.get('rowIndex')];
  204. if (!sectionRow) { sectionRow = sectionRows[section.get('rowIndex')] = []; }
  205. sectionRow.push(section);
  206. //process subsections
  207. var subsections = section.get('subSections');
  208. var subsectionRows = [];
  209. for (var k = 0; k < subsections.get('length'); k++) {
  210. var subsection = subsections.objectAt(k);
  211. var subsectionRow = subsectionRows[subsection.get('rowIndex')];
  212. if (!subsectionRow) { subsectionRow = subsectionRows[subsection.get('rowIndex')] = []; }
  213. subsectionRow.push(subsection);
  214. // leave a title gap if one of the subsection on the same row within the same section has title
  215. if (subsection.get('displayName')) {subsectionRow.hasTitleGap = true;}
  216. }
  217. section.set('subsectionRows', subsectionRows);
  218. }
  219. tab.set('sectionRows', sectionRows);
  220. }
  221. },
  222. /**
  223. * Mark isHiddenByFilter flag for configs, sub-sections, and tab
  224. * @method filterEnhancedConfigs
  225. */
  226. filterEnhancedConfigs: function () {
  227. if (!this.get('controller.selectedService')) return true;
  228. var self = this;
  229. var serviceConfigs = this.get('controller.selectedService.configs').filterProperty('isVisible', true);
  230. var filter = (this.get('filter')|| '').toLowerCase();
  231. var selectedFilters = (this.get('columns') || []).filterProperty('selected');
  232. if (selectedFilters.length > 0 || filter.length > 0) {
  233. serviceConfigs.forEach(function (config) {
  234. var passesFilters = true;
  235. selectedFilters.forEach(function (filter) {
  236. if (config.get(filter.attributeName) !== filter.attributeValue) {
  237. passesFilters = false;
  238. }
  239. });
  240. if (!passesFilters) {
  241. config.set('isHiddenByFilter', true);
  242. return false;
  243. }
  244. var searchString = config.get('savedValue') + config.get('description') +
  245. config.get('displayName') + config.get('name') + config.get('value') + config.getWithDefault('stackConfigProperty.displayName', '');
  246. if (config.get('overrides')) {
  247. config.get('overrides').forEach(function (overriddenConf) {
  248. searchString += overriddenConf.get('value') + overriddenConf.get('group.name');
  249. });
  250. }
  251. if (filter != null && typeof searchString === "string") {
  252. config.set('isHiddenByFilter', !(searchString.toLowerCase().indexOf(filter) > -1));
  253. } else {
  254. config.set('isHiddenByFilter', false);
  255. }
  256. });
  257. }
  258. else {
  259. serviceConfigs.setEach('isHiddenByFilter', false);
  260. }
  261. Em.run.next(function () {
  262. self.pickActiveTab(self.get('tabs'));
  263. });
  264. }.observes('filter', 'columns.@each.selected', 'tabs.@each.isHiddenByFilter')
  265. });