From fb5e99cdc29bdfe9e6e271929f6edbef832b0b30 Mon Sep 17 00:00:00 2001 From: Tim Van Baak Date: Tue, 2 Jun 2020 19:47:28 -0700 Subject: [PATCH] Add mass-deactivate functionality --- inquisitor/app.py | 23 ++++++++++++++++++++++- inquisitor/templates/feed.html | 27 ++++++++++++++++++++++++--- 2 files changed, 46 insertions(+), 4 deletions(-) diff --git a/inquisitor/app.py b/inquisitor/app.py index f78136c..bdc778b 100644 --- a/inquisitor/app.py +++ b/inquisitor/app.py @@ -92,8 +92,14 @@ def root(): } active_items.insert(0, feed_control) - return render_template("feed.html", items=active_items[:100]) + selection = active_items[:100] + return render_template("feed.html", + items=selection, + mdeac=[ + {'source': item['source'], 'itemid': item['id']} + for item in selection + if 'id' in item]) @app.route("/deactivate/", methods=['POST']) def deactivate(): @@ -119,3 +125,18 @@ def punt(): til_then = morning.timestamp() - item['created'] item['tts'] = til_then return jsonify(item.item) + +@app.route("/mass-deactivate/", methods=['POST']) +def mass_deactivate(): + params = request.get_json() + if 'items' not in params: + logger.error("Bad request params: {}".format(params)) + for info in params.get('items', []): + source = info['source'] + itemid = info['itemid'] + item = loader.WritethroughDict(os.path.join( + DUNGEON_PATH, source, itemid + ".item")) + if item['active']: + logger.debug(f"Deactivating {info['source']}/{info['itemid']}") + item['active'] = False + return jsonify({}) diff --git a/inquisitor/templates/feed.html b/inquisitor/templates/feed.html index 8b020c9..9a845ed 100644 --- a/inquisitor/templates/feed.html +++ b/inquisitor/templates/feed.html @@ -10,7 +10,7 @@ word-break: break-word; } .item-title { font-size: 1.4em; } - .readable-item button { + .item-button { font-size: 1em; float:right; margin-left: 2px; @@ -65,6 +65,19 @@ } }); }; + var mdeactivate = function (items) { + fetch('mass-deactivate/', { + method: 'POST', + headers: { + 'Content-Type': 'application/json; charset=UTF-8', + }, + body: JSON.stringify({items: items}), + }) + .then(response => response.json()) + .then(function () { + location.reload() + }); + }; @@ -72,8 +85,8 @@ {% if items %} {% for item in items %}
- {% if item.id %}{% endif %} - {% if item.id %}{% endif %} + {% if item.id %}{% endif %} + {% if item.id %}{% endif %} {% if item.link %}{% endif %} {% if item.body %}
{{item.title}} @@ -95,6 +108,14 @@ {% endif %}
{% endfor %} +
+
+ Feed Management +
+ +
+
+
{% else %}
Feed is empty