working milestones prototype in dashboard

This commit is contained in:
Lili (Tlapka) 2023-03-14 16:26:04 +01:00
parent 68b8588c76
commit cb574618a6
3 changed files with 73 additions and 31 deletions

View File

@ -184,27 +184,50 @@ def add_to_redeem_queue(db, user_id, redeem_name, note=None):
return False
def add_to_milestone(db, redeem_name, points):
def start_milestone(db, redeem_name):
try:
cursor = db.execute(
"SELECT count, goal FROM milestones WHERE name = ?",
(redeem_name,)
)
milestone = cursor.fetchone()
current_app.logger.error(f"Milestone: {milestone}")
if milestone is None:
current_app.logger.error(f"Adding milestone to db.")
cursor = db.execute(
"INSERT INTO milestones(name, count, goal) VALUES(?, ?, ?)",
(redeem_name, 0, current_app.config['REDEEMS'][redeem_name]['goal'])
)
db.commit()
except Error as e:
current_app.logger.error(f"Error occured adding a milestone: {e.args[0]}")
def add_to_milestone(db, redeem_name, points):
try:
start_milestone(db, redeem_name)
cursor = db.execute(
"SELECT count, goal FROM milestones WHERE name = ?",
(redeem_name,)
)
row = cursor.fetchone()
if row is not None:
count = row[0]
goal = row[1]
result = count + points
if result > goal:
result = goal
current_app.logger.error(f"Doing db operation to add to milestone.")
cursor = db.execute(
"UPDATE milestones SET count = ? WHERE name = ?",
(result, redeem_name)
)
db.commit()
return True
except (Error) as e:
except Error as e:
current_app.logger.error(f"Error occured updating milestone: {e.args[0]}")
current_app.logger.error(f"Milestone add failed.")
return False

View File

@ -51,8 +51,8 @@ def handle_redeem(message, user_id):
send_chat(f"Cannot redeem {redeem}, no amount of points specified.")
elif not note.isdigit():
send_chat(f"Cannot redeem {redeem}, amount of points is not an integer.")
elif int(note) < points:
send_chat(f"Can't redeem {redeem}, you don't have enough points.")
elif int(note) > points:
send_chat(f"Can't redeem {redeem}, you don't have enough points.2")
else:
add_to_milestone(db, redeem, int(note))
else:

View File

@ -1,6 +1,7 @@
<!DOCTYPE html>
<html lang="en">
<link rel="stylesheet" href="{{ url_for('static', filename='style.css') }}">
<head>
<title>Redeems Dashboard</title>
</head>
@ -19,6 +20,7 @@
</div>
<div id='dashboard' class="tabcontent">
<body>
<h3>Redeems Dashboard</h3>
{% if (username and users ) %}
@ -59,10 +61,17 @@
</table>
{% endif %}
{% if milestones %}
<table>
<thead>
<tr>
<th>Active milestones</th>
</tr>
</thead>
{% for milestone in milestones %}
<label for="file"> {{ milestone[0] }}</label>
<progress id="file" max={{ milestone[2] }} value={{ milestone[1] }}></progress>
<tbody>
<td> <label for="file"> {{ milestone[0] }}</label> </td>
<td> <progress id="file" max={{ milestone[2] }} value={{ milestone[1] }}></progress> </td>
</tbody>
{% endfor %}
{% endif %}
{% endif %}
@ -70,13 +79,18 @@
</div>
<div id='redeem-queue' class="tabcontent">
<p>Tlap tlap.</p>
<body>
<h3>Redeems Queue</h3>
<p>Tlap tlap 2.</p>
{% if queue %}
<p>Tlap tlap. 3</p>
<table>
<thead>
<tr>
<th colspan="2">Recent redeems</th>
<p>Tlap tlap. 4</p>
</tr>
<tr>
<th>Time</th>
@ -94,10 +108,14 @@
<td>{{ row[2] }}</td>
{% endif %}
</tbody>
<p>Tlap tlap. 5</p>
{% endfor %}
</table>
<p>Tlap tlap. 6</p>
{% endif %}
<p>Tlap tlap. 7</p>
</body>
<p>Tlap tlap. 8</p>
</div>
<div id='redeems-list' class="tabcontent">
@ -107,9 +125,10 @@
<li><strong>Counter</strong> redeems add +1 to their counter.</li>
<li><strong>List</strong> redeems get added to the list of recent redeems (without a note).</li>
<li><strong>Note</strong> redeems require you to send a message together with the redeem.</li>
<li><strong>Milestone</strong> redeems are long-term goals to which you can donate any amount of points you want.</li>
<li>They will be completed once the amount of points donated reaches the goal.</li>
<li><strong>Milestone</strong> redeems are long-term goals to which you can donate any amount of points you
want. They will be completed once the amount of points donated reaches the goal.</li>
</ul>
<body>
{% if redeems %}
<table>