mirror of
https://github.com/khoaliber/khoj.git
synced 2026-03-06 21:29:12 +00:00
Use new config/types API to set enabled content types on web interface
This commit is contained in:
@@ -63,7 +63,7 @@
|
|||||||
function search(rerank=false) {
|
function search(rerank=false) {
|
||||||
// Extract required fields for search from form
|
// Extract required fields for search from form
|
||||||
query = document.getElementById("query").value.trim();
|
query = document.getElementById("query").value.trim();
|
||||||
type = document.getElementById("type").value;
|
type = document.getElementById("type").value.toLowerCase();
|
||||||
results_count = document.getElementById("results-count").value || 6;
|
results_count = document.getElementById("results-count").value || 6;
|
||||||
console.log(`Query: ${query}, Type: ${type}`);
|
console.log(`Query: ${query}, Type: ${type}`);
|
||||||
|
|
||||||
@@ -116,21 +116,21 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
function populate_type_dropdown() {
|
function populate_type_dropdown() {
|
||||||
// Populate type dropdown field with enabled search types only
|
// Populate type dropdown field with enabled content types only
|
||||||
var possible_search_types = ["org", "markdown", "ledger", "music", "image"];
|
fetch("/api/config/types")
|
||||||
fetch("/api/config/data")
|
|
||||||
.then(response => response.json())
|
.then(response => response.json())
|
||||||
.then(data => {
|
.then(enabled_types => {
|
||||||
document.getElementById("type").innerHTML =
|
document.getElementById("type").innerHTML =
|
||||||
possible_search_types
|
enabled_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>`)
|
.map(type => `<option value="${type}">${type.slice(0,1).toUpperCase() + type.slice(1)}</option>`)
|
||||||
.join('');
|
.join('');
|
||||||
|
|
||||||
|
return enabled_types;
|
||||||
})
|
})
|
||||||
.then(() => {
|
.then(enabled_types => {
|
||||||
// Set type field to search type passed in URL query parameter, if valid
|
// Set type field to content type passed in URL query parameter, if valid
|
||||||
var type_via_url = new URLSearchParams(window.location.search).get("t");
|
var type_via_url = new URLSearchParams(window.location.search).get("t");
|
||||||
if (type_via_url && possible_search_types.includes(type_via_url))
|
if (type_via_url && enabled_types.includes(type_via_url))
|
||||||
document.getElementById("type").value = type_via_url;
|
document.getElementById("type").value = type_via_url;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -154,7 +154,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
window.onload = function () {
|
window.onload = function () {
|
||||||
// Dynamically populate type dropdown based on enabled search types and type passed as URL query parameter
|
// Dynamically populate type dropdown based on enabled content types and type passed as URL query parameter
|
||||||
populate_type_dropdown();
|
populate_type_dropdown();
|
||||||
|
|
||||||
// Set results count field with value passed in URL query parameters, if any.
|
// Set results count field with value passed in URL query parameters, if any.
|
||||||
|
|||||||
Reference in New Issue
Block a user