ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From onechipore...@apache.org
Subject ambari git commit: AMBARI-8506. Alerts UI: Alerts table sorting not working properly (onechiporenko)
Date Tue, 02 Dec 2014 12:31:14 GMT
Repository: ambari
Updated Branches:
  refs/heads/trunk 6967f5b02 -> b7ddffc76


AMBARI-8506. Alerts UI: Alerts table sorting not working properly (onechiporenko)


Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/b7ddffc7
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/b7ddffc7
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/b7ddffc7

Branch: refs/heads/trunk
Commit: b7ddffc76a628899687274e2b92b50b1650dbc8d
Parents: 6967f5b
Author: Oleg Nechiporenko <onechiporenko@apache.org>
Authored: Tue Dec 2 14:22:51 2014 +0200
Committer: Oleg Nechiporenko <onechiporenko@apache.org>
Committed: Tue Dec 2 14:22:51 2014 +0200

----------------------------------------------------------------------
 .../assets/data/alerts/alertDefinitions.json    | 20 +++++
 ambari-web/app/views/common/sort_view.js        | 28 +++----
 ambari-web/test/views/common/sort_view_test.js  | 84 +++++++++++++++++++-
 3 files changed, 114 insertions(+), 18 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/b7ddffc7/ambari-web/app/assets/data/alerts/alertDefinitions.json
----------------------------------------------------------------------
diff --git a/ambari-web/app/assets/data/alerts/alertDefinitions.json b/ambari-web/app/assets/data/alerts/alertDefinitions.json
index 8557980..c16b536 100644
--- a/ambari-web/app/assets/data/alerts/alertDefinitions.json
+++ b/ambari-web/app/assets/data/alerts/alertDefinitions.json
@@ -1218,6 +1218,26 @@
           "type" : "AGGREGATE"
         }
       }
+    },
+    {
+      "href" : "http://host:8080/api/v1/clusters/c1/alert_definitions/37",
+      "AlertDefinition" : {
+        "cluster_name" : "c1",
+        "component_name" : "AMBARI_AGENT",
+        "description" : null,
+        "enabled" : true,
+        "id" : 37,
+        "ignore_host" : false,
+        "interval" : 1,
+        "label" : "Ambari Agent Disk Usage",
+        "name" : "ambari_agent_disk_usage",
+        "scope" : "HOST",
+        "service_name" : "AMBARI",
+        "source" : {
+          "path" : "alert_disk_space.py",
+          "type" : "SCRIPT"
+        }
+      }
     }
   ]
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ambari/blob/b7ddffc7/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 4f28b74..880d74e 100644
--- a/ambari-web/app/views/common/sort_view.js
+++ b/ambari-web/app/views/common/sort_view.js
@@ -149,12 +149,14 @@ var wrapperView = Em.View.extend({
         break;
       case 'number':
         func = function (a, b) {
-          var a = parseFloat(a.get(property.get('name')));
-          var b = parseFloat(b.get(property.get('name')));
+          var a_p = a.get(property.get('name'));
+          var b_p = b.get(property.get('name'));
+          a_p = Em.isNone(a_p) ? -Infinity : parseFloat(a_p);
+          b_p = Em.isNone(b_p) ? -Infinity : parseFloat(b_p);
           if (order) {
-            return b - a;
+            return b_p - a_p;
           } else {
-            return a - b;
+            return a_p - b_p;
           }
         };
         break;
@@ -192,19 +194,11 @@ var wrapperView = Em.View.extend({
         break;
       default:
         func = function (a, b) {
-          if (order) {
-            if (a.get(property.get('name')) > b.get(property.get('name')))
-              return -1;
-            if (a.get(property.get('name')) < b.get(property.get('name')))
-              return 1;
-            return 0;
-          } else {
-            if (a.get(property.get('name')) < b.get(property.get('name')))
-              return -1;
-            if (a.get(property.get('name')) > b.get(property.get('name')))
-              return 1;
-            return 0;
-          }
+          var a_p = a.get(property.get('name'));
+          var b_p = b.get(property.get('name'));
+          a_p = Em.isNone(a_p) ? '' : a_p;
+          b_p = Em.isNone(b_p) ? '' : b_p;
+          return order ? a_p.localeCompare(b_p) : b_p.localeCompare(a_p)
         };
     }
     return func;

http://git-wip-us.apache.org/repos/asf/ambari/blob/b7ddffc7/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 f7d5f27..ef61551 100644
--- a/ambari-web/test/views/common/sort_view_test.js
+++ b/ambari-web/test/views/common/sort_view_test.js
@@ -63,6 +63,88 @@ describe('#wrapperView', function () {
 
     });
 
+    describe('number', function () {
+
+      var property = Em.Object.create({type: 'number', name: 'lastTriggered'});
+
+      Em.A([
+          {
+            a: Em.Object.create({lastTriggered: 1}),
+            b: Em.Object.create({lastTriggered: 0}),
+            order: true,
+            e: -1
+          },
+          {
+            a: Em.Object.create({lastTriggered: 1}),
+            b: Em.Object.create({lastTriggered: 0}),
+            order: false,
+            e: 1
+          },
+          {
+            a: Em.Object.create({lastTriggered: null}),
+            b: Em.Object.create({lastTriggered: 1}),
+            order: true,
+            e: Infinity
+          },
+          {
+            a: Em.Object.create({lastTriggered: null}),
+            b: Em.Object.create({lastTriggered: 1}),
+            order: false,
+            e: -Infinity
+          }
+        ]).forEach(function (test, i) {
+          it('test #' + (i + 1), function () {
+            var func = sort.wrapperView.create().getSortFunc(property, test.order);
+            expect(func(test.a, test.b)).to.equal(test.e);
+          });
+      });
+
+    });
+
+    describe('default', function () {
+
+      var property = Em.Object.create({type: 'string', name: 'serviceName'});
+
+      Em.A([
+          {
+            a: Em.Object.create({serviceName: 's1'}),
+            b: Em.Object.create({serviceName: 's2'}),
+            order: true,
+            e: -1
+          },
+          {
+            a: Em.Object.create({serviceName: 's1'}),
+            b: Em.Object.create({serviceName: 's2'}),
+            order: false,
+            e: 1
+          },
+          {
+            a: Em.Object.create({serviceName: 's1'}),
+            b: Em.Object.create({serviceName: 's1'}),
+            order: true,
+            e: 0
+          },
+          {
+            a: Em.Object.create({serviceName: null}),
+            b: Em.Object.create({serviceName: 's2'}),
+            order: true,
+            e: -1
+          },
+          {
+            a: Em.Object.create({serviceName: null}),
+            b: Em.Object.create({serviceName: 's2'}),
+            order: false,
+            e: 1
+          }
+        ]).forEach(function (test, i) {
+          it('test #' + (i + 1), function () {
+            var func = sort.wrapperView.create().getSortFunc(property, test.order);
+            expect(func(test.a, test.b)).to.equal(test.e);
+          });
+      });
+
+    });
+
   });
 
-});
+});
\ No newline at end of file


Mime
View raw message