Skip to content

Commit

Permalink
Somewhat finalized version of browse all page. Removed the loop, crea…
Browse files Browse the repository at this point in the history
…ted no results page, and updated appearance of text.
  • Loading branch information
hamim23z committed Oct 28, 2024
1 parent c5a4dcf commit 877ace2
Show file tree
Hide file tree
Showing 5 changed files with 185 additions and 60 deletions.
52 changes: 37 additions & 15 deletions vro/public/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
url_for,
session
)
from flask_paginate import Pagination, get_page_parameter
from flask_paginate import Pagination
from sqlalchemy.exc import DataError
from sqlalchemy.orm.exc import NoResultFound

Expand Down Expand Up @@ -85,22 +85,28 @@ def browse_all():
size = 50
q_list = []

# "Search by Year" for Search by Year Function/Parameter
year_value = request.args.get("year", "")
year_range_value = request.args.get("year_range", "")

if year_value:
q_list.append(Q("range", year={"gte": int(year_value), "lte": int(year_value)}))
year_range_value = f"{year_value} - {year_value}"
elif year_range_value and " to " in year_range_value: # Only process range if it contains "to"
year_range = [int(year.strip()) for year in year_range_value.split("to") if year.strip().isdigit()]
if len(year_range) == 2:
q_list.append(Q("range", year={"gte": year_range[0], "lte": year_range[1]}))

for key, value in [
("cert_type", request.args.get("certificate_type", "")),
("number", request.args.get("number", "").lstrip("0")),
("county", request.args.get("county", "")),
("year", request.args.get("year", "")),
("year_range", request.args.get("year_range", "")),
("first_name", request.args.get("first_name", "")),
("last_name", request.args.get("last_name", ""))
]:
if value:
if key == "year_range":
year_range = [int(year) for year in value.split() if year.isdigit()]
q_list.append(Q("range", year={"gte": year_range[0], "lte": year_range[1]}))
elif key in ["first_name", "last_name"]:
if key in ["first_name", "last_name"]:
q_list.append(Q("multi_match", query=value.capitalize(), fields=[key, "spouse_"+key]))
# Marriage certificates and marriage licenses are considered the same record type to the user
elif key == "cert_type" and value == "marriage":
q_list.append(Q("terms", cert_type=[certificate_types.MARRIAGE, certificate_types.MARRIAGE_LICENSE]))
else:
Expand Down Expand Up @@ -138,15 +144,18 @@ def browse_all():
# Calculate total pages
# total_pages = min((count + size - 1) // size, 200) - This was a previous version of what I had, newer is below#
total_pages = (count + size - 1) // size

# Flag for no results when going past a certain page
no_results = False

# This is the condition to get rid of the page loop
if page > total_pages and total_pages > 0:
query_params = request.args.to_dict()
query_params['page'] = total_pages
return redirect(url_for('public.browse_all', **query_params))
no_results = True

# Handle the case when the page is less than 1
elif page < 1:
query_params = request.args.to_dict()
query_params['page'] = 1
query_params['page'] = 1
return redirect(url_for('public.browse_all', **query_params))

# Flask Pagination Stuff
Expand Down Expand Up @@ -188,6 +197,10 @@ def browse_all():
value = "First Name: {}".format(value)
elif key == "last_name":
value = "Last Name: {}".format(value)
"""
elif key == "year":
value = f"Year: {value}"
"""

# Handle new URL
current_args.pop(key)
Expand All @@ -204,8 +217,8 @@ def browse_all():
form=form,
year_range_min=cached_year_range.year_min,
year_range_max=cached_year_range.year_max,
year_min_value=year_range[0] if request.args.get("year_range", "") else cached_year_range.year_min,
year_max_value=year_range[1] if request.args.get("year_range", "") else cached_year_range.year_max,
year_min_value=int(year_value) if year_value else (year_range[0] if year_range_value and " to " in year_range_value else cached_year_range.year_min),
year_max_value=int(year_value) if year_value else (year_range[1] if year_range_value and " to " in year_range_value else cached_year_range.year_max),
certificates=res,
page=page,
has_prev=has_prev,
Expand All @@ -215,6 +228,7 @@ def browse_all():
total_documents=format(count, ",d"),
remove_filters=remove_filters,
pagination=pagination,
no_results=no_results,
certificate_types=certificate_types)


Expand Down Expand Up @@ -303,4 +317,12 @@ def faq():
"""
FAQ page
"""
return render_template("public/faq.html")
return render_template("public/faq.html")


"""
@blueprint.route('/browse-ledgers')
def browse_ledgers():
Displaying Ledgers Page
return render_template('public/browse_ledgers.html')
"""
2 changes: 1 addition & 1 deletion vro/search/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def create_docs():
FROM certificates
LEFT OUTER JOIN marriage_data AS marriage_data_1 ON certificates.id = marriage_data_1.certificate_id
WHERE certificates.filename IS NOT NULL
GROUP BY certificates.id limit 500000;
GROUP BY certificates.id;
""")

count = 0
Expand Down
9 changes: 9 additions & 0 deletions vro/static/css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,15 @@ ul a {
outline: 0;
border-width: 0 0 2px;
border-color: #a9a9a9;
font-weight: bold;
font-size: 20px;
color: #111111;
}

#skip-to-page {
background-color: #ffffff;
font-weight: bold;
color: #111111;
}

#homepage-year-range {
Expand Down
1 change: 1 addition & 0 deletions vro/static/css/theme.css
Original file line number Diff line number Diff line change
Expand Up @@ -2135,6 +2135,7 @@ textarea.form-control {

.form-group {
margin-bottom: 3rem;
font-weight: bold;
}

.form-text {
Expand Down
181 changes: 137 additions & 44 deletions vro/templates/public/browse_all.html
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,21 @@ <h2>{{ total_documents }} Vital Record Results</h2>
<button class="btn btn-info">Update</button>
</div>
</div>

{# Commented Out - Search by Year Parameter
<div style="display: flex; flex-direction: column; justify-content: center; align-items: center;">
<br>
<br>
<span style="display: flex; align-items: center;">
<p style="margin: 0; margin-right: 10px;" id="skip-to-page">Search by Year:</p>
<input id="yearInput" type="number" style="height: 40px; width: 80px; margin-right: 10px; padding: 5px;" min="1855" max="1949">
<button id="selectYearButton" class="btn btn-info" style="height: 40px;">
Go
</button>
</span>
</div>
#}

</div>
</form>
{% if remove_filters %}
Expand Down Expand Up @@ -83,29 +98,47 @@ <h2>{{ total_documents }} Vital Record Results</h2>
<hr />
</div>
</div>
{% if num_results != "0" %}
{% if no_results %}
<div class="container">
<div class="row px-2 py-4">
<p class="large">
There are no results for your search. Read our
<a href="{{ url_for('public.search') }}">Search Tips</a> or see
<a href="{{ url_for('public.digital_vital_records') }}">
Digital Vital Records</a>
for what you can find on this site.
</p>
<p class="large">
Please note that the "No Results" message is generated when there is
not a digitized image associated with the search. Future versions of
this application will return the certificate number (if found) along
with instructions on how to view/order a copy of the certificate
pending digitization.
</p>
</div>
</div>
{% elif num_results != "0" %}
<div id="results">{% include "public/_browse_all_results.html" %}</div>
{% else %}
{% else %}
<div class="container">
<div class="row px-2 py-4">
<p class="large">
There are no results for your search. Read our
<a href="{{ url_for('public.search') }}">Search Tips</a> or see
<a href="{{ url_for('public.digital_vital_records') }}"
>Digital Vital Records</a
>
for what you can find on this site.
</p>
<p class="large">
Please note that the "No Results" message is generated when there is
not a digitized image associated with the search. Future versions of
this application will return the certificate number (if found) along
with instructions on how to view/order a copy of the certificate
pending digitization.
</p>
</div>
<div class="row px-2 py-4">
<p class="large">
There are no results for your search. Read our
<a href="{{ url_for('public.search') }}">Search Tips</a> or see
<a href="{{ url_for('public.digital_vital_records') }}">
Digital Vital Records</a>
for what you can find on this site.
</p>
<p class="large">
Please note that the "No Results" message is generated when there is
not a digitized image associated with the search. Future versions of
this application will return the certificate number (if found) along
with instructions on how to view/order a copy of the certificate
pending digitization.
</p>
</div>
</div>
{% endif %}
{% endif %}
</div>

{% if num_results != "0" %}
Expand All @@ -117,15 +150,15 @@ <h2>{{ total_documents }} Vital Record Results</h2>
<h6 class="center pt-2">{{ pagination.info.replace('displaying', 'Displaying') }}</h6>
<br>
<span style="display: flex; align-items: center;">
<p style="margin: 0; margin-right: 10px;">Skip to Page:</p>
<p style="margin: 0; margin-right: 10px;" id="skip-to-page">Skip to Page:</p>
<input id="pageInput" type="number" style="height: 40px; width: 80px; margin-right: 10px; padding: 5px;">
<button id="selectPageButton" class="btn btn-info" style="height: 40px;">
Go
</button>
</span>
</div>

{#This is the script for the "Skip to Page" and "Go Button"#}
{#This is the script for the "Skip to Page" and "Go" Button#}
<script>
document.getElementById('selectPageButton').addEventListener('click', function() {
var pageNumber = document.getElementById('pageInput').value;
Expand Down Expand Up @@ -153,30 +186,90 @@ <h6 class="center pt-2">{{ pagination.info.replace('displaying', 'Displaying') }
});
</script>

{% endif %}
{#This is the script for the "Search by Year" and "Go" Button
<script>
document.getElementById('selectYearButton').addEventListener('click', function (event) {
event.preventDefault();
var yearNumber = document.getElementById('yearInput').value.trim();

<!-- .container -->
</section>
{% endblock %} {% block js %}
<script src="{{ static_url_for('static', filename='js/public/pagination.js') }}"></script>
<script>
"use strict";

$(function () {
$("#browse-page-slider-range").slider({
range: true,
min: parseInt("{{ year_range_min }}"),
max: parseInt("{{ year_range_max }}"),
values: ["{{ year_min_value }}", "{{ year_max_value }}"],
slide: function (event, ui) {
$("#year-range").val(ui.values[0] + " to " + ui.values[1]);
},
if (yearNumber >= 1855 && yearNumber <= 1949) {
var url = "{{ url_for('public.browse_all') }}?year=" + encodeURIComponent(yearNumber);
url += "&page=1";
var formElements = document.querySelectorAll('#browse-all-form input:not([name="year_range"]), #browse-all-form select:not([name="year_range"])');

formElements.forEach(function (element) {
if (element.name &&
element.value &&
element.name !== 'year' &&
element.name !== 'page' &&
element.name !== 'year_range') {
url += "&" + encodeURIComponent(element.name) + "=" + encodeURIComponent(element.value);
}
});

window.location.href = url;
} else {
alert("Enter a year between 1855 and 1949.");
}
});
$("#year-range").val(
$("#browse-page-slider-range").slider("values", 0) +
document.getElementById('selectPageButton').addEventListener('click', function () {
var pageNumber = document.getElementById('pageInput').value;

if (pageNumber && pageNumber > 0) {
var url = "{{ url_for('public.browse_all', page='') }}" + pageNumber;

var formElements = document.querySelectorAll('#browse-all-form input, #browse-all-form select');
formElements.forEach(function (element) {
if (element.name && element.value) {
url += "&" + encodeURIComponent(element.name) + "=" + encodeURIComponent(element.value);
}
});
window.location.href = url;
}
});
</script>
#}
{% endif %}

<!-- .container -->
</section>
{% endblock %} {% block js %}
<script src="{{ static_url_for('static', filename='js/public/pagination.js') }}"></script>
<script>
"use strict";
$(function () {
$("#browse-page-slider-range").slider({
range: true,
min: parseInt("{{ year_range_min }}"),
max: parseInt("{{ year_range_max }}"),
values: ["{{ year_min_value }}", "{{ year_max_value }}"],
slide: function (event, ui) {
$("#year-range").val(ui.values[0] + " to " + ui.values[1]);
$("#yearInput").val("");
}
});

$("#year-range").val(
$("#browse-page-slider-range").slider("values", 0) +
" to " +
$("#browse-page-slider-range").slider("values", 1)
);
});
</script>
);

$("#browse-all-form").on("submit", function (event) {
event.preventDefault();
var url = "{{ url_for('public.browse_all') }}?page=1";

var sliderValues = $("#browse-page-slider-range").slider("values");
url += "&year_range=" + encodeURIComponent(sliderValues[0] + " to " + sliderValues[1]);

var formElements = document.querySelectorAll('#browse-all-form input:not([name="year"]):not([name="year_range"]), #browse-all-form select');
formElements.forEach(function (element) {
if (element.name && element.value && element.name !== 'page') {
url += "&" + encodeURIComponent(element.name) + "=" + encodeURIComponent(element.value);
}
});
window.location.href = url;
});
});
</script>
{% endblock %}

0 comments on commit 877ace2

Please sign in to comment.