From 4755206cf264042a1db7b38001df6d8b834e0ed4 Mon Sep 17 00:00:00 2001 From: Alexander Moisseev Date: Mon, 9 Jan 2017 19:10:38 +0300 Subject: [WebUI] Fix graph selectors state resetting on reconnect / reload Reported by: @denhli --- interface/js/rspamd.js | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/interface/js/rspamd.js b/interface/js/rspamd.js index be757ce4d..9ce9c76cb 100644 --- a/interface/js/rspamd.js +++ b/interface/js/rspamd.js @@ -37,11 +37,11 @@ var checked_server = "All SERVERS"; var timer_id = []; - var selected = []; // Keep graph selectors state + var selData; // Graph's dataset selector state // Bind event handlers to selectors $("#selData").change(function () { - selected.selData = this.value; + selData = this.value; tabClick("#throughput_nav"); }); $("#selConvert").change(function () { @@ -107,13 +107,13 @@ getChart(); break; case "#throughput_nav": - getGraphData(selected.selData); + getGraphData(selData); const autoRefresh = { hourly: 60000, daily: 300000 }; - timer_id.throughput = Visibility.every(autoRefresh[selected.selData] || 3600000, function () { - getGraphData(selected.selData); + timer_id.throughput = Visibility.every(autoRefresh[selData] || 3600000, function () { + getGraphData(selData); }); break; case "#configuration_nav": @@ -654,10 +654,6 @@ height: 370, yAxisLabel: "Message rate, msg/s", - type: selected.selType, - interpolate: selected.selInterpolate, - convert: selected.selConvert, - legend: { space: 140, entries: [{ @@ -684,13 +680,18 @@ function initGraph() { // Get selectors' current state - var selIds = ["selData", "selConvert", "selType", "selInterpolate"]; - selIds.forEach(function (id) { + function getSelector(id) { var e = document.getElementById(id); - selected[id] = e.options[e.selectedIndex].value; - }); + return e.options[e.selectedIndex].value; + } + + selData = getSelector("selData"); - graph = new D3Evolution("graph", graph_options); + graph = new D3Evolution("graph", $.extend({}, graph_options, { + type: getSelector("selType"), + interpolate: getSelector("selInterpolate"), + convert: getSelector("selConvert"), + })); } function getRrdSummary(json) { -- cgit v1.2.3