goals.html 3.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <title>Active goals</title>
  7. <link rel="stylesheet" href="{{ url_for('static', filename='style.css') }}">
  8. <style>
  9. body {
  10. background-color: transparent;
  11. color: white;
  12. width: 600px;
  13. text-align: left;
  14. font-weight: bold;
  15. }
  16. body { position: absolute; bottom: 0; left: 0; }
  17. </style>
  18. <script>
  19. function checkForGoalUpdates() {
  20. fetch('/updateGoals')
  21. .then(response => response.json())
  22. .then(data => {
  23. const newGoals = data.goals;
  24. const currentGoals = Array.from(document.querySelectorAll('tbody tr')).map(tr => {
  25. const goalData = {
  26. name: tr.children[0].textContent.trim(),
  27. current: parseInt(tr.children[2].textContent.split('/')[0].trim()),
  28. target: parseInt(tr.children[2].textContent.split('/')[1].trim())
  29. };
  30. return goalData;
  31. });
  32. if (JSON.stringify(newGoals) !== JSON.stringify(currentGoals)) {
  33. window.location.reload(); // Refresh if goals have changed
  34. }
  35. })
  36. .catch(error => console.error('Error fetching updated goals:', error));
  37. }
  38. setInterval(checkForGoalUpdates, 15 * 1000); // Check every 15 seconds
  39. </script>
  40. </head>
  41. <body>
  42. {% if goals %}
  43. <table>
  44. <thead>
  45. <tr>
  46. <th>Description</th>
  47. <th style="width: 50%"></th>
  48. <th>Progress</th>
  49. </tr>
  50. </thead>
  51. <tbody>
  52. {% for goal in goals %}
  53. <tr>
  54. <td style="text-align: left;">{{ goal[3] }}</td>
  55. {% set progress = goal[1] / goal[2] * 100 %}
  56. <td>
  57. <div class="bar-light-grey bar-tiny bar-round" style="position: relative;">
  58. <div class="bar-round bar-blue" style="text-align: center; width:{{ progress }}%;">{{ '%0.0f' | format(progress | float) }}%
  59. </div>
  60. {% set milestones = rewards[goal[0]]["milestones"] %}
  61. {% for milestone_key, milestone in milestones.items() %}
  62. {% if milestones[milestone_key][0] and milestones[milestone_key][1] %}
  63. {% if milestones[milestone_key][1] < goal[2] %}
  64. {% set milestone_progress = milestones[milestone_key][1] / goal[2] * 100 %}
  65. <div class="milestone-marker" style="position: absolute; left: {{ milestone_progress }}%; transform: translateX(-50%);">
  66. <img src="/static/img/milestone.png" style="width: 16px; height: 16px;" title="{{ milestones[milestone_key][1] }} points. {{ milestones[milestone_key][0] }}">
  67. </div>
  68. {% endif %}
  69. {% endif %}
  70. {% endfor %}
  71. </div>
  72. </td>
  73. {% if goal[1] == goal[2] %}
  74. <td style="text-align: right;">{{ goal[1] }} / {{ goal[2] }} <img src="/static/img/tada.png" style="width: 24px; height: 24px;"></td>
  75. {% else %}
  76. <td style="text-align: right;">{{ goal[1] }} / {{ goal[2] }}</td>
  77. {% endif %}
  78. </tr>
  79. {% endfor %}
  80. </tbody>
  81. </table>
  82. {% else %}
  83. <p>No active goals at the moment.</p>
  84. {% endif %}
  85. </body>
  86. </html>