From 3ea3361a8c17f35223854dd8b814e9220ffd0726 Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Tue, 31 Jan 2017 17:33:33 +0000 Subject: [WebUI] Fix symbols config --- interface/js/app/rspamd.js | 113 ++--------------------------------- interface/js/app/symbols.js | 141 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 146 insertions(+), 108 deletions(-) create mode 100644 interface/js/app/symbols.js (limited to 'interface') diff --git a/interface/js/app/rspamd.js b/interface/js/app/rspamd.js index fcf462dfd..e5d91495c 100644 --- a/interface/js/app/rspamd.js +++ b/interface/js/app/rspamd.js @@ -22,8 +22,9 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -define(['jquery', 'd3pie', 'visibility', 'app/stats', 'app/graph', 'app/config'], - function ($, d3pie, visibility, tab_stat, tab_graph, tab_config) { +define(['jquery', 'd3pie', 'visibility', 'app/stats', 'app/graph', 'app/config', + 'app/symbols'], + function ($, d3pie, visibility, tab_stat, tab_graph, tab_config, tab_symbols) { // begin var graphs = {}; var tables = {}; @@ -106,7 +107,7 @@ define(['jquery', 'd3pie', 'visibility', 'app/stats', 'app/graph', 'app/config'] tab_config.getMaps(interface); break; case "#symbols_nav": - getSymbols(); + tab_symbols.getSymbols(interface, tables, checked_server); break; case "#history_nav": getHistory(); @@ -196,6 +197,7 @@ define(['jquery', 'd3pie', 'visibility', 'app/stats', 'app/graph', 'app/config'] } }); tab_config.setup(interface); + tab_symbols.setup(interface, tables); }; interface.alertMessage = function (alertState, alertText) { @@ -625,108 +627,6 @@ define(['jquery', 'd3pie', 'visibility', 'app/stats', 'app/graph', 'app/config'] }); } - function decimalStep(number) { - var digits = ((+number).toFixed(20)).replace(/^-?\d*\.?|0+$/g, '').length; - if (digits === 0 || digits > 4) { - return 0.1; - } else { - return 1.0 / (Math.pow(10, digits)); - } - } - // @get symbols into modal form - function getSymbols() { - if (symbols) { - symbols.destroy(); - symbols = null; - $('#symbolsTable').children('tbody').remove(); - } - var items = []; - $.ajax({ - dataType: 'json', - type: 'GET', - url: 'symbols', - jsonp: false, - beforeSend: function (xhr) { - xhr.setRequestHeader('Password', getPassword()); - }, - success: function (data) { - $.each(data, function (i, group) { - $.each(group.rules, function (i, item) { - var max = 20; - var min = -20; - if (item.weight > max) { - max = item.weight * 2; - } - if (item.weight < min) { - min = item.weight * 2; - } - var label_class = ''; - if (item.weight < 0) { - label_class = 'scorebar-ham'; - } else { - label_class = 'scorebar-spam'; - } - - if (!item.time) { - item.time = 0; - } - if (!item.frequency) { - item.frequency = 0; - } - items.push('' + - '
' + group.group + '
' + - '' + item.symbol + '' + - '
' + item.description + '
' + - '' + - '' + item.frequency + '' + - '' + Number(item.time).toFixed(2) + 'ms' + - '' + - ''); - }); - }); - $('', { - html: items.join('') - }).insertAfter('#symbolsTable thead'); - symbols = $('#symbolsTable').DataTable({ - "paging": false, - "orderMulti": true, - "order": [ - [0, "asc"], - [1, "asc"], - [3, "desc"] - ], - "info": false, - "columns": [ - {"width": "7%", "searchable": true, "orderable": true}, - {"width": "20%", "searchable": true, "orderable": true}, - {"width": "30%", "searchable": false, "orderable": false}, - {"width": "7%", "searchable": false, "orderable": true, "type": "num"}, - {"searchable": false, "orderable": true, "type": "num"}, - {"searchable": false, "orderable": true, "type": "num"}, - {"width": "5%", "searchable": false, "orderable": false, "type": "html"}, - {"width": "7%", "searchable": false, "orderable": false, "type": "html"} - ], - }); - symbols.columns.adjust().draw(); - $('#symbolsTable :button').on('click', function() { - var value = $(this).attr("value"); - saveSymbols("./savesymbols", "symbolsTable", - value == 'Save cluster'); - }); - if (interface.read_only) { - $( ".mb-disabled" ).attr('disabled', true); - } - }, - error: function (data) { - alertMessage('alert-modal alert-error', data.statusText); - } - }); - } // @reset history log $('#resetHistory').on('click', function () { if (!confirm("Are you sure you want to reset history log?")) { @@ -762,9 +662,6 @@ define(['jquery', 'd3pie', 'visibility', 'app/stats', 'app/graph', 'app/config'] getErrors(); }); - $('#updateSymbols').on('click', function () { - getSymbols(); - }); // @upload text function uploadText(data, source, headers) { diff --git a/interface/js/app/symbols.js b/interface/js/app/symbols.js new file mode 100644 index 000000000..cead52dc7 --- /dev/null +++ b/interface/js/app/symbols.js @@ -0,0 +1,141 @@ +/* + The MIT License (MIT) + + Copyright (C) 2017 Vsevolod Stakhov + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. + */ + +define(['jquery', 'datatables'], +function($) { + var interface = {} + + function decimalStep(number) { + var digits = ((+number).toFixed(20)).replace(/^-?\d*\.?|0+$/g, '').length; + if (digits === 0 || digits > 4) { + return 0.1; + } else { + return 1.0 / (Math.pow(10, digits)); + } + } + // @get symbols into modal form + interface.getSymbols = function(rspamd, tables, checked_server) { + var symbols = tables.symbols + if (symbols) { + symbols.destroy(); + tables.symbols = undefined; + $('#symbolsTable').children('tbody').remove(); + } + + var items = []; + $.ajax({ + dataType: 'json', + type: 'GET', + url: 'symbols', + jsonp: false, + beforeSend: function (xhr) { + xhr.setRequestHeader('Password', rspamd.getPassword()); + }, + success: function (data) { + $.each(data, function (i, group) { + $.each(group.rules, function (i, item) { + var max = 20; + var min = -20; + if (item.weight > max) { + max = item.weight * 2; + } + if (item.weight < min) { + min = item.weight * 2; + } + var label_class = ''; + if (item.weight < 0) { + label_class = 'scorebar-ham'; + } else { + label_class = 'scorebar-spam'; + } + + if (!item.time) { + item.time = 0; + } + if (!item.frequency) { + item.frequency = 0; + } + items.push('' + + '
' + group.group + '
' + + '' + item.symbol + '' + + '
' + item.description + '
' + + '' + + '' + item.frequency + '' + + '' + Number(item.time).toFixed(2) + 'ms' + + '' + + ''); + }); + }); + $('', { + html: items.join('') + }).insertAfter('#symbolsTable thead'); + tables.symbols = $('#symbolsTable').DataTable({ + "paging": false, + "orderMulti": true, + "order": [ + [0, "asc"], + [1, "asc"], + [3, "desc"] + ], + "info": false, + "columns": [ + {"width": "7%", "searchable": true, "orderable": true}, + {"width": "20%", "searchable": true, "orderable": true}, + {"width": "30%", "searchable": false, "orderable": false}, + {"width": "7%", "searchable": false, "orderable": true, "type": "num"}, + {"searchable": false, "orderable": true, "type": "num"}, + {"searchable": false, "orderable": true, "type": "num"}, + {"width": "5%", "searchable": false, "orderable": false, "type": "html"}, + {"width": "7%", "searchable": false, "orderable": false, "type": "html"} + ], + }); + tables.symbols.columns.adjust().draw(); + $('#symbolsTable :button').on('click', function() { + var value = $(this).attr("value"); + saveSymbols(rspamd, "./savesymbols", "symbolsTable", + value == 'Save cluster'); + }); + if (rspamd.read_only) { + $( ".mb-disabled" ).attr('disabled', true); + } + }, + error: function (data) { + rspamd.alertMessage('alert-modal alert-error', data.statusText); + } + }); + }; + + interface.setup = function(rspamd, tables) { + $('#updateSymbols').on('click', function () { + interface.getSymbols(rspamd, tables); + }); + }; + + return interface; +}); \ No newline at end of file -- cgit v1.2.3