]> git.proxmox.com Git - pve-manager.git/commitdiff
gui: add compare_ceph_versions
authorDominik Csapak <d.csapak@proxmox.com>
Fri, 31 May 2019 10:15:50 +0000 (12:15 +0200)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Fri, 31 May 2019 13:28:14 +0000 (15:28 +0200)
this correctly compares ceph versions by its numeric parts
the way it is written, it can be used as a function for 'sort'

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
www/manager6/Utils.js

index b3a2840062ba76f82409854a300c7c19d71a06ff..4dc8ab6a0c071035f744fcdb5d8772d7a666dba9 100644 (file)
@@ -117,6 +117,38 @@ Ext.define('PVE.Utils', { utilities: {
        return undefined;
     },
 
+    compare_ceph_versions: function(a, b) {
+       if (a === b) {
+           return 0;
+       }
+
+       var match_a = a.toString().match(/^(\d+)\.(\d+).(\d+)$/);
+       var match_b = b.toString().match(/^(\d+)\.(\d+).(\d+)$/);
+
+       if (!match_a && !match_b) {
+           // both versions invalid/undefined
+           return 0;
+       } else if(!match_a) {
+           // a is undefined/invalid but b not
+           return -1;
+       } else if(!match_b) {
+           // b is undefined/invalid but a not
+           return 1;
+       }
+
+       var i;
+       for (i = 1; i <= 3; i++) {
+           var ver_a = parseInt(match_a[i], 10);
+           var ver_b = parseInt(match_b[i], 10);
+           if (ver_a !== ver_b) {
+               return ver_a - ver_b;
+           }
+       }
+
+       // all parts were the same
+       return 0;
+    },
+
     get_ceph_icon_html: function(health, fw) {
        var state = PVE.Utils.map_ceph_health[health];
        var cls = PVE.Utils.get_health_icon(state);