]> git.proxmox.com Git - proxmox-widget-toolkit.git/blobdiff - src/Utils.js
utils: updateColumnWidth: allow overriding tresholdWidth and make that more general
[proxmox-widget-toolkit.git] / src / Utils.js
index 6526ec21fadf581b6f2e7890e5d23adde3321d9c..546cd64339e77da34b035963fe7b63bcaf243368 100644 (file)
@@ -253,12 +253,12 @@ utilities: {
     },
 
     render_username: function(userid) {
-       let username = PVE.Utils.parse_userid(userid)[0] || "";
+       let username = Proxmox.Utils.parse_userid(userid)[0] || "";
        return Ext.htmlEncode(username);
     },
 
     render_realm: function(userid) {
-       let username = PVE.Utils.parse_userid(userid)[1] || "";
+       let username = Proxmox.Utils.parse_userid(userid)[1] || "";
        return Ext.htmlEncode(username);
     },
 
@@ -544,7 +544,7 @@ utilities: {
        });
     },
 
-    updateColumnWidth: function(container) {
+    updateColumnWidth: function(container, tresholdWidth) {
        let mode = Ext.state.Manager.get('summarycolumns') || 'auto';
        let factor;
        if (mode !== 'auto') {
@@ -553,7 +553,8 @@ utilities: {
                factor = 1;
            }
        } else {
-           factor = container.getSize().width < 1600 ? 1 : 2;
+           tresholdWidth = (tresholdWidth || 1400) + 1;
+           factor = Math.ceil(container.getSize().width / tresholdWidth);
        }
 
        if (container.oldFactor === factor) {
@@ -574,6 +575,9 @@ utilities: {
        container.updateLayout();
     },
 
+    // NOTE: depreacated, use updateColumnWidth
+    updateColumns: container => Proxmox.Utils.updateColumnWidth(container),
+
     dialog_title: function(subject, create, isAdd) {
        if (create) {
            if (isAdd) {
@@ -1111,34 +1115,40 @@ utilities: {
        return acme;
     },
 
-    updateColumns: function(container) {
-       let mode = Ext.state.Manager.get('summarycolumns') || 'auto';
-       let factor;
-       if (mode !== 'auto') {
-           factor = parseInt(mode, 10);
-           if (Number.isNaN(factor)) {
-               factor = 1;
-           }
-       } else {
-           factor = container.getSize().width < 1400 ? 1 : 2;
+    get_health_icon: function(state, circle) {
+       if (circle === undefined) {
+           circle = false;
        }
 
-       if (container.oldFactor === factor) {
-           return;
+       if (state === undefined) {
+           state = 'uknown';
        }
 
-       let items = container.query('>'); // direct childs
-       factor = Math.min(factor, items.length);
-       container.oldFactor = factor;
+       var icon = 'faded fa-question';
+       switch (state) {
+           case 'good':
+               icon = 'good fa-check';
+               break;
+           case 'upgrade':
+               icon = 'warning fa-upload';
+               break;
+           case 'old':
+               icon = 'warning fa-refresh';
+               break;
+           case 'warning':
+               icon = 'warning fa-exclamation';
+               break;
+           case 'critical':
+               icon = 'critical fa-times';
+               break;
+           default: break;
+       }
 
-       items.forEach((item) => {
-           item.columnWidth = 1 / factor;
-       });
+       if (circle) {
+           icon += '-circle';
+       }
 
-       // we have to update the layout twice, since the first layout change
-       // can trigger the scrollbar which reduces the amount of space left
-       container.updateLayout();
-       container.updateLayout();
+       return icon;
     },
 },