Forráskód Böngészése

js was overly complicated. Changed to let web_panels.py determine the difference.

deadtom 1 hónapja
szülő
commit
a9008584b6

+ 18 - 28
ownchatbot/templates/goals.html

@@ -13,41 +13,33 @@
             text-align: left;
             font-weight: bold;
         }
-        body { position: absolute; bottom: 0; left: 0; }
     </style>
     <script>
-      function checkForGoalUpdates() {
-          fetch('/updateGoals')
-              .then(response => response.json())
-              .then(data => {
-                  const newGoals = data.goals;
-                  const currentGoals = Array.from(document.querySelectorAll('tbody tr')).map(tr => {
-                      const goalData = {
-                          name: tr.children[0].textContent.trim(),
-                          current: parseInt(tr.children[2].textContent.split('/')[0].trim()),
-                          target: parseInt(tr.children[2].textContent.split('/')[1].trim())
-                      };
-                      return goalData;
-                  });
-
-                  if (JSON.stringify(newGoals) !== JSON.stringify(currentGoals)) {
-                      window.location.reload();  // Refresh if goals have changed
-                  }
-              })
-              .catch(error => console.error('Error fetching updated goals:', error));
-      }
+        function checkForUpdates() {
+            fetch('/updateGoals')
+                .then(response => response.json())
+                .then(data => {
+                    if (data.updated) {
+                        console.log('Goals have changed, refreshing the page...');
+                        window.location.reload();  // Refresh if goals have changed
+                    } else {
+                        console.log('No changes detected.'); // Log if no changes
+                    }
+                })
+                .catch(error => console.error('Error fetching updated goals:', error));
+        }
 
-      setInterval(checkForGoalUpdates, 15 * 1000); // Check every 15 seconds
+        setInterval(checkForUpdates, 15 * 1000); // Check every 15 seconds
     </script>
 </head>
-<body>
+<body style="position: absolute; bottom: 0; left: 0;">
     {% if goals %}
         <table>
             <thead>
                 <tr>
-                    <th>Description</th>
+                    <th></th>
                     <th style="width: 50%"></th>
-                    <th>Progress</th>
+                    <th></th>
                 </tr>
             </thead>
             <tbody>
@@ -57,7 +49,7 @@
                     {% set progress = goal[1] / goal[2] * 100 %}
                     <td>
                         <div class="bar-light-grey bar-tiny bar-round" style="position: relative;">
-                            <div class="bar-round bar-blue" style="text-align: center; width:{{ progress }}%;">{{ '%0.0f' | format(progress | float) }}%
+                            <div class="bar-round bar-blue" style="text-align: center; width:{{ progress }}%;">{{ '%0.0f'| format(progress| float) }}%
                             </div>
                             {% set milestones = rewards[goal[0]]["milestones"] %}
                             {% for milestone_key, milestone in milestones.items() %}
@@ -81,8 +73,6 @@
             {% endfor %}
             </tbody>
         </table>
-    {% else %}
-        <p>No active goals at the moment.</p>
     {% endif %}
 </body>
 </html>

+ 14 - 17
ownchatbot/templates/list.html

@@ -12,24 +12,21 @@
         }
     </style>
     <script>
-      function checkForUpdates() {
-          fetch('/checkTodo')
-              .then(response => response.json())
-              .then(data => {
-                  const newList = data.items; // Assuming LIST is returned as JSON with { items: [...] }
-
-                  // Compare current list with new list (you can customize this comparison)
-                  const currentItems = Array.from(document.querySelectorAll('li')).map(li => li.textContent);
-
-                  if (newList.length !== currentItems.length || !currentItems.every((item, index) => item === newList[index].name)) {
-                      // Refresh the page if the list has changed
-                      window.location.reload();
-                  }
-              })
-              .catch(error => console.error('Error fetching the to-do list:', error));
-      }
+        function checkForUpdates() {
+            fetch('/updateTodo')
+                .then(response => response.json())
+                .then(data => {
+                    if (data.updated) {
+                        console.log('List has changed, refreshing the page...');
+                        window.location.reload();  // Refresh if votes have changed
+                    } else {
+                        console.log('No changes detected.'); // Log if no changes
+                    }
+                })
+                .catch(error => console.error('Error fetching updated list:', error));
+        }
 
-      setInterval(checkForUpdates, 15 * 1000); // Check every 15 seconds
+        setInterval(checkForUpdates, 15 * 1000); // Check every 15 seconds
     </script>
 </head>
 <body>

+ 24 - 26
ownchatbot/templates/votes.html

@@ -3,8 +3,8 @@
 <head>
     <meta charset="UTF-8">
     <meta name="viewport" content="width=device-width, initial-scale=1.0">
-    <title>Active votes</title>
     <link rel="stylesheet" href="{{ url_for('static', filename='style.css') }}">
+    <title>Active votes</title>
     <style>
         body {
             background-color: transparent;
@@ -12,30 +12,25 @@
             width: 400px;
             position: absolute;
             bottom: 0; left: 0;
-            font-weight: bold;
+        font-weight: bold;
         }
     </style>
     <script>
-      function checkForVoteUpdates() {
-          fetch('/updateVotes')
-              .then(response => response.json())
-              .then(data => {
-                  const newVotes = data.votes;
-                  const currentVotes = Array.from(document.querySelectorAll('tbody tr')).map(tr => {
-                      return {
-                          text: tr.children[0].textContent,
-                          count: parseInt(tr.children[1].textContent)
-                      };
-                  });
-
-                  if (JSON.stringify(newVotes) !== JSON.stringify(currentVotes)) {
-                      window.location.reload();  // Refresh if votes have changed
-                  }
-              })
-              .catch(error => console.error('Error fetching updated votes:', error));
-      }
+        function checkForUpdates() {
+            fetch('/updateVotes')
+                .then(response => response.json())
+                .then(data => {
+                    if (data.updated) {
+                        console.log('Votes have changed, refreshing the page...');
+                        window.location.reload();  // Refresh if votes have changed
+                    } else {
+                        console.log('No changes detected.'); // Log if no changes
+                    }
+                })
+                .catch(error => console.error('Error fetching updated votes:', error));
+        }
 
-      setInterval(checkForVoteUpdates, 15 * 1000); // Check every 15 seconds
+        setInterval(checkForUpdates, 15 * 1000); // Check every 15 seconds
     </script>
 </head>
 <body>
@@ -43,21 +38,24 @@
         <table>
             <thead>
                 <tr>
-                    <th>Item</th>
-                    <th>Votes</th>
+                    <th></th>
+                    <th></th>
+                    <th></th>
                 </tr>
             </thead>
             <tbody>
             {% for vote in votes %}
                 <tr>
                     <td>{{ vote[2] }}</td>
-                    <td>{{ vote[1] }} vote{% if vote[1] != 1 %}s{% endif %}</td>
+                    {% if vote[1] == 1 %}
+                    <td>{{ vote[1] }} vote</td>
+                    {% else %}
+                    <td>{{ vote[1] }} votes</td>
+                    {% endif %}
                 </tr>
             {% endfor %}
             </tbody>
         </table>
-    {% else %}
-        <p>No active votes at the moment.</p>
     {% endif %}
 </body>
 </html>