Add links to show/hide hidden items

This commit is contained in:
Tim Van Baak 2023-06-19 15:15:03 -07:00
parent dddb46a627
commit 547699a9fc
2 changed files with 48 additions and 16 deletions

View File

@ -29,6 +29,19 @@ def item_sort_key(item: Item):
return item.sort_key
def get_show_hidden(default: bool):
"""
Get the value of the ?hidden query parameter, with a default value if it is
absent or set to an unnown value.
"""
hidden = request.args.get("hidden")
if hidden == "true":
return True
if hidden == "false":
return False
return default
@app.template_filter("datetimeformat")
def datetimeformat(value):
if not value:
@ -37,6 +50,20 @@ def datetimeformat(value):
return dt.strftime("%Y-%m-%d %H:%M:%S")
@app.template_global()
def set_query(**kwargs):
"""
Helper function to create a URL plus or minus some query parameters.
"""
args = request.args.copy()
for key, val in kwargs.items():
if val is None and key in args:
del args[key]
else:
args[key] = val
return url_for(request.endpoint, **request.view_args, **args)
def auth_check(route):
"""
Checks the HTTP Basic Auth header against the stored credential.
@ -95,7 +122,7 @@ def source_feed(name):
if not source.source_path.exists():
abort(404)
return _sources_feed(name, [source], show_hidden=request.args.get("hidden", True))
return _sources_feed(name, [source], show_hidden=get_show_hidden(True))
@app.get("/channel/<string:name>")
@ -112,7 +139,7 @@ def channel_feed(name):
abort(404)
sources = [LocalSource(intake_data_dir(), name) for name in channels[name]]
return _sources_feed(name, sources, show_hidden=request.args.get("hidden", False))
return _sources_feed(name, sources, show_hidden=get_show_hidden(False))
def _sources_feed(name: str, sources: List[LocalSource], show_hidden: bool):
@ -154,8 +181,9 @@ def _sources_feed(name: str, sources: List[LocalSource], show_hidden: bool):
for item in paged_items
if "id" in item
],
pager_prev=pager_prev,
pager_next=pager_next,
page_num=page,
page_count=count,
item_count=len(all_items),
)
@ -340,11 +368,7 @@ def add_item():
if form_body := request.form.get("body"):
fields["body"] = form_body
if form_tags := request.form.get("tags"):
fields["tags"] = [
tag.strip()
for tag in form_tags.split()
if tag.strip()
]
fields["tags"] = [tag.strip() for tag in form_tags.split() if tag.strip()]
if form_tts := request.form.get("tts"):
fields["tts"] = _get_ttx_for_date(datetime.fromisoformat(form_tts))
if form_ttl := request.form.get("ttl"):

View File

@ -57,7 +57,7 @@ pre {
table.feed-control td {
font-family: monospace; padding: 5px 10px;
}
div.center {
article.center {
text-align: center;
}
</style>
@ -122,7 +122,15 @@ var doAction = function (source, itemid, action) {
<body>
<main>
<article class="center">
<span class="item-title"><a href="{{url_for('root')}}">Home</a></span>
<span class="item-title">
<a href="{{url_for('root')}}">Home</a>
[<a href="{{ set_query(hidden='false', page=None, count=None) }}">Active</a> | <a href="{{ set_query(hidden='true', page=None, count=None) }}">All</a>]
{% if item_count > items|length -%}
[<a {% if page_num is greaterthan(0) -%} href="{{ set_query(page=page_num - 1) }}" {%- endif %}>Prev</a>
|
<a {% if ((page_num + 1) * page_count) is lessthan(item_count) -%} href="{{ set_query(page=page_num + 1) }}" {%- endif %}>Next</a>]
{%- endif %}
</span>
</article>
{% if items %}
{% for item in items %}
@ -176,18 +184,18 @@ var doAction = function (source, itemid, action) {
</article>
{% endfor %}
{% if pager_prev or pager_next %}
{% if item_count > items|length %}
<article class="center">
<span class="item-title">
<a {% if pager_prev -%} href="{{pager_prev}}" {%- endif %}>Prev</a> | <a {% if pager_next -%} href="{{pager_next}}" {%- endif %}>Next</a>
<a {% if page_num is greaterthan(0) -%} href="{{ set_query(page=page_num - 1) }}" {%- endif %}>Prev</a>
|
<a {% if ((page_num + 1) * page_count) is lessthan(item_count) -%} href="{{ set_query(page=page_num + 1) }}" {%- endif %}>Next</a>
</span>
</article>
{% endif %}
<article>
<div style="text-align:center;">
<article class="center">
<button onclick="javascript:mdeactivate({{ mdeac|safe }})">Deactivate All</button>
</div>
</article>
{# if items #}