Made settings a proper checkbox (single setting), fixed other issues regarding settings getting and setting
This commit is contained in:
@@ -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<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")]
|
||||
public ActionResult<SearchdomainSearchesResults> GetSearches(string searchdomain)
|
||||
{
|
||||
|
||||
@@ -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<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;
|
||||
_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<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()
|
||||
{
|
||||
searchCache = [];
|
||||
|
||||
@@ -55,16 +55,11 @@
|
||||
<div class="row align-items-center mb-3">
|
||||
<label class="form-label">Settings</label>
|
||||
<div class="col-md-6">
|
||||
<input
|
||||
id="searchdomainConfig"
|
||||
type="text"
|
||||
class="form-control"
|
||||
placeholder="JSON-string"
|
||||
disabled
|
||||
/>
|
||||
<input type="checkbox" class="form-check-input" id="searchdomainConfigCacheReconciliation" />
|
||||
<label class="form-check-label" for="searchdomainConfigCacheReconciliation">@T["Cache reconsiliation"]</label>
|
||||
</div>
|
||||
<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>
|
||||
|
||||
@@ -149,8 +144,8 @@
|
||||
<table class="table table-sm table-bordered mb-4">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Key</th>
|
||||
<th>Value</th>
|
||||
<th>@T["Key"]</th>
|
||||
<th>@T["Value"]</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody id="entityAttributesBody">
|
||||
@@ -162,9 +157,9 @@
|
||||
<table class="table table-sm table-striped">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Name</th>
|
||||
<th>ProbMethod</th>
|
||||
<th>SimilarityMethod</th>
|
||||
<th>@T["Name"]</th>
|
||||
<th>@T["ProbMethod"]</th>
|
||||
<th>@T["SimilarityMethod"]</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody id="entityDatapointsBody">
|
||||
@@ -174,7 +169,7 @@
|
||||
|
||||
<div class="modal-footer">
|
||||
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">
|
||||
Close
|
||||
@T["Close"]
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
@@ -194,7 +189,7 @@
|
||||
<div class="modal-body">
|
||||
|
||||
<!-- Access times -->
|
||||
<h6>Access times</h6>
|
||||
<h3>Access times</h3>
|
||||
<ul id="queryAccessTimes" class="list-group mb-4"></ul>
|
||||
|
||||
<!-- Results -->
|
||||
@@ -335,6 +330,13 @@
|
||||
deleteSearchdomain(domainKey);
|
||||
selectDomain(0);
|
||||
});
|
||||
document
|
||||
.getElementById('searchdomainConfigUpdate')
|
||||
.addEventListener('click', () => {
|
||||
const domainKey = getSelectedDomainKey();
|
||||
const cacheReconciliation = document.getElementById('searchdomainConfigCacheReconciliation').checked;
|
||||
updateSearchdomainConfig(domainKey, { CacheReconciliation: cacheReconciliation});
|
||||
});
|
||||
});
|
||||
|
||||
function deleteSearchdomain(domainKey) {
|
||||
@@ -367,7 +369,7 @@
|
||||
// Update sidebar and header name
|
||||
var domainItem = document.getElementById('sidebar_domain_' + domainKey);
|
||||
domainItem.innerText = newName;
|
||||
document.querySelector('.section-card h4').innerText = newName;
|
||||
document.querySelector('.section-card h3').innerText = newName;
|
||||
domains[domainKey] = newName;
|
||||
|
||||
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() {
|
||||
return document.querySelector('.domain-item.active').id.split("_")[2] - 0;
|
||||
}
|
||||
@@ -398,7 +421,10 @@
|
||||
selectedItem.classList.add('active');
|
||||
|
||||
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 ---------- */
|
||||
let entitiesUrl = `/Entity/List?searchdomain=${encodeURIComponent(domainName)}&returnEmbeddings=false`;
|
||||
@@ -436,6 +462,20 @@
|
||||
console.error('Error fetching queries:', err);
|
||||
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() {
|
||||
@@ -488,8 +528,6 @@
|
||||
function populateQueriesTable(filterText = '') {
|
||||
if (!queries) return;
|
||||
|
||||
let searchdomainConfigPromise = getSearchdomainConfig(getSelectedDomainKey());
|
||||
let configElement = document.getElementById('searchdomainConfig');
|
||||
|
||||
const tbody = document.querySelector('#queriesTable tbody');
|
||||
tbody.innerHTML = '';
|
||||
@@ -520,17 +558,6 @@
|
||||
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');
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -44,4 +44,8 @@ body {
|
||||
|
||||
.d-none {
|
||||
display: none;
|
||||
}
|
||||
}
|
||||
|
||||
.modal-title {
|
||||
font-size: 1.25rem;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user