},
render_language: function(value) {
- if (!value) {
+ if (!value || value === '__default__') {
return Proxmox.Utils.defaultText + ' (English)';
}
let text = Proxmox.Utils.language_map[value];
// somewhat like a human would tell durations, omit zero values and do not
// give seconds precision if we talk days already
format_duration_human: function(ut) {
- let seconds = 0, minutes = 0, hours = 0, days = 0;
+ let seconds = 0, minutes = 0, hours = 0, days = 0, years = 0;
if (ut <= 0.1) {
return '<0.1s';
hours = remaining % 24;
remaining = Math.trunc(remaining / 24);
if (remaining > 0) {
- days = remaining;
+ days = remaining % 365;
+ remaining = Math.trunc(remaining / 365); // yea, just lets ignore leap years...
+ if (remaining > 0) {
+ years = remaining;
+ }
}
}
}
return t > 0;
};
+ let addMinutes = !add(years, 'y');
let addSeconds = !add(days, 'd');
add(hours, 'h');
- add(minutes, 'm');
- if (addSeconds) {
- add(seconds, 's');
+ if (addMinutes) {
+ add(minutes, 'm');
+ if (addSeconds) {
+ add(seconds, 's');
+ }
}
return res.join(' ');
},
if (Proxmox.LoggedOut) {
return;
}
- Ext.util.Cookies.clear(Proxmox.Setup.auth_cookie_name);
+ Ext.util.Cookies.set(Proxmox.Setup.auth_cookie_name, "", new Date(0), null, null, true);
window.localStorage.removeItem("ProxmoxUser");
},
return;
}
- let items = container.query('>'); // direct childs
+ let items = container.query('>'); // direct children
factor = Math.min(factor, items.length);
container.oldFactor = factor;
return `${size.toFixed(commaDigits)} ${unit}B`;
},
+ SizeUnits: {
+ 'B': 1,
+
+ 'KiB': 1024,
+ 'MiB': 1024*1024,
+ 'GiB': 1024*1024*1024,
+ 'TiB': 1024*1024*1024*1024,
+ 'PiB': 1024*1024*1024*1024*1024,
+
+ 'KB': 1000,
+ 'MB': 1000*1000,
+ 'GB': 1000*1000*1000,
+ 'TB': 1000*1000*1000*1000,
+ 'PB': 1000*1000*1000*1000*1000,
+ },
+
+ parse_size_unit: function(val) {
+ //let m = val.match(/([.\d])+\s?([KMGTP]?)(i?)B?\s*$/i);
+ let m = val.match(/(\d+(?:\.\d+)?)\s?([KMGTP]?)(i?)B?\s*$/i);
+ let size = parseFloat(m[1]);
+ let scale = m[2].toUpperCase();
+ let binary = m[3].toLowerCase();
+
+ let unit = `${scale}${binary}B`;
+ let factor = Proxmox.Utils.SizeUnits[unit];
+
+ return { size, factor, unit, binary }; // for convenience return all we got
+ },
+
+ size_unit_to_bytes: function(val) {
+ let { size, factor } = Proxmox.Utils.parse_size_unit(val);
+ return size * factor;
+ },
+
+ autoscale_size_unit: function(val) {
+ let { size, factor, binary } = Proxmox.Utils.parse_size_unit(val);
+ return Proxmox.Utils.format_size(size * factor, binary !== "i");
+ },
+
+ size_unit_ratios: function(a, b) {
+ a = typeof a !== "undefined" ? a : 0;
+ b = typeof b !== "undefined" ? b : Infinity;
+ let aBytes = typeof a === "number" ? a : Proxmox.Utils.size_unit_to_bytes(a);
+ let bBytes = typeof b === "number" ? b : Proxmox.Utils.size_unit_to_bytes(b);
+ return aBytes / (bBytes || Infinity); // avoid division by zero
+ },
+
render_upid: function(value, metaData, record) {
let task = record.data;
let type = task.type || task.worker_type;
singleton: true,
// Returns a Promise resolving to the result of an `API2Request` or rejecting to the error
- // repsonse on failure
+ // response on failure
api2: function(reqOpts) {
return new Promise((resolve, reject) => {
delete reqOpts.callback; // not allowed in this api