diff --git a/idr_gallery/static/idr_gallery/model.js b/idr_gallery/static/idr_gallery/model.js index 7bf839b1..9a93c823 100644 --- a/idr_gallery/static/idr_gallery/model.js +++ b/idr_gallery/static/idr_gallery/model.js @@ -379,7 +379,7 @@ class StudiesModel { } filterStudiesAnyText(text) { - // Search for studies with text in their keys, values, or description. + // Search for studies with text in their keys, values, name or description. // Returns a list of matching studies. Each study is returned along with kvps that match text // [study, [{key: value}, {Description: this study is great}]] @@ -393,6 +393,13 @@ class StudiesModel { let keyValuePairs = []; if (study.mapValues) { keyValuePairs = [...study.mapValues]; + + // Don't want to find "annotation.csv" KVPs + keyValuePairs = keyValuePairs.filter( + (kvp) => !kvp[1].includes("annotation.csv") + ); + + keyValuePairs.push(["Name", study.Name]); } keyValuePairs.push(["Description", study.StudyDescription]); let match = keyValuePairs.some((kvp) => regex.test(kvp[1])); diff --git a/idr_gallery/static/idr_gallery/omero_search_form.js b/idr_gallery/static/idr_gallery/omero_search_form.js index 507a4f14..0a4ed866 100644 --- a/idr_gallery/static/idr_gallery/omero_search_form.js +++ b/idr_gallery/static/idr_gallery/omero_search_form.js @@ -10,8 +10,8 @@ const AND_CLAUSE_HTML = `
@@ -59,6 +59,262 @@ const FILTER_ICON_SVG = ` C58.1,59.1,81.058,61.387,105.34,61.387c24.283,0,47.24-2.287,65.034-6.449L119.631,116.486z"/> `; +const NAME_KEY = "name"; +// display this on the keyFields key = $(".keyFields", $orClause).val(); - let data = { value: request.term }; - let url = `${SEARCH_ENGINE_URL}resources/image/searchvalues/`; + let operator = $(".condition", $orClause).val(); if (key != "Any") { - data.key = key; + // if we know the key, we will switch to 'equals' (except for the first 'contains' option) + operator = "equals"; } - // showSpinner(); - $.ajax({ - dataType: "json", - data, - type: "GET", - url: url, - success: function (data) { - // hideSpinner(); - let results = [{ label: "No results found.", value: -1 }]; - if (data.data.length > 0) { - // only try to show top 100 items... - let max_shown = 100; - let result_count = data.data.length; - let data_results = data.data; - // sort to put exact and 'known' matches first - data_results.sort(self.autocompleteSort(request.term)); - results = data_results.slice(0, 100).map((result) => { - let showKey = key === "Any" ? `(${result.Key})` : ""; - return { - key: result.Key, - label: `${result.Value} ${showKey} ${result["Number of images"]} images`, - value: `${result.Value}`, - }; - }); - if (result_count > max_shown) { - results.push({ - key: -1, - label: `...and ${ - result_count - max_shown - } more matches not shown`, - value: -1, - }); - } - } - response(results); - }, - error: function (data) { - console.log("ERROR", data); - // hideSpinner(); - response([{ label: "Failed to load", value: -1 }]); - }, - }); + const query = request.term; + const results = await getAutoCompleteResults( + key, + query, + knownKeys, + operator + ); + response(results); }, minLength: 1, open: function () {}, @@ -330,7 +567,11 @@ class OmeroSearchForm { } if (key == "Any") { // Use 'key' to update KeyField - self.setKeyField($orClause, ui.item.key); + self.setKeyField($orClause, ui.item.key, ui.item.dtype); + } else { + const operator = + ui.item.operator == "contains" ? "contains" : "equals"; + self.setOperator($orClause, operator); } // We perform search with chosen value... setTimeout(() => { @@ -345,17 +586,36 @@ class OmeroSearchForm { .append("" + item.label + "") .appendTo(ul); }; + $this.on("keyup", (event) => { + if (!(event.which == 38 || event.which == 40)) { + // on any keystroke (except up/down arrows), + // hide auto-complete immediately to avoid selection of old results + $this.autocomplete("close"); + } + }); } - setKeyField($parent, key) { + setKeyField($parent, key, resource) { // Adds the Key as an