]> git.proxmox.com Git - proxmox-backup.git/blob - www/Utils.js
87e2dc63b13f364ba44289a3e253c73866a7c646
[proxmox-backup.git] / www / Utils.js
1 /*global Proxmox */
2 Ext.ns('PBS');
3
4 console.log("Starting Backup Server GUI");
5
6 Ext.define('PBS.Utils', {
7 singleton: true,
8
9 updateLoginData: function(data) {
10 Proxmox.CSRFPreventionToken = data.CSRFPreventionToken;
11 Proxmox.UserName = data.username;
12 //console.log(data.ticket);
13 // fixme: use secure flag once we have TLS
14 //Ext.util.Cookies.set('PBSAuthCookie', data.ticket, null, '/', null, true );
15 Ext.util.Cookies.set('PBSAuthCookie', data.ticket, null, '/', null, false);
16 },
17
18 dataStorePrefix: 'DataStore-',
19
20 getDataStoreFromPath: function(path) {
21 return path.slice(PBS.Utils.dataStorePrefix.length);
22 },
23
24 isDataStorePath: function(path) {
25 return path.indexOf(PBS.Utils.dataStorePrefix) === 0;
26 },
27
28 render_datetime_utc: function(datetime) {
29 let pad = (number) => number < 10 ? '0' + number : number;
30 return datetime.getUTCFullYear() +
31 '-' + pad(datetime.getUTCMonth() + 1) +
32 '-' + pad(datetime.getUTCDate()) +
33 'T' + pad(datetime.getUTCHours()) +
34 ':' + pad(datetime.getUTCMinutes()) +
35 ':' + pad(datetime.getUTCSeconds()) +
36 'Z';
37 },
38
39 render_datastore_worker_id: function(id, what) {
40 const result = id.match(/^(\S+)_([^_\s]+)_([^_\s]+)$/);
41 if (result) {
42 let datastore = result[1], type = result[2], id = result[3];
43 return `Datastore ${datastore} - ${what} ${type}/${id}`;
44 }
45 return what;
46 },
47 render_datastore_time_worker_id: function(id, what) {
48 const res = id.match(/^(\S+)_([^_\s]+)_([^_\s]+)_([^_\s]+)$/);
49 if (res) {
50 let datastore = res[1], type = res[2], id = res[3];
51 let datetime = Ext.Date.parse(parseInt(res[4], 16), 'U');
52 let utctime = PBS.Utils.render_datetime_utc(datetime);
53 return `Datastore ${datastore} - ${what} ${type}/${id}/${utctime}`;
54 }
55 return what;
56 },
57
58 constructor: function() {
59 var me = this;
60
61 // do whatever you want here
62 Proxmox.Utils.override_task_descriptions({
63 garbage_collection: ['Datastore', gettext('Garbage collect') ],
64 prune: (type, id) => {
65 return PBS.Utils.render_datastore_worker_id(id, gettext('Prune'));
66 },
67 backup: (type, id) => {
68 return PBS.Utils.render_datastore_worker_id(id, gettext('Backup'));
69 },
70 reader: (type, id) => {
71 return PBS.Utils.render_datastore_time_worker_id(id, gettext('Read objects'));
72 },
73 });
74 }
75 });