mirror of
https://github.com/khoaliber/khoj.git
synced 2026-03-09 21:29:11 +00:00
Populate type dropdown with only enabled search types in web interface
- Get /config API and check config for which available search types is populated. This gives us the list of enabled search types - Dynamically populate search type field with enabled search types only
This commit is contained in:
@@ -82,9 +82,30 @@
|
|||||||
event.key === 'Enter' ? search(rerank=true) : search(rerank=false);
|
event.key === 'Enter' ? search(rerank=true) : search(rerank=false);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fill search form with values passed in URL query parameters, if any.
|
function populate_type_dropdown() {
|
||||||
|
// Populate type dropdown field with enabled search types only
|
||||||
|
var possible_search_types = ["org", "markdown", "ledger", "music", "image"];
|
||||||
|
fetch("/config")
|
||||||
|
.then(response => response.json())
|
||||||
|
.then(data => {
|
||||||
|
document.getElementById("type").innerHTML =
|
||||||
|
possible_search_types
|
||||||
|
.filter(type => data["content-type"].hasOwnProperty(type) && data["content-type"][type])
|
||||||
|
.map(type => `<option value="${type}">${type.slice(0,1).toUpperCase() + type.slice(1)}</option>`)
|
||||||
|
.join('');
|
||||||
|
});
|
||||||
|
|
||||||
|
// Set type field to search type passed in URL query parameter, if valid
|
||||||
|
var type_via_url = new URLSearchParams(window.location.search).get("t");
|
||||||
|
if (type_via_url && type_via_url in possible_search_types)
|
||||||
|
document.getElementById("type").value = type_via_url;
|
||||||
|
}
|
||||||
|
|
||||||
window.onload = function () {
|
window.onload = function () {
|
||||||
document.getElementById("type").value = new URLSearchParams(window.location.search).get("t") || "org";
|
// Dynamically populate type dropdown based on enabled search types and type passed as URL query parameter
|
||||||
|
populate_type_dropdown();
|
||||||
|
|
||||||
|
// Fill query field with value passed in URL query parameters, if any.
|
||||||
var query_via_url = new URLSearchParams(window.location.search).get("q");
|
var query_via_url = new URLSearchParams(window.location.search).get("q");
|
||||||
if (query_via_url) {
|
if (query_via_url) {
|
||||||
document.getElementById("query").value = query_via_url;
|
document.getElementById("query").value = query_via_url;
|
||||||
@@ -98,16 +119,8 @@
|
|||||||
<!--Add Text Box To Enter Query, Trigger Incremental Search OnChange -->
|
<!--Add Text Box To Enter Query, Trigger Incremental Search OnChange -->
|
||||||
<input type="text" id="query" onkeyup=incremental_search(event) placeholder="What is the meaning of life?">
|
<input type="text" id="query" onkeyup=incremental_search(event) placeholder="What is the meaning of life?">
|
||||||
|
|
||||||
<!--Add Dropdown to Select Query Type.
|
<!--Add Dropdown to Select Query Type -->
|
||||||
Query Types can be: org, ledger, image, music, markdown.
|
<select id="type"></select>
|
||||||
Set Default type to org-->
|
|
||||||
<select id="type">
|
|
||||||
<option value="org">Org</option>
|
|
||||||
<option value="ledger">Ledger</option>
|
|
||||||
<option value="music">Music</option>
|
|
||||||
<option value="image">Image</option>
|
|
||||||
<option value="markdown">Markdown</option>
|
|
||||||
</select>
|
|
||||||
|
|
||||||
<!--Add Button To Regenerate -->
|
<!--Add Button To Regenerate -->
|
||||||
<button id="regenerate" onclick="regenerate()">Regenerate</button>
|
<button id="regenerate" onclick="regenerate()">Regenerate</button>
|
||||||
|
|||||||
Reference in New Issue
Block a user