Merge pull request #4380 from Ansuel/ddns-fix-pt2
[project/luci.git] / applications / luci-app-statistics / htdocs / luci-static / resources / view / statistics / plugins / disk.js
1 'use strict';
2 'require baseclass';
3 'require fs';
4 'require form';
5
6 return baseclass.extend({
7 title: _('Disk Plugin Configuration'),
8 description: _('The disk plugin collects detailed usage statistics for selected partitions or whole disks.'),
9
10 addFormOptions: function(s) {
11 var o;
12
13 o = s.option(form.Flag, 'enable', _('Enable this plugin'));
14
15 o = s.option(form.DynamicList, 'Disks', _('Monitor disks and partitions'),
16 _('When none selected, all disks will be monitored.'));
17 o.depends('enable', '1');
18 o.load = function(section_id) {
19 return fs.trimmed('/proc/partitions').then(L.bind(function(str) {
20 var lines = (str || '').split(/\n/);
21
22 for (var i = 0; i < lines.length; i++) {
23 var m = lines[i].match(/^ +[0-9]+ +[0-9]+ +[0-9]+ (\S+)$/);
24 if (m)
25 this.value(m[1]);
26 }
27
28 return this.super('load', [section_id]);
29 }, this));
30 };
31
32 o = s.option(form.Flag, 'IgnoreSelected', _('Monitor all except specified'));
33 o.depends('enable', '1');
34 },
35
36 configSummary: function(section) {
37 var disks = L.toArray(section.Disks),
38 invert = section.IgnoreSelected == '1';
39
40 if (disks.length == 0)
41 return _('Monitoring all disks');
42 else if (invert)
43 return N_(disks.length, 'Monitoring all but one disk', 'Monitoring all but %d disks').format(disks.length);
44 else
45 return N_(disks.length, 'Monitoring one disk', 'Monitoring %d disks').format(disks.length);
46 }
47 });