]> git.ipfire.org Git - thirdparty/rspamd.git/commitdiff
[Minor] Use explicit class for colorizing ham/spam in Bayesian statistics table 5899/head
authorAlexander Moisseev <moiseev@mezonplus.ru>
Fri, 20 Feb 2026 19:18:37 +0000 (22:18 +0300)
committerAlexander Moisseev <moiseev@mezonplus.ru>
Fri, 20 Feb 2026 19:30:22 +0000 (22:30 +0300)
Use statfile.class field from /stat response to determine CSS class
for table cells instead of guessing from symbol name. Falls back to
symbol name matching for backward compatibility with older Rspamd.

interface/js/app/stats.js

index f45d9c7659ee6784cf2472df54d3036bb18c7a55..bd7a34ea6ad91d83f28d494341ea475237986d15 100644 (file)
@@ -204,7 +204,7 @@ define(["jquery", "app/common", "d3pie", "d3"],
 
             function addStatfiles(server, statfiles) {
                 const safeStatfiles = Array.isArray(statfiles) ? statfiles : [];
-                const symbolClassMap = {BAYES_SPAM: "symbol-positive", BAYES_HAM: "symbol-negative"};
+                const classToSymbolClass = {spam: "symbol-positive", ham: "symbol-negative"};
                 const rowsCount = safeStatfiles.length;
 
                 function coerceNumber(value) { return (Number.isFinite(value) ? value : Number(value) || 0); }
@@ -237,7 +237,8 @@ define(["jquery", "app/common", "d3pie", "d3"],
 
                 $.each(safeStatfiles, (i, statfile) => {
                     const symbol = statfile.symbol ?? "-";
-                    const cls = symbolClassMap[symbol] || "";
+                    const classValue = statfile.class ?? guessClassFromSymbol(symbol);
+                    const cls = classToSymbolClass[classValue] || "";
                     const clName = statfile.classifier?.name ?? "-";
                     const prevClName = i > 0 ? (safeStatfiles[i - 1].classifier?.name ?? "-") : null;
 
@@ -255,7 +256,7 @@ define(["jquery", "app/common", "d3pie", "d3"],
                     }
 
                     $("#bayesTable tbody").append(`<tr>${serverCell}${classifierCell}${[
-                        renderCell(common.escapeHTML(statfile.class ?? guessClassFromSymbol(symbol)), cls),
+                        renderCell(common.escapeHTML(classValue), cls),
                         renderCell(common.escapeHTML(symbol), cls),
                         renderCell(common.escapeHTML(statfile.type ?? "-"), cls),
                         renderCell(coerceNumber(statfile.revision), `text-end ${cls}`),