Repository: ambari Updated Branches: refs/heads/trunk 556f1249a -> cd171c7d5
AMBARI-8787. Hosts page: Sorting by host name does not work (onechiporenko) Project: http://git-wip-us.apache.org/repos/asf/ambari/repo Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/cd171c7d Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/cd171c7d Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/cd171c7d Branch: refs/heads/trunk Commit: cd171c7d5331460ffc8b7257206f19e4c1e58fe9 Parents: 556f124 Author: Oleg Nechiporenko <[email protected]> Authored: Thu Dec 18 14:42:33 2014 +0200 Committer: Oleg Nechiporenko <[email protected]> Committed: Thu Dec 18 14:42:33 2014 +0200 ---------------------------------------------------------------------- ambari-web/app/controllers/main/host.js | 13 ++++++--- ambari-web/app/views/common/sort_view.js | 6 ++--- ambari-web/app/views/main/host.js | 2 +- ambari-web/test/controllers/main/host_test.js | 31 ++++++++++++++++++++-- 4 files changed, 43 insertions(+), 9 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ambari/blob/cd171c7d/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 989bd05..019ef65 100644 --- a/ambari-web/app/controllers/main/host.js +++ b/ambari-web/app/controllers/main/host.js @@ -171,10 +171,16 @@ App.MainHostController = Em.ArrayController.extend(App.TableServerMixin, { return value; }, + /** + * Sort by host_name by default + * @method getSortProps + * @returns {{value: 'asc|desc', name: string, type: 'SORT'}[]} + */ getSortProps: function () { - // sort by host_name by default - if (App.db.getSortingStatuses(this.get('name')) && App.db.getSortingStatuses(this.get('name')).length === 0) { - App.db.setSortingStatuses(this.get('name'), { + var controllerName = this.get('name'), + db = App.db.getSortingStatuses(controllerName); + if (db && db.everyProperty('status', 'sorting')) { + App.db.setSortingStatuses(controllerName, { name: 'hostName', status: 'sorting_asc' }); @@ -184,6 +190,7 @@ App.MainHostController = Em.ArrayController.extend(App.TableServerMixin, { /** * get query parameters computed from filter properties, sort properties and custom properties of view + * @param {boolean} [skipNonFilterProperties] * @return {Array} * @method getQueryParameters */ http://git-wip-us.apache.org/repos/asf/ambari/blob/cd171c7d/ambari-web/app/views/common/sort_view.js ---------------------------------------------------------------------- diff --git a/ambari-web/app/views/common/sort_view.js b/ambari-web/app/views/common/sort_view.js index 3615af1..4cd8315 100644 --- a/ambari-web/app/views/common/sort_view.js +++ b/ambari-web/app/views/common/sort_view.js @@ -219,13 +219,13 @@ var serverWrapperView = Em.View.extend({ }, /** - * Initialize and save sorting statuses: publicHostName sorting_asc + * Initialize and save sorting statuses: hostName sorting_asc */ loadSortStatuses: function () { var statuses = []; var childViews = this.get('childViews'); childViews.forEach(function (childView) { - var sortStatus = (childView.get('name') == 'publicHostName' && childView.get('status') == 'sorting') ? 'sorting_asc' : childView.get('status'); + var sortStatus = (childView.get('name') == 'hostName' && childView.get('status') == 'sorting') ? 'sorting_asc' : childView.get('status'); statuses.push({ name: childView.get('name'), status: sortStatus @@ -233,7 +233,7 @@ var serverWrapperView = Em.View.extend({ childView.set('status', sortStatus); }); App.db.setSortingStatuses(this.get('controller.name'), statuses); - this.get('controller').set('sortingColumn', childViews.findProperty('name', 'publicHostName')); + this.get('controller').set('sortingColumn', childViews.findProperty('name', 'hostName')); }, /** http://git-wip-us.apache.org/repos/asf/ambari/blob/cd171c7d/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 b44619c..d85296b 100644 --- a/ambari-web/app/views/main/host.js +++ b/ambari-web/app/views/main/host.js @@ -496,7 +496,7 @@ App.MainHostView = App.TableView.extend(App.TableServerViewMixin, { sortView: sort.serverWrapperView, nameSort: sort.fieldView.extend({ column: 1, - name:'publicHostName', + name:'hostName', displayName: Em.I18n.t('common.name') }), ipSort: sort.fieldView.extend({ http://git-wip-us.apache.org/repos/asf/ambari/blob/cd171c7d/ambari-web/test/controllers/main/host_test.js ---------------------------------------------------------------------- diff --git a/ambari-web/test/controllers/main/host_test.js b/ambari-web/test/controllers/main/host_test.js index 26cbb86..cb55bb4 100644 --- a/ambari-web/test/controllers/main/host_test.js +++ b/ambari-web/test/controllers/main/host_test.js @@ -24,7 +24,7 @@ require('mappers/server_data_mapper'); describe('MainHostController', function () { - var hostController; + var hostController, db; // @todo add unit tests after bulk ops reimplementing describe('#bulkOperation', function() { @@ -213,5 +213,32 @@ describe('MainHostController', function () { expect(hostController.getQueryParameters().findProperty('key', 'Hosts/host_name').value).to.equal('.*someval.*'); }); }); - + + describe('#getSortProps', function () { + + beforeEach(function () { + db = {mainHostController: [ + {name: 'hostName', status: 'sorting'} + ]}; + hostController = App.MainHostController.create({}); + sinon.stub(App.db, 'getSortingStatuses', function (k) { + return db[k]; + }); + sinon.stub(App.db, 'setSortingStatuses', function (k, v) { + db[k] = Em.typeOf(v) === 'array' ? v : [v]; + }); + }); + + afterEach(function () { + App.db.getSortingStatuses.restore(); + App.db.setSortingStatuses.restore(); + }); + + it('should set default sorting condition', function () { + hostController.getSortProps(); + expect(db.mainHostController).to.eql([{name: 'hostName', status: 'sorting_asc'}]); + }); + + }); + });
