Skip to content

Commit

Permalink
Adjust search fields
Browse files Browse the repository at this point in the history
  • Loading branch information
frankwiles committed Feb 29, 2024
1 parent b5b1d9d commit 0bfafc3
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 21 deletions.
4 changes: 0 additions & 4 deletions web/nuremberg/core/static/style/search.less
Original file line number Diff line number Diff line change
Expand Up @@ -217,10 +217,6 @@ section.results {
.advanced-search-help {
.transition(~"max-height 0.5s");

overflow: hidden;
max-height: 1000px;


&.hide {
max-height: 0px;
display: block;
Expand Down
53 changes: 46 additions & 7 deletions web/nuremberg/search/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,8 @@ def apply_field_query(self, sqs, field_query):
else:
field_query.append('ignored')

print("SQS")
print(sqs.query)
return sqs


Expand Down Expand Up @@ -516,6 +518,11 @@ class AdvancedDocumentSearchForm(forms.Form):
],
list,
)
AND_OR_OR_CHOICES = (
('and', 'all'),
('or', 'any'),
)

m = forms.CheckboxSelectMultiple()
keywords = forms.CharField(
required=False, widget=forms.TextInput(attrs={"class": "large"})
Expand All @@ -535,17 +542,27 @@ class AdvancedDocumentSearchForm(forms.Form):
choices=AUTHOR_CHOICES,
help_text="Personal author: the author's name, with a title or other identifying information if available. This information is usually drawn from the document itself, but often other documents provide additional information. Group author: provided if the document was produced by an agency or group or another collective source (e.g., laws published in the official state gazette).",
)
defendant = forms.MultipleChoiceField(
author_and_or_or = forms.MultipleChoiceField(
required=False,
choices=DEFENDANT_CHOICES,
help_text="Applies to case files only; indicates which defendants are involved or relevant to the subjects covered by the document.",
choices=AND_OR_OR_CHOICES,
help_text="Whether to AND or OR these selections",
)
issue = forms.MultipleChoiceField(
label=_('Trial Issues'),
required=False,
choices=ISSUE_CHOICES,
help_text="Subjects of trial documents; applies to case files only; indicates the subject areas of the document that are relevant for the trial. Other subjects are not indicated.",
)
issue_and_or_or = forms.MultipleChoiceField(
required=False,
choices=AND_OR_OR_CHOICES,
help_text="Whether to AND or OR these selections",
)
defendant = forms.MultipleChoiceField(
required=False,
choices=DEFENDANT_CHOICES,
help_text="Applies to case files only; indicates which defendants are involved or relevant to the subjects covered by the document.",
)
trial = forms.MultipleChoiceField(required=False, choices=TRIAL_CHOICES)
language = forms.MultipleChoiceField(
required=False,
Expand Down Expand Up @@ -617,9 +634,9 @@ def clean(self):
)
elif evidence:
suffix = cleaned_data.get('evidence_suffix', '')
cleaned_data[
'evidence_code'
] = f'{evidence}-{evidence_num}{suffix}'
cleaned_data['evidence_code'] = (
f'{evidence}-{evidence_num}{suffix}'
)

exhibit = cleaned_data.get('exhibit')
exhibit_num = cleaned_data.get('exhibit_num')
Expand Down Expand Up @@ -674,8 +691,30 @@ def as_search_qs(self, data=None):
# choice field entries
for term in (
'author',
'defendant',
'issue',
):
values = _getlist(data, term)
if values:
# Determine if the user wants an AND or OR search here from
# the select boxes next to these fields which are named after
# the field
option_name = f"{term}_and_or_or"
print(f"OPTION NAME: {option_name}")
print(f"OPTION VALUE: {data.get(option_name)}")
if data.get(option_name) == 'and':
terms.extend(
f'{term}:"{value}"' for value in values if value
)
else:
items = [value for value in values if value]
new_values = "|".join(items)
terms.append(f'{term}:"{new_values}"')
print("TERMS")
print(terms)

# single choice field entries
for term in (
'defendant',
'trial',
'language',
'source',
Expand Down
46 changes: 36 additions & 10 deletions web/nuremberg/search/templates/search/new-advanced-search.html
Original file line number Diff line number Diff line change
Expand Up @@ -1205,24 +1205,28 @@
placeholder: 'Choose one or more...',
});

$('#id_defendant').select2({
$('#id_issue').select2({
placeholder: 'Choose one or more...',
});

$('#id_issue').select2({
placeholder: 'Choose one or more...',
$('#id_defendant').select2({
placeholder: 'Choose one...',
multiple: false,
});

$('#id_trial').select2({
placeholder: 'Choose one or more...',
placeholder: 'Choose one...',
multiple: false,
});

$('#id_language').select2({
placeholder: 'Choose one or more...',
placeholder: 'Choose one...',
multiple: false,
});

$('#id_source').select2({
placeholder: 'Choose one or more...',
placeholder: 'Choose one...',
multiple: false,
});

// clear the selection when button pressed
Expand Down Expand Up @@ -1252,7 +1256,7 @@

<section id="search" role="search" aria-label="Search the archive" class="theme-beige thin">
<h1 class="h4">Search the archive &mdash; Advanced</h1>
<div class="full-width">
<div class="full-width" style="height: 100%">
<div class="advanced-search-help">

{% for message in messages %}
Expand All @@ -1264,6 +1268,7 @@ <h1 class="h4">Search the archive &mdash; Advanced</h1>
{% endfor %}

<form class="advanced-search" role="search" aria-label="advanced search" action="{% url 'search:advanced' %}" method="POST">
<h3>Main Search Criteria</h3>
<p>{% trans 'Match all entered search terms below' %}</p>
<p style="margin-top: 10px; margin-bottom: 10px">
<label style="margin-right: 50px;">Search Type:</label>
Expand All @@ -1285,16 +1290,35 @@ <h1 class="h4">Search the archive &mdash; Advanced</h1>
</label>
</p>
{% for field in form %}
{% if field.name == "author" %}
<h3>The options below here are AND or ORed</h3>
{% endif %}
{% if field.name == "defendant" %}
<h3>The options below here are ORed</h3>
{% endif %}
{% if field.name != 'evidence' and field.name != 'exhibit' and field.name != 'book' and field.name != 'm' and '_' not in field.name %}
<div class="{% if field.errors %}has-error{% endif %}">
<p>
<p style="display: inline-flex">
<label for="id_{{ field.name }}" {% if field.help_text %}class="help-label" data-content_id="adv-help-{{ field.name }}"{% endif %}>
{{ field.label }}
{% if field.help_text %}
<svg class="label"><use href="#i-icon" /></svg>
{% endif %}
</label>

{% if field.name == "author" %}
<select name="author_and_or_or" id="author_and_or_or">
<option value="and" checked>Match all</option>
<option value="or">Match any</option>
</select>
{% endif %}

{% if field.name == "issue" %}
<select name="issue_and_or_or" id="issue_and_or_or">
<option value="and" checked>Match all</option>
<option value="or">Match any</option>
</select>
{% endif %}
{{ field }}

{% if field.help_text %}
Expand All @@ -1311,6 +1335,9 @@ <h1 class="h4">Search the archive &mdash; Advanced</h1>
{% endif %}
{% endfor %}

<div style="margin-top: 50px">
<h3>Additional Options</h3>
</div>
<div class="{% if form.evidence.errors %}has-error{% endif %}">
<p>
<label for="id_{{ form.evidence.name }}" class="help-label" data-content_id="adv-help-{{ form.evidence.name }}">
Expand Down Expand Up @@ -1375,11 +1402,10 @@ <h1 class="h4">Search the archive &mdash; Advanced</h1>
<p><small class="has-error">{{ error }}</small></p>
{% endfor %}

<div class="advanced-search-button-group">
<div style="float: right">
<button class="button search-button" type="submit">Advanced Search</button>
<button class="button search-button" type="reset" id="clear-button">Clear</button>
</div>

</form>

</div>
Expand Down

0 comments on commit 0bfafc3

Please sign in to comment.