[pve-devel] [PATCH manager v2 1/4] gui: add compare_ceph_versions
Dominik Csapak
d.csapak at proxmox.com
Fri May 31 12:15:50 CEST 2019
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 at proxmox.com>
---
new in v2
www/manager6/Utils.js | 32 ++++++++++++++++++++++++++++++++
1 file changed, 32 insertions(+)
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);
--
2.11.0
More information about the pve-devel
mailing list