diff --git a/src/interface/web/index.html b/src/interface/web/index.html index b364f670..1229d9b8 100644 --- a/src/interface/web/index.html +++ b/src/interface/web/index.html @@ -82,9 +82,30 @@ 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 => ``) + .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 () { - 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"); if (query_via_url) { document.getElementById("query").value = query_via_url; @@ -98,16 +119,8 @@ - - + +