]> git.proxmox.com Git - pve-manager.git/blobdiff - www/manager6/Utils.js
website: update external links to www.proxmox.com
[pve-manager.git] / www / manager6 / Utils.js
index 2ff0fbd81b8c3fc733f05c992bf5c4fe7e209e55..6d4842df2578cfe466d38f93a0c53458ede1c8cc 100644 (file)
@@ -34,12 +34,20 @@ Ext.define('PVE.Utils', {
     },
 
     noSubKeyHtml: 'You do not have a valid subscription for this server. Please visit '
-      +'<a target="_blank" href="https://www.proxmox.com/products/proxmox-ve/subscription-service-plans">'
+      +'<a target="_blank" href="https://www.proxmox.com/en/proxmox-virtual-environment/pricing">'
       +'www.proxmox.com</a> to get a list of available options.',
 
+    getClusterSubscriptionLevel: async function() {
+       let { result } = await Proxmox.Async.api2({ url: '/cluster/status' });
+       let levelMap = Object.fromEntries(
+         result.data.filter(v => v.type === 'node').map(v => [v.name, v.level]),
+       );
+       return levelMap;
+    },
+
     kvm_ostypes: {
        'Linux': [
-           { desc: '5.x - 2.6 Kernel', val: 'l26' },
+           { desc: '6.x - 2.6 Kernel', val: 'l26' },
            { desc: '2.4 Kernel', val: 'l24' },
        ],
        'Microsoft Windows': [
@@ -393,6 +401,8 @@ Ext.define('PVE.Utils', {
        'efidisk but no OMVF BIOS': gettext('EFI Disk without OMVF BIOS'),
     },
 
+    renderNotFound: what => Ext.String.format(gettext("No {0} found"), what),
+
     get_kvm_osinfo: function(value) {
        var info = { base: 'Other' }; // default
        if (value) {
@@ -473,6 +483,8 @@ Ext.define('PVE.Utils', {
                    virtio: "VirtIO",
                };
                displayText = map[value] || Proxmox.Utils.unknownText;
+           } else if (key === 'freeze-fs-on-backup' && PVE.Parser.parseBoolean(value)) {
+               continue;
            } else if (PVE.Parser.parseBoolean(value)) {
                displayText = Proxmox.Utils.enabledText;
            }
@@ -991,15 +1003,18 @@ Ext.define('PVE.Utils', {
     },
 
     render_storage_content: function(value, metaData, record) {
-       var data = record.data;
+       let data = record.data;
+       let result;
        if (Ext.isNumber(data.channel) &&
            Ext.isNumber(data.id) &&
            Ext.isNumber(data.lun)) {
-           return "CH " +
+           result = "CH " +
                Ext.String.leftPad(data.channel, 2, '0') +
                " ID " + data.id + " LUN " + data.lun;
+       } else {
+           result = data.volid.replace(/^.*?:(.*?\/)?/, '');
        }
-       return data.volid.replace(/^.*?:(.*?\/)?/, '');
+       return Ext.String.htmlEncode(result);
     },
 
     render_serverity: function(value) {
@@ -1278,6 +1293,21 @@ Ext.define('PVE.Utils', {
        return Ext.htmlEncode(first + " " + last);
     },
 
+    // expecting the following format:
+    // [v2:10.10.10.1:6802/2008,v1:10.10.10.1:6803/2008]
+    render_ceph_osd_addr: function(value) {
+       value = value.trim();
+       if (value.startsWith('[') && value.endsWith(']')) {
+           value = value.slice(1, -1); // remove []
+       }
+       value = value.replaceAll(',', '\n'); // split IPs in lines
+       let retVal = '';
+       for (const i of value.matchAll(/^(v[0-9]):(.*):([0-9]*)\/([0-9]*)$/gm)) {
+           retVal += `${i[1]}: ${i[2]}:${i[3]}<br>`;
+       }
+       return retVal.length < 1 ? value : retVal;
+    },
+
     windowHostname: function() {
        return window.location.hostname.replace(Proxmox.Utils.IP6_bracket_match,
             function(m, addr, offset, original) { return addr; });
@@ -1332,7 +1362,7 @@ Ext.define('PVE.Utils', {
            allowSpice = consoles.spice;
            allowXtermjs = !!consoles.xtermjs;
        }
-       let dv = PVE.UIOptions.console || (type === 'kvm' ? 'vv' : 'xtermjs');
+       let dv = PVE.UIOptions.options.console || (type === 'kvm' ? 'vv' : 'xtermjs');
        if (dv === 'vv' && !allowSpice) {
            dv = allowXtermjs ? 'xtermjs' : 'html5';
        } else if (dv === 'xtermjs' && !allowXtermjs) {
@@ -1683,6 +1713,9 @@ Ext.define('PVE.Utils', {
                    });
                    win.getViewModel().set('isInstalled', isInstalled);
                    container.add(win);
+                   win.on('close', () => {
+                       container.el.unmask();
+                   });
                    win.show();
                    callback(win);
                }
@@ -1702,7 +1735,7 @@ Ext.define('PVE.Utils', {
            rstore,
            /not (installed|initialized)/i,
            (_, error) => {
-               nodename = nodename || 'localhost';
+               nodename = nodename || Proxmox.NodeName;
                let maskTarget = maskOwnerCt ? view.ownerCt : view;
                rstore.stopUpdate();
                PVE.Utils.showCephInstallOrMask(maskTarget, error.statusText, nodename, win => {
@@ -1855,74 +1888,33 @@ Ext.define('PVE.Utils', {
 
     notesTemplateVars: ['cluster', 'guestname', 'node', 'vmid'],
 
-    updateUIOptions: function() {
-       Proxmox.Utils.API2Request({
-           url: '/cluster/options',
-           method: 'GET',
-           success: function(response) {
-               PVE.UIOptions = {
-                   'allowed-tags': [],
-               };
-               for (const option of ['allowed-tags', 'console', 'tag-style']) {
-                   PVE.UIOptions[option] = response?.result?.data?.[option];
-               }
-
-               PVE.Utils.updateTagList(PVE.UIOptions['allowed-tags']);
-               PVE.Utils.updateTagSettings(PVE.UIOptions?.['tag-style']);
-           },
-       });
-    },
-
-    tagList: [],
-
-    updateTagList: function(tags) {
-       PVE.Utils.tagList = [...new Set([...tags])].sort();
-    },
-
-    parseTagOverrides: function(overrides) {
-       let colors = {};
-       (overrides || "").split(';').forEach(color => {
-           if (!color) {
-               return;
-           }
-           let [tag, color_hex, font_hex] = color.split(':');
-           let r = parseInt(color_hex.slice(0, 2), 16);
-           let g = parseInt(color_hex.slice(2, 4), 16);
-           let b = parseInt(color_hex.slice(4, 6), 16);
-           colors[tag] = [r, g, b];
-           if (font_hex) {
-               colors[tag].push(parseInt(font_hex.slice(0, 2), 16));
-               colors[tag].push(parseInt(font_hex.slice(2, 4), 16));
-               colors[tag].push(parseInt(font_hex.slice(4, 6), 16));
+    renderTags: function(tagstext, overrides) {
+       let text = '';
+       if (tagstext) {
+           let tags = (tagstext.split(/[,; ]/) || []).filter(t => !!t);
+           if (PVE.UIOptions.shouldSortTags()) {
+               tags = tags.sort((a, b) => {
+                   let alc = a.toLowerCase();
+                   let blc = b.toLowerCase();
+                   return alc < blc ? -1 : blc < alc ? 1 : a.localeCompare(b);
+               });
            }
-       });
-       return colors;
-    },
-
-    tagOverrides: {},
-
-    updateTagOverrides: function(colors) {
-       let sp = Ext.state.Manager.getProvider();
-       let color_state = sp.get('colors', '');
-       let browser_colors = PVE.Utils.parseTagOverrides(color_state);
-       PVE.Utils.tagOverrides = Ext.apply({}, browser_colors, colors);
+           text += ' ';
+           tags.forEach((tag) => {
+               text += Proxmox.Utils.getTagElement(tag, overrides);
+           });
+       }
+       return text;
     },
 
-    updateTagSettings: function(style) {
-       let overrides = style?.['color-map'];
-       PVE.Utils.updateTagOverrides(PVE.Utils.parseTagOverrides(overrides ?? ""));
-
-       let shape = style?.shape ?? 'circle';
-       if (shape === '__default__') {
-           style = 'circle';
-       }
+    tagCharRegex: /^[a-z0-9+_.-]+$/i,
 
-       Ext.ComponentQuery.query('pveResourceTree')[0].setUserCls(`proxmox-tags-${shape}`);
-       PVE.data.ResourceStore.fireEvent('load');
-       Ext.GlobalEvents.fireEvent('loadedUiOptions');
+    verificationStateOrder: {
+       'failed': 0,
+       'none': 1,
+       'ok': 2,
+       '__default__': 3,
     },
-
-    tagCharRegex: /^[a-z0-9+_.-]$/i,
 },
 
     singleton: true,
@@ -1993,6 +1985,7 @@ Ext.define('PVE.Utils', {
            qmstop: ['VM', gettext('Stop')],
            qmsuspend: ['VM', gettext('Hibernate')],
            qmtemplate: ['VM', gettext('Convert to template')],
+           resize: ['VM/CT', gettext('Resize')],
            spiceproxy: ['VM/CT', gettext('Console') + ' (Spice)'],
            spiceshell: ['', gettext('Shell') + ' (Spice)'],
            startall: ['', gettext('Start all VMs and Containers')],