Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 5D789200B27 for ; Wed, 22 Jun 2016 11:06:25 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id 5C096160A35; Wed, 22 Jun 2016 09:06:25 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id A39BE160A2E for ; Wed, 22 Jun 2016 11:06:24 +0200 (CEST) Received: (qmail 36898 invoked by uid 500); 22 Jun 2016 09:06:23 -0000 Mailing-List: contact commits-help@ambari.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: ambari-dev@ambari.apache.org Delivered-To: mailing list commits@ambari.apache.org Received: (qmail 36889 invoked by uid 99); 22 Jun 2016 09:06:23 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 22 Jun 2016 09:06:23 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 87997DFEDA; Wed, 22 Jun 2016 09:06:23 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: ababiichuk@apache.org To: commits@ambari.apache.org Message-Id: <1924f22530f242d9921efb52b7fbeccf@git.apache.org> X-Mailer: ASF-Git Admin Mailer 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:06:23 +0000 (UTC) archived-at: Wed, 22 Jun 2016 09:06:25 -0000 Repository: ambari Updated Branches: refs/heads/branch-2.4 e9d9cbaeb -> bdf3fb219 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/bdf3fb21 Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/bdf3fb21 Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/bdf3fb21 Branch: refs/heads/branch-2.4 Commit: bdf3fb21999aaa05e487d9c90fa3163cf3dc5af4 Parents: e9d9cba Author: ababiichuk Authored: Tue Jun 21 19:51:37 2016 +0300 Committer: ababiichuk Committed: Wed Jun 22 11:59:21 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/bdf3fb21/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; } };