2020-05-09 02:04:25 +00:00
|
|
|
'use strict';
|
|
|
|
'require form';
|
|
|
|
'require fs';
|
|
|
|
'require view';
|
2021-10-13 19:24:56 +00:00
|
|
|
'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') || ''));
|
|
|
|
}
|
2020-05-09 02:04:25 +00:00
|
|
|
|
|
|
|
return view.extend({
|
|
|
|
load: function() {
|
2021-10-13 19:24:56 +00:00
|
|
|
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'] : [];
|
2020-05-09 02:04:25 +00:00
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
render: function(devs) {
|
|
|
|
var m, s, o;
|
2021-10-13 19:24:56 +00:00
|
|
|
m = new form.Map('hd-idle', _('HDD Idle'), _('HDD Idle is a utility program for spinning-down disks after a period of idle time.'));
|
2020-05-09 02:04:25 +00:00
|
|
|
|
2021-10-13 19:24:56 +00:00
|
|
|
s = m.section(form.GridSection, 'hd-idle', _('Settings'));
|
2020-05-09 02:04:25 +00:00
|
|
|
s.anonymous = true;
|
|
|
|
s.addremove = true;
|
2021-10-13 19:24:56 +00:00
|
|
|
s.sortable = true;
|
2020-05-09 02:04:25 +00:00
|
|
|
s.addbtntitle = _('Add new hdd setting...');
|
|
|
|
|
2021-10-13 19:24:56 +00:00
|
|
|
|
|
|
|
s.tab('general', _('Disk Settings'));
|
|
|
|
|
|
|
|
|
|
|
|
o = s.taboption('general', form.Flag, 'enabled', _('Enable'));
|
2020-05-09 02:04:25 +00:00
|
|
|
o.rmempty = false;
|
2021-10-13 19:24:56 +00:00
|
|
|
o.editable = true;
|
2020-05-09 02:04:25 +00:00
|
|
|
|
2021-10-13 19:24:56 +00:00
|
|
|
o = s.taboption('general', form.ListValue, 'disk', _('Disk'));
|
2020-05-09 02:04:25 +00:00
|
|
|
devs.forEach(function(dev) {
|
2021-10-13 19:24:56 +00:00
|
|
|
if( dev.rota ) {
|
|
|
|
o.value(dev.name, `/dev/${dev.name} [${dev.tran}:${dev.vendor} ${dev.model}]`);
|
|
|
|
}
|
2020-05-09 02:04:25 +00:00
|
|
|
});
|
|
|
|
|
2021-10-13 19:24:56 +00:00
|
|
|
|
|
|
|
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;
|
2020-05-09 02:04:25 +00:00
|
|
|
o.default = 10;
|
|
|
|
|
2021-10-13 19:24:56 +00:00
|
|
|
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'));
|
2020-05-09 02:04:25 +00:00
|
|
|
o.default = 'minutes';
|
|
|
|
|
2021-10-13 19:24:56 +00:00
|
|
|
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);
|
|
|
|
|
2020-05-09 02:04:25 +00:00
|
|
|
return m.render();
|
|
|
|
}
|
|
|
|
});
|