widgets: add a re-useable filtered logread view
[project/luci.git] / applications / luci-app-travelmate / htdocs / luci-static / resources / view / travelmate / logread.js
index d004ed4d2fbba708a84a53266e107d0abf7d26d8..fc9323aa148c9939fb4d9d26c81f93b3c0dceee6 100644 (file)
@@ -1,42 +1,4 @@
 'use strict';
-'require view';
-'require poll';
-'require fs';
+'require tools.views as views';
 
-return view.extend({
-       load: function() {
-               return Promise.all([
-                       L.resolveDefault(fs.stat('/sbin/logread'), null),
-                       L.resolveDefault(fs.stat('/usr/sbin/logread'), null)
-               ]);
-       },
-       render: function(stat) {
-               var logger = stat[0] ? stat[0].path : stat[1] ? stat[1].path : null;
-               poll.add(function() {
-                       return L.resolveDefault(fs.exec_direct(logger, ['-e', 'trm-'])).then(function(res) {
-                               var log = document.getElementById("logfile");
-                               if (res) {
-                                       log.value = res.trim();
-                               }
-                               else {
-                                       log.value = _('No travelmate related logs yet!');
-                               }
-                               log.scrollTop = log.scrollHeight;
-                       });
-               });
-               return E('div', { class: 'cbi-map' },
-                       E('div', { class: 'cbi-section' }, [
-                       E('div', { class: 'cbi-section-descr' }, _('The syslog output, pre-filtered for travelmate related messages only.')),
-                       E('textarea', {
-                               'id': 'logfile',
-                               'style': 'width: 100% !important; padding: 5px; font-family: monospace',
-                               'readonly': 'readonly',
-                               'wrap': 'off',
-                               'rows': 25
-                       })
-               ]));
-       },
-       handleSaveApply: null,
-       handleSave: null,
-       handleReset: null
-});
+return views.LogreadBox("trm-", "travelmate");