You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by at...@apache.org on 2017/08/21 13:09:57 UTC
ambari git commit: AMBARI-21762 Sometimes alerts order is not
correctly arranged if ordering by Status. (atkach)
Repository: ambari
Updated Branches:
refs/heads/trunk 13589bbdf -> f901e15ba
AMBARI-21762 Sometimes alerts order is not correctly arranged if ordering by Status. (atkach)
Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/f901e15b
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/f901e15b
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/f901e15b
Branch: refs/heads/trunk
Commit: f901e15bac6728215ab5adea54775565bb8bdd46
Parents: 13589bb
Author: Andrii Tkach <at...@apache.org>
Authored: Mon Aug 21 15:17:50 2017 +0300
Committer: Andrii Tkach <at...@apache.org>
Committed: Mon Aug 21 15:17:50 2017 +0300
----------------------------------------------------------------------
ambari-web/app/views/common/sort_view.js | 26 ++++++++++-
.../app/views/main/alert_definitions_view.js | 7 ++-
ambari-web/test/views/common/sort_view_test.js | 49 +++++++++++++++++++-
.../views/main/alert_definitions_view_test.js | 2 +-
4 files changed, 78 insertions(+), 6 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ambari/blob/f901e15b/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 0fc1db7..290a12f 100644
--- a/ambari-web/app/views/common/sort_view.js
+++ b/ambari-web/app/views/common/sort_view.js
@@ -30,6 +30,8 @@ var App = require('app');
var wrapperView = Em.View.extend({
tagName: 'tr',
+ name: 'SortWrapperView',
+
classNames: ['sort-wrapper'],
willInsertElement: function () {
@@ -87,9 +89,10 @@ var wrapperView = Em.View.extend({
* @param property {object}
* @param order {Boolean} true - DESC, false - ASC
* @param returnSorted {Boolean}
+ * @param content {Array}
*/
- sort: function (property, order, returnSorted) {
- var content = this.get('content').toArray();
+ sort: function (property, order, returnSorted, content) {
+ content = content || this.get('content').toArray();
var sortFunc = this.getSortFunc(property, order);
var status = order ? 'sorting_desc' : 'sorting_asc';
@@ -122,6 +125,25 @@ var wrapperView = Em.View.extend({
}.observes('controller.contentUpdater'),
/**
+ *
+ * @param {Em.Object[]} content
+ * @returns {Em.Object[]}
+ */
+ getSortedContent: function(content) {
+ if (!this.get('isSorting') && content.get('length')) {
+ var activeSortViews = this.get('childViews').rejectProperty('status', 'sorting');
+ if (activeSortViews[0]) {
+ var status = activeSortViews[0].get('status');
+ this.set('isSorting', true);
+ content = this.sort(activeSortViews[0], status === 'sorting_desc', true, content);
+ this.set('isSorting', false);
+ activeSortViews[0].set('status', status);
+ }
+ }
+ return content;
+ },
+
+ /**
* reset all sorts fields
*/
resetSort: function () {
http://git-wip-us.apache.org/repos/asf/ambari/blob/f901e15b/ambari-web/app/views/main/alert_definitions_view.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/views/main/alert_definitions_view.js b/ambari-web/app/views/main/alert_definitions_view.js
index 530bca7..f7515bc 100644
--- a/ambari-web/app/views/main/alert_definitions_view.js
+++ b/ambari-web/app/views/main/alert_definitions_view.js
@@ -32,7 +32,10 @@ App.MainAlertDefinitionsView = App.TableView.extend({
contentObsOnce: function() {
var content = this.get('controller.content') && App.get('router.clusterController.isAlertsLoaded') ?
- this.get('controller.content').toArray().sort(App.AlertDefinition.getSortDefinitionsByStatus(true)) : [];
+ this.get('controller.content').toArray() : [];
+ if (this.get('childViews').someProperty('name', 'SortWrapperView')) {
+ content = this.get('childViews').findProperty('name', 'SortWrapperView').getSortedContent(content);
+ }
this.set('content', content);
},
@@ -46,7 +49,7 @@ App.MainAlertDefinitionsView = App.TableView.extend({
if (savedSortConditions.everyProperty('status', 'sorting')) {
savedSortConditions.push({
name: "summary",
- status: "sorting_asc"
+ status: "sorting_desc"
});
App.db.setSortingStatuses(controllerName, savedSortConditions);
}
http://git-wip-us.apache.org/repos/asf/ambari/blob/f901e15b/ambari-web/test/views/common/sort_view_test.js
----------------------------------------------------------------------
diff --git a/ambari-web/test/views/common/sort_view_test.js b/ambari-web/test/views/common/sort_view_test.js
index a21a352..9d095ec 100644
--- a/ambari-web/test/views/common/sort_view_test.js
+++ b/ambari-web/test/views/common/sort_view_test.js
@@ -182,6 +182,53 @@ describe('#wrapperView', function () {
});
})
- })
+ });
+
+ describe('#getSortedContent', function() {
+ var wrapperView;
+ var content = [
+ Em.Object.create({
+ id: 1
+ }),
+ Em.Object.create({
+ id: 2
+ })
+ ];
+
+ beforeEach(function() {
+ wrapperView = sort.wrapperView.create({
+ childViews: [],
+ isSorting: false
+ });
+ sinon.stub(wrapperView, 'sort', function(arg1, arg2, arg3, arg4) {
+ return arg4.reverse();
+ });
+ });
+ afterEach(function() {
+ wrapperView.sort.restore();
+ });
+
+ it('should return content without sorting', function() {
+ expect(wrapperView.getSortedContent(content)).to.be.eql(content);
+ expect(wrapperView.sort.called).to.be.false;
+ });
+
+ it('should return content with sorting', function() {
+ wrapperView.set('childViews', [
+ Em.Object.create({
+ status: 'sorting_desc'
+ })
+ ]);
+ expect(wrapperView.getSortedContent(content)).to.be.eql(content.reverse());
+ expect(wrapperView.sort.calledWith(
+ Em.Object.create({
+ status: 'sorting_desc'
+ }),
+ true,
+ true,
+ content
+ )).to.be.true;
+ });
+ });
});
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ambari/blob/f901e15b/ambari-web/test/views/main/alert_definitions_view_test.js
----------------------------------------------------------------------
diff --git a/ambari-web/test/views/main/alert_definitions_view_test.js b/ambari-web/test/views/main/alert_definitions_view_test.js
index edba415..93d1f65 100644
--- a/ambari-web/test/views/main/alert_definitions_view_test.js
+++ b/ambari-web/test/views/main/alert_definitions_view_test.js
@@ -100,7 +100,7 @@ describe('App.MainAlertDefinitionsView', function () {
},
{
name: "summary",
- status: "sorting_asc"
+ status: "sorting_desc"
}
])).to.be.true;
});