From 96fabe686cbbff862fd61f338996654ea539a206 Mon Sep 17 00:00:00 2001 From: Simon Li Date: Mon, 4 Jul 2016 11:56:38 +0100 Subject: [PATCH 1/7] Add option to build link-to weburls with client-side javascript --- components/tools/OmeroWeb/omeroweb/settings.py | 6 ++++++ .../templates/webclient/annotations/metadata_general.html | 2 ++ components/tools/OmeroWeb/omeroweb/webclient/views.py | 7 +++++-- 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/components/tools/OmeroWeb/omeroweb/settings.py b/components/tools/OmeroWeb/omeroweb/settings.py index c2b374d113b..25901243bf2 100644 --- a/components/tools/OmeroWeb/omeroweb/settings.py +++ b/components/tools/OmeroWeb/omeroweb/settings.py @@ -675,6 +675,12 @@ def leave_none_unset_int(s): " 'webtest/webclient_plugins/center_plugin.overlay.js.html'," " 'channel_overlay_panel']``. " "The javascript loads data into ``$('#div_id')``.")], + "omero.web.ui.use_client_host": + ["WEB_URL_USE_CLIENT_HOST", + False, + bool, + ("If True build link-to URLs using client-side javascript, otherwise" + " use the server side HOST header")], } DEPRECATED_SETTINGS_MAPPINGS = { diff --git a/components/tools/OmeroWeb/omeroweb/webclient/templates/webclient/annotations/metadata_general.html b/components/tools/OmeroWeb/omeroweb/webclient/templates/webclient/annotations/metadata_general.html index f05d151a1b6..4f619906a4e 100644 --- a/components/tools/OmeroWeb/omeroweb/webclient/templates/webclient/annotations/metadata_general.html +++ b/components/tools/OmeroWeb/omeroweb/webclient/templates/webclient/annotations/metadata_general.html @@ -105,6 +105,8 @@ $("#link_info_popup").show(); {% if webclient_path %} var lnk = "{{ webclient_path }}"; + {% elif webclient_pathname %} + var lnk = location.protocol + "//" + location.host + "{{ webclient_pathname }}"; {% else %} var lnk = location.href.substring(0,location.href.length - location.search.length); if (lnk.charAt( lnk.length-1 ) == "#") { lnk = lnk.substring(0, lnk.length-1)} diff --git a/components/tools/OmeroWeb/omeroweb/webclient/views.py b/components/tools/OmeroWeb/omeroweb/webclient/views.py index 3f24338d948..35073fccf84 100755 --- a/components/tools/OmeroWeb/omeroweb/webclient/views.py +++ b/components/tools/OmeroWeb/omeroweb/webclient/views.py @@ -1566,8 +1566,11 @@ def load_metadata_details(request, c_type, c_id, conn=None, share_id=None, context['figScripts'] = figScripts context['template'] = template - context['webclient_path'] = request.build_absolute_uri( - reverse('webindex')) + if settings.WEB_URL_USE_CLIENT_HOST: + context['webclient_pathname'] = reverse('webindex') + else: + context['webclient_path'] = request.build_absolute_uri( + reverse('webindex')) return context From b602c8f8c5553edc200648ec5bca74b9d179bcaf Mon Sep 17 00:00:00 2001 From: Simon Li Date: Mon, 4 Jul 2016 12:58:40 +0100 Subject: [PATCH 2/7] Link to host can be overriden by omero.web.ui.default_client_baseurl --- components/tools/OmeroWeb/omeroweb/settings.py | 8 ++++++++ components/tools/OmeroWeb/omeroweb/webclient/views.py | 3 +++ 2 files changed, 11 insertions(+) diff --git a/components/tools/OmeroWeb/omeroweb/settings.py b/components/tools/OmeroWeb/omeroweb/settings.py index 25901243bf2..20bd6e845cb 100644 --- a/components/tools/OmeroWeb/omeroweb/settings.py +++ b/components/tools/OmeroWeb/omeroweb/settings.py @@ -675,6 +675,14 @@ def leave_none_unset_int(s): " 'webtest/webclient_plugins/center_plugin.overlay.js.html'," " 'channel_overlay_panel']``. " "The javascript loads data into ``$('#div_id')``.")], + "omero.web.ui.default_client_baseurl": + ["WEB_URL_DEFAULT_CLIENT_BASEURL", + None, + identity, + ("Use this host (including protocol) for absolute urls displayed in " + "the client. If omero.web.ui.use_client_host=True this will only be " + "used for absolute URLs which cannot be created with client-side " + "javascript.")], "omero.web.ui.use_client_host": ["WEB_URL_USE_CLIENT_HOST", False, diff --git a/components/tools/OmeroWeb/omeroweb/webclient/views.py b/components/tools/OmeroWeb/omeroweb/webclient/views.py index 35073fccf84..9b836ef75f9 100755 --- a/components/tools/OmeroWeb/omeroweb/webclient/views.py +++ b/components/tools/OmeroWeb/omeroweb/webclient/views.py @@ -1568,6 +1568,9 @@ def load_metadata_details(request, c_type, c_id, conn=None, share_id=None, context['template'] = template if settings.WEB_URL_USE_CLIENT_HOST: context['webclient_pathname'] = reverse('webindex') + elif settings.WEB_URL_DEFAULT_CLIENT_BASEURL: + context['webclient_path'] = "%s%s" % ( + settings.WEB_URL_DEFAULT_CLIENT_BASEURL, reverse('webindex')) else: context['webclient_path'] = request.build_absolute_uri( reverse('webindex')) From f8d827266c947a9db6b8f92907f157f4510bae06 Mon Sep 17 00:00:00 2001 From: Simon Li Date: Mon, 4 Jul 2016 13:00:07 +0100 Subject: [PATCH 3/7] twitter/opengraph use omero.web.ui.default_client_baseurl if set --- .../tools/OmeroWeb/omeroweb/webgateway/views.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/components/tools/OmeroWeb/omeroweb/webgateway/views.py b/components/tools/OmeroWeb/omeroweb/webgateway/views.py index 4059ef4d0ef..aa67a3fad2f 100644 --- a/components/tools/OmeroWeb/omeroweb/webgateway/views.py +++ b/components/tools/OmeroWeb/omeroweb/webgateway/views.py @@ -1974,12 +1974,16 @@ def full_viewer(request, iid, conn=None, **kwargs): prefix = kwargs.get( 'thumbprefix', 'webgateway.views.render_thumbnail') - def urlprefix(iid): - return reverse(prefix, args=(iid,)) + def reverse_urlprefix(p, iid): + r = reverse(p, args=(iid,)) + if settings.WEB_URL_DEFAULT_CLIENT_BASEURL: + return "%s%s" % ( + settings.WEB_URL_DEFAULT_CLIENT_BASEURL, r) + else: + return request.build_absolute_uri(r) - image_preview = request.build_absolute_uri(urlprefix(iid)) - page_url = request.build_absolute_uri(reverse( - 'webgateway.views.full_viewer', args=(iid,))) + image_preview = reverse_urlprefix(prefix, iid) + page_url = reverse_urlprefix('webgateway.views.full_viewer', iid) d = {'blitzcon': conn, 'image': image, From bf30db8c01e9cf28d8fb5a8403d3cb081444b6d7 Mon Sep 17 00:00:00 2001 From: Simon Li Date: Mon, 4 Jul 2016 14:10:28 +0100 Subject: [PATCH 4/7] Always use client-side javascript for link-to URL This removes the need for another config property --- components/tools/OmeroWeb/omeroweb/settings.py | 10 +--------- .../webclient/annotations/metadata_general.html | 4 +--- components/tools/OmeroWeb/omeroweb/webclient/views.py | 9 +-------- 3 files changed, 3 insertions(+), 20 deletions(-) diff --git a/components/tools/OmeroWeb/omeroweb/settings.py b/components/tools/OmeroWeb/omeroweb/settings.py index 20bd6e845cb..10befc2116e 100644 --- a/components/tools/OmeroWeb/omeroweb/settings.py +++ b/components/tools/OmeroWeb/omeroweb/settings.py @@ -680,15 +680,7 @@ def leave_none_unset_int(s): None, identity, ("Use this host (including protocol) for absolute urls displayed in " - "the client. If omero.web.ui.use_client_host=True this will only be " - "used for absolute URLs which cannot be created with client-side " - "javascript.")], - "omero.web.ui.use_client_host": - ["WEB_URL_USE_CLIENT_HOST", - False, - bool, - ("If True build link-to URLs using client-side javascript, otherwise" - " use the server side HOST header")], + "the client. This does not include client-side generated URLs.")], } DEPRECATED_SETTINGS_MAPPINGS = { diff --git a/components/tools/OmeroWeb/omeroweb/webclient/templates/webclient/annotations/metadata_general.html b/components/tools/OmeroWeb/omeroweb/webclient/templates/webclient/annotations/metadata_general.html index 4f619906a4e..adecc446e2b 100644 --- a/components/tools/OmeroWeb/omeroweb/webclient/templates/webclient/annotations/metadata_general.html +++ b/components/tools/OmeroWeb/omeroweb/webclient/templates/webclient/annotations/metadata_general.html @@ -104,9 +104,7 @@ $("#show_link_btn").click(function(){ $("#link_info_popup").show(); {% if webclient_path %} - var lnk = "{{ webclient_path }}"; - {% elif webclient_pathname %} - var lnk = location.protocol + "//" + location.host + "{{ webclient_pathname }}"; + var lnk = location.protocol + "//" + location.host + "{{ webclient_path }}"; {% else %} var lnk = location.href.substring(0,location.href.length - location.search.length); if (lnk.charAt( lnk.length-1 ) == "#") { lnk = lnk.substring(0, lnk.length-1)} diff --git a/components/tools/OmeroWeb/omeroweb/webclient/views.py b/components/tools/OmeroWeb/omeroweb/webclient/views.py index 9b836ef75f9..42952210f1a 100755 --- a/components/tools/OmeroWeb/omeroweb/webclient/views.py +++ b/components/tools/OmeroWeb/omeroweb/webclient/views.py @@ -1566,14 +1566,7 @@ def load_metadata_details(request, c_type, c_id, conn=None, share_id=None, context['figScripts'] = figScripts context['template'] = template - if settings.WEB_URL_USE_CLIENT_HOST: - context['webclient_pathname'] = reverse('webindex') - elif settings.WEB_URL_DEFAULT_CLIENT_BASEURL: - context['webclient_path'] = "%s%s" % ( - settings.WEB_URL_DEFAULT_CLIENT_BASEURL, reverse('webindex')) - else: - context['webclient_path'] = request.build_absolute_uri( - reverse('webindex')) + context['webclient_path'] = reverse('webindex') return context From d0668bdb989d6b4783903152a377074ddff96479 Mon Sep 17 00:00:00 2001 From: Simon Li Date: Tue, 5 Jul 2016 11:50:13 +0100 Subject: [PATCH 5/7] Use client-side JS for batch-annotate URL --- .../webclient/annotations/includes/toolbar.html | 10 ++++------ components/tools/OmeroWeb/omeroweb/webclient/views.py | 2 +- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/components/tools/OmeroWeb/omeroweb/webclient/templates/webclient/annotations/includes/toolbar.html b/components/tools/OmeroWeb/omeroweb/webclient/templates/webclient/annotations/includes/toolbar.html index 2e65d80f1cd..27a5415bd04 100644 --- a/components/tools/OmeroWeb/omeroweb/webclient/templates/webclient/annotations/includes/toolbar.html +++ b/components/tools/OmeroWeb/omeroweb/webclient/templates/webclient/annotations/includes/toolbar.html @@ -33,10 +33,12 @@ $(this).css('visibility', 'hidden'); }).hide(); + {% if link_string %} + $("#link_info_popup_string").val(location.protocol + "//" + location.host + "{{ webclient_path }}?show={{ link_string }}"); + {% endif %} // We do this here and in batch_annotate panel OME.initToolbarDropdowns(); - }); @@ -54,11 +56,7 @@ diff --git a/components/tools/OmeroWeb/omeroweb/webclient/views.py b/components/tools/OmeroWeb/omeroweb/webclient/views.py index 42952210f1a..ce19f854f48 100755 --- a/components/tools/OmeroWeb/omeroweb/webclient/views.py +++ b/components/tools/OmeroWeb/omeroweb/webclient/views.py @@ -2094,7 +2094,7 @@ def batch_annotate(request, conn=None, **kwargs): context['differentGroups'] = True # E.g. don't run scripts etc context['canDownload'] = manager.canDownload(objs) context['template'] = "webclient/annotations/batch_annotate.html" - context['webclient_path'] = request.build_absolute_uri(reverse('webindex')) + context['webclient_path'] = reverse('webindex') return context From daa7893f07b5b9f305501965b125ee9c6b3b8857 Mon Sep 17 00:00:00 2001 From: Simon Li Date: Thu, 7 Jul 2016 16:00:57 +0100 Subject: [PATCH 6/7] Assume webclient_path will always be defined --- .../templates/webclient/annotations/metadata_general.html | 5 ----- 1 file changed, 5 deletions(-) diff --git a/components/tools/OmeroWeb/omeroweb/webclient/templates/webclient/annotations/metadata_general.html b/components/tools/OmeroWeb/omeroweb/webclient/templates/webclient/annotations/metadata_general.html index adecc446e2b..af2ba444603 100644 --- a/components/tools/OmeroWeb/omeroweb/webclient/templates/webclient/annotations/metadata_general.html +++ b/components/tools/OmeroWeb/omeroweb/webclient/templates/webclient/annotations/metadata_general.html @@ -103,12 +103,7 @@ // show a link to the current object $("#show_link_btn").click(function(){ $("#link_info_popup").show(); - {% if webclient_path %} var lnk = location.protocol + "//" + location.host + "{{ webclient_path }}"; - {% else %} - var lnk = location.href.substring(0,location.href.length - location.search.length); - if (lnk.charAt( lnk.length-1 ) == "#") { lnk = lnk.substring(0, lnk.length-1)} - {% endif %} var obj_type = "{{manager.obj_type}}"; if (obj_type === "acquisition") { obj_type = "run"; From 5e1ad812cdd0eb4911649a68a1f287cf6c54873e Mon Sep 17 00:00:00 2001 From: Simon Li Date: Thu, 7 Jul 2016 16:22:18 +0100 Subject: [PATCH 7/7] Change setting name default_client_baseurl -> external_link_baseurl This more accurately reflects how it's currently used (twitter and opengraph integration) --- components/tools/OmeroWeb/omeroweb/settings.py | 9 +++++---- components/tools/OmeroWeb/omeroweb/webgateway/views.py | 4 ++-- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/components/tools/OmeroWeb/omeroweb/settings.py b/components/tools/OmeroWeb/omeroweb/settings.py index 10befc2116e..00bd6e5bd85 100644 --- a/components/tools/OmeroWeb/omeroweb/settings.py +++ b/components/tools/OmeroWeb/omeroweb/settings.py @@ -675,12 +675,13 @@ def leave_none_unset_int(s): " 'webtest/webclient_plugins/center_plugin.overlay.js.html'," " 'channel_overlay_panel']``. " "The javascript loads data into ``$('#div_id')``.")], - "omero.web.ui.default_client_baseurl": - ["WEB_URL_DEFAULT_CLIENT_BASEURL", + "omero.web.ui.external_link_baseurl": + ["WEB_EXTERNAL_LINK_BASEURL", None, identity, - ("Use this host (including protocol) for absolute urls displayed in " - "the client. This does not include client-side generated URLs.")], + ("Use this host (including protocol) for absolute HTML urls " + "in the client, such as social media links. This does not include " + "client-side generated URLs.")], } DEPRECATED_SETTINGS_MAPPINGS = { diff --git a/components/tools/OmeroWeb/omeroweb/webgateway/views.py b/components/tools/OmeroWeb/omeroweb/webgateway/views.py index aa67a3fad2f..af4b77a9303 100644 --- a/components/tools/OmeroWeb/omeroweb/webgateway/views.py +++ b/components/tools/OmeroWeb/omeroweb/webgateway/views.py @@ -1976,9 +1976,9 @@ def full_viewer(request, iid, conn=None, **kwargs): def reverse_urlprefix(p, iid): r = reverse(p, args=(iid,)) - if settings.WEB_URL_DEFAULT_CLIENT_BASEURL: + if settings.WEB_EXTERNAL_LINK_BASEURL: return "%s%s" % ( - settings.WEB_URL_DEFAULT_CLIENT_BASEURL, r) + settings.WEB_EXTERNAL_LINK_BASEURL, r) else: return request.build_absolute_uri(r)
- +