ui: refactor render_estimate

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
This commit is contained in:
Dominik Csapak 2020-11-09 16:01:22 +01:00 committed by Thomas Lamprecht
parent 6e880f19cc
commit f2d6324958
2 changed files with 19 additions and 19 deletions

View File

@ -167,6 +167,24 @@ Ext.define('PBS.Utils', {
return tokenid.match(/^(.+)!([^!]+)$/)[2]; return tokenid.match(/^(.+)!([^!]+)$/)[2];
}, },
render_estimate: function(value) {
if (!value) {
return gettext('Not enough data');
}
let now = new Date();
let estimate = new Date(value*1000);
let timespan = (estimate - now)/1000;
if (Number(estimate) <= Number(now) || isNaN(timespan)) {
return gettext('Never');
}
let duration = Proxmox.Utils.format_duration_human(timespan);
return Ext.String.format(gettext("in {0}"), duration);
},
constructor: function() { constructor: function() {
var me = this; var me = this;

View File

@ -47,24 +47,6 @@ Ext.define('PBS.DatastoreStatistics', {
controller: { controller: {
xclass: 'Ext.app.ViewController', xclass: 'Ext.app.ViewController',
render_estimate: function(value) {
if (!value) {
return gettext('Not enough data');
}
let now = new Date();
let estimate = new Date(value*1000);
let timespan = (estimate - now)/1000;
if (Number(estimate) <= Number(now) || isNaN(timespan)) {
return gettext('Never');
}
let duration = Proxmox.Utils.format_duration_human(timespan);
return Ext.String.format(gettext("in {0}"), duration);
},
init: function(view) { init: function(view) {
Proxmox.Utils.monStoreErrors(view, view.getStore().rstore); Proxmox.Utils.monStoreErrors(view, view.getStore().rstore);
}, },
@ -111,7 +93,7 @@ Ext.define('PBS.DatastoreStatistics', {
text: gettext('Estimated Full'), text: gettext('Estimated Full'),
dataIndex: 'estimated-full-date', dataIndex: 'estimated-full-date',
sortable: true, sortable: true,
renderer: 'render_estimate', renderer: PBS.Utils.render_estimate,
flex: 1, flex: 1,
minWidth: 130, minWidth: 130,
maxWidth: 200, maxWidth: 200,