Skip to content

Commit

Permalink
Use open_with and ALLOWED_PARAM to populate form
Browse files Browse the repository at this point in the history
  • Loading branch information
will-moore committed May 27, 2024
1 parent d603620 commit 76ff534
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 31 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@ open the index page of this app:
$ omero config append omero.web.ui.top_links '["Script UI", "omero_script_ui_index", {"title": "Open Script UI in new tab", "target": "_blank"}]'


Configure Open-with...

$ omero config append omero.web.open_with '["Import Annotations from CSV", "omero_script_ui_import_from_csv", {"supported_objects": ["projects", "datasets", "images", "screens", "plates"]}]'


Now restart your `omero-web` server and go to
<http://localhost:4080/omero_script_ui/> in your browser.

Expand Down
48 changes: 18 additions & 30 deletions omero_script_ui/templates/omero_script_ui/import_from_csv.html
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,12 @@ <h3 id="scriptName">Import from CSV</h3>
<div><b>Version:</b> 2.0.0</div>
</div>

{% if source_names %}
<h3>Annotating {{ source_dtype }}{{ source_names|pluralize }}:
{{ source_names|join:", " }}
</h3>
{% endif %}

<div class="required parent">
<div class="param" title="Data type of the parent objects.">
<table border="0" cellpadding="0" cellspacing="1">
Expand All @@ -109,23 +115,21 @@ <h3 id="scriptName">Import from CSV</h3>

<!-- drop-down list of enums -->
<select tabindex="1" name="Data_Type">
<option value="Project">Project</option>

<option value="Dataset" selected="True">Dataset</option>
<option value="Project" {% if source_dtype == "Project" %}selected="True"{% endif %}>Project</option>

<option value="Image">Image</option>
<option value="Dataset" {% if source_dtype == "Dataset" %}selected="True"{% endif %}>Dataset</option>

<option value="Screen">Screen</option>
<option value="Image" {% if source_dtype == "Image" %}selected="True"{% endif %}>Image</option>

<option value="Plate">Plate</option>
<option value="Screen" {% if source_dtype == "Screen" %}selected="True"{% endif %}>Screen</option>

<option value="Well">Well</option>
<option value="Plate" {% if source_dtype == "Plate" %}selected="True"{% endif %}>Plate</option>

<option value="Acquisition">Acquisition</option>
<option value="Well" {% if source_dtype == "Well" %}selected="True"{% endif %}>Well</option>

<option value="Image">Image</option>
<option value="Acquisition" {% if source_dtype == "Acquisition" %}selected="True"{% endif %}>Acquisition</option>

<option value="Tag">Tag</option>
<option value="Tag" {% if source_dtype == "Tag" %}selected="True"{% endif %}>Tag</option>
</select>

<!-- If "File Annotation", allow user to choose file to upload, to create a File-Annotation -->
Expand All @@ -150,7 +154,7 @@ <h3 id="scriptName">Import from CSV</h3>
src="/static/webclient/image/info16.png"
title="Add items to list, separated by ','"
/>
<input tabindex="1" type="text" name="IDs" value="" />
<input tabindex="1" type="text" name="IDs" value="{{ source_ids|join:',' }}" />

<!-- If "File Annotation", allow user to choose file to upload, to create a File-Annotation -->
</td>
Expand All @@ -174,25 +178,9 @@ <h3 id="scriptName">Import from CSV</h3>

<!-- drop-down list of enums -->
<select tabindex="1" name="Target Data_Type">
<option value="&lt;on current&gt;" selected="True">
&lt;on current&gt;
</option>

<option value="Project">Project</option>

<option value="- Dataset">- Dataset</option>

<option value="-- Image">-- Image</option>

<option value="Screen">Screen</option>

<option value="- Plate">- Plate</option>

<option value="-- Well">-- Well</option>

<option value="-- Acquisition">-- Acquisition</option>

<option value="--- Image">--- Image</option>
{% for dtype in target_types %}
<option value="{% if dtype != source_dtype %}-- {% endif %}{{ dtype }}">{{ dtype }}</option>
{% endfor %}
</select>

<!-- If "File Annotation", allow user to choose file to upload, to create a File-Annotation -->
Expand Down
33 changes: 32 additions & 1 deletion omero_script_ui/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,17 @@

from omeroweb.decorators import login_required

ALLOWED_PARAM = {
"Project": ["Project", "Dataset", "Image"],
"Dataset": ["Dataset", "Image"],
"Image": ["Image"],
"Screen": ["Screen", "Plate", "Well", "Acquisition", "Image"],
"Plate": ["Plate", "Well", "Acquisition", "Image"],
"Well": ["Well", "Image"],
"Acquisition": ["Acquisition", "Image"],
"Tag": ["Project", "Dataset", "Image",
"Screen", "Plate", "Well", "Acquisition"]
}

# login_required: if not logged-in, will redirect to webclient
# login page. Then back to here, passing in the 'conn' connection
Expand Down Expand Up @@ -49,5 +60,25 @@ def import_from_csv(request, conn=None, **kwargs):
script_service = conn.getScriptService()
sid = script_service.getScriptID("/omero/annotation_scripts/Import_from_csv.py")

context = {"script_id": sid}
source_ids = []
source_names = []
source_dtype = None
target_types = []
for dtype in ALLOWED_PARAM.keys():
obj_ids = request.GET.getlist(dtype.lower())
if len(obj_ids) > 0:
source_dtype = dtype
target_types = ALLOWED_PARAM[dtype]
for obj in conn.getObjects(dtype, obj_ids):
source_names.append(obj.getName())
source_ids.append(obj.getId())
break

context = {"script_id": sid,
"source_dtype": source_dtype,
"source_names": source_names,
"source_ids": source_ids,
"target_types": target_types
}

return render(request, "omero_script_ui/import_from_csv.html", context)

0 comments on commit 76ff534

Please sign in to comment.