luci-mod-system: restore rc.local editing functionality

Signed-off-by: Jo-Philipp Wich <jo@mein.io>
This commit is contained in:
Jo-Philipp Wich 2019-09-12 14:41:30 +02:00
parent 113e2c0217
commit 0eb5661e8c

View file

@ -15,8 +15,24 @@ return L.view.extend({
expect: { result: false }
}),
callFileRead: rpc.declare({
object: 'file',
method: 'read',
params: [ 'path' ],
expect: { data: '' }
}),
callFileWrite: rpc.declare({
object: 'file',
method: 'write',
params: [ 'path', 'data' ]
}),
load: function() {
return this.callInitList();
return Promise.all([
this.callFileRead('/etc/rc.local'),
this.callInitList()
]);
},
handleAction: function(name, action, ev) {
@ -42,6 +58,16 @@ return L.view.extend({
}, this, name, !isEnabled, ev.currentTarget.parentNode));
},
handleSave: function(ev) {
var value = document.querySelector('textarea').value || '';
return this.callFileWrite('/etc/rc.local', value.replace(/\r\n/g, '\n')).then(function() {
L.ui.addNotification(null, E('p', _('Contents have been saved.')), 'info');
}, function() {
L.ui.addNotification(null, E('p', _('Unable to save contents.')));
});
},
renderEnableDisable: function(init) {
return E('button', {
class: 'btn cbi-button-%s'.format(init.enabled ? 'positive' : 'negative'),
@ -49,7 +75,11 @@ return L.view.extend({
}, init.enabled ? _('Enabled') : _('Disabled'));
},
render: function(initList) {
render: function(data) {
var rcLocal = data[0],
initList = data[1],
rows = [], list = [];
var table = E('div', { 'class': 'table' }, [
E('div', { 'class': 'tr table-titles' }, [
E('div', { 'class': 'th' }, _('Start priority')),
@ -61,8 +91,6 @@ return L.view.extend({
])
]);
var rows = [], list = [];
for (var init in initList)
if (initList[init].index < 100)
list.push(Object.assign({ name: init }, initList[init]));
@ -87,6 +115,25 @@ return L.view.extend({
cbi_update_table(table, rows);
return table;
var view = E('div', {}, E('div', {}, [
E('div', { 'data-tab': 'init', 'data-tab-title': _('Initscripts') }, [
E('p', {}, _('You can enable or disable installed init scripts here. Changes will applied after a device reboot.<br /><strong>Warning: If you disable essential init scripts like "network", your device might become inaccessible!</strong>')),
table
]),
E('div', { 'data-tab': 'rc', 'data-tab-title': _('Local Startup') }, [
E('p', {}, _('This is the content of /etc/rc.local. Insert your own commands here (in front of \'exit 0\') to execute them at the end of the boot process.')),
E('p', {}, E('textarea', { 'style': 'width:100%', 'rows': 20 }, rcLocal != null ? rcLocal : '')),
E('div', { 'class': 'right' }, [
E('button', {
'class': 'btn cbi-button-positive important',
'click': L.ui.createHandlerFn(this, 'handleSave')
}, _('Save'))
])
])
]));
L.ui.tabs.initTabGroup(view.firstElementChild.childNodes);
return view;
}
});