luci-app-statistics: clean and fix plugin configurations
[project/luci.git] / applications / luci-app-statistics / htdocs / luci-static / resources / view / statistics / plugins / thermal.js
1 'use strict';
2 'require fs';
3 'require form';
4
5 return L.Class.extend({
6 title: _('Thermal Plugin Configuration'),
7 description: _('The thermal plugin will monitor temperature of the system. Data is typically read from /sys/class/thermal/*/temp ( \'*\' denotes the thermal device to be read, e.g. thermal_zone1 )'),
8
9 addFormOptions: function(s) {
10 var o;
11
12 o = s.option(form.Flag, 'enable', _('Enable this plugin'));
13
14 o = s.option(form.DynamicList, 'Device', _('Monitor device(s) / thermal zone(s)'), _('Empty value = monitor all'));
15 o.load = function(section_id) {
16 return Promise.all([
17 L.resolveDefault(fs.list('/sys/class/thermal'), []),
18 L.resolveDefault(fs.list('/proc/acpi/thermal_zone'), [])
19 ]).then(L.bind(function(res) {
20 var entries = res[0].concat(res[1]);
21
22 for (var i = 0; i < entries.length; i++)
23 if (entries[i].type == 'directory' && !entries[i].name.match(/^cooling_device/))
24 o.value(entries[i].name);
25
26 return this.super('load', [ section_id ]);
27 }, this));
28 };
29
30 o.optional = true;
31 o.depends('enable', '1');
32
33 o = s.option(form.Flag, 'IgnoreSelected', _('Monitor all except specified'));
34 o.default = '0';
35 o.optional = true;
36 o.depends('enable', '1');
37 },
38
39 configSummary: function(section) {
40 var zones = L.toArray(section.Device),
41 invert = section.IgnoreSelected == '1';
42
43 if (zones.length)
44 return (invert
45 ? _('Monitoring all thermal zones except %s')
46 : _('Monitoring thermal zones %s')
47 ).format(zones.join(', '));
48 else
49 return _('Monitoring all thermal zones');
50 }
51 });