]> source.dussan.org Git - rspamd.git/commitdiff
[WebUI] Rework symbols scores
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Tue, 1 Nov 2016 09:14:44 +0000 (09:14 +0000)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Tue, 1 Nov 2016 09:14:44 +0000 (09:14 +0000)
interface/index.html
interface/js/rspamd.js

index efdf783c8bce478827f55dcb2338c1dfc5b6783c..17f14738f77848596d7811b6e2642a3e972226df 100644 (file)
@@ -29,6 +29,7 @@
                        <li role="presentation"><a id="throughput_nav" aria-controls="throughput" role="tab" href="#throughput" data-toggle="tab">Throughput</a></li>
 
                        <li role="presentation"><a id="configuration_nav" aria-controls="configuration" role="tab" href="#configuration" data-toggle="tab">Configuration</a></li>
+                       <li role="presentation"><a id="symbols_nav" aria-controls="symbols" role="tab" href="#symbols" data-toggle="tab">Symbols</a></li>
                        <li role="presentation"><a id="learning_nav" aria-controls="learning" role="tab" href="#learning" data-toggle="tab">Learning</a></li>
                        <li role="presentation"><a id="scan_nav"aria-controls="scan" role="tab"  href="#scan" data-toggle="tab">Scan</a></li>
                        <li role="presentation"><a id="history_nav" aria-controls="history" role="tab" href="#history" data-toggle="tab">History</a></li>
                                </div>
                                <div class="widget-box">
                                        <div class="widget-title">
-                                               <span class="icon"><i class="glyphicon glyphicon-filter"></i></span><h5>Rules</h5>
+                                               <span class="icon"><i class="glyphicon glyphicon-list"></i></span><h5>Lists</h5>
                                        </div>
-                                       <div class="widget-content">
-                                               <button role="button" class="btn btn-primary"
-                                                               data-toggle="modal"
-                                                               data-source="#symbolsForm"
-                                                               data-target="#modalDialog"
-                                                               data-title="Symbols">Edit Rules</button>
+                                       <div class="widget-content nopadding">
+                                               <table class="table table-condensed table-hover" id="listMaps">
+                                               </table>
                                        </div>
                                </div>
+                       </div>
+
+                       <div class="tab-pane" id="symbols">
                                <div class="widget-box">
                                        <div class="widget-title">
-                                               <span class="icon"><i class="glyphicon glyphicon-list"></i></span><h5>Lists</h5>
+                                               <div class="buttons pull-right">
+                                                       <button class="btn btn-info btn-sm" id="refreshSymbols">
+                                                               <i class="glyphicon glyphicon-refresh"></i> Update
+                                                       </button>
+                                               </div>
+                                               <span class="icon"><i class="glyphicon glyphicon-filters"></i></span>
+                                               <h5>Symbols and rules</h5>
                                        </div>
                                        <div class="widget-content nopadding">
-                                               <table class="table table-condensed table-hover" id="listMaps">
+                                               <table class="table table-log table-hover" id="symbolsTable">
+                                                       <thead>
+                                                               <th class="col1" title="Symbol">Symbol name</th>
+                                                               <th class="col2" title="Group">Group</th>
+                                                               <th class="col2" title="Description">Description</th>
+                                                               <th class="col3" title="Score">Score</th>
+                                                               <th class="col4" title="Hits">Hits</th>
+                                                               <th class="col5" title="Avg. time">Avg. time</th>
+                                                               <th class="col6" title=""></th>
+                                                       </thead>
                                                </table>
                                        </div>
                                </div>
 
                        </div>
 
-
                </div>
        </div>
 
index 7bb7cdf98be4e4675904a03aca3e278da9275b26..7cd267da11d916e42681776e3e98e56a2be2a8f6 100644 (file)
@@ -29,6 +29,7 @@
         var pie;
         var history;
         var graph;
+        var symbols;
 
         var selected = []; // Keep graph selectors state
 
             if (history) {
                 history.destroy();
             }
+            if (symbols) {
+                symbols.destroy();
+                symbols = null;
+            }
             cleanCredentials();
             connectRSPAMD();
             // window.location.reload();
             }
             $('#statWidgets').empty();
             $('#listMaps').empty();
-            $('#historyLog tbody').remove();
             $('#modalBody').empty();
+            $('#historyLog tbody').remove();
+            $('#symbolsTable tbody').remove();
             password = '';
         }
         function isLogged() {
             }
             if (mode === 'update') {
                 $('#modalBody').empty();
-                getSymbols();
+                getMaps();
             }
             $.each(data, function (i, item) {
                 $.ajax({
 
                         items.push(
                             '<tr><td data-order="' + item.unix_time + '">' + item.time + '</td>' +
-                            '<td data-order="' + item.id + '"><div class="cell-overflow" tabindex="1" title="' + item.id + '">' + item.id + '</td>' +
+                            '<td data-order="' + item.id + '"><div class="cell-overflow" tabindex="1" title="' + item.id + '">' + item.id + '</div></td>' +
                             '<td data-order="' + item.ip + '"><div class="cell-overflow" tabindex="1" title="' + item.ip + '">' + item.ip + '</div></td>' +
                             '<td data-order="' + item.action + '"><span class="label ' + action + '">' + item.action + '</span></td>' +
                             '<td data-order="' + item.score + '"><span class="label ' + score + '">' + item.score.toFixed(2) + ' / ' + item.required_score.toFixed(2) + '</span></td>' +
         }
         // @get symbols into modal form
         function getSymbols() {
+            var symbols_length = 50;
+
+            if (symbols) {
+                var sl = document.getElementsByName('symbols_length')[0];
+                if (sl !== undefined) {
+                  symbols_length = parseInt(sl.value);
+                } else {
+                  symbols_length = 50;
+                }
+                symbols.destroy();
+                symbols = null;
+                $('#symbolsTable').children('tbody').remove();
+            }
             var items = [];
             $.ajax({
                 dataType: 'json',
                     xhr.setRequestHeader('Password', getPassword());
                 },
                 success: function (data) {
-                    $('#modalBody').empty();
-                    data.sort(function(a, b) {
-                        return a.group.localeCompare(b.group);
-                    });
                     $.each(data, function (i, group) {
-                        items.push('   <div class="row row-bordered" data-slider="hover">' +
-                            '<h4>' + group.group + '</h4>' +
-                            '</div>');
-                        group.rules.sort(function(a, b) {
-                            return a.symbol.localeCompare(b.symbol);
-                        });
                         $.each(group.rules, function (i, item) {
                             var max = 20;
                             var min = -20;
                             if (item.weight < min) {
                                 min = item.weight * 2;
                             }
-                            items.push('       <div class="row row-bordered" data-slider="hover">' +
-                                '<label class="col-md-7" for="' + item.symbol + '" title="' + item.description + '">' +
-                                '<code>' + item.symbol + '</code><p class="symbol-description">' + item.description + '</p>' +
-                                '</label>' +
-                                '<div class="col-md-3 spin-cell">' +
-                                '<input class="numeric" data-role="numerictextbox" autocomplete="off" "type="number" class="input-mini" min="' +
+                            item.time = 0;
+                            item.frequency = 0;
+                            items.push('<tr>' +
+                                '<td data-order="' + item.symbol + '">' + item.symbol + '</td>' +
+                                '<td data-order="' + group.group + '"><div class="cell-overflow" tabindex="1" title="' + group.group + '">' + group.group + '</div></td>' +
+                                '<td data-order="' + item.description + '"><div class="cell-overflow" tabindex="1" title="' + item.description + '">' + item.description + '</div></td>' +
+                                '<td data-order="' + item.weight + '"><input class="numeric" data-role="numerictextbox" autocomplete="off" "type="number" class="input" min="' +
                                 min + '" max="' +
                                 max + '" step="' + decimalStep(item.weight) +
                                 '" tabindex="1" value="' + Number(item.weight).toFixed(2) +
                                 '" id="' + item.symbol + '">' +
-                                '</div>' +
-                                '</div>');
+                                '</td>' +
+                                '<td data-order="' + item.frequency + '">' + item.frequency + '</td>' +
+                                '<td data-order="' + item.time + '">' + Number(item.time).toFixed(2) + 'ms</td>' +
+                                '<td></td>' +
+                                '</tr>');
                         });
                     });
-                    $('<form/>', {
-                        id: 'symbolsForm',
-                        method: 'post',
-                        action: '/savesymbols',
-                        'data-type': 'symbols',
-                        style: 'display:none',
-                        html: items.join('') }).appendTo('#modalBody');
+                    $('<tbody/>', { html: items.join('') }).insertAfter('#symbolsTable thead');
+                    symbols = $('#symbolsTable').DataTable({
+                        "aLengthMenu": [[100, 200, -1], [100, 200, "All"]],
+                        "bStateSave": true,
+                        "orderMulti": true,
+                        "order": [[ 1, "asc" ], [0, "asc"], [3, "desc"]],
+                        "pageLength": symbols_length
+                    });
                 },
                 error: function (data) {
                     alertMessage('alert-modal alert-error', data.statusText);
         $('#configuration_nav').bind('click', function (e) {
             getActions();
             getMaps();
-            getSymbols();
         });
 
         $(document).ajaxStart(function () {
         $('#history_nav').bind('click', function() {
             getHistory();
         });
+        $('#symbols_nav').bind('click', function() {
+            getSymbols();
+        });
     });
 })();