'require uci';
'require statistics.rrdtool as rrdtool';
-var pollFn = null,
- activePlugin = null,
- activeInstance = null;
+let pollFn = null;
+let activePlugin = null;
+let activeInstance = null;
return view.extend({
load() {
},
updatePluginTab(host, span, time, ev) {
- var container = ev.target,
- width = Math.max(200, container.offsetWidth - 100),
- plugin = ev.detail.tab,
- render_instances = [],
- plugin_instances = rrdtool.pluginInstances(host.value, plugin),
- cache = {};
+ const container = ev.target;
+ const width = Math.max(200, container.offsetWidth - 100);
+ const plugin = ev.detail.tab;
+ const render_instances = [];
+ const plugin_instances = rrdtool.pluginInstances(host.value, plugin);
+ const cache = {};
activePlugin = plugin;
])
]);
- for (var i = 0; i < plugin_instances.length; i++) {
+ for (let i = 0; i < plugin_instances.length; i++) {
if (rrdtool.hasInstanceDetails(host.value, plugin, plugin_instances[i])) {
render_instances.push([
plugin_instances[i],
Promise.all(render_instances.map(function(instance) {
if (instance[0] == '-') {
- var tasks = [];
+ const tasks = [];
- for (var i = 0; i < plugin_instances.length; i++)
+ for (let i = 0; i < plugin_instances.length; i++)
tasks.push(rrdtool.render(plugin, plugin_instances[i], true, host.value, span.value, width, null, cache));
return Promise.all(tasks).then(function(blobs) {
return rrdtool.render(plugin, instance[0], false, host.value, span.value, width, null, cache);
}
})).then(function(blobs) {
- var multiple = blobs.length > 1;
+ const multiple = blobs.length > 1;
dom.content(container, E('div', {}, blobs.map(function(blobs, i) {
- var plugin_instance = i ? render_instances[i][0] : plugin_instances.join('|'),
- title = render_instances[i][1];
+ const plugin_instance = i ? render_instances[i][0] : plugin_instances.join('|');
+ const title = render_instances[i][1];
return E('div', {
'class': 'center',
},
updateGraphs(host, span, time, container, ev) {
- var plugin_names = rrdtool.pluginNames(host.value);
+ const plugin_names = rrdtool.pluginNames(host.value);
container.querySelectorAll('img').forEach(function(img) {
URL.revokeObjectURL(img.src);
container.parentNode.removeChild(container.previousElementSibling);
}
- for (var i = 0; i < plugin_names.length; i++) {
+ for (let i = 0; i < plugin_names.length; i++) {
if (!rrdtool.hasDefinition(plugin_names[i]))
continue;
},
refreshGraphs(host, span, time, container) {
- var div = document.querySelector('[data-plugin="%s"][data-plugin-instance="%s"]'.format(activePlugin, activeInstance || '')),
- width = Math.max(200, container.offsetWidth - 100),
- render_instances = activeInstance.split(/\|/);
+ const div = document.querySelector('[data-plugin="%s"][data-plugin-instance="%s"]'.format(activePlugin, activeInstance || ''));
+ const width = Math.max(200, container.offsetWidth - 100);
+ const render_instances = activeInstance.split(/\|/);
return Promise.all(render_instances.map(function(render_instance) {
return rrdtool.render(activePlugin, render_instance || '', div.hasAttribute('data-is-index'), host.value, span.value, width);
}).then(function(blobs) {
return Promise.all(blobs.map(function(blob) {
return new Promise(function(resolveFn, rejectFn) {
- var img = E('img', { 'src': URL.createObjectURL(new Blob([blob], { type: 'image/png' })) });
+ const img = E('img', { 'src': URL.createObjectURL(new Blob([blob], { type: 'image/png' })) });
img.onload = function(ev) { resolveFn(img) };
img.onerror = function(ev) { resolveFn(img) };
});
while (div.childNodes.length > imgs.length)
div.removeChild(div.lastElementChild);
- for (var i = 0; i < imgs.length; i++) {
+ for (let i = 0; i < imgs.length; i++) {
if (i < div.childNodes.length) {
URL.revokeObjectURL(div.childNodes[i].src);
div.childNodes[i].src = imgs[i].src;
},
togglePolling(host, span, time, container, ev) {
- var btn = ev.currentTarget;
+ const btn = ev.currentTarget;
if (pollFn) {
poll.remove(pollFn);
},
render() {
- var hosts = rrdtool.hostInstances();
+ const hosts = rrdtool.hostInstances();
return hosts.length ? this.renderGraphs() : this.renderNoData();
},
},
renderGraphs() {
- var hostSel = E('select', { 'style': 'max-width:170px', 'data-name': 'host' }, rrdtool.hostInstances().map(function(host) {
+ const hostSel = E('select', { 'style': 'max-width:170px', 'data-name': 'host' }, rrdtool.hostInstances().map(function(host) {
return E('option', {
'selected': (rrdtool.opts.host == host) ? 'selected' : null
}, [ host ])
}));
- var spanSel = E('select', { 'style': 'max-width:170px', 'data-name': 'timespan' }, L.toArray(uci.get('luci_statistics', 'collectd_rrdtool', 'RRATimespans')).map(function(span) {
+ const spanSel = E('select', { 'style': 'max-width:170px', 'data-name': 'timespan' }, L.toArray(uci.get('luci_statistics', 'collectd_rrdtool', 'RRATimespans')).map(function(span) {
return E('option', {
'selected': (rrdtool.opts.timespan == span) ? 'selected' : null
}, [ span ])
}));
- var timeSel = E('select', { 'style': 'max-width:170px', 'data-name': 'refresh' }, [
+ const timeSel = E('select', { 'style': 'max-width:170px', 'data-name': 'refresh' }, [
E('option', { 'value': 0 }, [ _('Do not refresh') ]),
E('option', { 'value': 5 }, [ _('Every 5 seconds') ]),
E('option', { 'value': 30 }, [ _('Every 30 seconds') ]),
E('option', { 'value': 60 }, [ _('Every minute') ])
]);
- var graphDiv = E('div', { 'data-name': 'graphs' });
+ const graphDiv = E('div', { 'data-name': 'graphs' });
- var view = E([], [
+ const view = E([], [
E('h2', {}, [ _('Statistics') ]),
E('div', {}, [
E('p', { 'class': 'controls' }, [
requestAnimationFrame(L.bind(this.updateGraphs, this, hostSel, spanSel, timeSel, graphDiv));
- var resizeTimeout;
- var rgCallback = L.bind(this.refreshGraphs, this, hostSel, spanSel, timeSel, graphDiv);
+ let resizeTimeout;
+ const rgCallback = L.bind(this.refreshGraphs, this, hostSel, spanSel, timeSel, graphDiv);
addEventListener('resize', function() { clearTimeout(resizeTimeout); resizeTimeout = setTimeout(rgCallback, 250); });
return view;