add task list class

This commit is contained in:
Dietmar Maurer 2017-01-31 09:25:24 +01:00
parent 0669450939
commit 09d6446578
3 changed files with 218 additions and 3 deletions

View File

@ -22,6 +22,7 @@ JSSRC= \
grid/ObjectGrid.js \
window/Edit.js \
window/TaskViewer.js \
node/Tasks.js \
node/TimeEdit.js \
node/TimeView.js

View File

@ -1,7 +1,7 @@
Ext.define('Proxmox.RestProxy', {
extend: 'Ext.data.RestProxy',
alias : 'proxy.proxmox',
pageParam : null,
startParam: null,
limitParam: null,
@ -17,14 +17,14 @@ Ext.define('Proxmox.RestProxy', {
constructor: function(config) {
Ext.applyIf(config, {
Ext.applyIf(config, {
reader: {
type: 'json',
rootProperty: config.root || 'data'
}
});
this.callParent([config]);
this.callParent([config]);
}
}, function() {
@ -34,4 +34,40 @@ Ext.define('Proxmox.RestProxy', {
idProperty: 'key'
});
Ext.define('proxmox-tasks', {
extend: 'Ext.data.Model',
fields: [
{ name: 'starttime', type : 'date', dateFormat: 'timestamp' },
{ name: 'endtime', type : 'date', dateFormat: 'timestamp' },
{ name: 'pid', type: 'int' },
'node', 'upid', 'user', 'status', 'type', 'id'
],
idProperty: 'upid'
});
Ext.define('proxmox-cluster-log', {
extend: 'Ext.data.Model',
fields: [
{ name: 'uid' , type: 'int' },
{ name: 'time', type : 'date', dateFormat: 'timestamp' },
{ name: 'pri', type: 'int' },
{ name: 'pid', type: 'int' },
'node', 'user', 'tag', 'msg',
{
name: 'id',
convert: function(value, record) {
var info = record.data;
var text;
if (value) {
return value;
}
// compute unique ID
return info.uid + ':' + info.node;
}
}
],
idProperty: 'id'
});
});

178
node/Tasks.js Normal file
View File

@ -0,0 +1,178 @@
Ext.define('Proxmox.node.Tasks', {
extend: 'Ext.grid.GridPanel',
alias: ['widget.proxmoxNodeTasks'],
stateful: true,
stateId: 'grid-node-tasks',
loadMask: true,
sortableColumns: false,
vmidFilter: 0,
render_upid: function(upid) {
var task = Proxmox.Utils.parse_task_upid(upid);
return task.type + ' ' + task.id;
},
initComponent : function() {
var me = this;
if (!me.nodename) {
throw "no node name specified";
}
var store = Ext.create('Ext.data.BufferedStore', {
pageSize: 500,
autoLoad: true,
remoteFilter: true,
model: 'proxmox-tasks',
proxy: {
type: 'proxmox',
startParam: 'start',
limitParam: 'limit',
url: "/api2/json/nodes/" + me.nodename + "/tasks"
}
});
var userfilter = '';
var filter_errors = 0;
var updateProxyParams = function() {
var params = {
errors: filter_errors
};
if (userfilter) {
params.userfilter = userfilter;
}
if (me.vmidFilter) {
params.vmid = me.vmidFilter;
}
store.proxy.extraParams = params;
};
updateProxyParams();
var reload_task = Ext.create('Ext.util.DelayedTask',function() {
updateProxyParams();
store.reload();
});
var run_task_viewer = function() {
var sm = me.getSelectionModel();
var rec = sm.getSelection()[0];
if (!rec) {
return;
}
var win = Ext.create('Proxmox.window.TaskViewer', {
upid: rec.data.upid
});
win.show();
};
var view_btn = new Ext.Button({
text: gettext('View'),
disabled: true,
handler: run_task_viewer
});
Ext.apply(me, {
store: store,
viewConfig: {
trackOver: false,
stripeRows: false, // does not work with getRowClass()
getRowClass: function(record, index) {
var status = record.get('status');
if (status && status != 'OK') {
return "x-form-invalid-field";
}
}
},
tbar: [
view_btn, '->', gettext('User name') +':', ' ',
{
xtype: 'textfield',
width: 200,
value: userfilter,
enableKeyEvents: true,
listeners: {
keyup: function(field, e) {
userfilter = field.getValue();
reload_task.delay(500);
}
}
}, ' ', gettext('Only Errors') + ':', ' ',
{
xtype: 'checkbox',
hideLabel: true,
checked: filter_errors,
listeners: {
change: function(field, checked) {
filter_errors = checked ? 1 : 0;
reload_task.delay(10);
}
}
}, ' '
],
columns: [
{
header: gettext("Start Time"),
dataIndex: 'starttime',
width: 100,
renderer: function(value) {
return Ext.Date.format(value, "M d H:i:s");
}
},
{
header: gettext("End Time"),
dataIndex: 'endtime',
width: 100,
renderer: function(value, metaData, record) {
return Ext.Date.format(value,"M d H:i:s");
}
},
{
header: gettext("Node"),
dataIndex: 'node',
width: 100
},
{
header: gettext("User name"),
dataIndex: 'user',
width: 150
},
{
header: gettext("Description"),
dataIndex: 'upid',
flex: 1,
renderer: me.render_upid
},
{
header: gettext("Status"),
dataIndex: 'status',
width: 200,
renderer: function(value, metaData, record) {
if (value == 'OK') {
return 'OK';
}
// metaData.attr = 'style="color:red;"';
return "ERROR: " + value;
}
}
],
listeners: {
itemdblclick: run_task_viewer,
selectionchange: function(v, selections) {
view_btn.setDisabled(!(selections && selections[0]));
},
show: function() { reload_task.delay(10); },
destroy: function() { reload_task.cancel(); }
}
});
me.callParent();
}
});