Add mass-deactivate functionality
This commit is contained in:
parent
065a0f3480
commit
fb5e99cdc2
|
@ -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({})
|
||||
|
|
|
@ -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()
|
||||
});
|
||||
};
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
|
@ -72,8 +85,8 @@
|
|||
{% if items %}
|
||||
{% for item in items %}
|
||||
<div class="readable-item" id="{{item.source}}-{{item.id}}">
|
||||
{% if item.id %}<button onclick="javascript:deactivate('{{item.source}}', '{{item.id}}')" title="Deactivate">✕</button>{% endif %}
|
||||
{% if item.id %}<button onclick="javascript:punt('{{item.source}}', '{{item.id}}')" title="Punt to tomorrow">↷</button>{% endif %}
|
||||
{% if item.id %}<button class="item-button" onclick="javascript:deactivate('{{item.source}}', '{{item.id}}')" title="Deactivate">✕</button>{% endif %}
|
||||
{% if item.id %}<button class="item-button" onclick="javascript:punt('{{item.source}}', '{{item.id}}')" title="Punt to tomorrow">↷</button>{% endif %}
|
||||
{% if item.link %}<a class="item-link" href="{{item.link}}" target="_blank">⇗</a>{% endif %}
|
||||
{% if item.body %}<details>
|
||||
<summary><span class="item-title">{{item.title}}</span></summary>
|
||||
|
@ -95,6 +108,14 @@
|
|||
{% endif %}
|
||||
</div>
|
||||
{% endfor %}
|
||||
<div class="readable-item">
|
||||
<details>
|
||||
<summary><span class="item-title">Feed Management</span></summary>
|
||||
<div style="text-align:center;">
|
||||
<button style="font-size: 1.4em;" onclick="javascript:mdeactivate({{ mdeac|safe }})">Deactivate All</button>
|
||||
</div>
|
||||
</details>
|
||||
</div>
|
||||
{% else %}
|
||||
<div class="readable-item">
|
||||
<span class="item-title">Feed is empty</span>
|
||||
|
|
Loading…
Reference in New Issue