Repository: ambari Updated Branches: refs/heads/trunk 760be48e9 -> 630ecd582
AMBARI-20255 Sometimes the Hosts page shows a different page for page 1. (atkach) Project: http://git-wip-us.apache.org/repos/asf/ambari/repo Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/630ecd58 Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/630ecd58 Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/630ecd58 Branch: refs/heads/trunk Commit: 630ecd58219136a220aeca7901c047fcbd236d04 Parents: 760be48 Author: Andrii Tkach <[email protected]> Authored: Wed Mar 1 16:23:59 2017 +0200 Committer: Andrii Tkach <[email protected]> Committed: Wed Mar 1 18:00:02 2017 +0200 ---------------------------------------------------------------------- .../app/controllers/global/update_controller.js | 3 ++- ambari-web/app/controllers/main/host.js | 25 ++++++++++--------- .../mixins/common/table_server_view_mixin.js | 2 ++ ambari-web/app/views/common/table_view.js | 8 ++++++ ambari-web/app/views/main/host.js | 8 ++++-- .../common/table_server_view_mixin_test.js | 17 +++++++++++++ ambari-web/test/views/common/table_view_test.js | 26 +++++++++++++++++++- ambari-web/test/views/main/host_test.js | 7 ++++++ 8 files changed, 81 insertions(+), 15 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ambari/blob/630ecd58/ambari-web/app/controllers/global/update_controller.js ---------------------------------------------------------------------- diff --git a/ambari-web/app/controllers/global/update_controller.js b/ambari-web/app/controllers/global/update_controller.js index 75b4a00..59eaf3e 100644 --- a/ambari-web/app/controllers/global/update_controller.js +++ b/ambari-web/app/controllers/global/update_controller.js @@ -244,7 +244,8 @@ App.UpdateController = Em.Controller.extend({ { key: 'Hosts/host_name', value: [hostDetailsFilter], - type: 'MULTIPLE' + type: 'MULTIPLE', + isHostDetails: true } ]); } http://git-wip-us.apache.org/repos/asf/ambari/blob/630ecd58/ambari-web/app/controllers/main/host.js ---------------------------------------------------------------------- diff --git a/ambari-web/app/controllers/main/host.js b/ambari-web/app/controllers/main/host.js index 336bd25..05551af 100644 --- a/ambari-web/app/controllers/main/host.js +++ b/ambari-web/app/controllers/main/host.js @@ -312,17 +312,20 @@ App.MainHostController = Em.ArrayController.extend(App.TableServerMixin, { } }, this); - if (queryParams.filterProperty('isFilter').length !== oldProperties.filterProperty('isFilter').length) { - queryParams.findProperty('key', 'from').value = 0; - this.set('resetStartIndex', true); - } else { - queryParams.filterProperty('isFilter').forEach(function (queryParam) { - var oldProperty = oldProperties.filterProperty('isFilter').findProperty('key', queryParam.key); - if (!oldProperty || JSON.stringify(oldProperty.value) !== JSON.stringify(queryParam.value)) { - queryParams.findProperty('key', 'from').value = 0; - this.set('resetStartIndex', true); - } - }, this); + if (!oldProperties.findProperty('isHostDetails')) { + // shouldn't reset start index after coming back from Host Details page + if (queryParams.filterProperty('isFilter').length !== oldProperties.filterProperty('isFilter').length) { + queryParams.findProperty('key', 'from').value = 0; + this.set('resetStartIndex', true); + } else { + queryParams.filterProperty('isFilter').forEach(function (queryParam) { + var oldProperty = oldProperties.filterProperty('isFilter').findProperty('key', queryParam.key); + if (!oldProperty || JSON.stringify(oldProperty.value) !== JSON.stringify(queryParam.value)) { + queryParams.findProperty('key', 'from').value = 0; + this.set('resetStartIndex', true); + } + }, this); + } } if (!skipNonFilterProperties) { http://git-wip-us.apache.org/repos/asf/ambari/blob/630ecd58/ambari-web/app/mixins/common/table_server_view_mixin.js ---------------------------------------------------------------------- diff --git a/ambari-web/app/mixins/common/table_server_view_mixin.js b/ambari-web/app/mixins/common/table_server_view_mixin.js index 4e982d7..ae949d0 100644 --- a/ambari-web/app/mixins/common/table_server_view_mixin.js +++ b/ambari-web/app/mixins/common/table_server_view_mixin.js @@ -157,6 +157,8 @@ App.TableServerViewMixin = Em.Mixin.create({ resetStartIndex: function () { if (this.get('controller.resetStartIndex') && this.get('filteredCount') > 0) { this.set('startIndex', 1); + this.saveStartIndex(); + this.updatePagination('SKIP_REFRESH'); } }.observes('controller.resetStartIndex') }); http://git-wip-us.apache.org/repos/asf/ambari/blob/630ecd58/ambari-web/app/views/common/table_view.js ---------------------------------------------------------------------- diff --git a/ambari-web/app/views/common/table_view.js b/ambari-web/app/views/common/table_view.js index 9fcefc7..c394d47 100644 --- a/ambari-web/app/views/common/table_view.js +++ b/ambari-web/app/views/common/table_view.js @@ -341,6 +341,14 @@ App.TableView = Em.View.extend(App.UserPref, { return result; }, + clearStartIndex: function() { + if (this.get('controller.startIndex') !== 1) { + this.set('controller.resetStartIndex', true); + return true; + } + return false; + }, + /** * Contain filter conditions for each column * @type {Array} http://git-wip-us.apache.org/repos/asf/ambari/blob/630ecd58/ambari-web/app/views/main/host.js ---------------------------------------------------------------------- diff --git a/ambari-web/app/views/main/host.js b/ambari-web/app/views/main/host.js index 8959dde..f74e1b1 100644 --- a/ambari-web/app/views/main/host.js +++ b/ambari-web/app/views/main/host.js @@ -169,8 +169,10 @@ App.MainHostView = App.TableView.extend(App.TableServerViewMixin, { */ willInsertElement: function () { if (!this.get('controller.showFilterConditionsFirstLoad')) { - var didClearedSomething = this.clearFilterConditionsFromLocalStorage(); - this.set('controller.filterChangeHappened', didClearedSomething); + // filters and start index should be cleared when we enter Hosts page + var didClearedFilters = this.clearFilterConditionsFromLocalStorage(); + var didClearStartIndex = this.clearStartIndex(); + this.set('controller.filterChangeHappened', didClearedFilters || didClearStartIndex); } this._super(); this.set('startIndex', this.get('controller.startIndex')); @@ -193,6 +195,8 @@ App.MainHostView = App.TableView.extend(App.TableServerViewMixin, { this.addObserver('startIndex', this, 'updatePagination'); this.addObserver('displayLength', this, 'updatePagination'); this.addObserver('filteredCount', this, this.updatePaging); + // should show overlay even when filtering has begun before observer was added + this.overlayObserver(); }, willDestroyElement: function () { http://git-wip-us.apache.org/repos/asf/ambari/blob/630ecd58/ambari-web/test/mixins/common/table_server_view_mixin_test.js ---------------------------------------------------------------------- diff --git a/ambari-web/test/mixins/common/table_server_view_mixin_test.js b/ambari-web/test/mixins/common/table_server_view_mixin_test.js index 2a9c409..e5b6f08 100644 --- a/ambari-web/test/mixins/common/table_server_view_mixin_test.js +++ b/ambari-web/test/mixins/common/table_server_view_mixin_test.js @@ -28,6 +28,7 @@ describe('App.MainConfigHistoryView', function() { filteredContent: [], refresh: Em.K, saveFilterConditions: Em.K, + saveStartIndex: sinon.spy(), controller: Em.Object.create({ name: 'mainConfigHistoryController', paginationProps: [ @@ -183,12 +184,14 @@ describe('App.MainConfigHistoryView', function() { beforeEach(function () { sinon.stub(view, 'saveFilterConditions', Em.K); sinon.stub(view, 'refresh', Em.K); + sinon.stub(view, 'resetStartIndex'); sinon.spy(view, 'updateFilter'); this.clock = sinon.useFakeTimers(); }); afterEach(function () { view.saveFilterConditions.restore(); view.updateFilter.restore(); + view.resetStartIndex.restore(); view.refresh.restore(); this.clock.restore(); }); @@ -231,12 +234,20 @@ describe('App.MainConfigHistoryView', function() { }); describe('#resetStartIndex()', function() { + beforeEach(function () { + sinon.stub(view, 'updatePagination'); + }); + afterEach(function () { + view.updatePagination.restore(); + }); it('resetStartIndex is false and filteredCount is 0', function() { view.set('filteredCount', 0); view.set('controller.resetStartIndex', false); view.set('startIndex', 0); view.resetStartIndex(); expect(view.get('startIndex')).to.equal(0); + expect(view.saveStartIndex.called).to.be.false; + expect(view.updatePagination.called).to.be.false; }); it('resetStartIndex is true and filteredCount is 0', function() { view.set('filteredCount', 0); @@ -244,6 +255,8 @@ describe('App.MainConfigHistoryView', function() { view.set('startIndex', 0); view.resetStartIndex(); expect(view.get('startIndex')).to.equal(0); + expect(view.saveStartIndex.called).to.be.false; + expect(view.updatePagination.called).to.be.false; }); it('resetStartIndex is false and filteredCount is 5', function() { view.set('filteredCount', 5); @@ -251,6 +264,8 @@ describe('App.MainConfigHistoryView', function() { view.set('startIndex', 0); view.resetStartIndex(); expect(view.get('startIndex')).to.equal(0); + expect(view.saveStartIndex.called).to.be.false; + expect(view.updatePagination.called).to.be.false; }); it('resetStartIndex is true and filteredCount is 5', function() { view.set('controller.resetStartIndex', true); @@ -258,6 +273,8 @@ describe('App.MainConfigHistoryView', function() { view.set('startIndex', 0); view.resetStartIndex(); expect(view.get('startIndex')).to.equal(1); + expect(view.saveStartIndex.called).to.be.true; + expect(view.updatePagination.called).to.be.true; }); }); http://git-wip-us.apache.org/repos/asf/ambari/blob/630ecd58/ambari-web/test/views/common/table_view_test.js ---------------------------------------------------------------------- diff --git a/ambari-web/test/views/common/table_view_test.js b/ambari-web/test/views/common/table_view_test.js index 37dd911..dd289b0 100644 --- a/ambari-web/test/views/common/table_view_test.js +++ b/ambari-web/test/views/common/table_view_test.js @@ -25,7 +25,9 @@ require('mixins/common/userPref'); require('views/common/table_view'); function getView() { - return App.TableView.create(); + return App.TableView.create({ + controller: Em.Object.create() + }); } describe('App.TableView', function () { @@ -393,4 +395,26 @@ describe('App.TableView', function () { }); + describe('#clearStartIndex', function() { + var view; + + beforeEach(function() { + view = getView(); + }); + + it('should reset start index', function() { + view.set('controller.resetStartIndex', false); + view.set('controller.startIndex', 11); + expect(view.clearStartIndex()).to.be.true; + expect(view.get('controller.resetStartIndex')).to.be.true; + }); + + it('should not reset start index', function() { + view.set('controller.resetStartIndex', false); + view.set('controller.startIndex', 1); + expect(view.clearStartIndex()).to.be.false; + expect(view.get('controller.resetStartIndex')).to.be.false; + }); + }); + }); http://git-wip-us.apache.org/repos/asf/ambari/blob/630ecd58/ambari-web/test/views/main/host_test.js ---------------------------------------------------------------------- diff --git a/ambari-web/test/views/main/host_test.js b/ambari-web/test/views/main/host_test.js index a5fce45..8d66b05 100644 --- a/ambari-web/test/views/main/host_test.js +++ b/ambari-web/test/views/main/host_test.js @@ -81,12 +81,14 @@ describe('App.MainHostView', function () { cases.forEach(function (item) { sinon.stub(view, item.methodName, Em.K); }); + sinon.stub(view, 'overlayObserver'); }); afterEach(function () { cases.forEach(function (item) { view[item.methodName].restore(); }); + view.overlayObserver.restore(); }); cases.forEach(function (item) { @@ -96,6 +98,11 @@ describe('App.MainHostView', function () { expect(view[item.methodName].callCount).to.equal(item.callCount); }); }); + + it('overlayObserver should be called', function () { + view.didInsertElement(); + expect(view.overlayObserver.calledOnce).to.be.true; + }); }); describe("#onRequestErrorHandler()", function () {
