From 9b36247f8f4f5d6416f080ee7128008b18c4a21b Mon Sep 17 00:00:00 2001 From: peregrineshahin <41402573+peregrineshahin@users.noreply.github.com> Date: Thu, 11 Jul 2024 11:31:06 +0300 Subject: [PATCH] Use an IIFE to Reduce Global Scope Pollution --- server/fishtest/static/js/application.js | 10 +- server/fishtest/static/js/spsa.js | 2 +- server/fishtest/templates/contributors.mak | 3 +- server/fishtest/templates/tests.mak | 134 +-- server/fishtest/templates/tests_live_elo.mak | 8 +- server/fishtest/templates/tests_run.mak | 684 ++++++------ server/fishtest/templates/tests_view.mak | 973 +++++++++--------- server/fishtest/templates/user.mak | 40 +- server/fishtest/templates/user_management.mak | 41 +- server/fishtest/templates/workers.mak | 98 +- 10 files changed, 993 insertions(+), 1000 deletions(-) diff --git a/server/fishtest/static/js/application.js b/server/fishtest/static/js/application.js index d1fa8e0f3..ccfa51c5d 100644 --- a/server/fishtest/static/js/application.js +++ b/server/fishtest/static/js/application.js @@ -375,8 +375,7 @@ function padDotVersionStr(dn) { } // Filters tables client-side -function filterTable(inputValue, tableId, originalRows, predicate) { - const table = document.getElementById(tableId); +function filterTable(inputValue, table, originalRows, predicate) { const tbody = table.querySelector("tbody"); let noDataRow = table.querySelector(".no-data"); inputValue = inputValue.toLowerCase(); @@ -442,13 +441,12 @@ function filterTable(inputValue, tableId, originalRows, predicate) { }); }; - const originalTable = document - .getElementById("my_table") - .cloneNode(true); + const originalTable = document.getElementById("my_table").cloneNode(true); const originalRows = Array.from(originalTable.querySelectorAll("tbody tr")); - const searchInput = document.getElementById("my_input"); + searchInput.addEventListener("input", (e) => { + const myTable = document.getElementById("my_table"); filterTable(e.target.value, "my_table", originalRows, myPredicate); }); })(); diff --git a/server/fishtest/static/js/spsa.js b/server/fishtest/static/js/spsa.js index 575f6a602..e9d20c7f8 100644 --- a/server/fishtest/static/js/spsa.js +++ b/server/fishtest/static/js/spsa.js @@ -1,4 +1,4 @@ -async function handleSPSA() { +async function handleSPSA(spsaData) { let raw = [], chart_object, chart_data, diff --git a/server/fishtest/templates/contributors.mak b/server/fishtest/templates/contributors.mak index b619c2413..b030ff82e 100644 --- a/server/fishtest/templates/contributors.mak +++ b/server/fishtest/templates/contributors.mak @@ -29,7 +29,8 @@ const searchInput = document.getElementById("search_contributors"); searchInput.addEventListener("input", (e) => { - filterTable(e.target.value, "contributors_table", originalRows, includes); + const contributorsTable = document.getElementById("contributors_table"); + filterTable(e.target.value, contributorsTable, originalRows, includes); }); })(); diff --git a/server/fishtest/templates/tests.mak b/server/fishtest/templates/tests.mak index 3e486fed7..9dade538e 100644 --- a/server/fishtest/templates/tests.mak +++ b/server/fishtest/templates/tests.mak @@ -47,72 +47,6 @@ - -