From: Dominik Csapak Date: Fri, 31 May 2019 10:15:50 +0000 (+0200) Subject: gui: add compare_ceph_versions X-Git-Url: https://git.proxmox.com/?a=commitdiff_plain;h=005e0a60917444fa629edc6570eddc8f79939a0b;hp=55b49d7ef212759b7628bad84eb51bf76d5c07db;p=pve-manager.git gui: add compare_ceph_versions 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 --- diff --git a/www/manager6/Utils.js b/www/manager6/Utils.js index b3a28400..4dc8ab6a 100644 --- a/www/manager6/Utils.js +++ b/www/manager6/Utils.js @@ -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);