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)
# Get all items
all_items = source.get_all_items()
sorted_items = sorted(all_items, key=item_sort_key)
all_items = sorted(source.get_all_items(), key=item_sort_key)
if count_arg := request.args.get("count"):
page_arg = request.args.get("page", "0")
if count_arg.isdigit() and page_arg.isdigit():
count = int(count_arg)
page = int(page_arg)
sorted_items = sorted_items[count * page : count * page + count]
# Apply paging parameters
count = int(request.args.get("count", "100"))
page = int(request.args.get("page", "0"))
paged_items = all_items[count * page : count * page + count]
pager_prev = (
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(
"feed.jinja2",
items=sorted_items,
items=paged_items,
now=int(time.time()),
mdeac=[
{"source": item["source"], "itemid": item["id"]}
for item in sorted_items
for item in paged_items
if "id" in item
],
pager_prev=pager_prev,
pager_next=pager_next,
)

View File

@ -1,7 +1,7 @@
<html>
<head>
<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=">
<style>
div#wrapper {
@ -57,6 +57,9 @@ pre {
table.feed-control td {
font-family: monospace; padding: 5px 10px;
}
div#pager {
text-align: center;
}
</style>
<script>
var deactivate = function (source, itemid) {
@ -164,6 +167,14 @@ var doAction = function (source, itemid, action) {
</div>
{% 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 %}
<div class="readable-item">
<details>