From 2d59e4cd4a132f355ac9f2ce3e4db52708eda529 Mon Sep 17 00:00:00 2001 From: dgtlmoon Date: Sat, 29 Apr 2023 17:24:14 +0200 Subject: [PATCH] Make sort order and sort attribute cookie sticky --- changedetectionio/__init__.py | 15 +++++++++++++-- changedetectionio/templates/watch-overview.html | 10 +++++----- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/changedetectionio/__init__.py b/changedetectionio/__init__.py index 61e8ca3e7..d3388972f 100644 --- a/changedetectionio/__init__.py +++ b/changedetectionio/__init__.py @@ -430,15 +430,26 @@ def changedetection_app(config=None, datastore_o=None): has_unviewed=datastore.has_unviewed, hosted_sticky=os.getenv("SALTED_PASS", False) == False, queued_uuids=[q_uuid.item['uuid'] for q_uuid in update_q.queue], + sort_attribute=request.args.get('sort') if request.args.get('sort') else request.cookies.get('sort'), + sort_order=request.args.get('order') if request.args.get('order') else request.cookies.get('order'), system_default_fetcher=datastore.data['settings']['application'].get('fetch_backend'), tags=existing_tags, watches=sorted_watches ) - if session.get('share-link'): del(session['share-link']) - return output + + resp = make_response(output) + + # The template can run on cookie or url query info + if request.args.get('sort'): + resp.set_cookie('sort', request.args.get('sort')) + if request.args.get('order'): + resp.set_cookie('order', request.args.get('order')) + + return resp + # AJAX endpoint for sending a test diff --git a/changedetectionio/templates/watch-overview.html b/changedetectionio/templates/watch-overview.html index f54f69081..9aa5e5e7c 100644 --- a/changedetectionio/templates/watch-overview.html +++ b/changedetectionio/templates/watch-overview.html @@ -49,17 +49,17 @@ {% endfor %} - {% set sort_order = request.args.get('order', 'asc') == 'asc' %} - {% set sort_attribute = request.args.get('sort', 'date_created') %} + {% set sort_order = sort_order or 'asc' %} + {% set sort_attribute = sort_attribute or 'last_changed' %} {% set pagination_page = request.args.get('page', 0) %}
- {% set link_order = "desc" if sort_order else "asc" %} + {% set link_order = "desc" if sort_order == 'asc' else "asc" %} {% set arrow_span = "" %} - + @@ -69,7 +69,7 @@ - {% for watch in watches|sort(attribute=sort_attribute, reverse=sort_order) %} + {% for watch in watches|sort(attribute=sort_attribute, reverse=sort_order == 'asc') %} {# WIP for pagination, disabled for now {% if not ( loop.index >= 3 and loop.index <=4) %}{% continue %}{% endif %} -->
# # Website Last Checked