Skip to content

Commit ccc00a7

Browse files
committed
[IEXP-595] most review comments for facets
Except top pills and authorities box
1 parent 149879f commit ccc00a7

File tree

4 files changed

+102
-129
lines changed

4 files changed

+102
-129
lines changed

isiscb/curation/templatetags/render_object.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -264,10 +264,6 @@ def get_other_subjects(obj):
264264
def get_time_and_place_subjects(obj):
265265
return ACRelation.objects.filter(type_controlled=ACRelation.SUBJECT, authority__type_controlled__in=[Authority.TIME_PERIOD, Authority.GEOGRAPHIC_TERM], citation_id=obj.id)
266266

267-
@register.filter
268-
def get_person_subjects(obj):
269-
return ACRelation.objects.filter(type_controlled=ACRelation.SUBJECT, authority__type_controlled__in=[Authority.PERSON], citation_id=obj.id)
270-
271267
@register.filter
272268
def get_person_and_institutions_subjects(obj):
273269
return ACRelation.objects.filter(type_controlled=ACRelation.SUBJECT, authority__type_controlled__in=[Authority.PERSON, Authority.INSTITUTION], citation_id=obj.id)

isiscb/isisdata/templatetags/facet_filters.py

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@
77
import urllib.request, urllib.parse, urllib.error
88
import re
99

10+
import logging
11+
1012
register = template.Library()
13+
logger = logging.getLogger(__name__)
1114

1215
@register.filter
1316
def get_authority_name(id):
@@ -29,7 +32,30 @@ def set_excluded_facets(url, available_facets):
2932

3033
@register.filter
3134
def remove_url_part(url, arg):
32-
return urllib.parse.unquote(url).replace(arg, "").replace("&&", "&")
35+
qs = urllib.parse.parse_qsl(url)
36+
if not len(arg.split("=")) == 2:
37+
return url
38+
39+
logger.error("remove url part")
40+
logger.error(qs)
41+
42+
key = arg.split("=")[0]
43+
value = arg.split("=")[1]
44+
45+
logger.error(key)
46+
logger.error(value)
47+
for para in qs:
48+
if para[0] == key and para[1] == value:
49+
qs.remove(para)
50+
# this is a hack but not sure a better way to do this at this point
51+
# if we didn't just delete the value with a '&' in it, then we need to quote the '&' to
52+
# make cases work in which a fact has an ampersand in the value
53+
# for some reason the facetting doesn't work if we don't do this
54+
if para in qs and "&" in para[1]:
55+
qs.remove(para)
56+
qs.append((para[0], urllib.parse.quote(para[1])))
57+
58+
return "&".join([f"{para[0]}={para[1]}" for para in qs])
3359

3460
@register.filter
3561
def add_selected_facet(url, facet):
@@ -70,6 +96,15 @@ def create_facet_with_field(facet, field):
7096
def are_reviews_excluded(url):
7197
return 'excluded_facets=citation_type:Review' in urllib.parse.unquote(url)
7298

99+
@register.filter
100+
def is_limited_to_tech_culture(url):
101+
return 'selected_facets=citation_dataset_typed_names:Technology & Culture Bibliography' in urllib.parse.unquote(url)
102+
103+
@register.filter
104+
def limit_to_tech_culture_facet(url):
105+
return (url + "&selected_facets=citation_dataset_typed_names:Technology%20%26%20Culture%20Bibliography")
106+
107+
73108
@register.filter
74109
def are_stubs_excluded(url):
75110
return 'excluded_facets=citation_stub_record_status:SR' in urllib.parse.unquote(url)

isiscb/tenants/templates/tenants/search/search_results_authorities.html

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,16 @@
33
{% load search_filters %}
44

55
{% if query %}
6+
<div class="panel-group hidden-print" id="type_panel">
67
<div class='panel panel-default'>
78
<div class='panel-heading'>
89
<h4 class='panel-title'>
9-
<a data-toggle="collapse" data-parent="#accordion" href=".collapseAuthorityResults" class="accordion-toggle">
10+
<a id="authoritiesHeading" data-toggle="collapse" data-parent="#accordion" href="#" class="accordion-toggle">
1011
All Authorities
1112
</a>
1213
</h4>
1314
</div>
14-
<div id="collapseAuthorityResults" class="collapseAuthorityResults panel-collapse collapse" style='height: 0px;'>
15+
<div id="collapseAuthorityResults" class="collapseAuthorityResults panel-collapse" >
1516
<div class='panel-body'>
1617
<div class="row" style="margin-bottom:10px;">
1718
<div class="col-md-12 panel-cell" style="padding-top:4px">
@@ -150,7 +151,7 @@ <h5 style="margin:4px 0"><small>Select the type of authority you would like see.
150151
</div>
151152
</div>
152153
</div>
153-
154+
</div>
154155
{% else %}
155156
{# Show some example queries to run, maybe query syntax, something else? #}
156157
{% endif %}

isiscb/tenants/templates/tenants/search/search_results_citations.html

Lines changed: 62 additions & 121 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@
2020
<div class="panel panel-default">
2121
<div class="panel-heading">
2222
<h4 class="panel-title">
23-
<a data-toggle="collapse" data-parent="#accordion"
24-
href=".collapseFilters" class="accordion-toggle">
23+
<a id="collapseFiltersHeading" data-toggle="collapse" data-parent="#accordion"
24+
href="#" class="accordion-toggle">
2525
Sort & Filter
2626
</a>
2727
</h4>
@@ -56,39 +56,42 @@ <h4 class="panel-title">
5656
<div class="col-md-12" style="padding-top: 10px;">
5757
<small>
5858
{% if request.get_full_path|are_reviews_excluded %}
59-
<input type="checkbox" name="exclude_reviews" >
60-
61-
<a href="{{ request.get_full_path|set_page_to_one|set_index_model:'models:isisdata.citation'|remove_url_part:'excluded_facets=citation_type:Review'|add_facet_or_operator }}"> Book Reviews are excluded</a>
59+
<a href="{{ request.get_full_path|set_page_to_one|set_index_model:'models:isisdata.citation'|remove_url_part:'excluded_facets=citation_type:Review'|add_facet_or_operator }}"><i class="far fa-square"></i> Include book reviews</a>
6260
{% endif %}
6361
{% if not request.get_full_path|are_reviews_excluded %}
64-
<input type="checkbox" name="exclude_reviews" checked>
65-
<a href="{{ request.get_full_path|set_page_to_one|set_index_model:'models:isisdata.citation'|add_excluded_citation_type_facet:'Review'|add_facet_or_operator }}"> Book Reviews are included</a>
62+
<a href="{{ request.get_full_path|set_page_to_one|set_index_model:'models:isisdata.citation'|add_excluded_citation_type_facet:'Review'|add_facet_or_operator }}"><i class="fa fa-check-square"></i> Include book reviews</a>
6663
{% endif %}
6764
</small>
6865
</div>
6966

7067
<div class="col-md-12" style="padding-top: 10px;">
7168
<small>
72-
{% if request.get_full_path|are_stubs_excluded %}
73-
<input type="checkbox" name="exclude_stubs" >
69+
{% if request.get_full_path|is_limited_to_tech_culture %}
70+
<a href="{{ request.get_full_path|set_page_to_one|set_index_model:'models:isisdata.citation'|remove_url_part:'selected_facets=citation_dataset_typed_names:Technology & Culture Bibliography'|add_facet_or_operator }}"><i class="fa fa-check-square"></i> Limit to just Technology and Culture data</a>
71+
{% endif %}
72+
{% if not request.get_full_path|is_limited_to_tech_culture %}
73+
<a href="{{ request.get_full_path|set_page_to_one|set_index_model:'models:isisdata.citation'|limit_to_tech_culture_facet|add_facet_or_operator }}"><i class="far fa-square"></i> Limit to just Technology and Culture data</a>
74+
{% endif %}
75+
</small>
76+
</div>
7477

75-
<a href="{{ request.get_full_path|set_page_to_one|set_index_model:'models:isisdata.citation'|remove_url_part:'excluded_facets=citation_stub_record_status:SR'|add_facet_or_operator }}"> Incomplete records are excluded</a>
78+
<div class="col-md-12" style="padding-top: 10px;">
79+
<small>
80+
{% if request.get_full_path|are_stubs_excluded %}
81+
<span style="color: #555"><i class="far fa-square"></i> Include incomplete records</span>
7682
{% endif %}
7783
{% if not request.get_full_path|are_stubs_excluded %}
78-
<input type="checkbox" name="exclude_stubs" checked>
79-
<a href="{{ request.get_full_path|set_page_to_one|set_index_model:'models:isisdata.citation'|add_excluded_stub_record_status_facet:'SR'|add_facet_or_operator }}"> Incomplete records are included</a>
84+
<span style="color: #555"><i class="fa fa-check-square"></i> Include incomplete records</span>
8085
{% endif %}
8186
</small>
8287
</div>
8388

8489
<div class="col-md-12" style="padding-top: 10px;">
8590
<small>
8691
{% if request.GET.owning_tenant %}
87-
<input type="checkbox" name="include_all_projects" >
88-
<a href="{{ request.get_full_path|remove_tenant }}">Include all projects</a>
92+
<span style="color: #555"><i class="far fa-square"></i> Include all projects</span>
8993
{% else %}
90-
<input type="checkbox" name="include_all_projects" checked>
91-
<a href="{{ request.get_full_path|add_tenant:tenant_id}}">All projects included</a>
94+
<span style="color: #555"><i class="far fa-square"></i>All projects included</span>
9295
{% endif %}
9396
</small>
9497
</div>
@@ -104,13 +107,13 @@ <h4 class="panel-title">
104107
<div class="panel panel-default">
105108
<div class="panel-heading">
106109
<h4 class="panel-title">
107-
<a data-toggle="collapse" data-parent="#accordion"
108-
href=".collapseCitationTypes" class="accordion-toggle">
109-
Filter by publication type
110+
<a id="publicationTypeHeading" data-toggle="collapse" data-parent="#accordion"
111+
href="#" class="accordion-toggle">
112+
Limit by publication type
110113
</a>
111114
</h4>
112115
</div>
113-
<div id="collapseCitationTypes" class="collapseCitationTypes panel-collapse {% if "citation_type" not in selected_facets.keys %}collapse{% else %}in{%endif%}" aria-expanded="true">
116+
<div id="collapseCitationTypes" class="collapseCitationTypes panel-collapse" aria-expanded="true">
114117
<div class="facet_panel panel-body">
115118
<div class="row panel-row">
116119
<div class="col-md-12 panel-cell">
@@ -158,13 +161,13 @@ <h5 style="margin:4px 0"><small>Select the type of publication you would like se
158161
<div class="panel panel-default">
159162
<div class="panel-heading">
160163
<h4 class="panel-title">
161-
<a data-toggle="collapse" data-parent="#accordion"
162-
href=".collapseLanguages" class="accordion-toggle">
163-
Filter by language
164+
<a id="languageFilterHeading" data-toggle="collapse" data-parent="#accordion"
165+
href="#" class="accordion-toggle">
166+
Limit by language
164167
</a>
165168
</h4>
166169
</div>
167-
<div id="collapseLanguages" class="collapseLanguages panel-collapse {% if "citation_language" not in selected_facets.keys %}collapse{% else %}in{%endif%}" aria-expanded="true">
170+
<div id="collapseLanguages" class="collapseLanguages panel-collapse" aria-expanded="true">
168171
<div class="facet_panel panel-body">
169172
<div class="row panel-row">
170173
<div class="col-md-12 panel-cell">
@@ -187,7 +190,9 @@ <h5 style="margin:4px 0"><small>Select the publication language(s) you would lik
187190
{% if language.0 %}
188191
{% if "citation_language" not in selected_facets.keys or language.0 not in selected_facets.citation_language %}
189192
<div class="col-md-12">
190-
<a title="Add Document Language facet" href="{{ request.get_full_path|set_page_to_one|set_index_model:'models:isisdata.citation' }}&amp;selected_facets=citation_language:{{ language.0|urlencode }}"><i class="far fa-square"></i></a> {{ language.0 }} ({{ language.1 }})
193+
{% with 'citation_language:'|add:language.0 as facet_string %}
194+
<a title="Add Document Language facet" href="{{ request.get_full_path|set_page_to_one|set_index_model:'models:isisdata.citation'|add_selected_facet:facet_string}}"><i class="far fa-square"></i></a> {{ language.0 }} ({{ language.1 }})
195+
{% endwith %}
191196
</div>
192197
{% endif %}
193198
{% endif %}
@@ -207,61 +212,6 @@ <h5 style="margin:4px 0"><small>Select the publication language(s) you would lik
207212
</div>
208213
<!-- END language facet -->
209214

210-
<!-- BEGIN dataset facet-->
211-
<div class="panel-group hidden-print" id="type_panel">
212-
<div class="panel panel-default">
213-
<div class="panel-heading">
214-
<h4 class="panel-title">
215-
<a data-toggle="collapse" data-parent="#accordion"
216-
href=".collapseDatasets" class="accordion-toggle">
217-
Filter by datasets
218-
</a>
219-
</h4>
220-
</div>
221-
<div id="collapseDatasets" class="collapseDatasets panel-collapse {% if "citation_dataset_typed_names" not in selected_facets.keys %}collapse{% else %}in{%endif%}" aria-expanded="true">
222-
<div class="facet_panel panel-body">
223-
224-
<div class="row panel-row">
225-
<div class="col-md-12 panel-cell">
226-
<h5 style="margin:4px 0"><small>Select the dataset you would like see.</small></h5>
227-
</div>
228-
</div>
229-
230-
<div class="row panel-row ">
231-
{% if facets_citation.fields.dataset_typed_names %}
232-
<div class="col-md-12">
233-
{% for dataset_name in selected_facets.citation_dataset_typed_names %}
234-
{% with dataset_name|create_facet_string:'citation_dataset_typed_names' as encoded_dataset_typed_names %}
235-
<div class="col-md-12">
236-
<a href="{{ request.get_full_path|remove_facet:encoded_dataset_typed_names|set_page_to_one|set_index_model:'models:isisdata.citation' }}"><i class="fa fa-check-square"></i></a> {{ dataset_name }}
237-
</div>
238-
{% endwith %}
239-
{% endfor %}
240-
241-
{% for dataset_name in facets_citation.fields.dataset_typed_names %}
242-
{% if dataset_name.0 %}
243-
{% if "citation_dataset_typed_names" not in selected_facets.keys or dataset_name.0 not in selected_facets.citation_dataset_typed_names %}
244-
<div class="col-md-12">
245-
<a title="Add Dataset facet" href="{{ request.get_full_path|set_page_to_one|set_index_model:'models:isisdata.citation' }}&amp;selected_facets=citation_dataset_typed_names:{{ dataset_name.0|urlencode }}"><i class="far fa-square"></i></a> {{ dataset_name.0 }} ({{ dataset_name.1 }})
246-
</div>
247-
{% endif %}
248-
{% endif %}
249-
{% endfor %}
250-
</div>
251-
{% else %}
252-
<div class="row panel-row">
253-
<div class="col-md-12 panel-cell">
254-
<p>No dataset facets.</p>
255-
</div>
256-
</div>
257-
{% endif %}
258-
</div>
259-
</div>
260-
</div>
261-
</div>
262-
</div>
263-
<!-- END dataset facet -->
264-
265215
{% include "tenants/search/search_results_authorities.html" %}
266216
</div>
267217
<div class="col-sm-12 col-md-8 menuContainer">
@@ -470,48 +420,39 @@ <h3>No results found . . . <i class="fas fa-child"></i></h3>
470420
</div>
471421
</div>
472422

473-
<link rel="stylesheet" href={% static "isisdata/switch/bootstrap-switch.css" %}>
474-
<script src={% static "isisdata/switch/bootstrap-switch.min.js" %} type="text/javascript"></script>
475423
<script>
476-
$("input[name='exclude_reviews']").bootstrapSwitch({
477-
'size':'mini',
478-
'offText': '<i class="fa fa-times" aria-hidden="true"></i>',
479-
'onText': '<i class="fa fa-check" aria-hidden="true"></i>',
480-
});
481-
482-
$('input[name="exclude_reviews"]').on('switchChange.bootstrapSwitch', function(event, includeReviews) {
483-
if (includeReviews) {
484-
window.location = "{{ request.get_full_path|set_page_to_one|set_index_model:'models:isisdata.citation'|remove_url_part:'excluded_facets=citation_type:Review'|add_facet_or_operator|safe }} "
485-
} else {
486-
window.location = "{{ request.get_full_path|set_page_to_one|set_index_model:'models:isisdata.citation'|add_excluded_citation_type_facet:'Review'|add_facet_or_operator|safe }}"
487-
}
488-
});
489-
490-
$("input[name='exclude_stubs']").bootstrapSwitch({
491-
'size':'mini',
492-
'offText': '<i class="fa fa-times" aria-hidden="true"></i>',
493-
'onText': '<i class="fa fa-check" aria-hidden="true"></i>',
494-
});
495-
496-
$('input[name="exclude_stubs"]').on('switchChange.bootstrapSwitch', function(event, includeStubs) {
497-
if (includeStubs) {
498-
window.location = "{{ request.get_full_path|set_page_to_one|set_index_model:'models:isisdata.citation'|remove_url_part:'excluded_facets=citation_stub_record_status:SR'|add_facet_or_operator|safe }} "
499-
} else {
500-
window.location = "{{ request.get_full_path|set_page_to_one|set_index_model:'models:isisdata.citation'|add_excluded_stub_record_status_facet:'SR'|add_facet_or_operator|safe }}"
424+
425+
function addToggleEventListener(boxId, contentBoxId, storageKey) {
426+
const box = document.getElementById(boxId);
427+
box.addEventListener('click', function() {
428+
localStorage.setItem(storageKey, (localStorage.getItem(storageKey) || "false") == "true" ? "false" : "true");
429+
toggleBox(contentBoxId, storageKey);
430+
})
501431
}
502-
});
503-
504-
$("input[name='include_all_projects']").bootstrapSwitch({
505-
'size':'mini',
506-
'offText': '<i class="fa fa-times" aria-hidden="true"></i>',
507-
'onText': '<i class="fa fa-check" aria-hidden="true"></i>',
508-
});
509-
510-
$('input[name="include_all_projects"]').on('switchChange.bootstrapSwitch', function(event, includeProjects) {
511-
if (!includeProjects) {
512-
window.location = "{{ request.get_full_path|set_page_to_one|set_index_model:'models:isisdata.citation'|add_excluded_stub_record_status_facet:'SR'|add_facet_or_operator|add_tenant:tenant_id|safe}}"
513-
} else {
514-
window.location = "{{ request.get_full_path|set_page_to_one|set_index_model:'models:isisdata.citation'|add_excluded_stub_record_status_facet:'SR'|add_facet_or_operator|remove_tenant|safe }}"
432+
433+
function toggleBox(contentBoxId, storageKey) {
434+
const isBoxOpen = localStorage.getItem(storageKey) || "false";
435+
if (isBoxOpen == "true") {
436+
document.getElementById(contentBoxId).classList.remove('collapse');
437+
document.getElementById(contentBoxId).classList.add('show');
438+
} else {
439+
document.getElementById(contentBoxId).classList.remove('show');
440+
document.getElementById(contentBoxId).classList.add('collapse');
441+
}
515442
}
516-
});
443+
444+
document.addEventListener('DOMContentLoaded', (event) => {
445+
446+
addToggleEventListener("collapseFiltersHeading", 'collapseFilters', "isSortOpen");
447+
addToggleEventListener("publicationTypeHeading", 'collapseCitationTypes', "isPublicationTypeOpen");
448+
addToggleEventListener("languageFilterHeading", 'collapseLanguages', "isLanguagesOpen");
449+
// authorities are in search_results_authorities.html
450+
addToggleEventListener("authoritiesHeading", 'collapseAuthorityResults', "isAuthoritiesOpen");
451+
452+
// set initial box states
453+
toggleBox('collapseFilters', "isSortOpen");
454+
toggleBox('collapseCitationTypes', "isPublicationTypeOpen");
455+
toggleBox('collapseLanguages', "isLanguagesOpen");
456+
toggleBox('collapseAuthorityResults', "isAuthoritiesOpen");
457+
});
517458
</script>

0 commit comments

Comments
 (0)