Skip to content

Commit

Permalink
Merge pull request #45 from will-moore/show_study
Browse files Browse the repository at this point in the history
Support ?show=screen-123 for mapr jstree
  • Loading branch information
sbesson committed May 27, 2019
2 parents e000d4b + a99b14c commit cbf48e1
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 1 deletion.
44 changes: 44 additions & 0 deletions omero_mapr/static/mapr/javascript/ome.mapr.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,4 +104,48 @@ $(function () {
return sortingStrategy(node1, node2);
};


// ----- Show -----
// e.g. /mapr/gene/?value=CDC5&show=screen-51
// $('#dataTree').on('loaded.jstree', function(e, data) {
$('#dataTree').on('load_node.jstree', function(e, data) {
// If we're not ROOT node, ignore
if (data.node.id !== 'j1_1') return;
var inst = data.instance;
// Check for e.g. ?show=screen-51
var show = OME.getURLParameter("show");
var value = OME.getURLParameter("value");
if (show && value) {
// Find node that contains study:
// /mapr/api/gene/paths_to_object/?map.value=CEP120&project=18328
var url = MAPANNOTATIONS.URLS.paths_to_object + '?' + show.replace('-', '=');
$.getJSON(url, {'map.value': value}, function(data) {
if (data.paths && data.paths.length > 0) {
// Just traverse the first path, start looking at child of root
let pathToObj = data.paths[0].slice(1);
// start at root node
let rootNode = jstreeInst.get_node('ul > li:first');

function traverse(node, path) {
if (path.length == 0) {
inst.select_node(node);
return;
}
let nodeData = path[0];
node = inst.locate_node(nodeData.type + '-' + nodeData.id, node)[0];
if (!node) {
return;
}
path = path.slice(1);
inst.open_node(node, function(){
traverse(node, path);
});
}
// start recursive traversing...
traverse(rootNode, pathToObj);
}
});
}
});

});
2 changes: 2 additions & 0 deletions omero_mapr/templates/mapr/base_mapr.html
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@

var MAPANNOTATIONS = {}
MAPANNOTATIONS.URLS = {'static_webclient': "{% static 'mapr' %}/"};
MAPANNOTATIONS.URLS.maprindex = "{% url 'maprindex' %}";
MAPANNOTATIONS.URLS.paths_to_object = "{% url 'mapannotations_api_paths_to_object' menu %}";
MAPANNOTATIONS.URLS.autocomplete = "{% url 'mapannotations_autocomplete' menu %}";
MAPANNOTATIONS.URLS.autocomplete_default = "{% url 'mapannotations_api_experimenters' menu %}";

Expand Down
2 changes: 1 addition & 1 deletion omero_mapr/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ def index(request, menu, conn=None, url=None, **kwargs):
kwargs['template'] = "mapr/base_mapr.html"
context = _webclient_load_template(request, menu,
conn=conn, url=url, **kwargs)
context['active_user'] = context['active_user'] or {'id': -1}
context['active_user'] = context.get('active_user', {'id': -1})
context['mapr_conf'] = {
'menu': menu,
'menu_all': mapr_settings.CONFIG[menu]['all'],
Expand Down

0 comments on commit cbf48e1

Please sign in to comment.