From be253bab39a00ae1aaf11eb7110eb21126dddd78 Mon Sep 17 00:00:00 2001 From: Debanjum Singh Solanky Date: Sun, 31 Jul 2022 23:07:40 +0300 Subject: [PATCH] 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 --- src/interface/web/index.html | 37 ++++++++++++++++++++++++------------ 1 file changed, 25 insertions(+), 12 deletions(-) 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 @@ - - + +