treewide: transition div tables to actual table markup
[project/luci.git] / modules / luci-mod-status / htdocs / luci-static / resources / view / status / processes.js
1 'use strict';
2 'require view';
3 'require fs';
4 'require ui';
5 'require rpc';
6
7 var callLuciProcessList = rpc.declare({
8 object: 'luci',
9 method: 'getProcessList',
10 expect: { result: [] }
11 });
12
13 return view.extend({
14 load: function() {
15 return callLuciProcessList();
16 },
17
18 handleSignal: function(signum, pid, ev) {
19 return fs.exec('/bin/kill', ['-%d'.format(signum), '%s'.format(pid)]).then(L.bind(function() {
20 return callLuciProcessList().then(L.bind(function(processes) {
21 this.updateTable('.table', processes);
22 }, this));
23 }, this)).catch(function(e) { ui.addNotification(null, E('p', e.message)) });
24 },
25
26 updateTable: function(table, processes) {
27 var rows = [];
28
29 processes.sort(function(a, b) {
30 return (a.PID - b.PID);
31 });
32
33 for (var i = 0; i < processes.length; i++) {
34 var proc = processes[i];
35
36 rows.push([
37 proc.PID,
38 proc.USER,
39 proc.COMMAND,
40 proc['%CPU'],
41 proc['%MEM'],
42 E('div', {}, [
43 E('button', {
44 'class': 'btn cbi-button-action',
45 'click': ui.createHandlerFn(this, 'handleSignal', 1, proc.PID)
46 }, _('Hang Up')), ' ',
47 E('button', {
48 'class': 'btn cbi-button-negative',
49 'click': ui.createHandlerFn(this, 'handleSignal', 15, proc.PID)
50 }, _('Terminate')), ' ',
51 E('button', {
52 'class': 'btn cbi-button-negative',
53 'click': ui.createHandlerFn(this, 'handleSignal', 9, proc.PID)
54 }, _('Kill'))
55 ])
56 ]);
57 }
58
59 cbi_update_table(table, rows, E('em', _('No information available')));
60 },
61
62 render: function(processes) {
63 var v = E([], [
64 E('h2', _('Processes')),
65 E('div', { 'class': 'cbi-map-descr' }, _('This list gives an overview over currently running system processes and their status.')),
66
67 E('table', { 'class': 'table' }, [
68 E('tr', { 'class': 'tr table-titles' }, [
69 E('th', { 'class': 'th' }, _('PID')),
70 E('th', { 'class': 'th' }, _('Owner')),
71 E('th', { 'class': 'th' }, _('Command')),
72 E('th', { 'class': 'th' }, _('CPU usage (%)')),
73 E('th', { 'class': 'th' }, _('Memory usage (%)')),
74 E('th', { 'class': 'th center nowrap cbi-section-actions' })
75 ])
76 ])
77 ]);
78
79 this.updateTable(v.lastElementChild, processes);
80
81 return v;
82 },
83
84 handleSaveApply: null,
85 handleSave: null,
86 handleReset: null
87 });