1
0

files.js 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. 'use strict';
  2. 'require fs';
  3. 'require view';
  4. return view.extend({
  5. load: function() {
  6. var list_files = ['conf', 'session'],
  7. actions = [];
  8. for (var index = 0; index < list_files.length; ++index) {
  9. actions.push(
  10. fs.exec_direct('/usr/libexec/aria2-call', [ 'cat', list_files[index] ])
  11. .then(function(json) {
  12. var res = {};
  13. try { res = JSON.parse(json); }
  14. catch(err) {}
  15. res.file = res.file || '';
  16. res.content = 'content' in res ? res.content.trim() : '';
  17. res.rows = res.content.split('\n', 20).length;
  18. return res;
  19. })
  20. );
  21. }
  22. return Promise.all(actions);
  23. },
  24. render: function(data) {
  25. var textareaEl = function(id, data, descr) {
  26. return E('div', {'class': 'cbi-section'}, [
  27. E('div', {'class': 'cbi-section-descr'}, descr.format(data.file)),
  28. E('div', { 'id' : id},
  29. E('textarea', {
  30. 'id': 'widget.' + id,
  31. 'style': 'width: 100%',
  32. 'readonly': true,
  33. 'wrap': 'off',
  34. 'rows': data.rows >= 20 ? 20 : data.rows + 1
  35. }, data.content)
  36. )
  37. ]);
  38. };
  39. return E('div', {'class': 'cbi-map'}, [
  40. E('h2', {'name': 'content'}, '%s - %s'.format(_('Aria2'), _('Files'))),
  41. E('div', {'class': 'cbi-map-descr'}, _('Here shows the files used by aria2.')),
  42. textareaEl('config_area', data[0], _('Content of config file: <code>%s</code>')),
  43. textareaEl('session_area', data[1], _('Content of session file: <code>%s</code>'))
  44. ]);
  45. },
  46. handleSave: null,
  47. handleSaveApply: null,
  48. handleReset: null
  49. });