From 30694569ca45e9b27fac441869dd31475718b4c8 Mon Sep 17 00:00:00 2001 From: Corban-Lee Jones Date: Wed, 10 Jul 2024 21:20:53 +0100 Subject: [PATCH] load filter algorithms from api via options --- apps/static/js/api.js | 4 ++ apps/static/js/home/filters.js | 41 +++++++++---------- apps/templates/home/includes/filtermodal.html | 6 +-- apps/templates/home/includes/servermodal.html | 2 +- 4 files changed, 27 insertions(+), 26 deletions(-) diff --git a/apps/static/js/api.js b/apps/static/js/api.js index f658592..2290926 100644 --- a/apps/static/js/api.js +++ b/apps/static/js/api.js @@ -122,6 +122,10 @@ async function editFilter(id, formData) { return await ajaxRequest(`/api/filter/${id}/`, "PUT", formData); } +async function getFilterOptions() { + return await ajaxRequest("/api/filter/", "OPTIONS") +} + // Tracked Content diff --git a/apps/static/js/home/filters.js b/apps/static/js/home/filters.js index 802d59e..0a356cf 100644 --- a/apps/static/js/home/filters.js +++ b/apps/static/js/home/filters.js @@ -189,11 +189,11 @@ async function loadFilters(guildId, page=1, pageSize=null) { } } -$(document).ready(function() { - loadMatchingAlgorithms(); +$(document).ready(async function() { + await loadMatchingAlgorithms(); }); -function loadMatchingAlgorithms() { +async function loadMatchingAlgorithms() { // Disable input while options are loading $("#filterAlgorithm").prop("disabled", true); @@ -206,25 +206,22 @@ function loadMatchingAlgorithms() { // Clear select2 input $("#filterAlgorithm").val("").change(); - algorithms = [ - {id: "", name: "None"}, - {id: 1, name: "Any Words"}, - {id: 2, name: "All Words"}, - {id: 3, name: "Exact Match"}, - {id: 4, name: "Regular Expression"}, - {id: 5, name: "Fuzzy Match"}, - ] - - algorithms.forEach(algorithm => { - $("#filterAlgorithm").append($("