From 1bf47d8220bb5d5d974b28fa35c84524a8969881 Mon Sep 17 00:00:00 2001 From: LD-Reborn Date: Thu, 18 Dec 2025 22:32:57 +0100 Subject: [PATCH] Made settings a proper checkbox (single setting), fixed other issues regarding settings getting and setting --- .../Controllers/SearchdomainController.cs | 30 ++++++- src/Server/Searchdomain.cs | 18 +++- src/Server/Views/Home/Index.cshtml | 87 ++++++++++++------- src/Server/wwwroot/css/site.css | 6 +- 4 files changed, 106 insertions(+), 35 deletions(-) diff --git a/src/Server/Controllers/SearchdomainController.cs b/src/Server/Controllers/SearchdomainController.cs index 11ca113..f76ecf1 100644 --- a/src/Server/Controllers/SearchdomainController.cs +++ b/src/Server/Controllers/SearchdomainController.cs @@ -1,3 +1,4 @@ +using System.Text.Json; using ElmahCore; using Microsoft.AspNetCore.Mvc; using Server.Exceptions; @@ -98,14 +99,39 @@ public class SearchdomainController : ControllerBase { _logger.LogError("Unable to update searchdomain {searchdomain} - not found", [searchdomain]); return Ok(new SearchdomainUpdateResults() { Success = false, Message = $"Unable to update searchdomain {searchdomain} - not found" }); - } catch (Exception) + } catch (Exception ex) { - _logger.LogError("Unable to update searchdomain {searchdomain}", [searchdomain]); + _logger.LogError("Unable to update searchdomain {searchdomain} - Exception: {ex.Message} - {ex.StackTrace}", [searchdomain, ex.Message, ex.StackTrace]); return Ok(new SearchdomainUpdateResults() { Success = false, Message = $"Unable to update searchdomain {searchdomain}" }); } return Ok(new SearchdomainUpdateResults(){Success = true}); } + [HttpPost("UpdateSettings")] + public ActionResult UpdateSettings(string searchdomain, [FromBody] SearchdomainSettings request) + { + try + { + Searchdomain searchdomain_ = _domainManager.GetSearchdomain(searchdomain); + Dictionary parameters = new() + { + {"settings", JsonSerializer.Serialize(request)}, + {"id", searchdomain_.id} + }; + searchdomain_.helper.ExecuteSQLNonQuery("UPDATE searchdomain set settings = @settings WHERE id = @id", parameters); + searchdomain_.settings = request; + } catch (SearchdomainNotFoundException) + { + _logger.LogError("Unable to update settings for searchdomain {searchdomain} - not found", [searchdomain]); + return Ok(new SearchdomainUpdateResults() { Success = false, Message = $"Unable to update settings for searchdomain {searchdomain} - not found" }); + } catch (Exception ex) + { + _logger.LogError("Unable to update settings for searchdomain {searchdomain} - Exception: {ex.Message} - {ex.StackTrace}", [searchdomain, ex.Message, ex.StackTrace]); + return Ok(new SearchdomainUpdateResults() { Success = false, Message = $"Unable to update settings for searchdomain {searchdomain}" }); + } + return Ok(new SearchdomainUpdateResults(){Success = true}); + } + [HttpGet("GetSearches")] public ActionResult GetSearches(string searchdomain) { diff --git a/src/Server/Searchdomain.cs b/src/Server/Searchdomain.cs index 053f518..019eb79 100644 --- a/src/Server/Searchdomain.cs +++ b/src/Server/Searchdomain.cs @@ -1,5 +1,6 @@ using System.Data; using System.Data.Common; +using System.Text.Json; using ElmahCore.Mvc.Logger; using MySql.Data.MySqlClient; using Server.Helper; @@ -24,7 +25,7 @@ public class Searchdomain public SQLHelper helper; private readonly ILogger _logger; - public Searchdomain(string searchdomain, string connectionString, AIProvider aIProvider, Dictionary> embeddingCache, ILogger logger, string provider = "sqlserver", bool runEmpty = false, SearchdomainSettings searchdomainSettings = new()) + public Searchdomain(string searchdomain, string connectionString, AIProvider aIProvider, Dictionary> embeddingCache, ILogger logger, string provider = "sqlserver", bool runEmpty = false) { _connectionString = connectionString; _provider = provider.ToLower(); @@ -34,10 +35,10 @@ public class Searchdomain this._logger = logger; searchCache = []; entityCache = []; - settings = searchdomainSettings; connection = new MySqlConnection(connectionString); connection.Open(); helper = new SQLHelper(connection, connectionString); + settings = GetSettings(); modelsInUse = []; // To make the compiler shut up - it is set in UpdateSearchDomain() don't worry // yeah, about that... if (!runEmpty) { @@ -231,6 +232,19 @@ public class Searchdomain return this.id; } + public SearchdomainSettings GetSettings() + { + Dictionary parameters = new() + { + ["name"] = searchdomain + }; + DbDataReader reader = helper.ExecuteSQLCommand("SELECT settings from searchdomain WHERE name = @name", parameters); + reader.Read(); + string settingsString = reader.GetString(0); + reader.Close(); + return JsonSerializer.Deserialize(settingsString); + } + public void InvalidateSearchCache() { searchCache = []; diff --git a/src/Server/Views/Home/Index.cshtml b/src/Server/Views/Home/Index.cshtml index d36f9fb..7332a80 100644 --- a/src/Server/Views/Home/Index.cshtml +++ b/src/Server/Views/Home/Index.cshtml @@ -55,16 +55,11 @@
- + +
- +
@@ -149,8 +144,8 @@ - - + + @@ -162,9 +157,9 @@
KeyValue@T["Key"]@T["Value"]
- - - + + + @@ -174,7 +169,7 @@ @@ -194,7 +189,7 @@
NameProbMethodSimilarityMethod@T["Name"]@T["ProbMethod"]@T["SimilarityMethod"]