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/7f9a5123 Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/7f9a5123 Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/7f9a5123 Branch: refs/heads/branch-dev-logsearch Commit: 7f9a5123eedb9043ce7102df9ae3cb3f2ebc8f76 Parents: 1b8b91d Author: Andrii Tkach <[email protected]> Authored: Mon Mar 6 21:10:03 2017 +0200 Committer: Andrii Tkach <[email protected]> Committed: Mon Mar 6 22:26:11 2017 +0200 ---------------------------------------------------------------------- .../app/controllers/global/update_controller.js | 3 +- ambari-web/app/controllers/main/host.js | 25 ++++++------ .../app/mixins/common/table_server_mixin.js | 2 +- .../mixins/common/table_server_view_mixin.js | 4 +- ambari-web/app/views/common/table_view.js | 8 ++++ ambari-web/app/views/main/host.js | 8 +++- .../common/table_server_view_mixin_test.js | 41 ++++++++------------ ambari-web/test/views/common/table_view_test.js | 26 ++++++++++++- ambari-web/test/views/main/host_test.js | 6 +++ 9 files changed, 81 insertions(+), 42 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ambari/blob/7f9a5123/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 7b8a80e..e53f79d 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/7f9a5123/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/7f9a5123/ambari-web/app/mixins/common/table_server_mixin.js ---------------------------------------------------------------------- diff --git a/ambari-web/app/mixins/common/table_server_mixin.js b/ambari-web/app/mixins/common/table_server_mixin.js index 5162a02..c9f0bba 100644 --- a/ambari-web/app/mixins/common/table_server_mixin.js +++ b/ambari-web/app/mixins/common/table_server_mixin.js @@ -69,7 +69,7 @@ App.TableServerMixin = Em.Mixin.create({ startIndex = (startIndex > 0) ? startIndex - 1 : startIndex; this.get('paginationProps').findProperty('name', 'startIndex').value = startIndex; } - return this.get('paginationProps'); + return this.get('paginationProps').slice(0); }, /** http://git-wip-us.apache.org/repos/asf/ambari/blob/7f9a5123/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..d44a09e 100644 --- a/ambari-web/app/mixins/common/table_server_view_mixin.js +++ b/ambari-web/app/mixins/common/table_server_view_mixin.js @@ -140,11 +140,9 @@ App.TableServerViewMixin = Em.Mixin.create({ updatePagination: function (key) { if (!Em.isNone(this.get('displayLength'))) { App.db.setDisplayLength(this.get('controller.name'), this.get('displayLength')); - this.get('controller.paginationProps').findProperty('name', 'displayLength').value = this.get('displayLength'); } if (!Em.isNone(this.get('startIndex'))) { App.db.setStartIndex(this.get('controller.name'), this.get('startIndex')); - this.get('controller.paginationProps').findProperty('name', 'startIndex').value = this.get('startIndex'); } if (key !== 'SKIP_REFRESH') { @@ -157,6 +155,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/7f9a5123/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 b8d4380..4cc266d 100644 --- a/ambari-web/app/views/common/table_view.js +++ b/ambari-web/app/views/common/table_view.js @@ -414,6 +414,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/7f9a5123/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 a7cdb29..52692cc 100644 --- a/ambari-web/app/views/main/host.js +++ b/ambari-web/app/views/main/host.js @@ -170,8 +170,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')); @@ -194,6 +196,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/7f9a5123/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..ae750de 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: [ @@ -99,12 +100,6 @@ describe('App.MainConfigHistoryView', function() { it('setDisplayLength is called with correct arguments', function () { expect(App.db.setDisplayLength.calledWith('mainConfigHistoryController', '50')).to.be.true; }); - it('paginationProps.startIndex = 0', function () { - expect(view.get('controller.paginationProps').findProperty('name', 'startIndex').value).to.equal(0); - }); - it('paginationProps.displayLength = 50', function () { - expect(view.get('controller.paginationProps').findProperty('name', 'displayLength').value).to.equal('50'); - }); }); describe('startIndex is correct', function() { @@ -123,12 +118,6 @@ describe('App.MainConfigHistoryView', function() { it('setDisplayLength is not called', function () { expect(App.db.setDisplayLength.called).to.be.false; }); - it('paginationProps.startIndex = 10', function () { - expect(view.get('controller.paginationProps').findProperty('name', 'startIndex').value).to.equal(10); - }); - it('paginationProps.displayLength = 50', function () { - expect(view.get('controller.paginationProps').findProperty('name', 'displayLength').value).to.equal('50'); - }); }); describe('displayLength and startIndex are correct', function() { @@ -147,12 +136,6 @@ describe('App.MainConfigHistoryView', function() { it('setDisplayLength is called with valid arguments', function () { expect(App.db.setDisplayLength.calledWith('mainConfigHistoryController', '100')).to.be.true; }); - it('paginationProps.startIndex = 20', function () { - expect(view.get('controller.paginationProps').findProperty('name', 'startIndex').value).to.equal(20); - }); - it('paginationProps.displayLength = 100', function () { - expect(view.get('controller.paginationProps').findProperty('name', 'displayLength').value).to.equal('100'); - }); }); describe('displayLength and startIndex are null', function() { @@ -170,12 +153,6 @@ describe('App.MainConfigHistoryView', function() { it('setDisplayLength is not called', function () { expect(App.db.setDisplayLength.called).to.be.false; }); - it('paginationProps.startIndex = 20', function () { - expect(view.get('controller.paginationProps').findProperty('name', 'startIndex').value).to.equal(20); - }); - it('paginationProps.displayLength = 100', function () { - expect(view.get('controller.paginationProps').findProperty('name', 'displayLength').value).to.equal('100'); - }); }); }); @@ -183,12 +160,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 +210,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 +231,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 +240,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 +249,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/7f9a5123/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/7f9a5123/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 6bb3462..7978fea 100644 --- a/ambari-web/test/views/main/host_test.js +++ b/ambari-web/test/views/main/host_test.js @@ -66,12 +66,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) { @@ -82,6 +84,10 @@ describe('App.MainHostView', function () { }); }); + it('overlayObserver should be called', function () { + view.didInsertElement(); + expect(view.overlayObserver.calledOnce).to.be.true; + }); }); describe('#HostView', function () {
