diff options
author | Florian Eckert <fe@dev.tdt.de> | 2021-11-25 11:13:57 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-11-25 11:13:57 +0300 |
commit | f737635e0fe7cfe0017f9049f02dd2351b8e6e12 (patch) | |
tree | 464a662dd3a7fccb280fd85fd0c7001dd5191ae3 | |
parent | 6c71c59e18827e158bdff0c92a9064c84cfa1ddb (diff) | |
parent | f09920f21ac05d37a4cbf2edff76a3f08e9c7c8e (diff) |
Merge pull request #5546 from TDT-AG/pr/20211124-luci-mod-status
luci-mod-status: add diskfree info
-rw-r--r-- | modules/luci-mod-status/htdocs/luci-static/resources/view/status/include/25_diskfree.js | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/modules/luci-mod-status/htdocs/luci-static/resources/view/status/include/25_diskfree.js b/modules/luci-mod-status/htdocs/luci-static/resources/view/status/include/25_diskfree.js new file mode 100644 index 0000000000..df6beac0b6 --- /dev/null +++ b/modules/luci-mod-status/htdocs/luci-static/resources/view/status/include/25_diskfree.js @@ -0,0 +1,51 @@ +'use strict'; +'require baseclass'; +'require rpc'; + +var callSystemInfo = rpc.declare({ + object: 'system', + method: 'info' +}); + +function progressbar(value, max, byte) { + var vn = parseInt(value) || 0, + mn = parseInt(max) || 100, + fv = byte ? String.format('%1024.2mB', value) : value, + fm = byte ? String.format('%1024.2mB', max) : max, + pc = Math.floor((100 / mn) * vn); + + return E('div', { + 'class': 'cbi-progressbar', + 'title': '%s / %s (%d%%)'.format(fv, fm, pc) + }, E('div', { 'style': 'width:%.2f%%'.format(pc) })); +} + +return baseclass.extend({ + title: _('Storage usage'), + + load: function() { + return L.resolveDefault(callSystemInfo(), {}); + }, + + render: function(systeminfo) { + var root = L.isObject(systeminfo.root) ? systeminfo.root : {}, + tmp = L.isObject(systeminfo.tmp) ? systeminfo.tmp : {}; + + var fields = []; + fields.push(_('Disk space'), root.used*1024, root.total*1024); + fields.push(_('Temp space'), tmp.used*1024, tmp.total*1024); + + var table = E('table', { 'class': 'table' }); + + for (var i = 0; i < fields.length; i += 3) { + table.appendChild(E('tr', { 'class': 'tr' }, [ + E('td', { 'class': 'td left', 'width': '33%' }, [ fields[i] ]), + E('td', { 'class': 'td left' }, [ + (fields[i + 1] != null) ? progressbar(fields[i + 1], fields[i + 2], true) : '?' + ]) + ])); + } + + return table; + } +}); |