1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
|
'use strict';
'require form';
'require fs';
'require view';
'require uci';
function disk(devs, options, section_id) {
var v = uci.get('hd-idle', section_id, 'disk') || '';
var disk = devs.find(function(itm){ return itm.name == v; });
var out = '';
if(disk != undefined){
out = options.map(function(opt){ return disk[opt].trim(); });
out = out.filter(function(o){ return o != ''; });
out = out.join(' ');
}
return E('span', out);
}
function prettytime(section_id) {
return E('span', (uci.get('hd-idle', section_id, 'idle_time_interval') || '')
+ ' '
+ (uci.get('hd-idle', section_id, 'idle_time_unit') || ''));
}
return view.extend({
load: function() {
return fs.exec("/usr/bin/lsblk", ["-n", "-J", "-do", "NAME,TRAN,ROTA,RM,VENDOR,MODEL"]).then(function(res) {
if( res.code )
return [];
var json = JSON.parse(res.stdout);
return ( 'blockdevices' in json ) ? json['blockdevices'] : [];
});
},
render: function(devs) {
var m, s, o;
m = new form.Map('hd-idle', _('HDD Idle'), _('HDD Idle is a utility program for spinning-down disks after a period of idle time.'));
s = m.section(form.GridSection, 'hd-idle', _('Settings'));
s.anonymous = true;
s.addremove = true;
s.sortable = true;
s.addbtntitle = _('Add new hdd setting...');
s.tab('general', _('Disk Settings'));
o = s.taboption('general', form.Flag, 'enabled', _('Enable'));
o.rmempty = false;
o.editable = true;
o = s.taboption('general', form.ListValue, 'disk', _('Disk'));
devs.forEach(function(dev) {
if( dev.rota ) {
o.value(dev.name, `/dev/${dev.name} [${dev.tran}:${dev.vendor} ${dev.model}]`);
}
});
o = s.taboption('general', form.Value, '_bus', _('Bus'));
o.rawhtml = true;
o.write = function() {};
o.remove = function() {};
o.modalonly = false;
o.textvalue = disk.bind(o, devs, ['tran']);
o = s.taboption('general', form.Value, '_vendorModel', _('Vendor / Model'));
o.rawhtml = true;
o.write = function() {};
o.remove = function() {};
o.modalonly = false;
o.textvalue = disk.bind(o, devs, ['vendor', 'model'] );
o = s.taboption('general', form.Value, 'idle_time_interval', _('Idle time'));
o.modalonly = true;
o.default = 10;
o = s.taboption('general', form.ListValue, 'idle_time_unit', _('Idle time unit'));
o.modalonly = true;
o.value('seconds', _('seconds', 'Abbreviation for seconds'));
o.value('minutes', _('minutes', 'Abbreviation for minutes'));
o.value('hours', _('hours', 'Abbreviation for hours'));
o.value('days', _('days', 'Abbreviation for days'));
o.default = 'minutes';
o = s.taboption('general', form.Value, '_prettytime', _('Idle time'));
o.rawhtml = true;
o.write = function() {};
o.remove = function() {};
o.modalonly = false;
o.textvalue = prettytime.bind(o);
return m.render();
}
});
|