]> git.proxmox.com Git - proxmox-widget-toolkit.git/commitdiff
Utils: refactor updateColumns from pve-manager
authorDominik Csapak <d.csapak@proxmox.com>
Mon, 19 Apr 2021 11:00:43 +0000 (13:00 +0200)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Thu, 22 Apr 2021 11:25:22 +0000 (13:25 +0200)
we want to reuse this in pbs

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

index 9d785a858ab917d9a0b5ebc991ef35cb1f7186a8..adff5f4886fe03f9a5510eac18319b91ed021946 100644 (file)
@@ -1060,6 +1060,36 @@ 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;
+       }
+
+       if (container.oldFactor === factor) {
+           return;
+       }
+
+       let items = container.query('>'); // direct childs
+       factor = Math.min(factor, items.length);
+       container.oldFactor = factor;
+
+       items.forEach((item) => {
+           item.columnWidth = 1 / factor;
+       });
+
+       // 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();
+    },
 },
 
     singleton: true,