Skip to content

Commit

Permalink
Merge pull request #16 from German-BioImaging/usertag_toggle
Browse files Browse the repository at this point in the history
Filtering tag on ownership option for current user
  • Loading branch information
Tom-TBT authored Oct 11, 2024
2 parents e59280c + 4f01146 commit 032d91d
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 37 deletions.
14 changes: 5 additions & 9 deletions omero_tagsearch/static/tagsearch/css/webtagging_search.css
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,7 @@
margin-bottom:25px;
}

#id_selectedTags {
width:200px;
}

#id_excludedTags {
#id_selectedTags, #id_excludedTags {
width:200px;
}

Expand Down Expand Up @@ -49,18 +45,18 @@
}

.tagnav-icon {
background-position: 0 0;
background-position: center top;
background-position: center bottom;
height: 16px;
width: 17px;
display: inline-block;
text-decoration: none;
margin: 0 0 3px 0;
margin: 3px 5px 2px 3px;
padding: 0;
}

.tagnav-user .tagnav-icon {
background: url('../image/icon_user.png') no-repeat;
margin: 0 0 0 0;
}

.tagnav-project .tagnav-icon {
Expand Down Expand Up @@ -122,7 +118,7 @@ ul#id_operation li{

#id_userName {
margin-top: 5px;
margin-bottom: 5px;
margin-bottom: 15px;
display: inline-block;
}

Expand Down
61 changes: 40 additions & 21 deletions omero_tagsearch/templates/omero_tagsearch/tagnav.html
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
<script src="{% static "tagsearch/3rd-party/chosen.order.jquery.js" %}"></script>

<script type="text/javascript">
var ownership_l = {{ ownership_l|safe }};
$(document).ready(function()
{

Expand Down Expand Up @@ -75,6 +76,24 @@
}
}

$('#user_filter_on').change(function() {
var filter_user = $("#user_filter_on").is(':checked');
$("#id_selectedTags option, #id_excludedTags option").each(function() {
var optionValue = parseInt(this.value);
var inOwnershipList = $.inArray(optionValue, ownership_l) !== -1;
if (filter_user && !inOwnershipList) {
$(this).hide();
} else if (!$(this).hasClass('hidfromresults')) {
$(this).show();
}
});
var selection_incl = $('#id_selectedTags').getSelectionOrder();
var selection_excl = $('#id_excludedTags').getSelectionOrder();
$('#id_selectedTags, #id_excludedTags').trigger("chosen:updated");
$('#id_selectedTags').setSelectionOrder(selection_incl);
$("#id_excludedTags").setSelectionOrder(selection_excl);
});

// Form Submission
$("#tagSearchForm").ajaxForm({
beforeSubmit: function() {
Expand All @@ -93,19 +112,19 @@

// Hide any options that are no longer possible and
// show any that have become possible
$("#id_selectedTags option").each(function() {
if (($.inArray(parseInt(this.value), data.navdata) == -1) && (data.navdata.length != 0)) {
$(this).hide();
} else {
$(this).css('display', '');
}
});

$("#id_excludedTags option").each(function() {
if (($.inArray(parseInt(this.value), data.navdata) == -1) && (data.navdata.length != 0)) {
// optionnaly filter on user's owned tags

$("#id_selectedTags option, #id_excludedTags option").each(function() {
var filter_user = $("#user_filter_on").is(':checked');
var tag_value = parseInt(this.value);
if ((($.inArray(tag_value, data.navdata) == -1)
&& (data.navdata.length != 0))
|| (filter_user && ($.inArray(tag_value, ownership_l) == -1))) {
$(this).hide();
$(this).addClass('hidfromresults');
} else {
$(this).css('display', '');
$(this).show();
$(this).removeClass('hidfromresults');
}
});

Expand All @@ -114,8 +133,7 @@
var selection_incl = $('#id_selectedTags').getSelectionOrder();
var selection_excl = $('#id_excludedTags').getSelectionOrder();
// Update the chosen selector
$("#id_selectedTags").trigger("chosen:updated");
$("#id_excludedTags").trigger("chosen:updated");
$("#id_selectedTags, #id_excludedTags").trigger("chosen:updated");
// Restore the ordering
$('#id_selectedTags').setSelectionOrder(selection_incl);
$("#id_excludedTags").setSelectionOrder(selection_excl);
Expand Down Expand Up @@ -201,9 +219,7 @@
} else {
$("#selectall_btn").text("Select all");
}

});

});
</script>

Expand All @@ -227,10 +243,13 @@ <h2>{% trans "Tag Search" %}</h2>
{{ tagnav_form.non_field_errors }}

{% if user_name %}
<div id="id_userName" class="tagnav-user">
<div class="tagnav-icon">&nbsp;</div>
&nbsp;<span>{{ user_name }}</span>
</div>
<div id="id_userName" class="tagnav-user">
<span>
<input type="checkbox" id="user_filter_on"> Filter tags for {{ user_name }}
&nbsp;<span class="tagnav-icon"></span>
</span>

</div>
{% endif %}

<div class="fieldWrapper">
Expand All @@ -240,7 +259,7 @@ <h2>{% trans "Tag Search" %}</h2>
<label for="id_selectedTags">Selected Tags:</label>
{{ tagnav_form.selectedTags }}&nbsp;
<span class="searching_info"
data-content="Search objects annotated with selected tags.</br>Only the tags of the selected group & user are listed.</br>Multiple tags are combined according to the joining method.">
data-content="Search objects annotated with selected tags.</br>Multiple tags are combined according to the joining method.">
<img class="search_tips__tag" src="{% static 'webgateway/img/help16.png' %}" />
</span>
</div><br/>
Expand All @@ -249,7 +268,7 @@ <h2>{% trans "Tag Search" %}</h2>
<label for="id_excludedTags">Excluded Tags:</label>
{{ tagnav_form.excludedTags }}&nbsp;
<span class="searching_info"
data-content="Remove from the results the objects annotated with excluded tags.</br>Only the tags of the selected group & user are listed.">
data-content="Remove from the results the objects annotated with excluded tags.">
<img class="search_tips__tag" src="{% static 'webgateway/img/help16.png' %}" />
</span>
</div><br/><br/>
Expand Down
20 changes: 13 additions & 7 deletions omero_tagsearch/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,27 +217,24 @@ def get_tags(obj, tagset_d):
params = Parameters()
hql = (
"""
SELECT DISTINCT ann.id, ann.textValue
SELECT DISTINCT ann.id, ann.textValue, ann.details.owner.id
FROM %sAnnotationLink link
JOIN link.child ann
WHERE ann.class IS TagAnnotation
"""
% obj
)

if user_id != -1:
hql += " AND ann.details.owner.id = (:uid)"
params.map = {"uid": rlong(user_id)}

return [
(result[0].val, result[1].val, tagset_d[result[0].val])
(result[0].val, result[1].val,
tagset_d[result[0].val], result[2].val)
for result in qs.projection(hql, params, service_opts)
]

tagset_d = defaultdict(str)
tagset_d.update(get_tagsets())

# List of tuples (id, value)
# List of tuples (id, value, tagset, owner)
tags = set(get_tags("Image", tagset_d))
tags.update(get_tags("Dataset", tagset_d))
tags.update(get_tags("Project", tagset_d))
Expand All @@ -249,6 +246,14 @@ def get_tags(obj, tagset_d):
# Convert back to an ordered list and sort
tags = list(tags)
tags.sort(key=lambda x: (x[2].lower(), x[1].lower()))
if user_id == -1:
ownership_l = [1] * len(tags)
else:
ownership_l = []
for i, (id_, _, _, owner) in enumerate(tags):
if int(owner == user_id):
ownership_l.append(id_)

tags = list(map(lambda t: (t[0], t[1] + t[2]), tags))

form = TagSearchForm(tags, conn, use_required_attribute=False)
Expand All @@ -271,6 +276,7 @@ def get_tags(obj, tagset_d):
context["template"] = template
context["tagnav_form"] = form
context["user_name"] = user_name
context["ownership_l"] = ownership_l

return context

Expand Down

0 comments on commit 032d91d

Please sign in to comment.