Skip to content

Commit

Permalink
Use server-side paging in aips page. (#209)
Browse files Browse the repository at this point in the history
To avoid slow page responses when there are a large amount of AIPs use
server-side paging to limit the number of AIP HTML sent to the browser.
  • Loading branch information
mcantelon committed Sep 28, 2023
1 parent 40b01a3 commit 33b0b6c
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 4 deletions.
25 changes: 24 additions & 1 deletion AIPscan/Reporter/templates/aips.html
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@

{% if aips %}

<table id="aiptable" class="table table-striped table-bordered">
<table id="aipstable" class="table table-striped table-bordered">
<thead>
<tr>
<th><strong>Transfer name</strong></th>
Expand Down Expand Up @@ -85,6 +85,29 @@

{% endif %}

{% if pagination.total %}

<div class="dataTables_wrapper">
<div class="row">
<div class="col-sm-12 col-md-5">
<div class="dataTables_info" id="aiptable_info" role="status" aria-live="polite">Showing {{ first_item }} to {{ last_item }} of {{ pagination.total }} entries</div>
</div>
<div class="col-sm-12 col-md-7">
<div class="dataTables_paginate paging_full_numbers" id="aiptable_paginate">
<ul class="pagination">
<li class="paginate_button page-item first"><a href="{{ url_for('reporter.view_aips') }}?page=1" class="page-link">First</a></li>
<li class="paginate_button page-item previous"><a href="{{ url_for('reporter.view_aips') }}?page={{ pagination.prev_num }}" class="page-link">Previous</a></li>
<li class="paginate_button page-item active"><a href="#" class="page-link">{{ pagination.page }}</a></li>
<li class="paginate_button page-item next"><a href="{{ url_for('reporter.view_aips') }}?page={{ pagination.next_num }}" class="page-link">Next</a></li>
<li class="paginate_button page-item last"><a href="{{ url_for('reporter.view_aips') }}?page={{ pagination.pages }}" class="page-link">Last</a></li>
</ul>
</div>
</div>
</div>
</div>

{% endif %}

<script>
$(document).ready(function(){
var storageServiceId = $('#ss').val();
Expand Down
16 changes: 13 additions & 3 deletions AIPscan/Reporter/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,17 @@ def view_aips():
except Exception as e:
print(e)

aips = AIP.query.filter_by(storage_service_id=storage_service.id)
page = int(request.args.get("page", default="1"))
pagination = AIP.query.paginate(page=page, per_page=5, error_out=False)

if storage_location:
aips = aips.filter_by(storage_location_id=storage_location_id)
aips = aips.all()
pagination = AIP.query.filter_by(storage_location_id=storage_location_id).paginate(page=page, per_page=5, error_out=False)
aips = pagination.items

first_item = ((pagination.page - 1) * pagination.per_page) + 1
last_item = pagination.page * pagination.per_page
if last_item > pagination.total:
last_item = pagination.total

return render_template(
"aips.html",
Expand All @@ -99,6 +106,9 @@ def view_aips():
),
storage_location=storage_location,
aips=aips,
pagination=pagination,
first_item=first_item,
last_item=last_item,
)


Expand Down

0 comments on commit 33b0b6c

Please sign in to comment.