Merge pull request #3619 from Andy2244/luci-app-samba4_new-UCI
[project/luci.git] / applications / luci-app-statistics / htdocs / luci-static / resources / view / statistics / plugins / sensors.js
1 'use strict';
2 'require fs';
3 'require form';
4
5 var sensorTypes = [
6 /^[0-9]+(?:\.[0-9]+)?v$/, 'voltage',
7 /^(?:ain|in|vccp|vdd|vid|vin|volt|voltbatt|vrm)[0-9]*$/, 'voltage',
8 /^(?:cpu_temp|remote_temp|temp)[0-9]*$/, 'temperature',
9 /^(?:fan)[0-9]*$/, 'fanspeed',
10 /^(?:power)[0-9]*$/, 'power'
11 ];
12
13 return L.Class.extend({
14 title: _('Sensors Plugin Configuration'),
15 description: _('The sensors plugin uses the Linux Sensors framework to gather environmental statistics.'),
16
17 addFormOptions: function(s) {
18 var o;
19
20 o = s.option(form.Flag, 'enable', _('Enable this plugin'));
21 o.default = '0';
22
23 o = s.option(form.DynamicList, 'Sensor', _('Sensor list'));
24 o.rmempty = true;
25 o.size = 18;
26 o.depends('enable', '1');
27 o.load = function(section_id) {
28 return fs.exec_direct('/usr/sbin/sensors', ['-j'], 'json').then(L.bind(function(output) {
29 for (var bus in output) {
30 for (var sensor in output[bus]) {
31 if (!L.isObject(output[bus][sensor]))
32 continue;
33
34 for (var j = 0; j < sensorTypes.length; j += 2) {
35 if (sensor.match(sensorTypes[j])) {
36 this.value('%s/%s-%s'.format(bus, sensorTypes[j + 1], sensor));
37 break;
38 }
39 }
40 }
41 }
42
43 return this.super('load', [section_id]);
44 }, this));
45 };
46
47 o = s.option(form.Flag, 'IgnoreSelected', _('Monitor all except specified'));
48 o.default = '0';
49 o.rmempty = true;
50 o.depends('enable', '1');
51 },
52
53 configSummary: function(section) {
54 var sensors = L.toArray(section.Sensor),
55 invert = section.IgnoreSelected == '1';
56
57 if (invert && sensors.length)
58 return N_(sensors.length, 'Monitoring all but one sensor', 'Monitoring all but %d sensors').format(sensors.length);
59 else if (sensors.length)
60 return N_(sensors.length, 'Monitoring one sensor', 'Monitoring %d sensors').format(sensors.length);
61 else
62 return _('Monitoring all sensors');
63 }
64 });