]> git.proxmox.com Git - pve-manager.git/commitdiff
Utils: add forEachMP
authorDominik Csapak <d.csapak@proxmox.com>
Thu, 5 Apr 2018 14:03:55 +0000 (16:03 +0200)
committerDietmar Maurer <dietmar@proxmox.com>
Fri, 6 Apr 2018 09:45:14 +0000 (11:45 +0200)
in the style of forEachBus, but for containers, so that we
only have to save the count once

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

index 6da4c178be7416b5ad08e102d7f0eb14eda9b182..af03958c58aa6bad26fda30f8b6f5e221edff021 100644 (file)
@@ -963,6 +963,29 @@ Ext.define('PVE.Utils', { utilities: {
                }
            }
        }
+    },
+
+    mp_counts: { mps: 10, unused: 10 },
+
+    forEachMP: function(func, includeUnused) {
+       var i, cont;
+       for (i = 0; i < PVE.Utils.mp_counts.mps; i++) {
+           cont = func('mp', i);
+           if (!cont && cont !== undefined) {
+               return;
+           }
+       }
+
+       if (!includeUnused) {
+           return;
+       }
+
+       for (i = 0; i < PVE.Utils.mp_counts.unused; i++) {
+           cont = func('unused', i);
+           if (!cont && cont !== undefined) {
+               return;
+           }
+       }
     }
 },
 
index d2835a27ed00d9ba48f9b39b773052b1320f89b2..c4ae2db8fa6ccce57926b0320b13a0b0accb0039 100644 (file)
@@ -90,25 +90,21 @@ Ext.define('PVE.lxc.RessourceView', {
            }
        };
 
-       for (i = 0; i < 10; i++) {
-           confid = "mp" + i;
-           rows[confid] = {
-               group: 1,
-               tdCls: 'pve-itype-icon-storage',
-               editor: mpeditor,
-               header: gettext('Mount Point') + ' (' + confid + ')'
-           };
-       }
-
-       for (i = 0; i < 8; i++) {
-           confid = "unused" + i;
+       PVE.Utils.forEachMP(function(bus, i) {
+           confid = bus + i;
+           var  header;
+           if (bus === 'mp') {
+               header = gettext('Mount Point') + ' (' + confid + ')';
+           } else {
+               header = gettext('Unused Disk') + ' ' + i;
+           }
            rows[confid] = {
                group: 1,
                tdCls: 'pve-itype-icon-storage',
                editor: mpeditor,
-               header: gettext('Unused Disk') + ' ' + i
+               header: header
            };
-       }
+       }, true);
 
        var baseurl = 'nodes/' + nodename + '/lxc/' + vmid + '/config';