Add pager block to the footer

This commit is contained in:
Tim Van Baak 2023-06-02 15:31:30 -07:00
parent dd114ab0ae
commit 11d4a7db41
2 changed files with 35 additions and 11 deletions

View File

@ -62,25 +62,38 @@ def source_feed(source_name):
abort(404) abort(404)
# Get all items # Get all items
all_items = source.get_all_items() all_items = sorted(source.get_all_items(), key=item_sort_key)
sorted_items = sorted(all_items, key=item_sort_key)
if count_arg := request.args.get("count"): # Apply paging parameters
page_arg = request.args.get("page", "0") count = int(request.args.get("count", "100"))
if count_arg.isdigit() and page_arg.isdigit(): page = int(request.args.get("page", "0"))
count = int(count_arg) paged_items = all_items[count * page : count * page + count]
page = int(page_arg) pager_prev = (
sorted_items = sorted_items[count * page : count * page + count] None
if page <= 0
else url_for(
request.endpoint, source_name=source_name, count=count, page=page - 1
)
)
pager_next = (
None
if (count * page + count) > len(all_items)
else url_for(
request.endpoint, source_name=source_name, count=count, page=page + 1
)
)
return render_template( return render_template(
"feed.jinja2", "feed.jinja2",
items=sorted_items, items=paged_items,
now=int(time.time()), now=int(time.time()),
mdeac=[ mdeac=[
{"source": item["source"], "itemid": item["id"]} {"source": item["source"], "itemid": item["id"]}
for item in sorted_items for item in paged_items
if "id" in item if "id" in item
], ],
pager_prev=pager_prev,
pager_next=pager_next,
) )

View File

@ -1,7 +1,7 @@
<html> <html>
<head> <head>
<meta name="viewport" content="width=device-width, initial-scale=1"> <meta name="viewport" content="width=device-width, initial-scale=1">
<title>Intake{% if items %} ({{ items|length - 1 }}){% endif %}</title> <title>Intake{% if items %} ({{ items|length }}){% endif %}</title>
<link rel="icon" type="image/png" href="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAABGdBTUEAALGPC/xhBQAAAAlwSFlzAAAOwgAADsIBFShKgAAAABh0RVh0U29mdHdhcmUAcGFpbnQubmV0IDQuMS41ZEdYUgAAAGFJREFUOE+lkFEKwDAIxXrzXXB3ckMm9EnAV/YRCxFCcUXEL3Jc77NDjpDA/VGL3RFWYEICfeGC8oQc9IPuCAnQDcoRVmBCAn3hgvKEHPSD7ggJ0A3KEVZgQgJ94YLSJ9YDUzNGDXGZ/JEAAAAASUVORK5CYII="> <link rel="icon" type="image/png" href="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAABGdBTUEAALGPC/xhBQAAAAlwSFlzAAAOwgAADsIBFShKgAAAABh0RVh0U29mdHdhcmUAcGFpbnQubmV0IDQuMS41ZEdYUgAAAGFJREFUOE+lkFEKwDAIxXrzXXB3ckMm9EnAV/YRCxFCcUXEL3Jc77NDjpDA/VGL3RFWYEICfeGC8oQc9IPuCAnQDcoRVmBCAn3hgvKEHPSD7ggJ0A3KEVZgQgJ94YLSJ9YDUzNGDXGZ/JEAAAAASUVORK5CYII=">
<style> <style>
div#wrapper { div#wrapper {
@ -57,6 +57,9 @@ pre {
table.feed-control td { table.feed-control td {
font-family: monospace; padding: 5px 10px; font-family: monospace; padding: 5px 10px;
} }
div#pager {
text-align: center;
}
</style> </style>
<script> <script>
var deactivate = function (source, itemid) { var deactivate = function (source, itemid) {
@ -164,6 +167,14 @@ var doAction = function (source, itemid, action) {
</div> </div>
{% endfor %} {% endfor %}
{% if pager_prev or pager_next %}
<div class="readable-item" id="pager">
<span class="item-title">
<a {% if pager_prev -%} href="{{pager_prev}}" {%- endif %}>Prev</a> | <a {% if pager_next -%} href="{{pager_next}}" {%- endif %}>Next</a>
</span>
</div>
{% endif %}
{% if items %} {% if items %}
<div class="readable-item"> <div class="readable-item">
<details> <details>