You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by ja...@apache.org on 2017/10/09 18:34:41 UTC
[27/50] [abbrv] ambari git commit: AMBARI-21762 Sometimes alerts
order is not correctly arranged if ordering by Status. (atkach)
AMBARI-21762 Sometimes alerts order is not correctly arranged if ordering by Status. (atkach)
(cherry picked from commit ba1fa0bfbcfccc1d182ce9f5d5928757c0fc2ea5)
Change-Id: I0f9a220fde73b5e466366d45fe7b9ccaa4e30502
Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/f146158e
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/f146158e
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/f146158e
Branch: refs/heads/2.5-maint
Commit: f146158e85cc817edd5b1beb1a7a3561e72f98d2
Parents: 5a80b52
Author: Andrii Tkach <at...@apache.org>
Authored: Mon Aug 21 16:11:44 2017 +0300
Committer: atkach@apache.org <je...@hortonworks.com>
Committed: Mon Aug 21 13:21:18 2017 +0000
----------------------------------------------------------------------
ambari-web/app/views/common/sort_view.js | 26 ++++++++++-
.../app/views/main/alert_definitions_view.js | 9 ++--
ambari-web/test/views/common/sort_view_test.js | 49 +++++++++++++++++++-
3 files changed, 78 insertions(+), 6 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ambari/blob/f146158e/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/f146158e/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 9fb517f..ec52075 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);
}
http://git-wip-us.apache.org/repos/asf/ambari/blob/f146158e/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