From 941f68c64971623d8eec8a90e1cdeedfcaa0f617 Mon Sep 17 00:00:00 2001 From: William Moore Date: Thu, 5 May 2016 00:01:44 +0100 Subject: [PATCH 01/29] Adding omero.web.open_with to settings.py --- components/tools/OmeroWeb/omeroweb/settings.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/components/tools/OmeroWeb/omeroweb/settings.py b/components/tools/OmeroWeb/omeroweb/settings.py index 6925daea5f4..ae075cfc962 100644 --- a/components/tools/OmeroWeb/omeroweb/settings.py +++ b/components/tools/OmeroWeb/omeroweb/settings.py @@ -533,6 +533,20 @@ def leave_none_unset_int(s): ("Django view which handles display of, or redirection to, the " "desired full image viewer.")], + # OPEN WITH + "omero.web.open_with": + ["OPEN_WITH", + ('[["Test", "api_paths_to_object"],' + '["OMERO.figure", "new_figure", ' + '{"objects":["images", "dataset"],"open":"tab"}]]'), + json.loads, + ("A list of viewers that can be used to display selected Images " + "or other objects. Each viewer is defined as " + "``[\"Name\", \"url\", options]``. Url is reverse(url). " + "Selected objects are added to the url as ?image=:1&image=2" + "The options object is optional E.g. {\"objects\":[\"images\"]} " + "to enable viewer for one or more images")], + # PIPELINE 1.3.20 # Pipeline is an asset packaging library for Django, providing both CSS From 8a1bf799b9dd2e85e0a33156c8e44f45ee1d3d6d Mon Sep 17 00:00:00 2001 From: William Moore Date: Thu, 5 May 2016 00:03:03 +0100 Subject: [PATCH 02/29] decorator parses settings.OPEN_WITH --- .../OmeroWeb/omeroweb/webclient/decorators.py | 28 +++++++++++++++++++ .../webclient/base/base_container.html | 7 +++++ 2 files changed, 35 insertions(+) diff --git a/components/tools/OmeroWeb/omeroweb/webclient/decorators.py b/components/tools/OmeroWeb/omeroweb/webclient/decorators.py index c8f7158cc6f..eb48dbf320c 100644 --- a/components/tools/OmeroWeb/omeroweb/webclient/decorators.py +++ b/components/tools/OmeroWeb/omeroweb/webclient/decorators.py @@ -24,6 +24,7 @@ """ import logging +import json import omeroweb.decorators from omero import constants @@ -191,3 +192,30 @@ def load_settings(self, request, context, conn): c_plugins.append({ "label": label, "include": include, "plugin_id": plugin_id}) context['ome']['center_plugins'] = c_plugins + + open_with = settings.OPEN_WITH + viewers = [] + for ow in open_with: + viewer = {} + viewer['objects'] = ['image'] + viewer['open'] = 'window' + # try non-essential parameters... + try: + if len(ow) > 2: + if 'objects' in ow[2]: + viewer['objects'] = ow[2]['objects'] + if 'open' in ow[2]: + viewer['open'] = ow[2]['open'] + except: + # ignore invalid params + pass + # try essential parameters... + try: + viewer['label'] = ow[0] + viewer['url'] = reverse(ow[1]) + # Only add if we have label and url + viewers.append(viewer) + except: + pass + viewers = json.dumps(viewers) + context['ome']['open_with'] = viewers diff --git a/components/tools/OmeroWeb/omeroweb/webclient/templates/webclient/base/base_container.html b/components/tools/OmeroWeb/omeroweb/webclient/templates/webclient/base/base_container.html index 296f9fa48a6..d7e4e041b22 100644 --- a/components/tools/OmeroWeb/omeroweb/webclient/templates/webclient/base/base_container.html +++ b/components/tools/OmeroWeb/omeroweb/webclient/templates/webclient/base/base_container.html @@ -195,6 +195,13 @@ {% if page_size %} var PAGE_SIZE = {{ page_size }}; {% endif %} + + WEBCLIENT.OPEN_WITH = []; + {% if ome.open_with %} + // This is a json dump, so we can add it directly without escaping + WEBCLIENT.OPEN_WITH = {{ ome.open_with|safe }}; + {% endif %} + $(document).ready(function(){ // initially hidden $("#user_dropdown ul").css('visibility', 'hidden'); From 1095f60ab1026a08727138251df8568befaea5bf Mon Sep 17 00:00:00 2001 From: William Moore Date: Thu, 5 May 2016 00:03:42 +0100 Subject: [PATCH 03/29] ome.tree.js uses OPEN_WITH in right-click menu --- .../static/webclient/javascript/ome.tree.js | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/components/tools/OmeroWeb/omeroweb/webclient/static/webclient/javascript/ome.tree.js b/components/tools/OmeroWeb/omeroweb/webclient/static/webclient/javascript/ome.tree.js index 1421a6e0763..5b0fb1e39e3 100644 --- a/components/tools/OmeroWeb/omeroweb/webclient/static/webclient/javascript/ome.tree.js +++ b/components/tools/OmeroWeb/omeroweb/webclient/static/webclient/javascript/ome.tree.js @@ -960,6 +960,48 @@ $(function() { } }; + if (WEBCLIENT.OPEN_WITH.length > 0) { + // build a submenu of viewers... + var viewers = WEBCLIENT.OPEN_WITH.map(function(v){ + return { + "label": v.label, + "action": function() { + var inst = $.jstree.reference('#dataTree'), + sel = inst.get_selected(true).map(function(s){ + return s.type + "=" + s.data.id; + }), + query = sel.join("&"), + url = v.url + "?" + query; + if (v.open && v.open === 'tab') { + // tries to open in a new tab (not reliable) + // see http://stackoverflow.com/questions/4907843/open-a-url-in-a-new-tab-and-not-a-new-window-using-javascript + window.open(url,'_blank'); + } else { + OME.openPopup(url); + } + }, + "_disabled": function() { + var sel = $.jstree.reference('#dataTree').get_selected(true), + // selType = 'image' or 'images' or 'dataset' + selType = sel.reduce(function(prev, s){ + return s.type + (sel.length > 1 ? "s" : ""); + }, "undefined"); + // v.objects is ['image'] or ['dataset', 'images'] + var enabled = v.objects.reduce(function(prev, o){ + return prev || o.indexOf(selType) > -1; + }, false); + return !enabled; + } + }; + }); + config["open_with"] = { + "label": "Open With...", + "_disabled": false, + "action": false, + "submenu": viewers + }; + } + // List of permissions related disabling // use canLink, canDelete etc classes on each node to enable/disable right-click menu From 3aa4d13ea47397da92b1968c0eb9624c0c6cbb0f Mon Sep 17 00:00:00 2001 From: William Moore Date: Thu, 5 May 2016 00:39:51 +0100 Subject: [PATCH 04/29] flake8 fix --- components/tools/OmeroWeb/omeroweb/settings.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/components/tools/OmeroWeb/omeroweb/settings.py b/components/tools/OmeroWeb/omeroweb/settings.py index ae075cfc962..9fddae31587 100644 --- a/components/tools/OmeroWeb/omeroweb/settings.py +++ b/components/tools/OmeroWeb/omeroweb/settings.py @@ -41,6 +41,8 @@ import string from omero_ext import portalocker +from omero.util.concurrency import get_event +from connector import Server logger = logging.getLogger(__name__) @@ -161,7 +163,6 @@ # Load custom settings from etc/grid/config.xml # Tue 2 Nov 2010 11:03:18 GMT -- ticket:3228 -from omero.util.concurrency import get_event CONFIG_XML = os.path.join(OMERO_HOME, 'etc', 'grid', 'config.xml') count = 10 event = get_event("websettings") @@ -1195,7 +1196,6 @@ def report_settings(module): SESSION_SERIALIZER = 'django.contrib.sessions.serializers.PickleSerializer' # Load server list and freeze -from connector import Server def load_server_list(): From 6ebb349997b06a96c2492d3d24a9c0d6e7170ec0 Mon Sep 17 00:00:00 2001 From: William Moore Date: Mon, 30 May 2016 12:46:03 +0100 Subject: [PATCH 05/29] Add support for 'open with' scripts --- components/tools/OmeroWeb/omeroweb/settings.py | 2 +- .../OmeroWeb/omeroweb/webclient/decorators.py | 8 ++++++-- .../static/webclient/javascript/ome.tree.js | 11 ++++++++--- .../webclient/base/base_container.html | 17 +++++++++++++++++ 4 files changed, 32 insertions(+), 6 deletions(-) diff --git a/components/tools/OmeroWeb/omeroweb/settings.py b/components/tools/OmeroWeb/omeroweb/settings.py index 9fddae31587..505ee23d6cb 100644 --- a/components/tools/OmeroWeb/omeroweb/settings.py +++ b/components/tools/OmeroWeb/omeroweb/settings.py @@ -539,7 +539,7 @@ def leave_none_unset_int(s): ["OPEN_WITH", ('[["Test", "api_paths_to_object"],' '["OMERO.figure", "new_figure", ' - '{"objects":["images", "dataset"],"open":"tab"}]]'), + '{"objects": ["images", "dataset"], "target": "tab", "script": "figure/openwith.js"}]]'), json.loads, ("A list of viewers that can be used to display selected Images " "or other objects. Each viewer is defined as " diff --git a/components/tools/OmeroWeb/omeroweb/webclient/decorators.py b/components/tools/OmeroWeb/omeroweb/webclient/decorators.py index eb48dbf320c..6a495652bac 100644 --- a/components/tools/OmeroWeb/omeroweb/webclient/decorators.py +++ b/components/tools/OmeroWeb/omeroweb/webclient/decorators.py @@ -195,6 +195,7 @@ def load_settings(self, request, context, conn): open_with = settings.OPEN_WITH viewers = [] + openwith_scripts = [] for ow in open_with: viewer = {} viewer['objects'] = ['image'] @@ -204,8 +205,10 @@ def load_settings(self, request, context, conn): if len(ow) > 2: if 'objects' in ow[2]: viewer['objects'] = ow[2]['objects'] - if 'open' in ow[2]: - viewer['open'] = ow[2]['open'] + if 'target' in ow[2]: + viewer['target'] = ow[2]['target'] + if 'script' in ow[2]: + openwith_scripts.append(ow[2]['script']) except: # ignore invalid params pass @@ -219,3 +222,4 @@ def load_settings(self, request, context, conn): pass viewers = json.dumps(viewers) context['ome']['open_with'] = viewers + context['ome']['open_with_scripts'] = openwith_scripts diff --git a/components/tools/OmeroWeb/omeroweb/webclient/static/webclient/javascript/ome.tree.js b/components/tools/OmeroWeb/omeroweb/webclient/static/webclient/javascript/ome.tree.js index 5b0fb1e39e3..87d0b22bb5f 100644 --- a/components/tools/OmeroWeb/omeroweb/webclient/static/webclient/javascript/ome.tree.js +++ b/components/tools/OmeroWeb/omeroweb/webclient/static/webclient/javascript/ome.tree.js @@ -972,7 +972,7 @@ $(function() { }), query = sel.join("&"), url = v.url + "?" + query; - if (v.open && v.open === 'tab') { + if (v.target && v.target === 'tab') { // tries to open in a new tab (not reliable) // see http://stackoverflow.com/questions/4907843/open-a-url-in-a-new-tab-and-not-a-new-window-using-javascript window.open(url,'_blank'); @@ -985,9 +985,14 @@ $(function() { // selType = 'image' or 'images' or 'dataset' selType = sel.reduce(function(prev, s){ return s.type + (sel.length > 1 ? "s" : ""); - }, "undefined"); + }, "undefined"), + enabled; + if (typeof v.isEnabled === "function") { + enabled = v.isEnabled(sel); + return !enabled; + } // v.objects is ['image'] or ['dataset', 'images'] - var enabled = v.objects.reduce(function(prev, o){ + enabled = v.objects.reduce(function(prev, o){ return prev || o.indexOf(selType) > -1; }, false); return !enabled; diff --git a/components/tools/OmeroWeb/omeroweb/webclient/templates/webclient/base/base_container.html b/components/tools/OmeroWeb/omeroweb/webclient/templates/webclient/base/base_container.html index d7e4e041b22..19d8d0e86ac 100644 --- a/components/tools/OmeroWeb/omeroweb/webclient/templates/webclient/base/base_container.html +++ b/components/tools/OmeroWeb/omeroweb/webclient/templates/webclient/base/base_container.html @@ -196,11 +196,28 @@ var PAGE_SIZE = {{ page_size }}; {% endif %} + + // ** "Open With" config used by E.g. ome.tree.js ** WEBCLIENT.OPEN_WITH = []; {% if ome.open_with %} // This is a json dump, so we can add it directly without escaping WEBCLIENT.OPEN_WITH = {{ ome.open_with|safe }}; {% endif %} + // Helper can be used by 'open with' plugins to add isEnabled() + // handlers to the OPEN_WITH object. + OME.setOpenWithEnabledHandler = function(label, fn) { + // look for label in OPEN_WITH + WEBCLIENT.OPEN_WITH.forEach(function(ow){ + if (ow.label === label) { + ow.isEnabled = fn; + } + }); + } + // Include any JavaScript snippets provided by 'open with' plugins + {% for ow in ome.open_with_scripts %} + {% include ow %} + {% endfor %} + $(document).ready(function(){ // initially hidden From 08f2fcdc7ed50089f7d87e8e6ac4faef514f30fa Mon Sep 17 00:00:00 2001 From: William Moore Date: Mon, 30 May 2016 13:02:04 +0100 Subject: [PATCH 06/29] Support external urls. try/excpet reverse(url) --- .../OmeroWeb/omeroweb/webclient/decorators.py | 21 ++++++++++--------- .../static/webclient/javascript/ome.tree.js | 2 ++ 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/components/tools/OmeroWeb/omeroweb/webclient/decorators.py b/components/tools/OmeroWeb/omeroweb/webclient/decorators.py index 6a495652bac..d0bd2ead89d 100644 --- a/components/tools/OmeroWeb/omeroweb/webclient/decorators.py +++ b/components/tools/OmeroWeb/omeroweb/webclient/decorators.py @@ -31,7 +31,7 @@ from django.http import HttpResponse from django.conf import settings -from django.core.urlresolvers import reverse +from django.core.urlresolvers import reverse, NoReverseMatch from omeroweb.webclient.forms import GlobalSearchForm @@ -197,10 +197,18 @@ def load_settings(self, request, context, conn): viewers = [] openwith_scripts = [] for ow in open_with: + if len(ow) < 2: + continue viewer = {} + viewer['label'] = ow[0] + try: + viewer['url'] = reverse(ow[1]) + except NoReverseMatch: + viewer['url'] = ow[1] + # try non-essential parameters... + # By default, we support single image, opening in new window viewer['objects'] = ['image'] viewer['open'] = 'window' - # try non-essential parameters... try: if len(ow) > 2: if 'objects' in ow[2]: @@ -212,14 +220,7 @@ def load_settings(self, request, context, conn): except: # ignore invalid params pass - # try essential parameters... - try: - viewer['label'] = ow[0] - viewer['url'] = reverse(ow[1]) - # Only add if we have label and url - viewers.append(viewer) - except: - pass + viewers.append(viewer) viewers = json.dumps(viewers) context['ome']['open_with'] = viewers context['ome']['open_with_scripts'] = openwith_scripts diff --git a/components/tools/OmeroWeb/omeroweb/webclient/static/webclient/javascript/ome.tree.js b/components/tools/OmeroWeb/omeroweb/webclient/static/webclient/javascript/ome.tree.js index 87d0b22bb5f..3a5f6f0b64b 100644 --- a/components/tools/OmeroWeb/omeroweb/webclient/static/webclient/javascript/ome.tree.js +++ b/components/tools/OmeroWeb/omeroweb/webclient/static/webclient/javascript/ome.tree.js @@ -987,10 +987,12 @@ $(function() { return s.type + (sel.length > 1 ? "s" : ""); }, "undefined"), enabled; + // If plugin has provided a function 'isEnabled'... if (typeof v.isEnabled === "function") { enabled = v.isEnabled(sel); return !enabled; } + // ...Otherwise use the supported objects list // v.objects is ['image'] or ['dataset', 'images'] enabled = v.objects.reduce(function(prev, o){ return prev || o.indexOf(selType) > -1; From 4f7e56f93cec0c1fbdd29a765a25cae9c81d2695 Mon Sep 17 00:00:00 2001 From: William Moore Date: Mon, 30 May 2016 14:30:47 +0100 Subject: [PATCH 07/29] Add action handling to 'open_with' plugins --- .../static/webclient/javascript/ome.tree.js | 11 ++++++++--- .../templates/webclient/base/base_container.html | 15 +++++++++++++-- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/components/tools/OmeroWeb/omeroweb/webclient/static/webclient/javascript/ome.tree.js b/components/tools/OmeroWeb/omeroweb/webclient/static/webclient/javascript/ome.tree.js index 3a5f6f0b64b..20e20687155 100644 --- a/components/tools/OmeroWeb/omeroweb/webclient/static/webclient/javascript/ome.tree.js +++ b/components/tools/OmeroWeb/omeroweb/webclient/static/webclient/javascript/ome.tree.js @@ -967,12 +967,17 @@ $(function() { "label": v.label, "action": function() { var inst = $.jstree.reference('#dataTree'), - sel = inst.get_selected(true).map(function(s){ + sel = inst.get_selected(true), + dtypes = sel.map(function(s){ return s.type + "=" + s.data.id; }), - query = sel.join("&"), + query = dtypes.join("&"), url = v.url + "?" + query; - if (v.target && v.target === 'tab') { + // if plugin has provided an action handler... + if (v.action) { + v.action(sel, v.url); + } + else if (v.target && v.target === 'tab') { // tries to open in a new tab (not reliable) // see http://stackoverflow.com/questions/4907843/open-a-url-in-a-new-tab-and-not-a-new-window-using-javascript window.open(url,'_blank'); diff --git a/components/tools/OmeroWeb/omeroweb/webclient/templates/webclient/base/base_container.html b/components/tools/OmeroWeb/omeroweb/webclient/templates/webclient/base/base_container.html index 19d8d0e86ac..4b3b261d6bb 100644 --- a/components/tools/OmeroWeb/omeroweb/webclient/templates/webclient/base/base_container.html +++ b/components/tools/OmeroWeb/omeroweb/webclient/templates/webclient/base/base_container.html @@ -212,10 +212,21 @@ ow.isEnabled = fn; } }); - } + }; + OME.setOpenWithActionHandler = function(label, fn) { + // look for label in OPEN_WITH + WEBCLIENT.OPEN_WITH.forEach(function(ow){ + if (ow.label === label) { + ow.action = fn; + } + }); + }; // Include any JavaScript snippets provided by 'open with' plugins {% for ow in ome.open_with_scripts %} - {% include ow %} + (function(){ + // Wrap them in self-executing function + {% include ow %} + }()); {% endfor %} From ee70460897fa31c0c9f493e7ebe4d7dd9737db37 Mon Sep 17 00:00:00 2001 From: William Moore Date: Mon, 30 May 2016 14:31:33 +0100 Subject: [PATCH 08/29] Add TEMP example openwith.js --- .../webclient/templates/webclient/openwith.js | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 components/tools/OmeroWeb/omeroweb/webclient/templates/webclient/openwith.js diff --git a/components/tools/OmeroWeb/omeroweb/webclient/templates/webclient/openwith.js b/components/tools/OmeroWeb/omeroweb/webclient/templates/webclient/openwith.js new file mode 100644 index 00000000000..a8a95d78768 --- /dev/null +++ b/components/tools/OmeroWeb/omeroweb/webclient/templates/webclient/openwith.js @@ -0,0 +1,23 @@ + + // Example openwith script + // TEMP - for evaluation of https://github.com/openmicroscopy/openmicroscopy/pull/4630 + // TODO: remove this before merging PR! + var isEnabled = function(selected) { + console.log('GenBank Protein, isEnabled()', selected); + if (selected.length !== 1) return false; + + // return True if name is a number (E.g. Gene ID) + var name = selected[0].data.obj.name; + return (parseInt(name, 10) == name); + }; + + var handleAction = function(selected, url) { + console.log('GenBank Protein, handleAction()', selected, url); + var name = selected[0].data.obj.name; + window.open(url + name, 'new'); + }; + + + OME.setOpenWithEnabledHandler("GenBank Protein", isEnabled); + OME.setOpenWithActionHandler("GenBank Protein", handleAction); + From 8a567a7be4558f75742669102df30413b263d00e Mon Sep 17 00:00:00 2001 From: William Moore Date: Mon, 30 May 2016 14:55:06 +0100 Subject: [PATCH 09/29] remove 'script' from hardcoded OMERO.figure openwith --- components/tools/OmeroWeb/omeroweb/settings.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/tools/OmeroWeb/omeroweb/settings.py b/components/tools/OmeroWeb/omeroweb/settings.py index 505ee23d6cb..c2ad5c06fe6 100644 --- a/components/tools/OmeroWeb/omeroweb/settings.py +++ b/components/tools/OmeroWeb/omeroweb/settings.py @@ -539,7 +539,7 @@ def leave_none_unset_int(s): ["OPEN_WITH", ('[["Test", "api_paths_to_object"],' '["OMERO.figure", "new_figure", ' - '{"objects": ["images", "dataset"], "target": "tab", "script": "figure/openwith.js"}]]'), + '{"objects": ["images", "dataset"], "target": "tab"}]]'), json.loads, ("A list of viewers that can be used to display selected Images " "or other objects. Each viewer is defined as " From a7cd108ffa5c3e807081a6eff258ac382fcebcc7 Mon Sep 17 00:00:00 2001 From: William Moore Date: Fri, 17 Jun 2016 11:46:14 +0100 Subject: [PATCH 10/29] Added fileannotation support to 'open with' --- .../ome.right_panel_fileanns_pane.js | 41 +++++++++++++++++++ .../static/webclient/javascript/ome.tree.js | 23 +++++++++-- .../annotations/fileanns_underscore.html | 12 ++++++ .../webclient/templates/webclient/openwith.js | 29 +++++++++++-- 4 files changed, 98 insertions(+), 7 deletions(-) diff --git a/components/tools/OmeroWeb/omeroweb/webclient/static/webclient/javascript/ome.right_panel_fileanns_pane.js b/components/tools/OmeroWeb/omeroweb/webclient/static/webclient/javascript/ome.right_panel_fileanns_pane.js index d631c728290..7a091c13bc1 100644 --- a/components/tools/OmeroWeb/omeroweb/webclient/static/webclient/javascript/ome.right_panel_fileanns_pane.js +++ b/components/tools/OmeroWeb/omeroweb/webclient/static/webclient/javascript/ome.right_panel_fileanns_pane.js @@ -117,6 +117,25 @@ var FileAnnsPane = function FileAnnsPane($element, opts) { OME.deleteItem(event, "file_ann_wrapper", url); }); + // Handle 'Open With'... + $("#fileanns_container").on("change", ".openWith", function(event) { + var label = this.value; + var annId = $(this).attr('data-id'); + + // get json data for this file, using cached self.annJson + var annData = self.annJson.filter(function(a){ + return a.id == annId; + })[0]; // should find single unique item matching annId + WEBCLIENT.OPEN_WITH.forEach(function(ow){ + if (ow.label === label) { + // need json data for fileannotation + annData = $.extend({'type': 'fileannotation'}, annData); + // action expects list of objects + ow.action([annData], ow.url); + } + }); + }); + var isNotCompanionFile = function isNotCompanionFile(ann) { return ann.ns !== OMERO.constants.namespaces.NSCOMPANIONFILE; @@ -210,6 +229,28 @@ var FileAnnsPane = function FileAnnsPane($element, opts) { } } + // We cache json - used for openWith handling above + self.annJson = anns; + + // for each annotation, we create an 'Open With' menu... + anns.forEach(function(ann){ + var openWith = WEBCLIENT.OPEN_WITH.map(function(v){ + var menu = {'label': v.label}; + //If plugin has provided a function 'isEnabled'... + if (typeof v.isEnabled === "function") { + // prepare json to pass to isEnabled() + var objJson = $.extend({'type': 'fileannotation'}, ann); + // isEnabled() expects a list of objects + menu.enabled = v.isEnabled([objJson]); + } else { + // Just test to see if plugin accepts fileannotations... + menu.enabled = (v.objects.indexOf("fileannotation") > -1); + } + return menu; + }); + ann.openWith = openWith; + }); + // Update html... var html = ""; if (anns.length > 0) { diff --git a/components/tools/OmeroWeb/omeroweb/webclient/static/webclient/javascript/ome.tree.js b/components/tools/OmeroWeb/omeroweb/webclient/static/webclient/javascript/ome.tree.js index 20e20687155..a7a3c9b0b6b 100644 --- a/components/tools/OmeroWeb/omeroweb/webclient/static/webclient/javascript/ome.tree.js +++ b/components/tools/OmeroWeb/omeroweb/webclient/static/webclient/javascript/ome.tree.js @@ -975,9 +975,18 @@ $(function() { url = v.url + "?" + query; // if plugin has provided an action handler... if (v.action) { - v.action(sel, v.url); + // prepare json of selected objects to pass to function + var selJson = sel.map(function(s){ + var o = $.extend({}, s.data.obj); + o.type = s.type; + return o; + }); + // see if it handles the event + var eventBubbled = v.action(selJson, v.url); + if (!eventBubbled) return; } - else if (v.target && v.target === 'tab') { + // ...otherwise we use default handling... + if (v.target && v.target === 'tab') { // tries to open in a new tab (not reliable) // see http://stackoverflow.com/questions/4907843/open-a-url-in-a-new-tab-and-not-a-new-window-using-javascript window.open(url,'_blank'); @@ -992,9 +1001,15 @@ $(function() { return s.type + (sel.length > 1 ? "s" : ""); }, "undefined"), enabled; - // If plugin has provided a function 'isEnabled'... if (typeof v.isEnabled === "function") { - enabled = v.isEnabled(sel); + // If plugin has provided a function 'isEnabled'... + // prepare json of selected objects to pass to function + var selJson = sel.map(function(s){ + var o = $.extend({}, s.data.obj); + o.type = s.type; + return o; + }); + enabled = v.isEnabled(selJson); return !enabled; } // ...Otherwise use the supported objects list diff --git a/components/tools/OmeroWeb/omeroweb/webclient/templates/webclient/annotations/fileanns_underscore.html b/components/tools/OmeroWeb/omeroweb/webclient/templates/webclient/annotations/fileanns_underscore.html index 936a4d3df8a..9a7b9e261ae 100644 --- a/components/tools/OmeroWeb/omeroweb/webclient/templates/webclient/annotations/fileanns_underscore.html +++ b/components/tools/OmeroWeb/omeroweb/webclient/templates/webclient/annotations/fileanns_underscore.html @@ -42,6 +42,18 @@
+ <% if (ann.openWith.length > 0) { %> + + <% } %> + <% if (ann.link.permissions.canDelete) { %> Date: Mon, 20 Jun 2016 13:56:51 +0100 Subject: [PATCH 11/29] Add default handling of 'open with...' for file annotations --- .../ome.right_panel_fileanns_pane.js | 20 +++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/components/tools/OmeroWeb/omeroweb/webclient/static/webclient/javascript/ome.right_panel_fileanns_pane.js b/components/tools/OmeroWeb/omeroweb/webclient/static/webclient/javascript/ome.right_panel_fileanns_pane.js index 7a091c13bc1..56c71ca1168 100644 --- a/components/tools/OmeroWeb/omeroweb/webclient/static/webclient/javascript/ome.right_panel_fileanns_pane.js +++ b/components/tools/OmeroWeb/omeroweb/webclient/static/webclient/javascript/ome.right_panel_fileanns_pane.js @@ -128,10 +128,22 @@ var FileAnnsPane = function FileAnnsPane($element, opts) { })[0]; // should find single unique item matching annId WEBCLIENT.OPEN_WITH.forEach(function(ow){ if (ow.label === label) { - // need json data for fileannotation - annData = $.extend({'type': 'fileannotation'}, annData); - // action expects list of objects - ow.action([annData], ow.url); + // if action has been provided... + if (ow.action) { + // need json data for fileannotation + annData = $.extend({'type': 'fileannotation'}, annData); + // action expects list of objects + var eventBubbled = ow.action([annData], ow.url); + if (!eventBubbled) return; + } + // ...otherwise we use default handling... + var url = ow.url + "?annotation=" + annId; + if (ow.target && ow.target === 'tab') { + // tries to open in a new tab (not reliable) + window.open(url,'_blank'); + } else { + OME.openPopup(url); + } } }); }); From 3eaa0be8f85e1883acb2bdf61745384e6a216943 Mon Sep 17 00:00:00 2001 From: William Moore Date: Mon, 4 Jul 2016 13:53:08 +0100 Subject: [PATCH 12/29] Remove fileannotation support from open_with This can be added back in a future PR --- .../ome.right_panel_fileanns_pane.js | 53 ------------------- .../annotations/fileanns_underscore.html | 12 ----- 2 files changed, 65 deletions(-) diff --git a/components/tools/OmeroWeb/omeroweb/webclient/static/webclient/javascript/ome.right_panel_fileanns_pane.js b/components/tools/OmeroWeb/omeroweb/webclient/static/webclient/javascript/ome.right_panel_fileanns_pane.js index 56c71ca1168..d631c728290 100644 --- a/components/tools/OmeroWeb/omeroweb/webclient/static/webclient/javascript/ome.right_panel_fileanns_pane.js +++ b/components/tools/OmeroWeb/omeroweb/webclient/static/webclient/javascript/ome.right_panel_fileanns_pane.js @@ -117,37 +117,6 @@ var FileAnnsPane = function FileAnnsPane($element, opts) { OME.deleteItem(event, "file_ann_wrapper", url); }); - // Handle 'Open With'... - $("#fileanns_container").on("change", ".openWith", function(event) { - var label = this.value; - var annId = $(this).attr('data-id'); - - // get json data for this file, using cached self.annJson - var annData = self.annJson.filter(function(a){ - return a.id == annId; - })[0]; // should find single unique item matching annId - WEBCLIENT.OPEN_WITH.forEach(function(ow){ - if (ow.label === label) { - // if action has been provided... - if (ow.action) { - // need json data for fileannotation - annData = $.extend({'type': 'fileannotation'}, annData); - // action expects list of objects - var eventBubbled = ow.action([annData], ow.url); - if (!eventBubbled) return; - } - // ...otherwise we use default handling... - var url = ow.url + "?annotation=" + annId; - if (ow.target && ow.target === 'tab') { - // tries to open in a new tab (not reliable) - window.open(url,'_blank'); - } else { - OME.openPopup(url); - } - } - }); - }); - var isNotCompanionFile = function isNotCompanionFile(ann) { return ann.ns !== OMERO.constants.namespaces.NSCOMPANIONFILE; @@ -241,28 +210,6 @@ var FileAnnsPane = function FileAnnsPane($element, opts) { } } - // We cache json - used for openWith handling above - self.annJson = anns; - - // for each annotation, we create an 'Open With' menu... - anns.forEach(function(ann){ - var openWith = WEBCLIENT.OPEN_WITH.map(function(v){ - var menu = {'label': v.label}; - //If plugin has provided a function 'isEnabled'... - if (typeof v.isEnabled === "function") { - // prepare json to pass to isEnabled() - var objJson = $.extend({'type': 'fileannotation'}, ann); - // isEnabled() expects a list of objects - menu.enabled = v.isEnabled([objJson]); - } else { - // Just test to see if plugin accepts fileannotations... - menu.enabled = (v.objects.indexOf("fileannotation") > -1); - } - return menu; - }); - ann.openWith = openWith; - }); - // Update html... var html = ""; if (anns.length > 0) { diff --git a/components/tools/OmeroWeb/omeroweb/webclient/templates/webclient/annotations/fileanns_underscore.html b/components/tools/OmeroWeb/omeroweb/webclient/templates/webclient/annotations/fileanns_underscore.html index 9a7b9e261ae..936a4d3df8a 100644 --- a/components/tools/OmeroWeb/omeroweb/webclient/templates/webclient/annotations/fileanns_underscore.html +++ b/components/tools/OmeroWeb/omeroweb/webclient/templates/webclient/annotations/fileanns_underscore.html @@ -42,18 +42,6 @@
- <% if (ann.openWith.length > 0) { %> - - <% } %> - <% if (ann.link.permissions.canDelete) { %> Date: Mon, 4 Jul 2016 14:02:56 +0100 Subject: [PATCH 13/29] Only pass {id, name, type} to script functions --- .../webclient/static/webclient/javascript/ome.tree.js | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/components/tools/OmeroWeb/omeroweb/webclient/static/webclient/javascript/ome.tree.js b/components/tools/OmeroWeb/omeroweb/webclient/static/webclient/javascript/ome.tree.js index a7a3c9b0b6b..fc93416edb2 100644 --- a/components/tools/OmeroWeb/omeroweb/webclient/static/webclient/javascript/ome.tree.js +++ b/components/tools/OmeroWeb/omeroweb/webclient/static/webclient/javascript/ome.tree.js @@ -977,8 +977,10 @@ $(function() { if (v.action) { // prepare json of selected objects to pass to function var selJson = sel.map(function(s){ - var o = $.extend({}, s.data.obj); - o.type = s.type; + // var o = $.extend({}, s.data.obj); + var o = {'id': s.data.obj.id, + 'name': s.data.obj.name, + 'type': s.type}; return o; }); // see if it handles the event @@ -1005,8 +1007,9 @@ $(function() { // If plugin has provided a function 'isEnabled'... // prepare json of selected objects to pass to function var selJson = sel.map(function(s){ - var o = $.extend({}, s.data.obj); - o.type = s.type; + var o = {'id': s.data.obj.id, + 'name': s.data.obj.name, + 'type': s.type}; return o; }); enabled = v.isEnabled(selJson); From 87e9dcd54b7566d9ad5961d9d23b09ec97b265c5 Mon Sep 17 00:00:00 2001 From: William Moore Date: Mon, 4 Jul 2016 14:49:57 +0100 Subject: [PATCH 14/29] Wrap isEnabled() and handleAction() in try/catch --- .../webclient/base/base_container.html | 24 +++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/components/tools/OmeroWeb/omeroweb/webclient/templates/webclient/base/base_container.html b/components/tools/OmeroWeb/omeroweb/webclient/templates/webclient/base/base_container.html index 4b3b261d6bb..5758fe6a5c4 100644 --- a/components/tools/OmeroWeb/omeroweb/webclient/templates/webclient/base/base_container.html +++ b/components/tools/OmeroWeb/omeroweb/webclient/templates/webclient/base/base_container.html @@ -209,7 +209,17 @@ // look for label in OPEN_WITH WEBCLIENT.OPEN_WITH.forEach(function(ow){ if (ow.label === label) { - ow.isEnabled = fn; + ow.isEnabled = function() { + // wrap fn with try/catch, return true by default + var args = Array.from(arguments); + try { + enabled = fn(args); + } catch (e) { + console.log("Open with " + label + ": " + e); + enabled = true; + } + return enabled; + } } }); }; @@ -217,7 +227,17 @@ // look for label in OPEN_WITH WEBCLIENT.OPEN_WITH.forEach(function(ow){ if (ow.label === label) { - ow.action = fn; + ow.action = function() { + // wrap fn with try/catch, return false if error + var args = Array.from(arguments); + try { + enabled = fn(args); + } catch (e) { + console.log("Open with " + label + ": " + e); + enabled = false; + } + return enabled; + } } }); }; From 9497b4297d3ec51f3488bf40160ba201adf346b4 Mon Sep 17 00:00:00 2001 From: William Moore Date: Mon, 4 Jul 2016 15:18:22 +0100 Subject: [PATCH 15/29] Removing default items from settings.OPEN_WITH Also adding to doc string. Add a url to the PR for docs. Can update to point to docs page once we have it. --- components/tools/OmeroWeb/omeroweb/settings.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/components/tools/OmeroWeb/omeroweb/settings.py b/components/tools/OmeroWeb/omeroweb/settings.py index c2ad5c06fe6..443b93ae918 100644 --- a/components/tools/OmeroWeb/omeroweb/settings.py +++ b/components/tools/OmeroWeb/omeroweb/settings.py @@ -537,16 +537,16 @@ def leave_none_unset_int(s): # OPEN WITH "omero.web.open_with": ["OPEN_WITH", - ('[["Test", "api_paths_to_object"],' - '["OMERO.figure", "new_figure", ' - '{"objects": ["images", "dataset"], "target": "tab"}]]'), + ('[]'), json.loads, ("A list of viewers that can be used to display selected Images " "or other objects. Each viewer is defined as " "``[\"Name\", \"url\", options]``. Url is reverse(url). " "Selected objects are added to the url as ?image=:1&image=2" - "The options object is optional E.g. {\"objects\":[\"images\"]} " - "to enable viewer for one or more images")], + "The options object is optional E.g. ``{\"objects\":[\"images\"]}`` " + "to enable viewer for one or more images, " + "``{\"target\":\"tab\"}`` to open in new tab. " + "See https://github.com/openmicroscopy/openmicroscopy/pull/4630")], # PIPELINE 1.3.20 From 94f67dce06f9a297172aeeede95d8ec15ecc25b0 Mon Sep 17 00:00:00 2001 From: William Moore Date: Tue, 27 Sep 2016 15:31:00 +0100 Subject: [PATCH 16/29] Load open_with options via JSON --- .../OmeroWeb/omeroweb/webclient/decorators.py | 34 +--------------- .../static/webclient/javascript/ome.tree.js | 12 +++--- .../webclient/base/base_container.html | 26 ++++++------ .../OmeroWeb/omeroweb/webgateway/urls.py | 5 ++- .../OmeroWeb/omeroweb/webgateway/views.py | 40 ++++++++++++++++++- 5 files changed, 62 insertions(+), 55 deletions(-) diff --git a/components/tools/OmeroWeb/omeroweb/webclient/decorators.py b/components/tools/OmeroWeb/omeroweb/webclient/decorators.py index d0bd2ead89d..e3d65cbf755 100644 --- a/components/tools/OmeroWeb/omeroweb/webclient/decorators.py +++ b/components/tools/OmeroWeb/omeroweb/webclient/decorators.py @@ -24,14 +24,13 @@ """ import logging -import json import omeroweb.decorators from omero import constants from django.http import HttpResponse from django.conf import settings -from django.core.urlresolvers import reverse, NoReverseMatch +from django.core.urlresolvers import reverse from omeroweb.webclient.forms import GlobalSearchForm @@ -193,34 +192,3 @@ def load_settings(self, request, context, conn): "label": label, "include": include, "plugin_id": plugin_id}) context['ome']['center_plugins'] = c_plugins - open_with = settings.OPEN_WITH - viewers = [] - openwith_scripts = [] - for ow in open_with: - if len(ow) < 2: - continue - viewer = {} - viewer['label'] = ow[0] - try: - viewer['url'] = reverse(ow[1]) - except NoReverseMatch: - viewer['url'] = ow[1] - # try non-essential parameters... - # By default, we support single image, opening in new window - viewer['objects'] = ['image'] - viewer['open'] = 'window' - try: - if len(ow) > 2: - if 'objects' in ow[2]: - viewer['objects'] = ow[2]['objects'] - if 'target' in ow[2]: - viewer['target'] = ow[2]['target'] - if 'script' in ow[2]: - openwith_scripts.append(ow[2]['script']) - except: - # ignore invalid params - pass - viewers.append(viewer) - viewers = json.dumps(viewers) - context['ome']['open_with'] = viewers - context['ome']['open_with_scripts'] = openwith_scripts diff --git a/components/tools/OmeroWeb/omeroweb/webclient/static/webclient/javascript/ome.tree.js b/components/tools/OmeroWeb/omeroweb/webclient/static/webclient/javascript/ome.tree.js index fc93416edb2..87be162ed55 100644 --- a/components/tools/OmeroWeb/omeroweb/webclient/static/webclient/javascript/ome.tree.js +++ b/components/tools/OmeroWeb/omeroweb/webclient/static/webclient/javascript/ome.tree.js @@ -959,7 +959,6 @@ $(function() { } } }; - if (WEBCLIENT.OPEN_WITH.length > 0) { // build a submenu of viewers... var viewers = WEBCLIENT.OPEN_WITH.map(function(v){ @@ -988,10 +987,9 @@ $(function() { if (!eventBubbled) return; } // ...otherwise we use default handling... - if (v.target && v.target === 'tab') { - // tries to open in a new tab (not reliable) - // see http://stackoverflow.com/questions/4907843/open-a-url-in-a-new-tab-and-not-a-new-window-using-javascript - window.open(url,'_blank'); + if (v.target) { + // E.g. target '_blank' tries to open in a new tab + window.open(url, v.target); } else { OME.openPopup(url); } @@ -1016,8 +1014,8 @@ $(function() { return !enabled; } // ...Otherwise use the supported objects list - // v.objects is ['image'] or ['dataset', 'images'] - enabled = v.objects.reduce(function(prev, o){ + // v.supported_objects is ['image'] or ['dataset', 'images'] + enabled = v.supported_objects.reduce(function(prev, o){ return prev || o.indexOf(selType) > -1; }, false); return !enabled; diff --git a/components/tools/OmeroWeb/omeroweb/webclient/templates/webclient/base/base_container.html b/components/tools/OmeroWeb/omeroweb/webclient/templates/webclient/base/base_container.html index 5758fe6a5c4..f07f061c2aa 100644 --- a/components/tools/OmeroWeb/omeroweb/webclient/templates/webclient/base/base_container.html +++ b/components/tools/OmeroWeb/omeroweb/webclient/templates/webclient/base/base_container.html @@ -199,10 +199,18 @@ // ** "Open With" config used by E.g. ome.tree.js ** WEBCLIENT.OPEN_WITH = []; - {% if ome.open_with %} - // This is a json dump, so we can add it directly without escaping - WEBCLIENT.OPEN_WITH = {{ ome.open_with|safe }}; - {% endif %} + $.getJSON("{% url 'webgateway.views.open_with_options' %}", function(data){ + if (data && data.open_with_options) { + WEBCLIENT.OPEN_WITH = data.open_with_options; + + WEBCLIENT.OPEN_WITH.forEach(function(ow){ + if (ow.script_url) { + $.getScript(ow.script_url); + } + }) + } + }); + // Helper can be used by 'open with' plugins to add isEnabled() // handlers to the OPEN_WITH object. OME.setOpenWithEnabledHandler = function(label, fn) { @@ -213,7 +221,7 @@ // wrap fn with try/catch, return true by default var args = Array.from(arguments); try { - enabled = fn(args); + enabled = fn.apply(this, args); } catch (e) { console.log("Open with " + label + ": " + e); enabled = true; @@ -241,14 +249,6 @@ } }); }; - // Include any JavaScript snippets provided by 'open with' plugins - {% for ow in ome.open_with_scripts %} - (function(){ - // Wrap them in self-executing function - {% include ow %} - }()); - {% endfor %} - $(document).ready(function(){ // initially hidden diff --git a/components/tools/OmeroWeb/omeroweb/webgateway/urls.py b/components/tools/OmeroWeb/omeroweb/webgateway/urls.py index a9866192291..c8cb5f8a9b0 100644 --- a/components/tools/OmeroWeb/omeroweb/webgateway/urls.py +++ b/components/tools/OmeroWeb/omeroweb/webgateway/urls.py @@ -406,6 +406,9 @@ 'client' is a list of paths for original files on the client when imported """ +open_with_options = url(r'^open_with/$', 'webgateway.views.open_with_options', + name='open_with_options') + urlpatterns = patterns( '', webgateway, @@ -454,7 +457,7 @@ annotations, table_query, object_table_query, - + open_with_options, # Debug stuff ) diff --git a/components/tools/OmeroWeb/omeroweb/webgateway/views.py b/components/tools/OmeroWeb/omeroweb/webgateway/views.py index 985411ca6c2..7ef76cb7941 100644 --- a/components/tools/OmeroWeb/omeroweb/webgateway/views.py +++ b/components/tools/OmeroWeb/omeroweb/webgateway/views.py @@ -22,7 +22,7 @@ from django.http import HttpResponseRedirect, HttpResponseNotAllowed, Http404 from django.template import loader as template_loader from django.views.decorators.http import require_POST -from django.core.urlresolvers import reverse +from django.core.urlresolvers import reverse, NoReverseMatch from django.conf import settings from django.template import RequestContext as Context from django.core.servers.basehttp import FileWrapper @@ -32,6 +32,7 @@ from plategrid import PlateGrid from omero_version import build_year from marshal import imageMarshal, shapeMarshal, rgb_int2rgba +from django.contrib.staticfiles.templatetags.staticfiles import static try: from hashlib import md5 @@ -1515,6 +1516,43 @@ def projectDetail_json(request, pid, conn=None, **kwargs): rv = pr.simpleMarshal() return rv +@jsonp +def open_with_options(request, **kwargs): + """ + Make the settings.OPEN_WITH available via JSON + """ + open_with = settings.OPEN_WITH + viewers = [] + for ow in open_with: + if len(ow) < 2: + continue + viewer = {} + viewer['label'] = ow[0] + try: + viewer['url'] = reverse(ow[1]) + except NoReverseMatch: + viewer['url'] = ow[1] + # try non-essential parameters... + # By default, we support single image, opening in new window + viewer['supported_objects'] = ['image'] + try: + if len(ow) > 2: + print ow[2] + if 'objects' in ow[2]: + viewer['supported_objects'] = ow[2]['objects'] + if 'target' in ow[2]: + viewer['target'] = ow[2]['target'] + if 'script_url' in ow[2]: + try: + viewer['script_url'] = static(ow[2]['script_url']) + except NoReverseMatch: + viewer['script_url'] = ow[2]['script_url'] + except: + # ignore invalid params + pass + viewers.append(viewer) + return {'open_with_options': viewers} + def searchOptFromRequest(request): """ From 66810ac9a737f36e60913ab02fc236c6f9a82fa4 Mon Sep 17 00:00:00 2001 From: William Moore Date: Tue, 27 Sep 2016 15:44:26 +0100 Subject: [PATCH 17/29] Update settings OPEN_WITH doc string and remove 'print' --- components/tools/OmeroWeb/omeroweb/settings.py | 6 +++--- components/tools/OmeroWeb/omeroweb/webgateway/views.py | 1 - 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/components/tools/OmeroWeb/omeroweb/settings.py b/components/tools/OmeroWeb/omeroweb/settings.py index ece6d50d12c..cfafc6f7ebf 100644 --- a/components/tools/OmeroWeb/omeroweb/settings.py +++ b/components/tools/OmeroWeb/omeroweb/settings.py @@ -543,10 +543,10 @@ def leave_none_unset_int(s): "or other objects. Each viewer is defined as " "``[\"Name\", \"url\", options]``. Url is reverse(url). " "Selected objects are added to the url as ?image=:1&image=2" - "The options object is optional E.g. ``{\"objects\":[\"images\"]}`` " + "The options object is optional " + "E.g. ``{\"supported_objects\":[\"images\"]}`` " "to enable viewer for one or more images, " - "``{\"target\":\"tab\"}`` to open in new tab. " - "See https://github.com/openmicroscopy/openmicroscopy/pull/4630")], + "``{\"target\":\"_blank\"}`` to open in new tab.")], # PIPELINE 1.3.20 diff --git a/components/tools/OmeroWeb/omeroweb/webgateway/views.py b/components/tools/OmeroWeb/omeroweb/webgateway/views.py index 6f9f41a9d3d..188eed0ebee 100644 --- a/components/tools/OmeroWeb/omeroweb/webgateway/views.py +++ b/components/tools/OmeroWeb/omeroweb/webgateway/views.py @@ -1543,7 +1543,6 @@ def open_with_options(request, **kwargs): viewer['supported_objects'] = ['image'] try: if len(ow) > 2: - print ow[2] if 'objects' in ow[2]: viewer['supported_objects'] = ow[2]['objects'] if 'target' in ow[2]: From 32a5b66a5b67da3b688b93a00cf4351a401903e5 Mon Sep 17 00:00:00 2001 From: William Moore Date: Tue, 27 Sep 2016 22:41:15 +0100 Subject: [PATCH 18/29] Small fixes, removing try/except, delete openwith.js --- .../OmeroWeb/omeroweb/webclient/decorators.py | 1 - .../static/webclient/javascript/ome.tree.js | 2 +- .../webclient/base/base_container.html | 13 ++---- .../webclient/templates/webclient/openwith.js | 46 ------------------- 4 files changed, 5 insertions(+), 57 deletions(-) delete mode 100644 components/tools/OmeroWeb/omeroweb/webclient/templates/webclient/openwith.js diff --git a/components/tools/OmeroWeb/omeroweb/webclient/decorators.py b/components/tools/OmeroWeb/omeroweb/webclient/decorators.py index 7f065b6d63f..bcda8d94a26 100644 --- a/components/tools/OmeroWeb/omeroweb/webclient/decorators.py +++ b/components/tools/OmeroWeb/omeroweb/webclient/decorators.py @@ -202,4 +202,3 @@ def load_settings(self, request, context, conn): c_plugins.append({ "label": label, "include": include, "plugin_id": plugin_id}) context['ome']['center_plugins'] = c_plugins - diff --git a/components/tools/OmeroWeb/omeroweb/webclient/static/webclient/javascript/ome.tree.js b/components/tools/OmeroWeb/omeroweb/webclient/static/webclient/javascript/ome.tree.js index f9b45af5e24..1c869006348 100644 --- a/components/tools/OmeroWeb/omeroweb/webclient/static/webclient/javascript/ome.tree.js +++ b/components/tools/OmeroWeb/omeroweb/webclient/static/webclient/javascript/ome.tree.js @@ -1044,7 +1044,7 @@ $(function() { // ...Otherwise use the supported objects list // v.supported_objects is ['image'] or ['dataset', 'images'] enabled = v.supported_objects.reduce(function(prev, o){ - return prev || o.indexOf(selType) > -1; + return prev || selType.indexOf(o) > -1; }, false); return !enabled; } diff --git a/components/tools/OmeroWeb/omeroweb/webclient/templates/webclient/base/base_container.html b/components/tools/OmeroWeb/omeroweb/webclient/templates/webclient/base/base_container.html index f408384be86..d1e6ad6c41d 100644 --- a/components/tools/OmeroWeb/omeroweb/webclient/templates/webclient/base/base_container.html +++ b/components/tools/OmeroWeb/omeroweb/webclient/templates/webclient/base/base_container.html @@ -203,7 +203,7 @@ $.getJSON("{% url 'webgateway.views.open_with_options' %}", function(data){ if (data && data.open_with_options) { WEBCLIENT.OPEN_WITH = data.open_with_options; - + // Try to load scripts if specified: WEBCLIENT.OPEN_WITH.forEach(function(ow){ if (ow.script_url) { $.getScript(ow.script_url); @@ -219,11 +219,12 @@ WEBCLIENT.OPEN_WITH.forEach(function(ow){ if (ow.label === label) { ow.isEnabled = function() { - // wrap fn with try/catch, return true by default + // wrap fn with try/catch, since error here will break jsTree menu var args = Array.from(arguments); try { enabled = fn.apply(this, args); } catch (e) { + // Give user a clue as to what went wrong console.log("Open with " + label + ": " + e); enabled = true; } @@ -237,14 +238,8 @@ WEBCLIENT.OPEN_WITH.forEach(function(ow){ if (ow.label === label) { ow.action = function() { - // wrap fn with try/catch, return false if error var args = Array.from(arguments); - try { - enabled = fn(args); - } catch (e) { - console.log("Open with " + label + ": " + e); - enabled = false; - } + enabled = fn.apply(this, args); return enabled; } } diff --git a/components/tools/OmeroWeb/omeroweb/webclient/templates/webclient/openwith.js b/components/tools/OmeroWeb/omeroweb/webclient/templates/webclient/openwith.js deleted file mode 100644 index 511a605215b..00000000000 --- a/components/tools/OmeroWeb/omeroweb/webclient/templates/webclient/openwith.js +++ /dev/null @@ -1,46 +0,0 @@ - - // Example openwith script - // TEMP - for evaluation of https://github.com/openmicroscopy/openmicroscopy/pull/4630 - // TODO: remove this before merging PR! - var isEnabled = function(selected) { - console.log('GenBank Protein, isEnabled()', selected); - if (selected.length !== 1) return false; - - // return True if name is a number (E.g. Gene ID) - var name = selected[0].name; - return (parseInt(name, 10) == name); - }; - - var handleAction = function(selected, url) { - console.log('GenBank Protein, handleAction()', selected, url); - var name = selected[0].name; - window.open(url + name, 'new'); - }; - - OME.setOpenWithEnabledHandler("GenBank Protein", isEnabled); - OME.setOpenWithActionHandler("GenBank Protein", handleAction); - - - - // We also configure a second 'Open With' plugin - // NB: This plugin doesn't specify it's own script - we are just - // piggy-backing on the 'GenBank Protein' plugin for convenience - - var isJpgEnabled = function(selected) { - if (selected.length === 1) { - var s = selected[0]; - return (s.type === 'fileannotation' && s.file && s.file.name.endsWith(".jpg")); - } - }; - var handleJpgAction = function(selected, url) { - // url for this plugin is webindex - // we want to open original file... - if (selected.length === 1) { - var s = selected[0], - origFileId = s.file.id; - window.open(url + 'get_original_file/' + origFileId + '/', 'new'); - } - }; - - OME.setOpenWithEnabledHandler("jpg viewer", isJpgEnabled); - OME.setOpenWithActionHandler("jpg viewer", handleJpgAction); From b14e7658644ea0bb5191fdc548b3bd0be38d6ecc Mon Sep 17 00:00:00 2001 From: William Moore Date: Tue, 27 Sep 2016 23:10:38 +0100 Subject: [PATCH 19/29] Simplify action function wrapping --- .../webclient/templates/webclient/base/base_container.html | 6 +----- components/tools/OmeroWeb/omeroweb/webgateway/views.py | 1 + 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/components/tools/OmeroWeb/omeroweb/webclient/templates/webclient/base/base_container.html b/components/tools/OmeroWeb/omeroweb/webclient/templates/webclient/base/base_container.html index d1e6ad6c41d..701ee51c6f2 100644 --- a/components/tools/OmeroWeb/omeroweb/webclient/templates/webclient/base/base_container.html +++ b/components/tools/OmeroWeb/omeroweb/webclient/templates/webclient/base/base_container.html @@ -237,11 +237,7 @@ // look for label in OPEN_WITH WEBCLIENT.OPEN_WITH.forEach(function(ow){ if (ow.label === label) { - ow.action = function() { - var args = Array.from(arguments); - enabled = fn.apply(this, args); - return enabled; - } + ow.action = fn; } }); }; diff --git a/components/tools/OmeroWeb/omeroweb/webgateway/views.py b/components/tools/OmeroWeb/omeroweb/webgateway/views.py index 188eed0ebee..a577b693191 100644 --- a/components/tools/OmeroWeb/omeroweb/webgateway/views.py +++ b/components/tools/OmeroWeb/omeroweb/webgateway/views.py @@ -1522,6 +1522,7 @@ def projectDetail_json(request, pid, conn=None, **kwargs): rv = pr.simpleMarshal() return rv + @jsonp def open_with_options(request, **kwargs): """ From 90019c4e643eee3c7d4bf65e04640f3483bb60e8 Mon Sep 17 00:00:00 2001 From: William Moore Date: Wed, 28 Sep 2016 10:37:40 +0100 Subject: [PATCH 20/29] Move OME.setOpenWithEnabledHandler() etc to actions.js --- .../javascript/ome.webclient.actions.js | 32 +++++++++++++++++++ .../webclient/base/base_container.html | 32 ++----------------- 2 files changed, 34 insertions(+), 30 deletions(-) diff --git a/components/tools/OmeroWeb/omeroweb/webclient/static/webclient/javascript/ome.webclient.actions.js b/components/tools/OmeroWeb/omeroweb/webclient/static/webclient/javascript/ome.webclient.actions.js index 7e38be275a2..ab71463cb2f 100644 --- a/components/tools/OmeroWeb/omeroweb/webclient/static/webclient/javascript/ome.webclient.actions.js +++ b/components/tools/OmeroWeb/omeroweb/webclient/static/webclient/javascript/ome.webclient.actions.js @@ -945,6 +945,38 @@ OME.hideScriptList = function() { $("#scriptList").hide(); }; +// Helper can be used by 'open with' plugins to add isEnabled() +// handlers to the OPEN_WITH object. +OME.setOpenWithEnabledHandler = function(label, fn) { + // look for label in OPEN_WITH + WEBCLIENT.OPEN_WITH.forEach(function(ow){ + if (ow.label === label) { + ow.isEnabled = function() { + // wrap fn with try/catch, since error here will break jsTree menu + var args = Array.from(arguments); + try { + enabled = fn.apply(this, args); + } catch (e) { + // Give user a clue as to what went wrong + console.log("Open with " + label + ": " + e); + enabled = true; + } + return enabled; + } + } + }); +}; +// Helper can be used by 'open with' plugins to add action() +// handlers to the OPEN_WITH object. +OME.setOpenWithActionHandler = function(label, fn) { + // look for label in OPEN_WITH + WEBCLIENT.OPEN_WITH.forEach(function(ow){ + if (ow.label === label) { + ow.action = fn; + } + }); +}; + OME.toggleFileAnnotationCheckboxes = function(event) { var checkboxes = $("#fileanns_container input[type=checkbox]"); checkboxes.toggle().prop("checked", false); diff --git a/components/tools/OmeroWeb/omeroweb/webclient/templates/webclient/base/base_container.html b/components/tools/OmeroWeb/omeroweb/webclient/templates/webclient/base/base_container.html index 701ee51c6f2..8d24a965c6e 100644 --- a/components/tools/OmeroWeb/omeroweb/webclient/templates/webclient/base/base_container.html +++ b/components/tools/OmeroWeb/omeroweb/webclient/templates/webclient/base/base_container.html @@ -199,6 +199,8 @@ // ** "Open With" config used by E.g. ome.tree.js ** + // Loaded scripts can call OME.setOpenWithEnabledHandler and/or + // OME.setOpenWithActionHandler to override default behaviour WEBCLIENT.OPEN_WITH = []; $.getJSON("{% url 'webgateway.views.open_with_options' %}", function(data){ if (data && data.open_with_options) { @@ -212,36 +214,6 @@ } }); - // Helper can be used by 'open with' plugins to add isEnabled() - // handlers to the OPEN_WITH object. - OME.setOpenWithEnabledHandler = function(label, fn) { - // look for label in OPEN_WITH - WEBCLIENT.OPEN_WITH.forEach(function(ow){ - if (ow.label === label) { - ow.isEnabled = function() { - // wrap fn with try/catch, since error here will break jsTree menu - var args = Array.from(arguments); - try { - enabled = fn.apply(this, args); - } catch (e) { - // Give user a clue as to what went wrong - console.log("Open with " + label + ": " + e); - enabled = true; - } - return enabled; - } - } - }); - }; - OME.setOpenWithActionHandler = function(label, fn) { - // look for label in OPEN_WITH - WEBCLIENT.OPEN_WITH.forEach(function(ow){ - if (ow.label === label) { - ow.action = fn; - } - }); - }; - $(document).ready(function(){ // initially hidden $("#user_dropdown ul").css('visibility', 'hidden'); From bd98e312bd1669e4cfa3c260f88b4f1017281147 Mon Sep 17 00:00:00 2001 From: William Moore Date: Wed, 28 Sep 2016 16:37:30 +0100 Subject: [PATCH 21/29] Test script_url for 'http...' or use static() --- components/tools/OmeroWeb/omeroweb/webgateway/views.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/components/tools/OmeroWeb/omeroweb/webgateway/views.py b/components/tools/OmeroWeb/omeroweb/webgateway/views.py index a577b693191..a162f355955 100644 --- a/components/tools/OmeroWeb/omeroweb/webgateway/views.py +++ b/components/tools/OmeroWeb/omeroweb/webgateway/views.py @@ -1549,10 +1549,12 @@ def open_with_options(request, **kwargs): if 'target' in ow[2]: viewer['target'] = ow[2]['target'] if 'script_url' in ow[2]: - try: - viewer['script_url'] = static(ow[2]['script_url']) - except NoReverseMatch: + # If we have an absolute url, use it... + if ow[2]['script_url'].startswith('http'): viewer['script_url'] = ow[2]['script_url'] + else: + # ...otherwise, assume within static + viewer['script_url'] = static(ow[2]['script_url']) except: # ignore invalid params pass From 08915a2b179dd8eddf472f3e27f297b0129c4552 Mon Sep 17 00:00:00 2001 From: William Moore Date: Fri, 30 Sep 2016 11:18:09 +0100 Subject: [PATCH 22/29] Fix usage of config 'supported_objects' instead of 'objects' --- components/tools/OmeroWeb/omeroweb/webgateway/views.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/components/tools/OmeroWeb/omeroweb/webgateway/views.py b/components/tools/OmeroWeb/omeroweb/webgateway/views.py index a162f355955..4f2d92af31b 100644 --- a/components/tools/OmeroWeb/omeroweb/webgateway/views.py +++ b/components/tools/OmeroWeb/omeroweb/webgateway/views.py @@ -1544,8 +1544,8 @@ def open_with_options(request, **kwargs): viewer['supported_objects'] = ['image'] try: if len(ow) > 2: - if 'objects' in ow[2]: - viewer['supported_objects'] = ow[2]['objects'] + if 'supported_objects' in ow[2]: + viewer['supported_objects'] = ow[2]['supported_objects'] if 'target' in ow[2]: viewer['target'] = ow[2]['target'] if 'script_url' in ow[2]: From fb3e6e1efef4bd6b9c651a72bccfe50b519fa73e Mon Sep 17 00:00:00 2001 From: William Moore Date: Fri, 30 Sep 2016 11:20:50 +0100 Subject: [PATCH 23/29] Fix handling of Open with: 'supported_objects' in jsTree menu --- .../webclient/static/webclient/javascript/ome.tree.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/components/tools/OmeroWeb/omeroweb/webclient/static/webclient/javascript/ome.tree.js b/components/tools/OmeroWeb/omeroweb/webclient/static/webclient/javascript/ome.tree.js index 1c869006348..38153e4e945 100644 --- a/components/tools/OmeroWeb/omeroweb/webclient/static/webclient/javascript/ome.tree.js +++ b/components/tools/OmeroWeb/omeroweb/webclient/static/webclient/javascript/ome.tree.js @@ -1042,9 +1042,10 @@ $(function() { return !enabled; } // ...Otherwise use the supported objects list - // v.supported_objects is ['image'] or ['dataset', 'images'] - enabled = v.supported_objects.reduce(function(prev, o){ - return prev || selType.indexOf(o) > -1; + // v.supported_objects is ['image'] or ['dataset', 'images'] etc. + enabled = v.supported_objects.reduce(function(prev, supported){ + // E.g. If supported_objects is 'images'... + return prev || supported.indexOf(selType) > -1; // ... selType 'image' OR 'images' are > -1 }, false); return !enabled; } From 7d9d83671d6f449d1a46e9b171ab43da33527d2d Mon Sep 17 00:00:00 2001 From: William Moore Date: Mon, 3 Oct 2016 12:41:11 +0100 Subject: [PATCH 24/29] Remove default 'supported_objects'. Now required --- .../static/webclient/javascript/ome.tree.js | 14 ++++++++------ .../tools/OmeroWeb/omeroweb/webgateway/views.py | 3 +-- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/components/tools/OmeroWeb/omeroweb/webclient/static/webclient/javascript/ome.tree.js b/components/tools/OmeroWeb/omeroweb/webclient/static/webclient/javascript/ome.tree.js index 38153e4e945..7ad44b37dc1 100644 --- a/components/tools/OmeroWeb/omeroweb/webclient/static/webclient/javascript/ome.tree.js +++ b/components/tools/OmeroWeb/omeroweb/webclient/static/webclient/javascript/ome.tree.js @@ -1028,7 +1028,7 @@ $(function() { selType = sel.reduce(function(prev, s){ return s.type + (sel.length > 1 ? "s" : ""); }, "undefined"), - enabled; + enabled = false; if (typeof v.isEnabled === "function") { // If plugin has provided a function 'isEnabled'... // prepare json of selected objects to pass to function @@ -1041,12 +1041,14 @@ $(function() { enabled = v.isEnabled(selJson); return !enabled; } - // ...Otherwise use the supported objects list + // ...Otherwise if supported_objects list is configured... // v.supported_objects is ['image'] or ['dataset', 'images'] etc. - enabled = v.supported_objects.reduce(function(prev, supported){ - // E.g. If supported_objects is 'images'... - return prev || supported.indexOf(selType) > -1; // ... selType 'image' OR 'images' are > -1 - }, false); + if (typeof v.supported_objects === "object" && v.supported_objects.length > 0) { + enabled = v.supported_objects.reduce(function(prev, supported){ + // E.g. If supported_objects is 'images'... + return prev || supported.indexOf(selType) > -1; // ... selType 'image' OR 'images' are > -1 + }, false); + } return !enabled; } }; diff --git a/components/tools/OmeroWeb/omeroweb/webgateway/views.py b/components/tools/OmeroWeb/omeroweb/webgateway/views.py index 4f2d92af31b..d83ce51a7b7 100644 --- a/components/tools/OmeroWeb/omeroweb/webgateway/views.py +++ b/components/tools/OmeroWeb/omeroweb/webgateway/views.py @@ -1540,8 +1540,7 @@ def open_with_options(request, **kwargs): except NoReverseMatch: viewer['url'] = ow[1] # try non-essential parameters... - # By default, we support single image, opening in new window - viewer['supported_objects'] = ['image'] + # NB: Need supported_objects OR script_url to enable plugin try: if len(ow) > 2: if 'supported_objects' in ow[2]: From 31344bf2a010687495c31038103a7f0dacf8dd6d Mon Sep 17 00:00:00 2001 From: William Moore Date: Mon, 3 Oct 2016 13:38:04 +0100 Subject: [PATCH 25/29] Always return after open_with action() --- .../webclient/static/webclient/javascript/ome.tree.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/components/tools/OmeroWeb/omeroweb/webclient/static/webclient/javascript/ome.tree.js b/components/tools/OmeroWeb/omeroweb/webclient/static/webclient/javascript/ome.tree.js index 7ad44b37dc1..078e80f8e45 100644 --- a/components/tools/OmeroWeb/omeroweb/webclient/static/webclient/javascript/ome.tree.js +++ b/components/tools/OmeroWeb/omeroweb/webclient/static/webclient/javascript/ome.tree.js @@ -1010,9 +1010,8 @@ $(function() { 'type': s.type}; return o; }); - // see if it handles the event - var eventBubbled = v.action(selJson, v.url); - if (!eventBubbled) return; + v.action(selJson, v.url); + return; } // ...otherwise we use default handling... if (v.target) { From b19fc2efdaa2b35f1bf650ff2ce27a786395d076 Mon Sep 17 00:00:00 2001 From: William Moore Date: Wed, 5 Oct 2016 12:12:23 +0100 Subject: [PATCH 26/29] Add doc string to urls.py --- components/tools/OmeroWeb/omeroweb/webgateway/urls.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/components/tools/OmeroWeb/omeroweb/webgateway/urls.py b/components/tools/OmeroWeb/omeroweb/webgateway/urls.py index 093d0d2bfb6..15f539d73b7 100644 --- a/components/tools/OmeroWeb/omeroweb/webgateway/urls.py +++ b/components/tools/OmeroWeb/omeroweb/webgateway/urls.py @@ -415,6 +415,9 @@ open_with_options = url(r'^open_with/$', 'webgateway.views.open_with_options', name='open_with_options') +""" +This makes the settings.OPEN_WITH configuration available via json +""" get_image_rdefs_json = url(r'^get_image_rdefs_json/(?P[0-9]+)/$', From 6855cacd79d32e14a8dbaf75ae668f66bbd3a0e5 Mon Sep 17 00:00:00 2001 From: William Moore Date: Wed, 12 Oct 2016 11:57:01 +0100 Subject: [PATCH 27/29] Use urlProvider instead of actionHandler for Open with --- .../webclient/static/webclient/javascript/ome.tree.js | 9 +++++---- .../static/webclient/javascript/ome.webclient.actions.js | 8 ++++---- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/components/tools/OmeroWeb/omeroweb/webclient/static/webclient/javascript/ome.tree.js b/components/tools/OmeroWeb/omeroweb/webclient/static/webclient/javascript/ome.tree.js index a5e3a0921de..458336349ee 100644 --- a/components/tools/OmeroWeb/omeroweb/webclient/static/webclient/javascript/ome.tree.js +++ b/components/tools/OmeroWeb/omeroweb/webclient/static/webclient/javascript/ome.tree.js @@ -999,9 +999,11 @@ $(function() { return s.type + "=" + s.data.id; }), query = dtypes.join("&"), + // default url includes objects in query url = v.url + "?" + query; - // if plugin has provided an action handler... - if (v.action) { + // if plugin has added a url provider, + // use it to update the url... + if (v.getUrl) { // prepare json of selected objects to pass to function var selJson = sel.map(function(s){ // var o = $.extend({}, s.data.obj); @@ -1010,8 +1012,7 @@ $(function() { 'type': s.type}; return o; }); - v.action(selJson, v.url); - return; + url = v.getUrl(selJson, v.url); } // ...otherwise we use default handling... if (v.target) { diff --git a/components/tools/OmeroWeb/omeroweb/webclient/static/webclient/javascript/ome.webclient.actions.js b/components/tools/OmeroWeb/omeroweb/webclient/static/webclient/javascript/ome.webclient.actions.js index ab71463cb2f..b3448696cc5 100644 --- a/components/tools/OmeroWeb/omeroweb/webclient/static/webclient/javascript/ome.webclient.actions.js +++ b/components/tools/OmeroWeb/omeroweb/webclient/static/webclient/javascript/ome.webclient.actions.js @@ -966,13 +966,13 @@ OME.setOpenWithEnabledHandler = function(label, fn) { } }); }; -// Helper can be used by 'open with' plugins to add action() -// handlers to the OPEN_WITH object. -OME.setOpenWithActionHandler = function(label, fn) { +// Helper can be used by 'open with' plugins to provide +// a url for the selected objects +OME.setOpenWithUrlProvider = function(label, fn) { // look for label in OPEN_WITH WEBCLIENT.OPEN_WITH.forEach(function(ow){ if (ow.label === label) { - ow.action = fn; + ow.getUrl = fn; } }); }; From e33d7226f34d3fb2f4e17716df7ec41b43caac06 Mon Sep 17 00:00:00 2001 From: William Moore Date: Wed, 12 Oct 2016 13:20:43 +0100 Subject: [PATCH 28/29] Add 'Image viewer' to 'open_with' settings --- .../tools/OmeroWeb/omeroweb/settings.py | 5 ++-- .../javascript/ome.openwith_viewer.js | 24 +++++++++++++++++++ 2 files changed, 27 insertions(+), 2 deletions(-) create mode 100644 components/tools/OmeroWeb/omeroweb/webclient/static/webclient/javascript/ome.openwith_viewer.js diff --git a/components/tools/OmeroWeb/omeroweb/settings.py b/components/tools/OmeroWeb/omeroweb/settings.py index cfafc6f7ebf..2fd550da489 100644 --- a/components/tools/OmeroWeb/omeroweb/settings.py +++ b/components/tools/OmeroWeb/omeroweb/settings.py @@ -537,13 +537,14 @@ def leave_none_unset_int(s): # OPEN WITH "omero.web.open_with": ["OPEN_WITH", - ('[]'), + ('[["Image viewer", "webindex", {"supported_objects": ["image"],' + '"script_url": "webclient/javascript/ome.openwith_viewer.js"}]]'), json.loads, ("A list of viewers that can be used to display selected Images " "or other objects. Each viewer is defined as " "``[\"Name\", \"url\", options]``. Url is reverse(url). " "Selected objects are added to the url as ?image=:1&image=2" - "The options object is optional " + "Objects supported must be specified in options with" "E.g. ``{\"supported_objects\":[\"images\"]}`` " "to enable viewer for one or more images, " "``{\"target\":\"_blank\"}`` to open in new tab.")], diff --git a/components/tools/OmeroWeb/omeroweb/webclient/static/webclient/javascript/ome.openwith_viewer.js b/components/tools/OmeroWeb/omeroweb/webclient/static/webclient/javascript/ome.openwith_viewer.js new file mode 100644 index 00000000000..043ccd452bf --- /dev/null +++ b/components/tools/OmeroWeb/omeroweb/webclient/static/webclient/javascript/ome.openwith_viewer.js @@ -0,0 +1,24 @@ + +// openwith.js + + +// This example 'enabledHandler' code is not needed since we configure +// {'supported_objects': ['image']} to only enable the viewer when a +// single image is selected. +// However, it can be used if you need more flexibility to set enable/disable +// status of your Open with option. +// OME.setOpenWithEnabledHandler("Image viewer", function(selected) { +// // selected is a list of {'id':1, 'name': 'test.tiff', 'type': 'image'} +// // Only enabled for single objects... +// if (selected.length !== 1) return false; +// // Only enable for images +// return (selected[0].type !== 'image') return false; +// }); + + +// We have already configured the base url to be 'webindex' /webclient/ so +// we just need to add 'img_detail/' and the selected image ID +OME.setOpenWithUrlProvider("Image viewer", function(selected, url) { + url += "img_detail/" + selected[0].id + "/"; + return url; +}); From e86448bfb3d09fedd5d1841d790b1b458480054d Mon Sep 17 00:00:00 2001 From: William Moore Date: Wed, 12 Oct 2016 15:48:15 +0100 Subject: [PATCH 29/29] Open with plugins enabled=false if error in script --- .../static/webclient/javascript/ome.webclient.actions.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/tools/OmeroWeb/omeroweb/webclient/static/webclient/javascript/ome.webclient.actions.js b/components/tools/OmeroWeb/omeroweb/webclient/static/webclient/javascript/ome.webclient.actions.js index b3448696cc5..d1b9ffefb77 100644 --- a/components/tools/OmeroWeb/omeroweb/webclient/static/webclient/javascript/ome.webclient.actions.js +++ b/components/tools/OmeroWeb/omeroweb/webclient/static/webclient/javascript/ome.webclient.actions.js @@ -954,12 +954,12 @@ OME.setOpenWithEnabledHandler = function(label, fn) { ow.isEnabled = function() { // wrap fn with try/catch, since error here will break jsTree menu var args = Array.from(arguments); + var enabled = false; try { enabled = fn.apply(this, args); } catch (e) { // Give user a clue as to what went wrong console.log("Open with " + label + ": " + e); - enabled = true; } return enabled; }