Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Kvp search #18

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 42 additions & 5 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,9 +1,46 @@
*.log
*.pot
*.pyc
__pycache__/
local_settings.py
.DS_Store
*.egg-info
dist
build
*.log
*.env
*.history
__pycache__/

### IntelliJ IDEA ###
/target/
*.iws
*.iml
*.ipr
*.releaseBackup
.idea

### Eclipse ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache
**/bin/

#Gradle
**/.gradle/
gradle.properties
/build/

### NetBeans ###
/nbproject/private/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/

### VS Code ###
.vscode/
.history/
*.vsix

### Mac OS ###
.DS_Store
24 changes: 21 additions & 3 deletions omero_tagsearch/forms.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
from django.forms import Form, MultipleChoiceField, BooleanField
from django.forms import Form, MultipleChoiceField, BooleanField, CharField
from django.forms import ChoiceField, RadioSelect


class TagSearchForm(Form):
selectedTags = MultipleChoiceField()
excludedTags = MultipleChoiceField()
selectedKey0 = ChoiceField()
selectedValue0 = MultipleChoiceField()
selectedNamespaces = MultipleChoiceField()
i = 1

operation = ChoiceField(
widget=RadioSelect,
choices=(("AND", "AND"), ("OR", "OR")),
Expand All @@ -18,10 +23,23 @@ class TagSearchForm(Form):
view_plate = BooleanField(initial=True)
view_screen = BooleanField(initial=True)

def __init__(self, tags, conn=None, *args, **kwargs):
super(TagSearchForm, self).__init__(*args, **kwargs)
def set_kvp_field(self, i):
selectedKey = ChoiceField()
selectedValue = MultipleChoiceField()
globals()[f"selectedKey{i}"] = selectedKey
globals()[f"selectedValue{i}"] = selectedValue
self.fields[f"selectedKey{i}"] = selectedKey
self.fields[f"selectedValue{i}"] = selectedValue

def __init__(self, tags, keys, values, namespaces, conn=None, *args, **kwargs):
super(TagSearchForm, self).__init__(*args, **kwargs)
# Process Tags into choices (lists of tuples)
self.fields["selectedTags"].choices = tags
self.fields["excludedTags"].choices = tags
self.fields["selectedKey0"].choices = keys
self.fields["selectedValue0"].choices = values
self.set_kvp_field(self.i)
self.fields[f"selectedKey{self.i}"].choices = keys
self.fields[f"selectedValue{self.i}"].choices = values
self.fields["selectedNamespaces"].choices = namespaces
self.conn = conn
24 changes: 22 additions & 2 deletions omero_tagsearch/static/tagsearch/css/webtagging_search.css
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.tagSearchDivider {
.tagSearchDivider, .keyValueSearchDivider {
border-bottom:solid 1px hsl(210,20%,90%);
-webkit-box-shadow:0 1px 0 rgba(255,255,255,.3);

Expand All @@ -10,14 +10,22 @@
margin-bottom:25px;
}

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

#id_excludedTags {
width:200px;
}

#id_selectedKeys {
width:200px;
}

#id_selectedNamespaces {
width:300px;
}

.tagSearchDivider .field {
display: flex;
flex-direction: row;
Expand All @@ -30,6 +38,18 @@
margin-right: 10px; /* Adjust as needed */
}

.keyValueSearchDivider .field {
display: flex;
flex-direction: row;
align-items: center;
margin-bottom: 1px; /* Adjust as needed */
}

.keyValueSearchDivider label {
width:150px;
margin-right: 10px; /* Adjust as needed */
}


.hidden {
display: none !important;
Expand Down
111 changes: 110 additions & 1 deletion omero_tagsearch/templates/omero_tagsearch/tagnav.html
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
var objTypes = ['project', 'dataset', 'image', 'screen', 'plate', 'acquisition', 'well']
$("#id_selectedTags").chosen({placeholder_text:'Choose tags'});
$("#id_excludedTags").chosen({placeholder_text:'Choose tags to exclude'});
$("#id_selectedNamespaces").chosen({placeholder_text:'Choose ns'});

$(".searching_info").tooltip({
track: true,
Expand Down Expand Up @@ -109,16 +110,35 @@
}
});

// update value fields according to what key is selected
Object.keys(data.values).forEach(function(key) {
if(data.values[key] && data.values[key].length != 0) {
$("#id_"+key+" option").each(function() {
if (($.inArray(this.value, data.values[key]) == -1)) {
$(this).hide();
} else {
$(this).css('display', '');
}
});
var selection = $("#id_"+key).getSelectionOrder();
$("#id_"+key).trigger("chosen:updated");
$("#id_"+key).setSelectionOrder(selection);
}
});

// Preserve the order of the select because otherwise Chosen will show the same order as
// the underlying select. i.e. the original option ordering
var selection_incl = $('#id_selectedTags').getSelectionOrder();
var selection_excl = $('#id_excludedTags').getSelectionOrder();
var selection_namespaces = $('#id_selectedNamespaces').getSelectionOrder();
// Update the chosen selector
$("#id_selectedTags").trigger("chosen:updated");
$("#id_excludedTags").trigger("chosen:updated");
$("#id_selectedNamespaces").trigger("chosen:updated");
// Restore the ordering
$('#id_selectedTags').setSelectionOrder(selection_incl);
$("#id_excludedTags").setSelectionOrder(selection_excl);
$('#id_selectedNamespaces').setSelectionOrder(selection_namespaces);

$('#id_search').quicksearch('table#dataTable tbody tr', {
'delay': 300,
Expand Down Expand Up @@ -161,6 +181,12 @@
$("#tagSearchForm").submit();
}
});
$( "#id_selectedNamespaces" ).chosen().change(function(event, params) {
// Tag selection or deselection made
if ((params.selected || params.deselected) && $('#enableCheckbox').is(':checked')) {
$("#tagSearchForm").submit();
}
});

$('#enableCheckbox').change(function() {
if ($(this).is(':checked')) {
Expand Down Expand Up @@ -252,7 +278,7 @@ <h2>{% trans "Tag Search" %}</h2>
data-content="Remove from the results the objects annotated with excluded tags.</br>Only the tags of the selected group & user are listed.">
<img class="search_tips__tag" src="{% static 'webgateway/img/help16.png' %}" />
</span>
</div><br/><br/>
</div><br/>
<div>
<label for="id_operation">Joining method:</label>
<span class="searching_info"
Expand All @@ -263,6 +289,89 @@ <h2>{% trans "Tag Search" %}</h2>
</div><br/>
</div>

<div class="keyValueSearchDivider">
<div class ="field">
{{ tagnav_form.selectedNamespaces.errors }}
<label for="id_selectedNamespaces">Selected Namespaces:</label>
{{ tagnav_form.selectedNamespaces }}
<span class="searching_info"
data-content="Select the namespace(s) you want to search into">
<img class="search_tips__tag" src="{% static 'webgateway/img/help16.png' %}" />
</span>
</div><br/><br/>
<div class ="field">
{{ tagnav_form.selectedKey0.errors }}
<label for="id_selectedKey0">Selected keys:</label>
{{ tagnav_form.selectedKey0 }}
<span class="searching_info"
data-content="Search objects annotated with selected keys.</br>Only the keys of the selected group & user are listed.</br>Multiple keys are combined according to the joining method.">
<img class="search_tips__tag" src="{% static 'webgateway/img/help16.png' %}" />
</span>
</div>
<div class ="field">
{{ tagnav_form.selectedValue0.errors }}
<label for="id_selectedValue0">Values:</label>
{{ tagnav_form.selectedValue0 }}
<span class="searching_info"
data-content="Search objects annotated with selected keys.</br>Only the keys of the selected group & user are listed.</br>Multiple keys are combined according to the joining method.">
<img class="search_tips__tag" src="{% static 'webgateway/img/help16.png' %}" />
</span>
</div>
<br/><br/>
<div class ="field">
{{ tagnav_form.selectedKey1.errors }}
<label for="id_selectedKey1">Selected keys:</label>
{{ tagnav_form.selectedKey1 }}
<span class="searching_info"
data-content="Search objects annotated with selected keys.</br>Only the keys of the selected group & user are listed.</br>Multiple keys are combined according to the joining method.">
<img class="search_tips__tag" src="{% static 'webgateway/img/help16.png' %}" />
</span>
</div>
<div class ="field">
{{ tagnav_form.selectedValue1.errors }}
<label for="id_selectedValue1">Values:</label>
{{ tagnav_form.selectedValue1 }}
<span class="searching_info"
data-content="Search objects annotated with selected keys.</br>Only the keys of the selected group & user are listed.</br>Multiple keys are combined according to the joining method.">
<img class="search_tips__tag" src="{% static 'webgateway/img/help16.png' %}" />
</span>
</div><br/><br/>
<script>
$( "#id_selectedKey0" ).chosen().change(function(event, params) {
// Tag selection or deselection made
if ((params.selected || params.deselected) && $('#enableCheckbox').is(':checked')) {
$("#tagSearchForm").submit();
}
});
</script>
<script>
$( "#id_selectedKey1" ).chosen().change(function(event, params) {
// Tag selection or deselection made
if ((params.selected || params.deselected) && $('#enableCheckbox').is(':checked')) {
$("#tagSearchForm").submit();
}
});
</script>
<script>
$("#id_selectedValue0").chosen({placeholder_text:'Choose values'});
$( "#id_selectedValue0" ).chosen().change(function(event, params) {
// Tag selection or deselection made
if ((params.selected || params.deselected) && $('#enableCheckbox').is(':checked')) {
$("#tagSearchForm").submit();
}
});
</script>
<script>
$("#id_selectedValue1").chosen({placeholder_text:'Choose values'});
$( "#id_selectedValue1" ).chosen().change(function(event, params) {
// Tag selection or deselection made
if ((params.selected || params.deselected) && $('#enableCheckbox').is(':checked')) {
$("#tagSearchForm").submit();
}
});
</script>
</div>

<h2>Results</h2>
<ul id="counts_list">
<li class="tagnav-project">{{ tagnav_form.view_project }}<div class="tagnav-icon">&nbsp;</div>Project:&nbsp;<span>0</span></li>
Expand Down
Loading