]> git.proxmox.com Git - proxmox-backup.git/blob - www/Utils.js
221a2f2b65d4b05bc0a41afd322a0f3c3cd8fa1e
[proxmox-backup.git] / www / Utils.js
1 Ext.ns('PBS');
2
3 console.log("Starting Backup Server GUI");
4
5 Ext.define('PBS.Utils', {
6 singleton: true,
7
8 updateLoginData: function(data) {
9 Proxmox.Utils.setAuthData(data);
10 },
11
12 dataStorePrefix: 'DataStore-',
13
14 cryptmap: [
15 'none',
16 'mixed',
17 'sign-only',
18 'encrypt',
19 ],
20
21 cryptText: [
22 Proxmox.Utils.noText,
23 gettext('Mixed'),
24 gettext('Signed'),
25 gettext('Encrypted'),
26 ],
27
28 cryptIconCls: [
29 '',
30 '',
31 'lock faded',
32 'lock good',
33 ],
34
35 calculateCryptMode: function(data) {
36 let mixed = data.mixed;
37 let encrypted = data.encrypt;
38 let signed = data['sign-only'];
39 let files = data.count;
40 if (mixed > 0) {
41 return PBS.Utils.cryptmap.indexOf('mixed');
42 } else if (files === encrypted && encrypted > 0) {
43 return PBS.Utils.cryptmap.indexOf('encrypt');
44 } else if (files === signed && signed > 0) {
45 return PBS.Utils.cryptmap.indexOf('sign-only');
46 } else if ((signed+encrypted) === 0) {
47 return PBS.Utils.cryptmap.indexOf('none');
48 } else {
49 return PBS.Utils.cryptmap.indexOf('mixed');
50 }
51 },
52
53 getDataStoreFromPath: function(path) {
54 return path.slice(PBS.Utils.dataStorePrefix.length);
55 },
56
57 isDataStorePath: function(path) {
58 return path.indexOf(PBS.Utils.dataStorePrefix) === 0;
59 },
60
61 render_datetime_utc: function(datetime) {
62 let pad = (number) => number < 10 ? '0' + number : number;
63 return datetime.getUTCFullYear() +
64 '-' + pad(datetime.getUTCMonth() + 1) +
65 '-' + pad(datetime.getUTCDate()) +
66 'T' + pad(datetime.getUTCHours()) +
67 ':' + pad(datetime.getUTCMinutes()) +
68 ':' + pad(datetime.getUTCSeconds()) +
69 'Z';
70 },
71
72 render_datastore_worker_id: function(id, what) {
73 const res = id.match(/^(\S+?)_(\S+?)_(\S+?)(_(.+))?$/);
74 if (res) {
75 let datastore = res[1], backupGroup = `${res[2]}/${res[3]}`;
76 if (res[4] !== undefined) {
77 let datetime = Ext.Date.parse(parseInt(res[5], 16), 'U');
78 let utctime = PBS.Utils.render_datetime_utc(datetime);
79 return `Datastore ${datastore} ${what} ${backupGroup}/${utctime}`;
80 } else {
81 return `Datastore ${datastore} ${what} ${backupGroup}`;
82 }
83 }
84 return `Datastore ${what} ${id}`;
85 },
86
87 constructor: function() {
88 var me = this;
89
90 // do whatever you want here
91 Proxmox.Utils.override_task_descriptions({
92 garbage_collection: ['Datastore', gettext('Garbage collect')],
93 sync: ['Datastore', gettext('Remote Sync')],
94 verify: ['Datastore', gettext('Verification')],
95 verify_group: ['Group', gettext('Verification')],
96 verify_snapshot: ['Snapshot', gettext('Verification')],
97 syncjob: [gettext('Sync Job'), gettext('Remote Sync')],
98 verifyjob: [gettext('Verify Job'), gettext('Scheduled Verification')],
99 prune: (type, id) => PBS.Utils.render_datastore_worker_id(id, gettext('Prune')),
100 backup: (type, id) => PBS.Utils.render_datastore_worker_id(id, gettext('Backup')),
101 reader: (type, id) => PBS.Utils.render_datastore_worker_id(id, gettext('Read objects')),
102 logrotate: [gettext('Log'), gettext('Rotation')],
103 });
104 },
105 });