From d61eba4cb4e0a29c446bbc3e80ea61169bc08e95 Mon Sep 17 00:00:00 2001 From: kingbri Date: Tue, 18 Jul 2023 01:09:00 -0400 Subject: [PATCH] Regex: Add script reordering The engine runs with a foreach, so the scripts run sequentially. Ideally, scripts should be one-liners, but if multiple scripts run in a chain, allow the user to reorder them. Signed-off-by: kingbri --- public/scripts/extensions/regex/index.js | 20 +++++++++++++++++++ .../extensions/regex/scriptTemplate.html | 1 + 2 files changed, 21 insertions(+) diff --git a/public/scripts/extensions/regex/index.js b/public/scripts/extensions/regex/index.js index cb84876ae..610fe5e09 100644 --- a/public/scripts/extensions/regex/index.js +++ b/public/scripts/extensions/regex/index.js @@ -236,5 +236,25 @@ jQuery(async () => { onRegexEditorOpenClick(false); }); + $('#saved_regex_scripts').sortable({ + stop: function () { + let newScripts = []; + $('#saved_regex_scripts').children().each(function () { + const scriptName = $(this).find(".regex_script_name").text(); + const existingScript = extension_settings.regex.find((e) => e.scriptName === scriptName); + if (existingScript) { + newScripts.push(existingScript); + } + }); + + extension_settings.regex = newScripts; + saveSettingsDebounced(); + + console.debug("Regex scripts reordered"); + // TODO: Maybe reload regex scripts after move + }, + }); + await loadRegexScripts(); + $("#saved_regex_scripts").sortable("enable"); }); diff --git a/public/scripts/extensions/regex/scriptTemplate.html b/public/scripts/extensions/regex/scriptTemplate.html index 382e20c48..6f2c758f8 100644 --- a/public/scripts/extensions/regex/scriptTemplate.html +++ b/public/scripts/extensions/regex/scriptTemplate.html @@ -1,4 +1,5 @@
+