]> git.proxmox.com Git - pve-manager.git/blob - www/mobile/TaskViewer.js
use Proxmox.Utils instead of PVE.Utils
[pve-manager.git] / www / mobile / TaskViewer.js
1 Ext.define('PVE.TaskViewer', {
2 extend: 'PVE.Page',
3 alias: 'widget.pveTaskViewer',
4
5 statics: {
6 pathMatch: function(loc) {
7 return loc.match(/^nodes\/([^\s\/]+)\/tasks\/([^\s\/]+)$/);
8 }
9 },
10
11 nodename: undefined,
12 upid: undefined,
13 taskInfo: undefined,
14 taskStatus: 'running', // assume running
15
16 config: {
17 items: [
18 {
19 xtype: 'pveTitleBar'
20 },
21 {
22 itemId: 'taskStatus',
23 xtype: 'component',
24 styleHtmlContent: true,
25 style: 'background-color:white;',
26 data: [],
27 tpl: [
28 '<table style="margin-bottom:0px;">',
29 '<tpl for=".">',
30 '<tr><td>{key}</td><td>{value}</td></tr>',
31 '</tpl>',
32 '</table>'
33 ]
34 },
35 {
36 xtype: 'component',
37 cls: 'dark',
38 padding: 5,
39 html: gettext('Log')
40 },
41 {
42 itemId: 'taskLog',
43 xtype: 'container',
44 flex: 1,
45 scrollable: 'both',
46 styleHtmlContent: true,
47 style: 'background-color:white;white-space: pre;font-family: Monospace;',
48 data: {},
49 tpl: '{text}'
50 }
51 ]
52 },
53
54 reloadLog: function() {
55 var me = this;
56
57 var logCmp = me.down('#taskLog');
58
59 PVE.Utils.API2Request({
60 url: "/nodes/" + me.nodename + "/tasks/" + me.upid + "/log",
61 method: 'GET',
62 success: function(response) {
63 var d = response.result.data;
64
65 var text = '';
66 Ext.Array.each(d, function(el) {
67 text += Ext.htmlEncode(el.t) + "\n";
68 });
69 logCmp.setData({ text: text });
70 },
71 failure: function(response) {
72 logCmp.setData({ text: response.htmlStatus } );
73 }
74 });
75 },
76
77 reload: function() {
78 var me = this;
79
80 var statusCmp = me.down('#taskStatus');
81 var logCmp = me.down('#taskLog');
82
83 PVE.Utils.API2Request({
84 url: "/nodes/" + me.nodename + "/tasks/" + me.upid + "/status",
85 method: 'GET',
86 success: function(response) {
87 me.reloadLog();
88
89 var d = response.result.data;
90 var kv = [];
91
92 kv.push({ key: gettext('Taskstatus'), value: d.status });
93 kv.push({ key: gettext('Node'), value: d.node });
94 kv.push({ key: gettext('User'), value: d.user });
95 kv.push({ key: gettext('Starttime'), value: Proxmox.Utils.render_timestamp(d.starttime) });
96
97 me.setMasked(false);
98 statusCmp.setData(kv);
99 if (d.status !== 'stopped') {
100 Ext.defer(me.reload, 2000, me);
101 }
102 },
103 failure: function(response) {
104 me.setMasked({ xtype: 'loadmask', message: response.htmlStatus} );
105 }
106 });
107 },
108
109 initialize: function() {
110 var me = this;
111
112 var match = me.self.pathMatch(me.getAppUrl());
113 if (!match) {
114 throw "pathMatch failed";
115 }
116
117 me.nodename = match[1];
118 me.upid = match[2];
119
120 me.taskInfo = Proxmox.Utils.parse_task_upid(me.upid);
121
122 me.down('titlebar').setTitle(me.taskInfo.desc);
123
124 me.reload();
125
126 this.callParent();
127 }
128 });