Tasks.js 2.71 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
Ext.define('PVE.dc.Tasks', {
    extend: 'Ext.grid.GridPanel',

    alias: ['widget.pveClusterTasks'],

    initComponent : function() {
	var me = this;

	var taskstore = new PVE.data.UpdateStore({
	    storeid: 'pve-cluster-tasks',
	    model: 'pve-tasks',
	    proxy: {
                type: 'pve',
		url: '/api2/json/cluster/tasks'
	    },
	    sorters: [
		{
		    property : 'starttime',
Dietmar Maurer's avatar
Dietmar Maurer committed
19
		    direction: 'DESC'
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
		}
	    ]
	});

	var store = Ext.create('PVE.data.DiffStore', { 
	    rstore: taskstore,
	    appendAtStart: true 
	});

	var run_task_viewer = function() {
	    var sm = me.getSelectionModel();
	    var rec = sm.getSelection()[0];
	    if (!rec) {
		return;
	    }

	    var win = Ext.create('PVE.window.TaskViewer', { 
		upid: rec.data.upid
	    });
	    win.show();
	};

	Ext.apply(me, {
	    store: store,
	    stateful: false,

	    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";
		    }
		}
	    },
	    sortableColumns: false,
	    columns: [
		{ 
61
		    header: gettext("Start Time"), 
62 63 64 65 66 67 68
		    dataIndex: 'starttime',
		    width: 100,
		    renderer: function(value) { 
			return Ext.Date.format(value, "M d H:i:s"); 
		    }
		},
		{ 
69
		    header: gettext("End Time"), 
70 71 72 73
		    dataIndex: 'endtime',
		    width: 100,
		    renderer: function(value, metaData, record) {
			if (record.data.pid) {
74 75 76
			    if (record.data.type == "vncproxy" || 
				record.data.type == "vncshell" ||
				record.data.type == "spiceproxy") {
77 78 79 80
				metaData.tdCls =  "x-grid-row-console";
			    } else {
				metaData.tdCls =  "x-grid-row-loading";
			    }
81 82 83 84 85 86
			    return "";
			}
			return Ext.Date.format(value, "M d H:i:s"); 
		    }
		},
		{ 
87
		    header: gettext("Node"), 
88 89 90 91
		    dataIndex: 'node',
		    width: 100
		},
		{ 
92
		    header: gettext("User name"), 
93 94 95 96
		    dataIndex: 'user',
		    width: 150
		},
		{ 
97
		    header: gettext("Description"), 
98 99 100 101 102
		    dataIndex: 'upid', 
		    flex: 1,		  
		    renderer: PVE.Utils.render_upid
		},
		{ 
103
		    header: gettext("Status"), 
104 105 106 107
		    dataIndex: 'status', 
		    width: 200,
		    renderer: function(value, metaData, record) { 
			if (record.data.pid) {
108 109 110
			    if (record.data.type != "vncproxy") {
				metaData.tdCls =  "x-grid-row-loading";
			    }
111 112 113 114 115 116
			    return "";
			}
			if (value == 'OK') {
			    return 'OK';
			}
			// metaData.attr = 'style="color:red;"'; 
117
			return PVE.Utils.errorText + ': ' + value;
118 119 120 121 122 123 124 125 126 127 128 129 130 131
		    }
		}
	    ],
	    listeners: {
		itemdblclick: run_task_viewer,
		show: taskstore.startUpdate,
		hide: taskstore.stopUpdate,
		destroy: taskstore.stopUpdate
	    }
	});

	me.callParent();
    }
});