luci2: adapt views to changed luci2 framework
[project/luci2/ui.git] / luci2 / htdocs / luci2 / view / status.processes.js
1 L.ui.view.extend({
2     title: L.tr('Processes'),
3     description: L.tr('This list gives an overview over currently running system processes and their status.'),
4     execute: function() {
5         var allow_signals = this.options.acls.status;
6         return L.system.getProcessList().then(function(list) {
7             var procTable = new L.ui.table({
8                 columns: [ {
9                     caption: L.tr('PID'),
10                     key:     'pid'
11                 }, {
12                     caption: L.tr('Owner'),
13                     key:     'user'
14                 }, {
15                     caption: L.tr('Command'),
16                     key:     'command'
17                 }, {
18                     caption: L.tr('CPU usage (%)'),
19                     key:     'cpu_percent',
20                     format:  '%d%%'
21                 }, {
22                     caption: L.tr('Memory usage (%)'),
23                     key:     'vsize_percent',
24                     format:  '%d%%'
25                 }, {
26                     key:    'pid',
27                     format: function(v, n) {
28                         return $('<div />')
29                             .addClass('btn-group')
30                             .append($('<button />')
31                                 .addClass('btn btn-primary btn-sm dropdown-toggle')
32                                 .attr('data-toggle', 'dropdown')
33                                 .text(L.tr('Signal…')))
34                             .append($('<ul />')
35                                 .addClass('dropdown-menu pull-right')
36                                 .append($('<li />')
37                                     .append($('<a />')
38                                         .attr('href', '#')
39                                         .html('%s (<code>%s</code>)'.format(L.trc('UNIX signal', 'Reload'), 'HUP'))
40                                         .click(function(ev) { L.system.sendSignal(v, 1).then(status); ev.preventDefault(); })))
41                                 .append($('<li />')
42                                     .append($('<a />')
43                                         .attr('href', '#')
44                                         .html('%s (<code>%s</code>)'.format(L.trc('UNIX signal', 'Terminate'), 'TERM'))
45                                         .click(function(ev) { L.system.sendSignal(v, 15).then(status); ev.preventDefault(); })))
46                                 .append($('<li />')
47                                     .append($('<a />')
48                                         .attr('href', '#')
49                                         .html('%s (<code>%s</code>)'.format(L.trc('UNIX signal', 'Kill immediately'), 'KILL'))
50                                         .click(function(ev) { L.system.sendSignal(v, 9).then(status); ev.preventDefault(); }))))
51                     }
52                 } ]
53             });
54
55             procTable.rows(list);
56             procTable.insertInto('#process_table');
57         });
58     }
59 });