Repository: ambari Updated Branches: refs/heads/branch-2.5 44b1c059f -> 09312eae0
AMBARI-18790. Implement lazy loading for Service configs Advanced tab (akovalenko) Project: http://git-wip-us.apache.org/repos/asf/ambari/repo Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/40052006 Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/40052006 Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/40052006 Branch: refs/heads/branch-2.5 Commit: 4005200673725b9077b83bc7e11b6e8b845ff3fe Parents: 44b1c05 Author: Aleksandr Kovalenko <akovale...@hortonworks.com> Authored: Mon Jan 23 22:24:07 2017 +0200 Committer: Aleksandr Kovalenko <akovale...@hortonworks.com> Committed: Mon Jan 23 22:24:07 2017 +0200 ---------------------------------------------------------------------- .../templates/common/configs/service_config.hbs | 20 +----- ambari-web/app/views.js | 1 + .../configs/config_category_container_view.js | 64 ++++++++++++++++++++ .../configs/service_configs_by_category_view.js | 42 ++++++------- .../notification_configs_view_test.js | 6 +- 5 files changed, 92 insertions(+), 41 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ambari/blob/40052006/ambari-web/app/templates/common/configs/service_config.hbs ---------------------------------------------------------------------- diff --git a/ambari-web/app/templates/common/configs/service_config.hbs b/ambari-web/app/templates/common/configs/service_config.hbs index b78fecf..420091c 100644 --- a/ambari-web/app/templates/common/configs/service_config.hbs +++ b/ambari-web/app/templates/common/configs/service_config.hbs @@ -134,15 +134,7 @@ <div {{bindAttr class=":tab-pane tab.isActive:active tab.id"}}> {{#if tab.isAdvanced}} {{#if tab.isRendered}} - {{#each category in selectedService.configCategories}} - <div class="accordion"> - {{#if category.isCustomView}} - {{view category.customView categoryBinding="category" serviceBinding="selectedService" canEditBinding="view.canEdit" serviceConfigsBinding="selectedService.configs"}} - {{else}} - {{view App.ServiceConfigsByCategoryView categoryBinding="category" canEditBinding="view.canEdit" serviceBinding="selectedService" serviceConfigsBinding="selectedService.configs" supportsHostOverridesBinding="view.supportsHostOverrides"}} - {{/if}} - </div> - {{/each}} + {{view App.ConfigCategoryContainerView categoriesBinding="selectedService.configCategories" canEditBinding="view.canEdit" serviceBinding="selectedService" serviceConfigsBinding="selectedService.configs" supportsHostOverridesBinding="view.supportsHostOverrides"}} {{else}} {{view App.SpinnerView}} {{/if}} @@ -154,15 +146,7 @@ {{/each}} </div> {{else}} - {{#each category in selectedService.configCategories}} - <div class="accordion"> - {{#if category.isCustomView}} - {{view category.customView categoryBinding="category" serviceBinding="selectedService" canEditBinding="view.canEdit" serviceConfigsBinding="selectedService.configs"}} - {{else}} - {{view App.ServiceConfigsByCategoryView categoryBinding="category" canEditBinding="view.canEdit" serviceBinding="selectedService" serviceConfigsBinding="selectedService.configs" supportsHostOverridesBinding="view.supportsHostOverrides"}} - {{/if}} - </div> - {{/each}} + {{view App.ConfigCategoryContainerView categoriesBinding="selectedService.configCategories" canEditBinding="view.canEdit" serviceBinding="selectedService" serviceConfigsBinding="selectedService.configs" supportsHostOverridesBinding="view.supportsHostOverrides"}} {{/if}} {{#if view.isAllConfigsHidden}} <div class="alert alert-info col-sm-12"> http://git-wip-us.apache.org/repos/asf/ambari/blob/40052006/ambari-web/app/views.js ---------------------------------------------------------------------- diff --git a/ambari-web/app/views.js b/ambari-web/app/views.js index 0dac227..c8b5a72 100644 --- a/ambari-web/app/views.js +++ b/ambari-web/app/views.js @@ -62,6 +62,7 @@ require('views/common/configs/service_config_container_view'); require('views/common/configs/service_configs_by_category_view'); require('views/common/configs/service_config_view'); require('views/common/configs/service_config_tab_view'); +require('views/common/configs/config_category_container_view'); require('views/common/configs/overriddenPropertyRow_view'); require('views/common/configs/overriddenProperty_view'); require('views/common/configs/compare_property_view'); http://git-wip-us.apache.org/repos/asf/ambari/blob/40052006/ambari-web/app/views/common/configs/config_category_container_view.js ---------------------------------------------------------------------- diff --git a/ambari-web/app/views/common/configs/config_category_container_view.js b/ambari-web/app/views/common/configs/config_category_container_view.js new file mode 100644 index 0000000..08cdb2c --- /dev/null +++ b/ambari-web/app/views/common/configs/config_category_container_view.js @@ -0,0 +1,64 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +var App = require('app'); + +var lazyLoading = require('utils/lazy_loading'); + +App.ConfigCategoryContainerView = Em.ContainerView.extend({ + + lazyLoading: null, + + categories: [], + + didInsertElement: function () { + this.pushViews(); + this._super(); + }, + + willDestroyElement: function () { + if (this.get('lazyLoading')) { + lazyLoading.terminate(this.get('lazyLoading')) + } + this._super(); + }, + + pushViews: function () { + var self = this; + var categoriesViews = []; + this.get('categories').forEach(function (category) { + var viewClass = category.isCustomView ? category.customView : App.ServiceConfigsByCategoryView; + categoriesViews.push(viewClass.create({ + category: category, + canEdit: self.get("canEdit"), + service: self.get("service"), + serviceConfigs: self.get("serviceConfigs"), + supportsHostOverrides: self.get("supportsHostOverrides") + })); + }); + this.set('lazyLoading', lazyLoading.run({ + destination: self.get('childViews'), + source: categoriesViews, + initSize: 3, + chunkSize: 3, + delay: 200, + context: this + })); + } + +}); http://git-wip-us.apache.org/repos/asf/ambari/blob/40052006/ambari-web/app/views/common/configs/service_configs_by_category_view.js ---------------------------------------------------------------------- diff --git a/ambari-web/app/views/common/configs/service_configs_by_category_view.js b/ambari-web/app/views/common/configs/service_configs_by_category_view.js index c38b672..d52b3e1 100644 --- a/ambari-web/app/views/common/configs/service_configs_by_category_view.js +++ b/ambari-web/app/views/common/configs/service_configs_by_category_view.js @@ -68,24 +68,24 @@ App.ServiceConfigsByCategoryView = Em.View.extend(App.UserPref, App.ConfigOverri var self = this; // If `this.categoryConfigsAll` is a computed property then don't set it. // some extended class like `App.NotificationsConfigsView` overrides `categoryConfigsAll` as computed property - if ($.isArray(this.categoryConfigsAll)) { - this.setCategoryConfigsAll(); - } - this.setVisibleCategoryConfigs(); - var isCollapsed = this.calcIsCollapsed(); - this.set('category.isCollapsed', isCollapsed); - if (isCollapsed) { - this.$('.accordion-body').hide(); - } - else { - this.$('.accordion-body').show(); - } - $('#serviceConfig').tooltip({ - selector: '[data-toggle=tooltip]', - placement: 'top' - }); - this.filteredCategoryConfigs(); Em.run.next(function () { + if ($.isArray(self.categoryConfigsAll)) { + self.setCategoryConfigsAll(); + } + self.setVisibleCategoryConfigs(); + var isCollapsed = self.calcIsCollapsed(); + self.set('category.isCollapsed', isCollapsed); + if (isCollapsed) { + self.$('.accordion-body').hide(); + } + else { + self.$('.accordion-body').show(); + } + $('#serviceConfig').tooltip({ + selector: '[data-toggle=tooltip]', + placement: 'top' + }); + self.filteredCategoryConfigs(); self.updateReadOnlyFlags(); }); }, @@ -175,9 +175,9 @@ App.ServiceConfigsByCategoryView = Em.View.extend(App.UserPref, App.ConfigOverri var hasFilteredAdvancedConfigs = this.get('categoryConfigs').filter(function (config) { return config.get('isHiddenByFilter') === false && Em.isNone(config.get('widget')); }, this).length > 0; - return (isCustomPropertiesCategory && this.get('controller.filter') === '' && !this.get('parentView.columns').someProperty('selected')) || + return (isCustomPropertiesCategory && this.get('controller.filter') === '' && !this.get('parentView.parentView.columns').someProperty('selected')) || hasFilteredAdvancedConfigs; - }.property('category.customCanAddProperty', 'categoryConfigs.@each.isHiddenByFilter', 'categoryConfigs.@each.widget', 'controller.filter', 'parentView.columns.@each.selected'), + }.property('category.customCanAddProperty', 'categoryConfigs.@each.isHiddenByFilter', 'categoryConfigs.@each.widget', 'controller.filter', 'parentView.parentView.columns.@each.selected'), /** * Re-order the configs to list content displayType properties at last in the category @@ -320,7 +320,7 @@ App.ServiceConfigsByCategoryView = Em.View.extend(App.UserPref, App.ConfigOverri collapseCategory: function () { if (this.get('state') === 'destroyed') return; $('.popover').remove(); - var filter = this.get('parentView.filter') + var filter = this.get('parentView.parentView.filter'); filter = filter? filter.toLowerCase() : filter; // filter can be undefined in some wizard var filteredResult = this.get('categoryConfigs'); var isInitialRendering = !arguments.length || arguments[1] != 'categoryConfigs'; @@ -643,7 +643,7 @@ App.ServiceConfigsByCategoryView = Em.View.extend(App.UserPref, App.ConfigOverri var controller = (App.router.get('currentState.name') == 'configs') ? App.router.get('mainServiceInfoConfigsController') : App.router.get('wizardStep7Controller'); - this.get('parentView').onClose(); + this.get('parentView.parentView').onClose(); controller.set('filter', event.view.get('serviceConfigObj.name')); } }) http://git-wip-us.apache.org/repos/asf/ambari/blob/40052006/ambari-web/test/views/common/configs/custom_category_views/notification_configs_view_test.js ---------------------------------------------------------------------- diff --git a/ambari-web/test/views/common/configs/custom_category_views/notification_configs_view_test.js b/ambari-web/test/views/common/configs/custom_category_views/notification_configs_view_test.js index b970c89..681d346 100644 --- a/ambari-web/test/views/common/configs/custom_category_views/notification_configs_view_test.js +++ b/ambari-web/test/views/common/configs/custom_category_views/notification_configs_view_test.js @@ -32,8 +32,10 @@ function getView() { categoryConfigs: [], categoryConfigsAll: [], parentView: Em.View.create({ - filter: '', - columns: [] + parentView: Em.View.create({ + filter: '', + columns: [] + }) }) }); }