forked from starnakin/ca42
Button logic is now working
This commit is contained in:
parent
c7e9d5de5a
commit
95ce30c5a9
3
main.py
3
main.py
@ -27,7 +27,8 @@ def update():
|
||||
@app.route("/", methods = ['GET'])
|
||||
def normal():
|
||||
print(values.split(" "))
|
||||
return render_template('home.html', dates = wrap(values, 10), total = len(values.split(' ')), days = values.split(' ')[-1])
|
||||
return render_template('home.html', dates = wrap(values, 10), total = len(values.split(' ')), days = (datetime.datetime.today().date() - datetime.datetime.strptime(values.split(' ')[-1], "%Y-%m-%d").date()).days)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
app.run(host='0.0.0.0', port=5000, debug=1)
|
||||
|
@ -66,6 +66,34 @@ header {
|
||||
}
|
||||
|
||||
</style>
|
||||
<script>
|
||||
// JavaScript function to handle button click
|
||||
document.addEventListener("DOMContentLoaded", function () {
|
||||
const incidentBtn = document.getElementById("incident-btn");
|
||||
|
||||
incidentBtn.addEventListener("click", function () {
|
||||
// Make a POST request to the /api/update route
|
||||
fetch("/api/update", {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json"
|
||||
}
|
||||
})
|
||||
.then(response => {
|
||||
if (response.redirected) {
|
||||
// If the request is successful and we are redirected
|
||||
window.location.href = response.url;
|
||||
} else {
|
||||
alert("Error: Could not update the incident.");
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
console.error("Error:", error);
|
||||
alert("An error occurred while updating the incident.");
|
||||
});
|
||||
});
|
||||
});
|
||||
</script>
|
||||
<header>
|
||||
<h1>ca42</h1>
|
||||
</header>
|
||||
@ -85,4 +113,4 @@ header {
|
||||
</div>
|
||||
</div>
|
||||
<div id="incident-btn" form action>Incident</div>
|
||||
<p class="btn-text">Note: Button doesn't actually work yet...</p>
|
||||
<p class="btn-text">Note: Un accident par jour pour éviter la redondance</p>
|
||||
|
Loading…
Reference in New Issue
Block a user