Made settings a proper checkbox (single setting), fixed other issues regarding settings getting and setting

This commit is contained in:
2025-12-18 22:32:57 +01:00
parent 1439fa7d58
commit 1bf47d8220
4 changed files with 106 additions and 35 deletions

View File

@@ -1,3 +1,4 @@
using System.Text.Json;
using ElmahCore; using ElmahCore;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Server.Exceptions; using Server.Exceptions;
@@ -98,14 +99,39 @@ public class SearchdomainController : ControllerBase
{ {
_logger.LogError("Unable to update searchdomain {searchdomain} - not found", [searchdomain]); _logger.LogError("Unable to update searchdomain {searchdomain} - not found", [searchdomain]);
return Ok(new SearchdomainUpdateResults() { Success = false, Message = $"Unable to update searchdomain {searchdomain} - not found" }); 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 = false, Message = $"Unable to update searchdomain {searchdomain}" });
} }
return Ok(new SearchdomainUpdateResults(){Success = true}); return Ok(new SearchdomainUpdateResults(){Success = true});
} }
[HttpPost("UpdateSettings")]
public ActionResult<SearchdomainUpdateResults> UpdateSettings(string searchdomain, [FromBody] SearchdomainSettings request)
{
try
{
Searchdomain searchdomain_ = _domainManager.GetSearchdomain(searchdomain);
Dictionary<string, dynamic> 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")] [HttpGet("GetSearches")]
public ActionResult<SearchdomainSearchesResults> GetSearches(string searchdomain) public ActionResult<SearchdomainSearchesResults> GetSearches(string searchdomain)
{ {

View File

@@ -1,5 +1,6 @@
using System.Data; using System.Data;
using System.Data.Common; using System.Data.Common;
using System.Text.Json;
using ElmahCore.Mvc.Logger; using ElmahCore.Mvc.Logger;
using MySql.Data.MySqlClient; using MySql.Data.MySqlClient;
using Server.Helper; using Server.Helper;
@@ -24,7 +25,7 @@ public class Searchdomain
public SQLHelper helper; public SQLHelper helper;
private readonly ILogger _logger; private readonly ILogger _logger;
public Searchdomain(string searchdomain, string connectionString, AIProvider aIProvider, Dictionary<string, Dictionary<string, float[]>> embeddingCache, ILogger logger, string provider = "sqlserver", bool runEmpty = false, SearchdomainSettings searchdomainSettings = new()) public Searchdomain(string searchdomain, string connectionString, AIProvider aIProvider, Dictionary<string, Dictionary<string, float[]>> embeddingCache, ILogger logger, string provider = "sqlserver", bool runEmpty = false)
{ {
_connectionString = connectionString; _connectionString = connectionString;
_provider = provider.ToLower(); _provider = provider.ToLower();
@@ -34,10 +35,10 @@ public class Searchdomain
this._logger = logger; this._logger = logger;
searchCache = []; searchCache = [];
entityCache = []; entityCache = [];
settings = searchdomainSettings;
connection = new MySqlConnection(connectionString); connection = new MySqlConnection(connectionString);
connection.Open(); connection.Open();
helper = new SQLHelper(connection, connectionString); 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... modelsInUse = []; // To make the compiler shut up - it is set in UpdateSearchDomain() don't worry // yeah, about that...
if (!runEmpty) if (!runEmpty)
{ {
@@ -231,6 +232,19 @@ public class Searchdomain
return this.id; return this.id;
} }
public SearchdomainSettings GetSettings()
{
Dictionary<string, dynamic> 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<SearchdomainSettings>(settingsString);
}
public void InvalidateSearchCache() public void InvalidateSearchCache()
{ {
searchCache = []; searchCache = [];

View File

@@ -55,16 +55,11 @@
<div class="row align-items-center mb-3"> <div class="row align-items-center mb-3">
<label class="form-label">Settings</label> <label class="form-label">Settings</label>
<div class="col-md-6"> <div class="col-md-6">
<input <input type="checkbox" class="form-check-input" id="searchdomainConfigCacheReconciliation" />
id="searchdomainConfig" <label class="form-check-label" for="searchdomainConfigCacheReconciliation">@T["Cache reconsiliation"]</label>
type="text"
class="form-control"
placeholder="JSON-string"
disabled
/>
</div> </div>
<div class="col-md-2 mt-3 mt-md-0"> <div class="col-md-2 mt-3 mt-md-0">
<button class="btn btn-warning w-100">Update</button> <button class="btn btn-warning w-100" id="searchdomainConfigUpdate">@T["Update"]</button>
</div> </div>
</div> </div>
@@ -149,8 +144,8 @@
<table class="table table-sm table-bordered mb-4"> <table class="table table-sm table-bordered mb-4">
<thead> <thead>
<tr> <tr>
<th>Key</th> <th>@T["Key"]</th>
<th>Value</th> <th>@T["Value"]</th>
</tr> </tr>
</thead> </thead>
<tbody id="entityAttributesBody"> <tbody id="entityAttributesBody">
@@ -162,9 +157,9 @@
<table class="table table-sm table-striped"> <table class="table table-sm table-striped">
<thead> <thead>
<tr> <tr>
<th>Name</th> <th>@T["Name"]</th>
<th>ProbMethod</th> <th>@T["ProbMethod"]</th>
<th>SimilarityMethod</th> <th>@T["SimilarityMethod"]</th>
</tr> </tr>
</thead> </thead>
<tbody id="entityDatapointsBody"> <tbody id="entityDatapointsBody">
@@ -174,7 +169,7 @@
<div class="modal-footer"> <div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal"> <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">
Close @T["Close"]
</button> </button>
</div> </div>
</div> </div>
@@ -194,7 +189,7 @@
<div class="modal-body"> <div class="modal-body">
<!-- Access times --> <!-- Access times -->
<h6>Access times</h6> <h3>Access times</h3>
<ul id="queryAccessTimes" class="list-group mb-4"></ul> <ul id="queryAccessTimes" class="list-group mb-4"></ul>
<!-- Results --> <!-- Results -->
@@ -335,6 +330,13 @@
deleteSearchdomain(domainKey); deleteSearchdomain(domainKey);
selectDomain(0); selectDomain(0);
}); });
document
.getElementById('searchdomainConfigUpdate')
.addEventListener('click', () => {
const domainKey = getSelectedDomainKey();
const cacheReconciliation = document.getElementById('searchdomainConfigCacheReconciliation').checked;
updateSearchdomainConfig(domainKey, { CacheReconciliation: cacheReconciliation});
});
}); });
function deleteSearchdomain(domainKey) { function deleteSearchdomain(domainKey) {
@@ -367,7 +369,7 @@
// Update sidebar and header name // Update sidebar and header name
var domainItem = document.getElementById('sidebar_domain_' + domainKey); var domainItem = document.getElementById('sidebar_domain_' + domainKey);
domainItem.innerText = newName; domainItem.innerText = newName;
document.querySelector('.section-card h4').innerText = newName; document.querySelector('.section-card h3').innerText = newName;
domains[domainKey] = newName; domains[domainKey] = newName;
console.log('Searchdomain renamed successfully'); console.log('Searchdomain renamed successfully');
@@ -380,6 +382,27 @@
}); });
} }
function updateSearchdomainConfig(domainKey, newSettings) {
// Implement update logic here
fetch(`/Searchdomain/UpdateSettings?searchdomain=${encodeURIComponent(domains[domainKey])}`, {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(newSettings)
}).then(response => {
if (response.ok) {
// TODO add toast
console.log('Searchdomain settings updated successfully');
} else {
// TODO add toast
console.error('Failed to update searchdomain settings');
}
}).catch(error => {
console.error('Error updating searchdomain settings:', error);
});
}
function getSelectedDomainKey() { function getSelectedDomainKey() {
return document.querySelector('.domain-item.active').id.split("_")[2] - 0; return document.querySelector('.domain-item.active').id.split("_")[2] - 0;
} }
@@ -398,7 +421,10 @@
selectedItem.classList.add('active'); selectedItem.classList.add('active');
var domainName = domains[domainKey]; var domainName = domains[domainKey];
document.querySelector('.section-card h4').innerText = domainName; document.querySelector('.section-card h3').innerText = domainName;
let searchdomainConfigPromise = getSearchdomainConfig(getSelectedDomainKey());
let configElementCacheReconsiliation = document.getElementById('searchdomainConfigCacheReconciliation');
/* ---------- ENTITIES ---------- */ /* ---------- ENTITIES ---------- */
let entitiesUrl = `/Entity/List?searchdomain=${encodeURIComponent(domainName)}&returnEmbeddings=false`; let entitiesUrl = `/Entity/List?searchdomain=${encodeURIComponent(domainName)}&returnEmbeddings=false`;
@@ -436,6 +462,20 @@
console.error('Error fetching queries:', err); console.error('Error fetching queries:', err);
hideQueriesLoading(queriesCard); hideQueriesLoading(queriesCard);
}); });
searchdomainConfigPromise.then(searchdomainConfig => {
if (searchdomainConfig != null && searchdomainConfig.Settings != null)
{
console.log(searchdomainConfig);
configElementCacheReconsiliation.checked = searchdomainConfig.Settings.CacheReconciliation;
configElementCacheReconsiliation.disabled = false;
} else {
//configElement.value = 'Error fetching searchdomain config';
configElementCacheReconsiliation.disabled = true;
// TODO add toast
console.error('Failed to fetch searchdomain config');
}
});
} }
function clearEntitiesTable() { function clearEntitiesTable() {
@@ -488,8 +528,6 @@
function populateQueriesTable(filterText = '') { function populateQueriesTable(filterText = '') {
if (!queries) return; if (!queries) return;
let searchdomainConfigPromise = getSearchdomainConfig(getSelectedDomainKey());
let configElement = document.getElementById('searchdomainConfig');
const tbody = document.querySelector('#queriesTable tbody'); const tbody = document.querySelector('#queriesTable tbody');
tbody.innerHTML = ''; tbody.innerHTML = '';
@@ -520,17 +558,6 @@
tbody.appendChild(row); tbody.appendChild(row);
}); });
searchdomainConfigPromise.then(searchdomainConfig => {
if (searchdomainConfig != null && searchdomainConfig.Settings != null)
{
configElement.value = JSON.stringify(searchdomainConfig.Settings, null, 2);
} else {
configElement.value = 'Error fetching searchdomain config';
console.log(searchdomainConfig);
// TODO add toast
console.error('Failed to fetch searchdomain config');
}
});
} }

View File

@@ -44,4 +44,8 @@ body {
.d-none { .d-none {
display: none; display: none;
} }
.modal-title {
font-size: 1.25rem;
}