45b483962d5f1a4e6b0a2e597de4801fa704a83e
[project/luci.git] / modules / luci-mod-status / htdocs / luci-static / resources / view / status / dmesg.js
1 'use strict';
2 'require view';
3 'require fs';
4 'require poll';
5 'require ui';
6
7 return view.extend({
8 retrieveLog: async function() {
9 return fs.exec_direct('/bin/dmesg', [ '-r' ]).then(logdata => {
10 const loglines = logdata.trim().split(/\n/).map(function(line) {
11 return line.replace(/^<\d+>/, '');
12 });
13 return { value: loglines.join('\n'), rows: loglines.length + 1 };
14 }).catch(function(err) {
15 ui.addNotification(null, E('p', {}, _('Unable to load log data: ' + err.message)));
16 return '';
17 });
18 },
19
20 pollLog: async function() {
21 const element = document.getElementById('syslog');
22 if (element) {
23 const log = await this.retrieveLog();
24 element.value = log.value;
25 element.rows = log.rows;
26 }
27 },
28
29 load: async function() {
30 poll.add(this.pollLog.bind(this));
31 return await this.retrieveLog();
32 },
33
34 render: function(loglines) {
35 var scrollDownButton = E('button', {
36 'id': 'scrollDownButton',
37 'class': 'cbi-button cbi-button-neutral',
38 }, _('Scroll to tail', 'scroll to bottom (the tail) of the log file')
39 );
40 scrollDownButton.addEventListener('click', function() {
41 scrollUpButton.focus();
42 });
43
44 var scrollUpButton = E('button', {
45 'id' : 'scrollUpButton',
46 'class': 'cbi-button cbi-button-neutral',
47 }, _('Scroll to head', 'scroll to top (the head) of the log file')
48 );
49 scrollUpButton.addEventListener('click', function() {
50 scrollDownButton.focus();
51 });
52
53 return E([], [
54 E('h2', {}, [ _('Kernel Log') ]),
55 E('div', { 'id': 'content_syslog' }, [
56 E('div', {'style': 'padding-bottom: 20px'}, [scrollDownButton]),
57 E('textarea', {
58 'id': 'syslog',
59 'style': 'font-size:12px',
60 'readonly': 'readonly',
61 'wrap': 'off',
62 'rows': loglines.rows
63 }, [ loglines.value ]),
64 E('div', {'style': 'padding-bottom: 20px'}, [scrollUpButton])
65 ])
66 ]);
67 },
68
69 handleSaveApply: null,
70 handleSave: null,
71 handleReset: null
72 });