Skip to content

Commit

Permalink
Port idr front page from omero-gallery PR
Browse files Browse the repository at this point in the history
See ome#91
  • Loading branch information
will-moore committed Mar 14, 2022
1 parent 6b65843 commit 2076e0d
Show file tree
Hide file tree
Showing 13 changed files with 2,187 additions and 1,298 deletions.
25 changes: 24 additions & 1 deletion idr_gallery/gallery_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,21 @@
["BASE_URL",
None,
str_slash,
("Base URL to use for JSON AJAX requests."
("Base URL to use for non-gallery JSON AJAX requests."
" e.g. 'https://demo.openmicroscopy.org'."
" This allows data to be loaded from another OMERO server."
" The default behaviour is to use the current server.")],

"omero.web.gallery.gallery_index":
["GALLERY_INDEX",
None,
str_slash,
("Base gallery URL to use for gallery JSON AJAX requests."
" e.g. 'https://idr.openmicroscopy.org/' is gallery index on IDR."
" This allows data to be loaded from another OMERO server, e.g. run"
" locally or on test server, but load data from IDR."
" Default behaviour is to use current server webgallery_index")],

"omero.web.gallery.category_queries":
["CATEGORY_QUERIES",
('{}'),
Expand Down Expand Up @@ -143,6 +153,19 @@
" If a 'regex' and 'template' are specified, we try"
" name.replace(regex, template).")],

"omero.web.gallery.index_json_url":
["INDEX_JSON_URL",
'https://raw.githubusercontent.com/will-moore/idr.openmicroscopy.org/idr_index_data/_data/idr_index.json',
str,
"URL to load JSON, with a 'tabs' list of {'title':'', 'text':'', 'videos':[]}"
],
"omero.web.gallery.idr_studies_url":
["IDR_STUDIES_URL",
'https://raw.githubusercontent.com/IDR/idr.openmicroscopy.org/master/_data/studies.tsv',
str,
"URL to IDR studies as a tsv table"
],

}

process_custom_settings(sys.modules[__name__], 'GALLERY_SETTINGS_MAPPING')
Expand Down
152 changes: 152 additions & 0 deletions idr_gallery/static/idr_gallery/autocomplete.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@

// ------ AUTO-COMPLETE -------------------

document.getElementById('maprConfig').onchange = (event) => {
document.getElementById('maprQuery').value = '';
let value = event.target.value.replace('mapr_', '');
let placeholder = `Type to filter values...`;
if (mapr_settings[value]) {
placeholder = `Type ${mapr_settings[value]['default'][0]}...`;
}
document.getElementById('maprQuery').placeholder = placeholder;
// Show all autocomplete options...
$("#maprQuery").focus();

// render();
}

function showAutocomplete(event) {
var configId = document.getElementById("maprConfig").value;
var autoCompleteValue = event.target.value;

if (configId.indexOf('mapr_') != 0) {
// If not MAPR search, show all auto-complete results
autoCompleteValue = '';
}

$("#maprQuery").autocomplete("search", autoCompleteValue);
}

document.getElementById('maprQuery').onfocus = function (event) {
showAutocomplete(event);
};

document.getElementById('maprQuery').onclick = function (event) {
showAutocomplete(event);
};

function showSpinner() {
document.getElementById('spinner').style.visibility = 'visible';
}
function hideSpinner() {
document.getElementById('spinner').style.visibility = 'hidden';
}

// Initial setup...
$("#maprQuery")
.keyup(event => {
if (event.which == 13) {
let configId = document.getElementById("maprConfig").value;
document.location.href = `search/?query=${configId}:${event.target.value}`;
}
})
.autocomplete({
autoFocus: false,
delay: 1000,
source: function (request, response) {

// if configId is not from mapr, we filter on mapValues...
let configId = document.getElementById("maprConfig").value;
if (configId.indexOf('mapr_') != 0) {

let matches;
if (configId === 'Name') {
matches = model.getStudiesNames(request.term);
} else if (configId === 'Group') {
matches = model.getStudiesGroups(request.term);
} else {
matches = model.getKeyValueAutoComplete(configId, request.term);
}
response(matches);
return;
}

// Don't handle empty query for mapr
if (request.term.length == 0) {
return;
}

// Auto-complete to filter by mapr...
configId = configId.replace('mapr_', '');
let case_sensitive = false;

let requestData = {
case_sensitive: case_sensitive,
}
let url;
if (request.term.length === 0) {
// Try to list all top-level values.
// This works for 'wild-card' configs where number of values is small e.g. Organism
// But will return empty list for e.g. Gene
url = `${BASE_URL}mapr/api/${configId}/`;
requestData.orphaned = true
} else {
// Find auto-complete matches
url = `${BASE_URL}mapr/api/autocomplete/${configId}/`;
requestData.value = case_sensitive ? request.term : request.term.toLowerCase();
requestData.query = true; // use a 'like' HQL query
}
showSpinner();
$.ajax({
dataType: "json",
type: 'GET',
url: url,
data: requestData,
success: function (data) {
hideSpinner();
if (request.term.length === 0) {
// Top-level terms in 'maps'
if (data.maps && data.maps.length > 0) {
let terms = data.maps.map(m => m.id);
terms.sort();
response(terms);
}
}
else if (data.length > 0) {
response($.map(data, function (item) {
return item;
}));
} else {
response([{ label: 'No results found.', value: -1 }]);
}
},
error: function (data) {
hideSpinner();
response([{ label: 'Loading auto-complete terms failed. Server may be busy.', value: -1 }]);
}
});
},
minLength: 0,
open: function () { },
close: function () {
// $(this).val('');
return false;
},
focus: function (event, ui) { },
select: function (event, ui) {
if (ui.item.value == -1) {
// Ignore 'No results found'
return false;
}
// show temp message in case loading search page is slow
$(this).val("loading search results...");
// Load search page...
let configId = document.getElementById("maprConfig").value;
document.location.href = `search/?query=${configId}:${ui.item.value}`;
return false;
}
}).data("ui-autocomplete")._renderItem = function (ul, item) {
return $("<li>")
.append("<a>" + item.label + "</a>")
.appendTo(ul);
}
Loading

0 comments on commit 2076e0d

Please sign in to comment.