Add punt-to-tomorrow button
This commit is contained in:
parent
098f97f4d9
commit
065a0f3480
|
@ -1,4 +1,5 @@
|
||||||
# Standard library imports
|
# Standard library imports
|
||||||
|
from datetime import datetime, timedelta
|
||||||
import os
|
import os
|
||||||
import traceback
|
import traceback
|
||||||
|
|
||||||
|
@ -99,6 +100,22 @@ def deactivate():
|
||||||
params = request.get_json()
|
params = request.get_json()
|
||||||
if 'source' not in params and 'itemid' not in params:
|
if 'source' not in params and 'itemid' not in params:
|
||||||
logger.error("Bad request params: {}".format(params))
|
logger.error("Bad request params: {}".format(params))
|
||||||
item = loader.WritethroughDict(os.path.join(DUNGEON_PATH, params['source'], params['itemid'] + '.item'))
|
item = loader.WritethroughDict(os.path.join(
|
||||||
|
DUNGEON_PATH, params['source'], params['itemid'] + '.item'))
|
||||||
|
if item['active']:
|
||||||
|
logger.debug(f"Deactivating {params['source']}/{params['itemid']}")
|
||||||
item['active'] = False
|
item['active'] = False
|
||||||
return jsonify({'active': item['active']})
|
return jsonify({'active': item['active']})
|
||||||
|
|
||||||
|
@app.route("/punt/", methods=['POST'])
|
||||||
|
def punt():
|
||||||
|
params = request.get_json()
|
||||||
|
if 'source' not in params and 'itemid' not in params:
|
||||||
|
logger.error("Bad request params: {}".format(params))
|
||||||
|
item = loader.WritethroughDict(os.path.join(
|
||||||
|
DUNGEON_PATH, params['source'], params['itemid'] + '.item'))
|
||||||
|
tomorrow = datetime.now() + timedelta(days=1)
|
||||||
|
morning = datetime(tomorrow.year, tomorrow.month, tomorrow.day, 6, 0, 0)
|
||||||
|
til_then = morning.timestamp() - item['created']
|
||||||
|
item['tts'] = til_then
|
||||||
|
return jsonify(item.item)
|
||||||
|
|
|
@ -10,11 +10,14 @@
|
||||||
word-break: break-word;
|
word-break: break-word;
|
||||||
}
|
}
|
||||||
.item-title { font-size: 1.4em; }
|
.item-title { font-size: 1.4em; }
|
||||||
.readable-item button { font-size: 1em; float:right; }
|
.readable-item button {
|
||||||
|
font-size: 1em;
|
||||||
|
float:right;
|
||||||
|
margin-left: 2px;
|
||||||
|
}
|
||||||
.item-link {
|
.item-link {
|
||||||
text-decoration: none;
|
text-decoration: none;
|
||||||
float:right;
|
float:right;
|
||||||
margin: 0px 2px;
|
|
||||||
font-size: 1em;
|
font-size: 1em;
|
||||||
padding: 2px 7px;
|
padding: 2px 7px;
|
||||||
border: 1px solid;
|
border: 1px solid;
|
||||||
|
@ -24,10 +27,8 @@
|
||||||
.readable-item img { max-width: 100%; }
|
.readable-item img { max-width: 100%; }
|
||||||
button, summary { cursor: pointer; }
|
button, summary { cursor: pointer; }
|
||||||
summary:focus { outline: 1px dotted gray; }
|
summary:focus { outline: 1px dotted gray; }
|
||||||
.strikethru span, .strikethru p {
|
.strikethru span, .strikethru p { text-decoration: line-through; }
|
||||||
text-decoration: line-through;
|
.fade span, .fade p { color: rgba(0, 0, 0, 0.2); }
|
||||||
color: rgba(0, 0, 0, 0.2);
|
|
||||||
}
|
|
||||||
pre { white-space: pre-wrap; }
|
pre { white-space: pre-wrap; }
|
||||||
table.feed-control td { font-family: monospace; padding: 5px 10px; }
|
table.feed-control td { font-family: monospace; padding: 5px 10px; }
|
||||||
</style>
|
</style>
|
||||||
|
@ -44,10 +45,26 @@
|
||||||
.then(function (data) {
|
.then(function (data) {
|
||||||
if (!data.active) {
|
if (!data.active) {
|
||||||
document.getElementById(source + "-" + itemid)
|
document.getElementById(source + "-" + itemid)
|
||||||
.classList.add("strikethru")
|
.classList.add("strikethru", "fade");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
};
|
||||||
|
var punt = function (source, itemid) {
|
||||||
|
fetch('punt/', {
|
||||||
|
method: 'POST',
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json; charset=UTF-8',
|
||||||
|
},
|
||||||
|
body: JSON.stringify({source: source, itemid: itemid}),
|
||||||
|
})
|
||||||
|
.then(response => response.json())
|
||||||
|
.then(function (data) {
|
||||||
|
if (data.tts) {
|
||||||
|
document.getElementById(source + "-" + itemid)
|
||||||
|
.classList.add("fade");
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
</script>
|
</script>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
@ -55,7 +72,8 @@
|
||||||
{% 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 %}<button onclick="javascript:deactivate('{{item.source}}', '{{item.id}}')">✕</button>{% endif %}
|
{% 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.link %}<a class="item-link" href="{{item.link}}" target="_blank">⇗</a>{% endif %}
|
{% if item.link %}<a class="item-link" href="{{item.link}}" target="_blank">⇗</a>{% endif %}
|
||||||
{% if item.body %}<details>
|
{% if item.body %}<details>
|
||||||
<summary><span class="item-title">{{item.title}}</span></summary>
|
<summary><span class="item-title">{{item.title}}</span></summary>
|
||||||
|
@ -72,6 +90,7 @@
|
||||||
{% if item.source %}{{item.source}}{% endif %}
|
{% if item.source %}{{item.source}}{% endif %}
|
||||||
{% if item.id %}{{item.id}}{% endif %}
|
{% if item.id %}{{item.id}}{% endif %}
|
||||||
{% if item.created %}{{item.created|datetimeformat}}{% endif %}
|
{% if item.created %}{{item.created|datetimeformat}}{% endif %}
|
||||||
|
{% if item.ttl %}L{% endif %}{% if item.ttd %}D{% endif %}{% if item.tts %}S{% endif %}
|
||||||
</span>
|
</span>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
|
|
Loading…
Reference in New Issue