]> git.proxmox.com Git - pve-manager.git/blob - www/mobile/NodeSummary.js
ui: restore: display "Hostname" for container
[pve-manager.git] / www / mobile / NodeSummary.js
1 Ext.define('PVE.NodeInfo', {
2 extend: 'Ext.Component',
3 alias: 'widget.pveNodeInfo',
4
5 config: {
6 style: 'background-color: white;',
7 styleHtmlContent: true,
8 data: [],
9 tpl: [
10 '<table style="margin-bottom:0px;">',
11 '<tr><td>Version:</td><td>{pveversion}</td></tr>',
12 '<tr><td>Memory:</td><td>{[this.meminfo(values)]}</td></tr>',
13 '<tr><td>CPU:</td><td>{[this.cpuinfo(values)]}</td></tr>',
14 '<tr><td>Uptime:</td><td>{[Proxmox.Utils.format_duration_long(values.uptime)]}</td></tr>',
15 '</table>',
16 {
17 meminfo: function(values) {
18 var d = values.memory;
19 if (!d) {
20 return '-';
21 }
22 return Proxmox.Utils.format_size(d.used || 0) + " of " + Proxmox.Utils.format_size(d.total);
23 },
24 cpuinfo: function(values) {
25 if (!values.cpuinfo) {
26 return '-';
27 }
28 var per = values.cpu * 100;
29 return per.toFixed(2) + "% (" + values.cpuinfo.cpus + " CPUs)";
30 }
31 }
32 ]
33 },
34 });
35
36 Ext.define('PVE.NodeSummary', {
37 extend: 'PVE.Page',
38 alias: 'widget.pveNodeSummary',
39
40 statics: {
41 pathMatch: function(loc) {
42 return loc.match(/^nodes\/([^\s\/]+)$/);
43 }
44 },
45
46 nodename: undefined,
47
48 config: {
49 items: [
50 {
51 xtype: 'pveTitleBar'
52 },
53 {
54 xtype: 'pveNodeInfo'
55 },
56 {
57 xtype: 'component',
58 cls: 'dark',
59 padding: 5,
60 html: gettext('Virtual machines')
61 },
62 {
63 xtype: 'list',
64 flex: 1,
65 disableSelection: true,
66 listeners: {
67 itemsingletap: function(list, index, target, record) {
68 PVE.Workspace.gotoPage('nodes/' + record.get('nodename') + '/' +
69 record.get('type') + '/' + record.get('vmid'));
70 }
71 },
72 grouped: true,
73 itemTpl: [
74 '{name}<br>',
75 '<small>',
76 'id: {vmid} ',
77 '<tpl if="uptime">',
78 'cpu: {[this.cpuinfo(values)]} ',
79 'mem: {[this.meminfo(values)]} ',
80 '</tpl>',
81 '</small>',
82 {
83 meminfo: function(values) {
84 if (!values.uptime) {
85 return '-';
86 }
87 return Proxmox.Utils.format_size(values.mem);
88 },
89 cpuinfo: function(values) {
90 if (!values.uptime) {
91 return '-';
92 }
93 return (values.cpu*100).toFixed(1) + '%';
94 }
95 }
96 ]
97 }
98 ]
99 },
100
101 reload: function() {
102 var me = this;
103
104 var ni = me.down('pveNodeInfo');
105
106 Proxmox.Utils.API2Request({
107 url: '/nodes/' + me.nodename + '/status',
108 method: 'GET',
109 success: function(response) {
110 var d = response.result.data;
111 if (d.pveversion) {
112 d.pveversion = d.pveversion.replace(/pve\-manager\//, '');
113 }
114 ni.setData(d);
115 }
116 });
117
118
119 var list = me.down('list');
120
121 list.setMasked(false);
122
123 var error_handler = function(response) {
124 list.setMasked({ xtype: 'loadmask', message: response.htmlStatus} );
125 };
126
127 Proxmox.Utils.API2Request({
128 url: '/nodes/' + me.nodename + '/lxc',
129 method: 'GET',
130 success: function(response) {
131 var d = response.result.data;
132 d.nodename = me.nodename;
133 d.forEach(function(el) { el.type = 'lxc'; el.nodename = me.nodename });
134 me.store.each(function(rec) {
135 if (rec.get('type') === 'lxc') {
136 rec.destroy();
137 }
138 });
139 me.store.add(d);
140 },
141 failure: error_handler
142 });
143
144 Proxmox.Utils.API2Request({
145 url: '/nodes/' + me.nodename + '/qemu',
146 method: 'GET',
147 success: function(response) {
148 var d = response.result.data;
149 d.forEach(function(el) { el.type = 'qemu'; el.nodename = me.nodename });
150 me.store.each(function(rec) {
151 if (rec.get('type') === 'qemu') {
152 rec.destroy();
153 }
154 });
155 me.store.add(d);
156 },
157 failure: error_handler
158 });
159
160 },
161
162 initialize: function() {
163 var me = this;
164
165 var match = me.self.pathMatch(me.getAppUrl());
166 if (!match) {
167 throw "pathMatch failed";
168 }
169
170 me.nodename = match[1];
171
172 me.down('titlebar').setTitle(gettext('Node') + ': ' + me.nodename);
173
174 me.down('pveMenuButton').setMenuItems([
175 {
176 text: gettext('Tasks'),
177 handler: function() {
178 PVE.Workspace.gotoPage('nodes/' + me.nodename + '/tasks');
179 }
180 },
181 ]);
182
183 me.store = Ext.create('Ext.data.Store', {
184 fields: [ 'name', 'vmid', 'nodename', 'type', 'memory', 'uptime', 'mem', 'maxmem', 'cpu', 'cpus'],
185 sorters: ['vmid'],
186 grouper: {
187 groupFn: function(record) {
188 return record.get('type');
189 }
190 },
191 });
192
193 var list = me.down('list');
194 list.setStore(me.store);
195
196 me.reload();
197
198 this.callParent();
199 }
200 });