ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ababiic...@apache.org
Subject ambari git commit: AMBARI-17347 Different order HDP versions in admin_view stackVersionsi and admin/stack/versions. (ababiichuk)
Date Wed, 22 Jun 2016 09:07:36 GMT
Repository: ambari
Updated Branches:
  refs/heads/trunk 67395fad5 -> a6b2c8f2b


AMBARI-17347 Different order HDP versions in admin_view stackVersionsi and admin/stack/versions.
(ababiichuk)


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

Branch: refs/heads/trunk
Commit: a6b2c8f2b6ce67dd4f88a99b7a868c5bfa2f4ad5
Parents: 67395fa
Author: ababiichuk <ababiichuk@hortonworks.com>
Authored: Tue Jun 21 19:51:37 2016 +0300
Committer: ababiichuk <ababiichuk@hortonworks.com>
Committed: Wed Jun 22 12:07:17 2016 +0300

----------------------------------------------------------------------
 .../ui/admin-web/app/scripts/services/Stack.js  | 36 +++++++++++++++++++-
 1 file changed, 35 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/a6b2c8f2/ambari-admin/src/main/resources/ui/admin-web/app/scripts/services/Stack.js
----------------------------------------------------------------------
diff --git a/ambari-admin/src/main/resources/ui/admin-web/app/scripts/services/Stack.js b/ambari-admin/src/main/resources/ui/admin-web/app/scripts/services/Stack.js
index 9b8fdfa..1131041 100644
--- a/ambari-admin/src/main/resources/ui/admin-web/app/scripts/services/Stack.js
+++ b/ambari-admin/src/main/resources/ui/admin-web/app/scripts/services/Stack.js
@@ -50,10 +50,16 @@ angular.module('ambariAdminConsole')
     return data;
   }
 
+
+  function  _parseId(id) {
+    return id.replace(/[^\d|\.]/g, '').split('.').map(function (i) {return parseInt(i, 10);});
+  }
+
   return {
     allStackVersions: function () {
       var url = Settings.baseUrl + '/stacks?fields=versions/*';
       var deferred = $q.defer();
+      var sortFunction = this.sortByIdAsVersion;
       $http.get(url, {mock: 'stack/allStackVersions.json'})
       .success(function (data) {
         var allStackVersions = [];
@@ -64,6 +70,7 @@ angular.module('ambariAdminConsole')
             var upgrade_packs = version.Versions.upgrade_packs;
             var active = version.Versions.active;
             allStackVersions.push({
+              id: stack_name + '-' + stack_version,
               stack_name: stack_name,
               stack_version: stack_version,
               displayName: stack_name + '-' + stack_version,
@@ -72,7 +79,7 @@ angular.module('ambariAdminConsole')
             });
           });
         });
-        deferred.resolve(allStackVersions)
+        deferred.resolve(allStackVersions.sort(sortFunction));
       })
       .error(function (data) {
         deferred.reject(data);
@@ -368,6 +375,33 @@ angular.module('ambariAdminConsole')
       invalidrepos.forEach(function(repo) {
         repo.hasError = true;
       });
+    },
+
+    /**
+     * Callback for sorting models with `id`-property equal to something like version number:
'HDP-1.2.3', '4.2.52' etc
+     *
+     * @param {{id: string}} obj1
+     * @param {{id: string}} obj2
+     * @returns {number}
+     */
+    sortByIdAsVersion: function (obj1, obj2) {
+      var id1 = _parseId(obj1.id);
+      var id2 = _parseId(obj2.id);
+      var lId1 = id1.length;
+      var lId2 = id2.length;
+      var limit = lId1 > lId2 ? lId2 : lId1;
+      for (var i = 0; i < limit; i++) {
+        if (id1[i] > id2[i]) {
+          return 1;
+        }
+        if (id1[i] < id2[i]) {
+          return -1;
+        }
+      }
+      if (lId1 === lId2) {
+        return 0
+      }
+      return lId1 > lId2 ? 1 : -1;
     }
 
   };


Mime
View raw message