forked from FrederikBaerentsen/BrickTracker
fix(parts): repair the empty result dead end, duplicate script load and page bounds
This commit is contained in:
@@ -28,6 +28,12 @@ def get_pagination_config(entity_type: str) -> Tuple[int, bool]:
|
||||
def build_pagination_context(page: int, per_page: int, total_count: int, is_mobile: bool) -> Dict[str, Any]:
|
||||
"""Build pagination context for templates"""
|
||||
total_pages = (total_count + per_page - 1) // per_page if total_count > 0 else 1
|
||||
|
||||
# ponytail: a page past the end still runs its query and comes back empty. This
|
||||
# only keeps the nav links sane so the user can walk back. Re-running the query
|
||||
# against the clamped page would mean counting before selecting.
|
||||
page = min(max(page, 1), total_pages)
|
||||
|
||||
has_prev = page > 1
|
||||
has_next = page < total_pages
|
||||
|
||||
@@ -47,6 +53,12 @@ def get_request_params() -> Tuple[str, str, str, int]:
|
||||
search_query = request.args.get('search', '').strip()
|
||||
sort_field = request.args.get('sort', '')
|
||||
sort_order = request.args.get('order', 'asc')
|
||||
page = int(request.args.get('page', 1))
|
||||
|
||||
# ?page=abc used to raise straight out of the view, and ?page=0 gave a negative
|
||||
# offset. Anything that is not a sensible page number is just page one.
|
||||
try:
|
||||
page = max(int(request.args.get('page', 1)), 1)
|
||||
except ValueError:
|
||||
page = 1
|
||||
|
||||
return search_query, sort_field, sort_order, page
|
||||
+3
-1
@@ -192,7 +192,9 @@
|
||||
<script src="{{ url_for('static', filename='scripts/parts.js') }}"></script>
|
||||
{% endif %}
|
||||
{% if request.endpoint == 'part.problem' %}
|
||||
<script src="{{ url_for('static', filename='scripts/parts.js') }}"></script>
|
||||
{# parts.js used to be loaded here too. It looks for a #parts table that does not
|
||||
exist on this page and retries every 100ms forever, and it double wired the
|
||||
Clear button. problems.js is all this page needs. #}
|
||||
<script src="{{ url_for('static', filename='scripts/problems.js') }}"></script>
|
||||
{% endif %}
|
||||
{% if request.endpoint == 'set.list' %}
|
||||
|
||||
+13
-12
@@ -5,7 +5,6 @@
|
||||
{% block title %} - All parts{% endblock %}
|
||||
|
||||
{% block main %}
|
||||
{% if table_collection | length %}
|
||||
<div class="container-fluid">
|
||||
<div class="row row-cols-lg-auto g-1 justify-content-center align-items-center pb-2">
|
||||
<div class="col-12 flex-grow-1">
|
||||
@@ -35,6 +34,10 @@
|
||||
{% include 'part/sort.html' %}
|
||||
{% include 'part/filter.html' %}
|
||||
|
||||
{# The guard starts here on purpose: filtering down to nothing must not
|
||||
take the filter bar away with the results. #}
|
||||
{% if table_collection | length %}
|
||||
|
||||
{% if use_pagination %}
|
||||
<!-- PAGINATION MODE -->
|
||||
<div class="table-responsive-sm">
|
||||
@@ -191,19 +194,17 @@
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
</div>
|
||||
{% else %}
|
||||
<div class="container-fluid">
|
||||
<div class="row justify-content-center">
|
||||
<div class="col-md-6">
|
||||
<div class="text-center">
|
||||
<i class="ri-shapes-line" style="font-size: 4rem; color: #6c757d;"></i>
|
||||
<h3 class="mt-3">No parts found</h3>
|
||||
<p class="text-muted">No parts are available for the selected owner.</p>
|
||||
</div>
|
||||
{% else %}
|
||||
<div class="row justify-content-center py-5">
|
||||
<div class="col-md-6">
|
||||
<div class="text-center">
|
||||
<i class="ri-shapes-line" style="font-size: 4rem; color: #6c757d;"></i>
|
||||
<h3 class="mt-3">No parts found</h3>
|
||||
<p class="text-muted">Nothing matches the current filters. Clear them to start over.</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
</div>
|
||||
|
||||
{% endblock %}
|
||||
+13
-12
@@ -5,7 +5,6 @@
|
||||
{% block title %} - Problematic parts{% endblock %}
|
||||
|
||||
{% block main %}
|
||||
{% if table_collection | length %}
|
||||
<div class="container-fluid">
|
||||
<div class="row row-cols-lg-auto g-1 justify-content-center align-items-center pb-2">
|
||||
<div class="col-12 flex-grow-1">
|
||||
@@ -30,6 +29,10 @@
|
||||
{% include 'problem/sort.html' %}
|
||||
{% include 'part/filter.html' %}
|
||||
|
||||
{# The guard starts here on purpose: filtering down to nothing must not
|
||||
take the filter bar away with the results. #}
|
||||
{% if table_collection | length %}
|
||||
|
||||
{% if use_pagination %}
|
||||
<!-- PAGINATION MODE -->
|
||||
<div class="table-responsive-sm">
|
||||
@@ -211,19 +214,17 @@
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
</div>
|
||||
{% else %}
|
||||
<div class="container-fluid">
|
||||
<div class="row justify-content-center">
|
||||
<div class="col-md-6">
|
||||
<div class="text-center">
|
||||
<i class="ri-error-warning-line" style="font-size: 4rem; color: #6c757d;"></i>
|
||||
<h3 class="mt-3">No problematic parts found</h3>
|
||||
<p class="text-muted">Great! All your parts are in perfect condition.</p>
|
||||
</div>
|
||||
{% else %}
|
||||
<div class="row justify-content-center py-5">
|
||||
<div class="col-md-6">
|
||||
<div class="text-center">
|
||||
<i class="ri-error-warning-line" style="font-size: 4rem; color: #6c757d;"></i>
|
||||
<h3 class="mt-3">No problematic parts found</h3>
|
||||
<p class="text-muted">Nothing matches the current filters. Clear them, or enjoy having no missing pieces.</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
</div>
|
||||
|
||||
{% endblock %}
|
||||
|
||||
Reference in New Issue
Block a user