]> git.ipfire.org Git - thirdparty/rspamd.git/commitdiff
[Minor] Refactor switch statements to object lookups 5797/head
authorAlexander Moisseev <moiseev@mezonplus.ru>
Sat, 13 Dec 2025 10:40:01 +0000 (13:40 +0300)
committerAlexander Moisseev <moiseev@mezonplus.ru>
Sat, 13 Dec 2025 10:40:01 +0000 (13:40 +0300)
interface/js/app/rspamd.js
interface/js/app/selectors.js
interface/js/app/stats.js

index 8aa288ac5d07b0a5bfcf915f61260b0f4edc7924..55cfface176a83447df09ac80b8348ea4a5c50ff 100644 (file)
@@ -354,17 +354,8 @@ define(["jquery", "app/common", "stickytabs", "visibility",
         const icon = $("#theme-icon");
         icon.removeClass("fa-moon fa-sun fa-display");
 
-        switch (theme) {
-            case "light":
-                icon.addClass("fa-sun");
-                break;
-            case "dark":
-                icon.addClass("fa-moon");
-                break;
-            default:
-                icon.addClass("fa-display");
-                break;
-        }
+        const iconMap = {light: "fa-sun", dark: "fa-moon", auto: "fa-display"};
+        icon.addClass(iconMap[theme] || "fa-display");
     }
 
     (function initSettings() {
@@ -523,21 +514,9 @@ define(["jquery", "app/common", "stickytabs", "visibility",
     $("#theme-toggle").on("click", (e) => {
         e.preventDefault();
         const currentTheme = localStorage.getItem("theme") || "auto";
-        // eslint-disable-next-line no-useless-assignment
-        let newTheme = null;
-
         // Cycle through: light -> dark -> auto -> light
-        switch (currentTheme) {
-            case "light":
-                newTheme = "dark";
-                break;
-            case "dark":
-                newTheme = "auto";
-                break;
-            default:
-                newTheme = "light";
-                break;
-        }
+        const themeMap = {light: "dark", dark: "auto", auto: "light"};
+        const newTheme = themeMap[currentTheme] || "light";
 
         if (window.rspamd && window.rspamd.theme) {
             window.rspamd.theme.applyPreference(newTheme);
index 6b287d693558d90967faa3b9e6fed7f5e73333a0..637a595253416f00c77c24065011fbcf153bbf67 100644 (file)
@@ -90,18 +90,10 @@ define(["jquery", "app/common"],
 
         function toggleSidebar(side) {
             $("#sidebar-" + side).toggleClass("collapsed");
-            let contentClass = "col-lg-6";
             const openSidebarsCount = $("#sidebar-left").hasClass("collapsed") +
                 $("#sidebar-right").hasClass("collapsed");
-            switch (openSidebarsCount) {
-                case 1:
-                    contentClass = "col-lg-9";
-                    break;
-                case 2:
-                    contentClass = "col-lg-12";
-                    break;
-                default:
-            }
+            const layoutMap = {1: "col-lg-9", 2: "col-lg-12"};
+            const contentClass = layoutMap[openSidebarsCount] || "col-lg-6";
             $("#content").removeClass("col-lg-12 col-lg-9 col-lg-6")
                 .addClass(contentClass);
         }
index a236d8d4d0de24d1f8b8bb4377ba6ef766f64e9d..42b1803760d829da44ad8d9f571c0707bbee958a 100644 (file)
@@ -223,16 +223,8 @@ define(["jquery", "app/common", "d3pie", "d3"],
 
             function addStatfiles(server, statfiles) {
                 $.each(statfiles, (i, statfile) => {
-                    let cls = "";
-                    switch (statfile.symbol) {
-                        case "BAYES_SPAM":
-                            cls = "symbol-positive";
-                            break;
-                        case "BAYES_HAM":
-                            cls = "symbol-negative";
-                            break;
-                        default:
-                    }
+                    const symbolClassMap = {BAYES_SPAM: "symbol-positive", BAYES_HAM: "symbol-negative"};
+                    const cls = symbolClassMap[statfile.symbol] || "";
                     $("#bayesTable tbody").append("<tr>" +
                       (i === 0 ? '<td rowspan="' + statfiles.length + '">' + server + "</td>" : "") +
                       '<td class="' + cls + '">' + statfile.symbol + "</td>" +