]> source.dussan.org Git - rspamd.git/commitdiff
[WebUI] Add preliminary save symbols clustering
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Mon, 30 Jan 2017 23:37:38 +0000 (23:37 +0000)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Mon, 30 Jan 2017 23:37:38 +0000 (23:37 +0000)
interface/index.html
interface/js/rspamd.js

index 11a0f3f5a89e07a026a17c03bd2373369a1c5165..d8f6e8c704a03eb4816914444d476f8d1c4dde07 100644 (file)
                                                                        <th title="Symbol">Symbol</th>
                                                                        <th title="Description">Description</th>
                                                                        <th title="Score">Score</th>
-                                                                       <th title="Hits">Hits</th>
+                                                                       <th title="Frequency">Frequency</th>
                                                                        <th title="Avg.time">Avg.time</th>
                                                                        <th title="Save data">Save data</th>
+                                                                       <th title="Save cluster">Save cluster</th>
                                                                </tr>
                                                        </thead>
                                                </table>
index ad0f5ce5f30270d122281189918814e015455790..5e2b5bfa725efb30d78b73170a1ad8552fedb6bf 100644 (file)
                                 '" id="_sym_' + item.symbol + '"></span></td>' +
                                 '<td data-order="' + item.frequency + '">' + item.frequency + '</td>' +
                                 '<td data-order="' + item.time + '">' + Number(item.time).toFixed(2) + 'ms</td>' +
-                                '<td><button type="button" class="btn btn-primary btn-sm mb-disabled">Save</button></td></tr>');
+                                '<td><button type="button" class="btn btn-primary btn-sm mb-disabled">Save</button></td>' +
+                                '<td><button type="button" class="btn btn-primary btn-sm mb-disabled">Save cluster</button></td></tr>');
                         });
                     });
                     $('<tbody/>', {
                             {"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": "5%", "searchable": false, "orderable": false, "type": "html"},
+                            {"width": "7%", "searchable": false, "orderable": false, "type": "html"}
                         ],
                     });
                     symbols.columns.adjust().draw();
-                    $('#symbolsTable :button').on('click',
-                        function(){saveSymbols("./savesymbols", "symbolsTable");});
+                    $('#symbolsTable :button').on('click', function() {
+                        var value = $(this).attr("value");
+                        saveSymbols("./savesymbols", "symbolsTable",
+                                value == 'Save cluster');
+                    });
                   if (read_only) {
                     $( ".mb-disabled" ).attr('disabled', true);
                   }
         }
 
         // @upload symbols from modal
-        function saveSymbols(action, id) {
+        function saveSymbols(action, id, is_cluster) {
             var inputs = $('#' + id + ' :input[data-role="numerictextbox"]');
             var url = action;
             var values = [];
                     value: parseFloat($(this).val())
                 });
             });
-            $.ajax({
-                data: JSON.stringify(values),
-                dataType: 'json',
-                type: 'POST',
-                url: url,
-                jsonp: false,
-                beforeSend: function (xhr) {
-                    xhr.setRequestHeader('Password', getPassword());
-                },
-                success: function () {
+            if (is_cluster) {
+                queryNeighbours(url, function () {
                     alertMessage('alert-modal alert-success', 'Symbols successfully saved');
-                },
-                error: function (data) {
-                    alertMessage('alert-modal alert-error', data.statusText);
-                }
-            });
-            $('#modalDialog').modal('hide');
-            return false;
+                }, function (serv, qXHR, textStatus, errorThrown) {
+                    alertMessage('alert-modal alert-error',
+                            'Save symbols error on ' +
+                            serv.name + ': ' + errorThrown);
+                }, "POST", {}, {
+                    data: JSON.stringify(values),
+                    dataType: "json",
+                });
+            }
+            else {
+                $.ajax({
+                    data: JSON.stringify(values),
+                    dataType: 'json',
+                    type: 'POST',
+                    url: url,
+                    jsonp: false,
+                    beforeSend: function (xhr) {
+                        xhr.setRequestHeader('Password', getPassword());
+                    },
+                    success: function () {
+                        alertMessage('alert-modal alert-success', 'Symbols successfully saved');
+                    },
+                    error: function (data) {
+                        alertMessage('alert-modal alert-error', data.statusText);
+                    }
+                });
+            }
         }
         // @connect to server
         function connectRSPAMD() {