mirror of
https://github.com/openwrt/luci.git
synced 2026-05-31 10:31:55 +08:00
luci-app-vnstat2: correctness fixes
Signed-off-by: Paul Donald <newtwen+github@gmail.com>
This commit is contained in:
@@ -8,9 +8,22 @@
|
|||||||
'require uci';
|
'require uci';
|
||||||
'require rpc';
|
'require rpc';
|
||||||
|
|
||||||
var RefreshIfaces = "";
|
var RefreshIfaces = [];
|
||||||
var RefreshTabs = ['s', 't', '5', 'h', 'd', 'm', 'y'];
|
var RefreshTabs = ['s', 't', '5', 'h', 'd', 'm', 'y'];
|
||||||
|
|
||||||
|
function setBlobImage(srcImg, blob) {
|
||||||
|
const prev = srcImg.src;
|
||||||
|
const next = URL.createObjectURL(blob);
|
||||||
|
|
||||||
|
srcImg.onload = function() {
|
||||||
|
if (prev && prev.startsWith('blob:'))
|
||||||
|
URL.revokeObjectURL(prev);
|
||||||
|
srcImg.onload = null;
|
||||||
|
};
|
||||||
|
|
||||||
|
srcImg.src = next;
|
||||||
|
}
|
||||||
|
|
||||||
const callServiceList = rpc.declare({
|
const callServiceList = rpc.declare({
|
||||||
object: 'service',
|
object: 'service',
|
||||||
method: 'list',
|
method: 'list',
|
||||||
@@ -24,7 +37,9 @@ function RefreshGraphs() {
|
|||||||
RefreshTabs.forEach(function (id) {
|
RefreshTabs.forEach(function (id) {
|
||||||
RefreshIfaces.forEach(function (iface) {
|
RefreshIfaces.forEach(function (iface) {
|
||||||
fs.exec_direct('/usr/bin/vnstati', [ '-' + id, '-i', iface, '-o', '-' ], 'blob').then(function(res) {
|
fs.exec_direct('/usr/bin/vnstati', [ '-' + id, '-i', iface, '-o', '-' ], 'blob').then(function(res) {
|
||||||
document.getElementById('graph_' + id + '_' + iface).src = URL.createObjectURL(res);
|
var img = document.getElementById('graph_' + id + '_' + iface);
|
||||||
|
if (img)
|
||||||
|
setBlobImage(img, res);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -74,7 +89,7 @@ return view.extend({
|
|||||||
ifaces.forEach(function(iface) {
|
ifaces.forEach(function(iface) {
|
||||||
fs.exec_direct('/usr/bin/vnstati', [ '-'+style, '-i', iface, '-o', '-' ], 'blob').then(function(res) {
|
fs.exec_direct('/usr/bin/vnstati', [ '-'+style, '-i', iface, '-o', '-' ], 'blob').then(function(res) {
|
||||||
var img = tab.querySelector('img[data-iface="%s"]'.format(iface));
|
var img = tab.querySelector('img[data-iface="%s"]'.format(iface));
|
||||||
img.src = URL.createObjectURL(res);
|
setBlobImage(img, res);
|
||||||
img.alt = _('Could not load graph, no data available: ') + iface;
|
img.alt = _('Could not load graph, no data available: ') + iface;
|
||||||
img.align = 'middle';
|
img.align = 'middle';
|
||||||
img.style.visibility = 'visible';
|
img.style.visibility = 'visible';
|
||||||
|
|||||||
Reference in New Issue
Block a user