summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrii Tkach <atkach@apache.org>2017-08-21 16:11:44 +0300
committerAndrii Tkach <atkach@apache.org>2017-08-21 16:11:44 +0300
commitba1fa0bfbcfccc1d182ce9f5d5928757c0fc2ea5 (patch)
tree5b693a8523a95d6d4279d1ba84231d3a4207d45c
parent2b50a560c34a278b67352b699e698a1cfd050406 (diff)
AMBARI-21762 Sometimes alerts order is not correctly arranged if ordering by Status. (atkach)
-rw-r--r--ambari-web/app/views/common/sort_view.js26
-rw-r--r--ambari-web/app/views/main/alert_definitions_view.js9
-rw-r--r--ambari-web/test/views/common/sort_view_test.js49
3 files changed, 78 insertions, 6 deletions
diff --git a/ambari-web/app/views/common/sort_view.js b/ambari-web/app/views/common/sort_view.js
index 0fc1db717b..290a12fa6e 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 () {
diff --git a/ambari-web/app/views/main/alert_definitions_view.js b/ambari-web/app/views/main/alert_definitions_view.js
index 9fb517f6ff..ec5207596c 100644
--- a/ambari-web/app/views/main/alert_definitions_view.js
+++ b/ambari-web/app/views/main/alert_definitions_view.js
@@ -28,11 +28,14 @@ App.MainAlertDefinitionsView = App.TableView.extend({
contentObs: function () {
Em.run.once(this, this.contentObsOnce);
- }.observes('controller.content.[]', 'App.router.clusterController.isAlertsLoaded'),
+ }.observes('controller.content.@each.summary', 'App.router.clusterController.isAlertsLoaded'),
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);
}
diff --git a/ambari-web/test/views/common/sort_view_test.js b/ambari-web/test/views/common/sort_view_test.js
index a21a352dc6..9d095ecf11 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