Skip to content

Commit c78f589

Browse files
committed
Add open-with support.
1 parent fbbea46 commit c78f589

File tree

2 files changed

+40
-5
lines changed

2 files changed

+40
-5
lines changed

omero_vitessce/urls.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,14 @@
2121

2222
urlpatterns = [
2323
# Right panel plugin
24-
2524
re_path(r"(?P<obj_type>[a-z]+)/(?P<obj_id>[0-9]+)",
2625
views.vitessce_panel, name='vitessce_tab'),
2726

28-
re_path(r"^$", views.vitessce_index, name="vitessce_tab")
27+
# Index placeholder for right panel plugin
28+
re_path(r"^$", views.vitessce_index, name="vitessce_tab"),
2929

30+
# Open-with
31+
re_path(r"^open/",
32+
views.vitessce_open, name='open_vitessce')
3033

3134
]

omero_vitessce/views.py

+35-3
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#
1717

1818
from django.shortcuts import render
19+
from django.http import HttpResponseRedirect
1920

2021
from omeroweb.decorators import login_required
2122

@@ -37,9 +38,6 @@ def vitessce_index(request, conn=None, **kwargs):
3738

3839
@login_required()
3940
def vitessce_panel(request, obj_type, obj_id, conn=None, **kwargs):
40-
41-
# Generate an openlink space
42-
4341
# Get all .json.txt attachements and generate links for them
4442
# This way the config files can be served as text
4543
# to the config argument of the vitessce webapp
@@ -60,3 +58,37 @@ def vitessce_panel(request, obj_type, obj_id, conn=None, **kwargs):
6058

6159
# Render the html template and return the http response
6260
return render(request, "omero_vitessce/vitessce_panel.html", context)
61+
62+
63+
@login_required()
64+
def vitessce_open(request, conn=None, **kwargs):
65+
# Get the first .json.txt attachement and generate a link for it
66+
# This way the config files can be served as text
67+
# If no config files are present send to the panel html to ask to make one
68+
if request.GET.get("project") is not None:
69+
obj_type = "project"
70+
obj_id = int(request.GET.get("project"))
71+
elif request.GET.get("dataset") is not None:
72+
obj_type = "dataset"
73+
obj_id = int(request.GET.get("dataset"))
74+
elif request.GET.get("image") is not None:
75+
obj_type = "image"
76+
obj_id = int(request.GET.get("image"))
77+
else:
78+
context = {"json_configs": dict(),
79+
"obj_type": obj_type, "obj_id": obj_id}
80+
return render(request, "omero_vitessce/vitessce_panel.html", context)
81+
82+
obj = conn.getObject(obj_type, obj_id)
83+
files = [i for i in obj.listAnnotations() if i.OMERO_TYPE().NAME ==
84+
"ome.model.annotations.FileAnnotation_name"]
85+
config_ids = [i.getId() for i in files
86+
if i.getFileName().endswith(".json.txt")]
87+
if len(config_ids) > 0:
88+
vitessce_url = SERVER + "/omero_vitessce/?config=" + SERVER + \
89+
"/webclient/annotation/" + str(config_ids[0])
90+
return HttpResponseRedirect(vitessce_url)
91+
else:
92+
context = {"json_configs": dict(),
93+
"obj_type": obj_type, "obj_id": obj_id}
94+
return render(request, "omero_vitessce/vitessce_panel.html", context)

0 commit comments

Comments
 (0)