Improve feed control item

This commit is contained in:
Tim Van Baak 2019-12-17 09:29:24 -08:00
parent 2ef3ba9d6a
commit d98fb246c0
3 changed files with 40 additions and 33 deletions

View File

@ -42,10 +42,13 @@ def root():
total = 0 total = 0
items, errors = loader.load_active_items() items, errors = loader.load_active_items()
active_items = [] active_items = []
active_tags = set() active_tags = {}
for item in items: for item in items:
if item['active']: if item['active']:
active_tags |= set(item['tags']) for tag in item['tags']:
if tag not in active_tags: active_tags[tag] = 0
active_tags[tag] += 1
# active_tags |= set(item['tags'])
total += 1 total += 1
if not any(map(lambda f: f(item), filters)): if not any(map(lambda f: f(item), filters)):
active_items.append(item) active_items.append(item)
@ -63,16 +66,28 @@ def root():
if total > 0: if total > 0:
# Create the feed control item # Create the feed control item
wl_minus = [make_query_link("only - {}".format(tag), [t for t in wl if t != tag], bl) for tag in wl] link_table = []
wl_plus = [make_query_link("only + {}".format(tag), wl + [tag], bl) for tag in active_tags if tag not in wl] for tag, count in sorted(active_tags.items()):
bl_minus = [make_query_link("not - {}".format(tag), wl, [t for t in bl if t != tag]) for tag in bl] links = [count]
bl_plus = [make_query_link("not + {}".format(tag), wl, bl + [tag]) for tag in active_tags if tag not in bl] links.append(make_query_link(tag, [tag], []))
body = "<pre>{}</pre>".format("\n".join(wl_minus + wl_plus + bl_minus + bl_plus)) if tag in wl:
new_wl = [t for t in wl if t != tag]
links.append(make_query_link("-only", new_wl, bl))
else:
new_bl = [t for t in bl if t != tag]
links.append(make_query_link("+only", wl + [tag], new_bl))
if tag in bl:
new_bl = [t for t in bl if t != tag]
links.append(make_query_link("-not", wl, new_bl))
else:
new_wl = [t for t in wl if t != tag]
links.append(make_query_link("+not", new_wl, bl + [tag]))
link_table.append("<tr><td>{0}</td><td>{1}</td><td>{2}</td><td>{3}</td></tr>".format(*links))
body = '<table class="feed-control">{}</table>'.format("\n".join(link_table))
feed_control = { feed_control = {
'title': 'Feed Control [{}]'.format(total), 'title': 'Feed Control [{}/{}]'.format(len(active_items), total),
'body': body, 'body': body,
'created': None,
} }
active_items.insert(0, feed_control) active_items.insert(0, feed_control)

View File

@ -44,3 +44,7 @@ summary:focus {
pre { pre {
white-space: pre-wrap; white-space: pre-wrap;
} }
table.feed-control td /*:nth-child(2), td:nth-child(3), td:nth-child(4)*/ {
font-family: monospace;
padding: 5px 10px;
}

View File

@ -26,37 +26,25 @@
{% if items %} {% if items %}
{% for item in items %} {% for item in items %}
<div class="readable-item" id="{{item.source}}-{{item.id}}"> <div class="readable-item" id="{{item.source}}-{{item.id}}">
{% if item.id %} {% if item.id %}<button onclick="javascript:deactivate('{{item.source}}', '{{item.id}}')">&#10005;</button>{% endif %}
<button onclick="javascript:deactivate('{{item.source}}', '{{item.id}}')">&#10005;</button> {% if item.link %}<a class="item-link" href="{{item.link}}" target="_blank">&#8663;</a>{% endif %}
{% endif %} {% if item.body %}<details>
{% if item.link %}
<a class="item-link" href="{{item.link}}" target="_blank">&#8663;</a>
{% endif %}
{% if item.body %}
<details>
<summary><span class="item-title">{{item.title}}</span></summary> <summary><span class="item-title">{{item.title}}</span></summary>
<p>{{item.body|safe}}</p> <p>{{item.body|safe}}</p>
</details> </details>
{% else %} {% else %}<span class="item-title">{{item.title}}</span><br>
<span class="item-title">{{item.title}}</span><br>
{% endif %} {% endif %}
{% if item.author or item.time %} {% if item.author or item.time %}<span class="item-info">
<span class="item-info"> {% if item.author %}{{item.author}}{% endif %}
{% if item.author %} {% if item.time %}{{item.time|datetimeformat}}{% endif %}
{{item.author}}
{% endif %}
{% if item.time %}
{{item.time|datetimeformat}}
{% endif %}
</span><br> </span><br>
{% endif %} {% endif %}
<span class="item-info" title="{{ 'Tags: {}'.format(', '.join(item.tags)) }}"> {% if item.source or item.id or item.created %}<span class="item-info" title="{{ 'Tags: {}'.format(', '.join(item.tags)) }}">
{{item.source}} {% if item.source %}{{item.source}}{% endif %}
{% if item.id %} {% if item.id %}{{item.id}}{% endif %}
{{item.id}} {% if item.created %}{{item.created|datetimeformat}}{% endif %}
{% endif %}
{{item.created|datetimeformat}}
</span> </span>
{% endif %}
</div> </div>
{% endfor %} {% endfor %}
{% else %} {% else %}