]> git.proxmox.com Git - proxmox-widget-toolkit.git/blob - src/data/ProxmoxProxy.js
ProxmoxProxy: add duration fields for proxmox-tasks
[proxmox-widget-toolkit.git] / src / data / ProxmoxProxy.js
1 Ext.define('Proxmox.RestProxy', {
2 extend: 'Ext.data.RestProxy',
3 alias: 'proxy.proxmox',
4
5 pageParam: null,
6 startParam: null,
7 limitParam: null,
8 groupParam: null,
9 sortParam: null,
10 filterParam: null,
11 noCache: false,
12
13 afterRequest: function(request, success) {
14 this.fireEvent('afterload', this, request, success);
15 },
16
17 constructor: function(config) {
18 Ext.applyIf(config, {
19 reader: {
20 type: 'json',
21 rootProperty: config.root || 'data',
22 },
23 });
24
25 this.callParent([config]);
26 },
27 }, function() {
28 Ext.define('KeyValue', {
29 extend: "Ext.data.Model",
30 fields: ['key', 'value'],
31 idProperty: 'key',
32 });
33
34 Ext.define('KeyValuePendingDelete', {
35 extend: "Ext.data.Model",
36 fields: ['key', 'value', 'pending', 'delete'],
37 idProperty: 'key',
38 });
39
40 Ext.define('proxmox-tasks', {
41 extend: 'Ext.data.Model',
42 fields: [
43 { name: 'starttime', type: 'date', dateFormat: 'timestamp' },
44 { name: 'endtime', type: 'date', dateFormat: 'timestamp' },
45 { name: 'pid', type: 'int' },
46 {
47 name: 'duration',
48 sortType: 'asInt',
49 calculate: function(data) {
50 let endtime = data.endtime;
51 let starttime = data.starttime;
52 if (endtime !== undefined) {
53 return (endtime - starttime)/1000;
54 }
55 return 0;
56 },
57 },
58 'node', 'upid', 'user', 'status', 'type', 'id',
59 ],
60 idProperty: 'upid',
61 });
62
63 Ext.define('proxmox-cluster-log', {
64 extend: 'Ext.data.Model',
65 fields: [
66 { name: 'uid', type: 'int' },
67 { name: 'time', type: 'date', dateFormat: 'timestamp' },
68 { name: 'pri', type: 'int' },
69 { name: 'pid', type: 'int' },
70 'node', 'user', 'tag', 'msg',
71 {
72 name: 'id',
73 convert: function(value, record) {
74 let info = record.data;
75
76 if (value) {
77 return value;
78 }
79 // compute unique ID
80 return info.uid + ':' + info.node;
81 },
82 },
83 ],
84 idProperty: 'id',
85 });
86 });