]> git.proxmox.com Git - pve-manager.git/blobdiff - www/manager6/Utils.js
ui: factor out backup verification renderer
[pve-manager.git] / www / manager6 / Utils.js
index 56a0407d3f74c989cb63ae630302ddf369d8731b..6d2f7a04c8aa92c8130fc15ac06230a53848c675 100644 (file)
@@ -219,6 +219,138 @@ Ext.define('PVE.Utils', { utilities: {
 
     },
 
+    render_pbs_fingerprint: fp => fp.substring(0, 23),
+
+    render_backup_encryption: function(v, meta, record) {
+       if (!v) {
+           return gettext('No');
+       }
+
+       let tip = '';
+       if (v.match(/^[a-fA-F0-9]{2}:/)) { // fingerprint
+           tip = `Key fingerprint ${PVE.Utils.render_pbs_fingerprint(v)}`;
+       }
+       let icon = `<i class="fa fa-fw fa-lock good"></i>`;
+       return `<span data-qtip="${tip}">${icon} ${gettext('Encrypted')}</span>`;
+    },
+
+    render_backup_verification: function(v, meta, record) {
+       let i = (cls, txt) => `<i class="fa fa-fw fa-${cls}"></i> ${txt}`;
+       if (v === undefined || v === null) {
+           return i('question-circle-o warning', gettext('None'));
+       }
+       let tip = ""
+       let txt = gettext('Failed');
+       let iconCls = 'times critical';
+       if (v.state === 'ok') {
+           txt = gettext('OK');
+           iconCls = 'check good';
+           let now = Date.now() / 1000;
+           let task = Proxmox.Utils.parse_task_upid(v.upid);
+           let verify_time = Proxmox.Utils.render_timestamp(task.starttime);
+           tip = `Last verify task started on ${verify_time}`;
+           if (now - v.starttime > 30 * 24 * 60 * 60) {
+               tip = `Last verify task over 30 days ago: ${verify_time}`;
+               iconCls = 'check warning';
+           }
+       }
+       return `<span data-qtip="${tip}"> ${i(iconCls, txt)} </span>`;
+    },
+
+    render_backup_status: function(value, meta, record) {
+       if (typeof value == 'undefined') {
+           return "";
+       }
+
+       let iconCls = 'check-circle good';
+       let text = gettext('Yes');
+
+       if (!PVE.Parser.parseBoolean(value.toString())) {
+           iconCls = 'times-circle critical';
+
+           text = gettext('No');
+
+           let reason = record.get('reason');
+           if (typeof reason !== 'undefined') {
+               if (reason in PVE.Utils.backup_reasons_table) {
+                   reason = PVE.Utils.backup_reasons_table[record.get('reason')];
+               }
+               text = `${text} - ${reason}`;
+           }
+       }
+
+       return `<i class="fa fa-${iconCls}"></i> ${text}`;
+    },
+
+    render_backup_days_of_week: function(val) {
+       var dows = ['sun', 'mon', 'tue', 'wed', 'thu', 'fri', 'sat'];
+       var selected = [];
+       var cur = -1;
+       val.split(',').forEach(function(day){
+           cur++;
+           var dow = (dows.indexOf(day)+6)%7;
+           if (cur === dow) {
+               if (selected.length === 0 || selected[selected.length-1] === 0) {
+                   selected.push(1);
+               } else {
+                   selected[selected.length-1]++;
+               }
+           } else {
+               while (cur < dow) {
+                   cur++;
+                   selected.push(0);
+               }
+               selected.push(1);
+           }
+       });
+
+       cur = -1;
+       var days = [];
+       selected.forEach(function(item) {
+           cur++;
+           if (item > 2) {
+               days.push(Ext.Date.dayNames[(cur+1)] + '-' + Ext.Date.dayNames[(cur+item)%7]);
+               cur += item-1;
+           } else if (item == 2) {
+               days.push(Ext.Date.dayNames[cur+1]);
+               days.push(Ext.Date.dayNames[(cur+2)%7]);
+               cur++;
+           } else if (item == 1) {
+               days.push(Ext.Date.dayNames[(cur+1)%7]);
+           }
+       });
+       return days.join(', ');
+    },
+
+    render_backup_selection: function(value, metaData, record) {
+       let allExceptText = gettext('All except {0}');
+       let allText = '-- ' + gettext('All') + ' --';
+       if (record.data.all) {
+           if (record.data.exclude) {
+               return Ext.String.format(allExceptText, record.data.exclude);
+           }
+           return allText;
+       }
+       if (record.data.vmid) {
+           return record.data.vmid;
+       }
+
+       if (record.data.pool) {
+           return "Pool '"+ record.data.pool + "'";
+       }
+
+       return "-";
+    },
+
+    backup_reasons_table: {
+       'backup=yes': gettext('Enabled'),
+       'backup=no': gettext('Disabled'),
+       'enabled': gettext('Enabled'),
+       'disabled': gettext('Disabled'),
+       'not a volume': gettext('Not a volume'),
+       'efidisk but no OMVF BIOS': gettext('EFI Disk without OMVF BIOS'),
+    },
+
     get_kvm_osinfo: function(value) {
        var info = { base: 'Other' }; // default
        if (value) {
@@ -647,9 +779,8 @@ Ext.define('PVE.Utils', { utilities: {
        },
        pbs: {
            name: 'Proxmox Backup Server',
-           //ipanel: '', // TODO
-           hideAdd: true,
-           faIcon: 'database',
+           ipanel: 'PBSInputPanel',
+           faIcon: 'floppy-o',
        },
        drbd: {
            name: 'DRBD',
@@ -669,6 +800,11 @@ Ext.define('PVE.Utils', { utilities: {
             name: 'zone',
             hideAdd: true
        },
+       simple: {
+           name: 'Simple',
+           ipanel: 'SimpleInputPanel',
+           faIcon: 'th'
+       },
        vlan: {
            name: 'VLAN',
            ipanel: 'VlanInputPanel',
@@ -1253,6 +1389,20 @@ Ext.define('PVE.Utils', { utilities: {
        reader.readAsText(file);
     },
 
+    loadTextFromFile: function(file, callback, maxBytes) {
+       let maxSize = maxBytes || 8192;
+       if (file.size > maxSize) {
+           Ext.Msg.alert(gettext('Error'), gettext("Invalid file size: ") + file.size);
+           return;
+       }
+       /*global
+         FileReader
+       */
+       let reader = new FileReader();
+       reader.onload = evt => callback(evt.target.result);
+       reader.readAsText(file);
+    },
+
     diskControllerMaxIDs: {
        ide: 4,
        sata: 6,
@@ -1468,6 +1618,91 @@ Ext.define('PVE.Utils', { utilities: {
     constructor: function() {
        var me = this;
        Ext.apply(me, me.utilities);
+
+       Proxmox.Utils.override_task_descriptions({
+           acmedeactivate: ['ACME Account', gettext('Deactivate')],
+           acmenewcert: ['SRV', gettext('Order Certificate')],
+           acmerefresh: ['ACME Account', gettext('Refresh')],
+           acmeregister: ['ACME Account', gettext('Register')],
+           acmerenew: ['SRV', gettext('Renew Certificate')],
+           acmerevoke: ['SRV', gettext('Revoke Certificate')],
+           acmeupdate: ['ACME Account', gettext('Update')],
+           'auth-realm-sync': [gettext('Realm'), gettext('Sync')],
+           'auth-realm-sync-test': [gettext('Realm'), gettext('Sync Preview')],
+           cephcreatemds: ['Ceph Metadata Server', gettext('Create')],
+           cephcreatemgr: ['Ceph Manager', gettext('Create')],
+           cephcreatemon: ['Ceph Monitor', gettext('Create')],
+           cephcreateosd: ['Ceph OSD', gettext('Create')],
+           cephcreatepool: ['Ceph Pool', gettext('Create')],
+           cephdestroymds: ['Ceph Metadata Server', gettext('Destroy')],
+           cephdestroymgr: ['Ceph Manager', gettext('Destroy')],
+           cephdestroymon: ['Ceph Monitor', gettext('Destroy')],
+           cephdestroyosd: ['Ceph OSD', gettext('Destroy')],
+           cephdestroypool: ['Ceph Pool', gettext('Destroy')],
+           cephfscreate: ['CephFS', gettext('Create')],
+           clustercreate: ['', gettext('Create Cluster')],
+           clusterjoin: ['', gettext('Join Cluster')],
+           dircreate: [gettext('Directory Storage'), gettext('Create')],
+           dirremove: [gettext('Directory'), gettext('Remove')],
+           download: ['', gettext('Download')],
+           hamigrate: ['HA', gettext('Migrate')],
+           hashutdown: ['HA', gettext('Shutdown')],
+           hastart: ['HA', gettext('Start')],
+           hastop: ['HA', gettext('Stop')],
+           imgcopy: ['', gettext('Copy data')],
+           imgdel: ['', gettext('Erase data')],
+           lvmcreate: [gettext('LVM Storage'), gettext('Create')],
+           lvmthincreate: [gettext('LVM-Thin Storage'), gettext('Create')],
+           migrateall: ['', gettext('Migrate all VMs and Containers')],
+           'move_volume': ['CT', gettext('Move Volume')],
+           pull_file: ['CT', gettext('Pull file')],
+           push_file: ['CT', gettext('Push file')],
+           qmclone: ['VM', gettext('Clone')],
+           qmconfig: ['VM', gettext('Configure')],
+           qmcreate: ['VM', gettext('Create')],
+           qmdelsnapshot: ['VM', gettext('Delete Snapshot')],
+           qmdestroy: ['VM', gettext('Destroy')],
+           qmigrate: ['VM', gettext('Migrate')],
+           qmmove: ['VM', gettext('Move disk')],
+           qmpause: ['VM', gettext('Pause')],
+           qmreboot: ['VM', gettext('Reboot')],
+           qmreset: ['VM', gettext('Reset')],
+           qmrestore: ['VM', gettext('Restore')],
+           qmresume: ['VM', gettext('Resume')],
+           qmrollback: ['VM', gettext('Rollback')],
+           qmshutdown: ['VM', gettext('Shutdown')],
+           qmsnapshot: ['VM', gettext('Snapshot')],
+           qmstart: ['VM', gettext('Start')],
+           qmstop: ['VM', gettext('Stop')],
+           qmsuspend: ['VM', gettext('Hibernate')],
+           qmtemplate: ['VM', gettext('Convert to template')],
+           spiceproxy: ['VM/CT', gettext('Console') + ' (Spice)'],
+           spiceshell: ['', gettext('Shell') + ' (Spice)'],
+           startall: ['', gettext('Start all VMs and Containers')],
+           stopall: ['', gettext('Stop all VMs and Containers')],
+           unknownimgdel: ['', gettext('Destroy image from unknown guest')],
+           vncproxy: ['VM/CT', gettext('Console')],
+           vncshell: ['', gettext('Shell')],
+           vzclone: ['CT', gettext('Clone')],
+           vzcreate: ['CT', gettext('Create')],
+           vzdelsnapshot: ['CT', gettext('Delete Snapshot')],
+           vzdestroy: ['CT', gettext('Destroy')],
+           vzdump: (type, id) => id ? `VM/CT ${id} - ${gettext('Backup')}` : gettext('Backup Job'),
+           vzmigrate: ['CT', gettext('Migrate')],
+           vzmount: ['CT', gettext('Mount')],
+           vzreboot: ['CT', gettext('Reboot')],
+           vzrestore: ['CT', gettext('Restore')],
+           vzresume: ['CT', gettext('Resume')],
+           vzrollback: ['CT', gettext('Rollback')],
+           vzshutdown: ['CT', gettext('Shutdown')],
+           vzsnapshot: ['CT', gettext('Snapshot')],
+           vzstart: ['CT', gettext('Start')],
+           vzstop: ['CT', gettext('Stop')],
+           vzsuspend: ['CT', gettext('Suspend')],
+           vztemplate: ['CT', gettext('Convert to template')],
+           vzumount: ['CT', gettext('Unmount')],
+           zfscreate: [gettext('ZFS Storage'), gettext('Create')],
+       });
     }
 
 });