Added query deleting
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
using System.Text.Json;
|
using System.Text.Json;
|
||||||
using ElmahCore;
|
using ElmahCore;
|
||||||
|
using Microsoft.AspNetCore.Http.HttpResults;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using Server.Exceptions;
|
using Server.Exceptions;
|
||||||
using Server.Helper;
|
using Server.Helper;
|
||||||
@@ -156,6 +157,34 @@ public class SearchdomainController : ControllerBase
|
|||||||
return Ok(new SearchdomainSearchesResults() { Searches = searchCache, Success = true });
|
return Ok(new SearchdomainSearchesResults() { Searches = searchCache, Success = true });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[HttpDelete("Searches")]
|
||||||
|
public ActionResult<SearchdomainDeleteSearchResult> DeleteSearch(string searchdomain, string query)
|
||||||
|
{
|
||||||
|
Searchdomain searchdomain_;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
searchdomain_ = _domainManager.GetSearchdomain(searchdomain);
|
||||||
|
}
|
||||||
|
catch (SearchdomainNotFoundException)
|
||||||
|
{
|
||||||
|
_logger.LogError("Unable to retrieve the searchdomain {searchdomain} - it likely does not exist yet", [searchdomain]);
|
||||||
|
return Ok(new SearchdomainDeleteSearchResult() { Success = false, Message = "Searchdomain not found" });
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError("Unable to retrieve the searchdomain {searchdomain} - {ex.Message} - {ex.StackTrace}", [searchdomain, ex.Message, ex.StackTrace]);
|
||||||
|
return Ok(new SearchdomainDeleteSearchResult() { Success = false, Message = ex.Message });
|
||||||
|
}
|
||||||
|
Dictionary<string, DateTimedSearchResult> searchCache = searchdomain_.searchCache;
|
||||||
|
bool containsKey = searchCache.ContainsKey(query);
|
||||||
|
if (containsKey)
|
||||||
|
{
|
||||||
|
searchCache.Remove(query);
|
||||||
|
return Ok(new SearchdomainDeleteSearchResult() {Success = true});
|
||||||
|
}
|
||||||
|
return Ok(new SearchdomainDeleteSearchResult() {Success = false, Message = "Query not found in search cache"});
|
||||||
|
}
|
||||||
|
|
||||||
[HttpGet("GetSettings")]
|
[HttpGet("GetSettings")]
|
||||||
public ActionResult<SearchdomainSettingsResults> GetSettings(string searchdomain)
|
public ActionResult<SearchdomainSettingsResults> GetSettings(string searchdomain)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -502,6 +502,33 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<!-- Delete query Modal -->
|
||||||
|
<div class="modal fade" id="deleteQueryModal" tabindex="-1" aria-hidden="true">
|
||||||
|
<div class="modal-dialog modal-m modal-dialog-scrollable">
|
||||||
|
<div class="modal-content">
|
||||||
|
|
||||||
|
<div class="modal-header bg-danger text-white">
|
||||||
|
<h2 class="modal-title" id="deleteQueryTitle">@T["Delete query"]</h2>
|
||||||
|
<button type="button" class="btn-close" data-bs-dismiss="modal"></button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="modal-body">
|
||||||
|
<p>@Html.Raw(T["GenericDeleteConfirmation", "deleteQueryConfirmationModalName"])</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="modal-footer">
|
||||||
|
<button type="button" id="queryConfirmDelete" class="btn btn-danger" data-bs-dismiss="modal">
|
||||||
|
@T["Delete"]
|
||||||
|
</button>
|
||||||
|
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">
|
||||||
|
@T["Close"]
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
var domains = JSON.parse('@Html.Raw(System.Text.Json.JsonSerializer.Serialize(domains))');
|
var domains = JSON.parse('@Html.Raw(System.Text.Json.JsonSerializer.Serialize(domains))');
|
||||||
var probMethods = JSON.parse('@Html.Raw(System.Text.Json.JsonSerializer.Serialize(probMethods))');
|
var probMethods = JSON.parse('@Html.Raw(System.Text.Json.JsonSerializer.Serialize(probMethods))');
|
||||||
@@ -763,6 +790,30 @@
|
|||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
document
|
||||||
|
.getElementById('queryConfirmDelete')
|
||||||
|
.addEventListener('click', () => {
|
||||||
|
let searchdomain = domains[getSelectedDomainKey()];
|
||||||
|
let query = document.getElementById('deleteQueryConfirmationModalName').textContent;
|
||||||
|
fetch(`/Searchdomain/Searches?searchdomain=${searchdomain}&query=${query}`, {
|
||||||
|
method: 'DELETE',
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json'
|
||||||
|
}
|
||||||
|
}).then(async response => {
|
||||||
|
result = await response.json();
|
||||||
|
if (response.ok && result.Success) {
|
||||||
|
// TODO add toast
|
||||||
|
console.log('Search query was deleted successfully');
|
||||||
|
selectDomain(getSelectedDomainKey());
|
||||||
|
} else {
|
||||||
|
// TODO add toast
|
||||||
|
console.error('Failed to delete query:', result.Message);
|
||||||
|
}
|
||||||
|
}).catch(error => {
|
||||||
|
console.error('Error creating entity:', error);
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
function deleteSearchdomain(domainKey) {
|
function deleteSearchdomain(domainKey) {
|
||||||
@@ -1054,14 +1105,29 @@
|
|||||||
row.appendChild(nameCell);
|
row.appendChild(nameCell);
|
||||||
|
|
||||||
const actionCell = document.createElement('td');
|
const actionCell = document.createElement('td');
|
||||||
const btn = document.createElement('button');
|
actionCell.classList.add('btn-group');
|
||||||
btn.className = 'btn btn-sm btn-info';
|
const btnDetails = document.createElement('button');
|
||||||
btn.textContent = '@T["Details"]';
|
btnDetails.className = 'btn btn-sm btn-info';
|
||||||
btn.addEventListener('click', () => {
|
btnDetails.textContent = '@T["Details"]';
|
||||||
|
btnDetails.addEventListener('click', () => {
|
||||||
showQueryDetails(query);
|
showQueryDetails(query);
|
||||||
});
|
});
|
||||||
|
const btnDelete = document.createElement('button');
|
||||||
|
btnDelete.className = 'btn btn-sm btn-danger';
|
||||||
|
btnDelete.textContent = '@T["Delete"]';
|
||||||
|
btnDelete.addEventListener('click', () => {
|
||||||
|
const modal = new bootstrap.Modal(
|
||||||
|
document.getElementById('deleteQueryModal')
|
||||||
|
);
|
||||||
|
modal.show();
|
||||||
|
let queryConfirmDelete = document.getElementById('queryConfirmDelete');
|
||||||
|
queryConfirmDelete.setAttribute('data-name', query.Name);
|
||||||
|
let deleteQueryConfirmationModalName = document.getElementById('deleteQueryConfirmationModalName');
|
||||||
|
deleteQueryConfirmationModalName.textContent = query.Name;
|
||||||
|
});
|
||||||
|
|
||||||
actionCell.appendChild(btn);
|
actionCell.appendChild(btnDetails);
|
||||||
|
actionCell.appendChild(btnDelete);
|
||||||
row.appendChild(actionCell);
|
row.appendChild(actionCell);
|
||||||
|
|
||||||
tbody.appendChild(row);
|
tbody.appendChild(row);
|
||||||
|
|||||||
@@ -55,6 +55,15 @@ public class SearchdomainSearchesResults
|
|||||||
public required Dictionary<string, DateTimedSearchResult> Searches { get; set; }
|
public required Dictionary<string, DateTimedSearchResult> Searches { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public class SearchdomainDeleteSearchResult
|
||||||
|
{
|
||||||
|
[JsonPropertyName("Success")]
|
||||||
|
public required bool Success { get; set; }
|
||||||
|
|
||||||
|
[JsonPropertyName("Message")]
|
||||||
|
public string? Message { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
public class SearchdomainSettingsResults
|
public class SearchdomainSettingsResults
|
||||||
{
|
{
|
||||||
[JsonPropertyName("Success")]
|
[JsonPropertyName("Success")]
|
||||||
|
|||||||
Reference in New Issue
Block a user