From ccf9ae2a9ab4e313db97daee879795da4975e712 Mon Sep 17 00:00:00 2001
From: Admin9705 <9705@duck.com>
Date: Sat, 3 May 2025 19:38:25 -0400
Subject: [PATCH] fixes
---
frontend/static/js/new-main.js | 2 +-
frontend/static/js/stats-reset.js | 80 +++++++++++++++++++++++++++++++
frontend/templates/index.html | 9 +---
src/primary/stats_manager.py | 12 ++++-
src/primary/web_server.py | 44 +++++++++++++++--
5 files changed, 132 insertions(+), 15 deletions(-)
create mode 100644 frontend/static/js/stats-reset.js
diff --git a/frontend/static/js/new-main.js b/frontend/static/js/new-main.js
index ad324512..79789f70 100644
--- a/frontend/static/js/new-main.js
+++ b/frontend/static/js/new-main.js
@@ -1797,7 +1797,7 @@ let huntarrUI = {
try {
const requestBody = appType ? { app_type: appType } : {};
- HuntarrUtils.fetchWithTimeout('/api/stats/reset', {
+ HuntarrUtils.fetchWithTimeout('/api/stats/reset_public', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
diff --git a/frontend/static/js/stats-reset.js b/frontend/static/js/stats-reset.js
new file mode 100644
index 00000000..21f9907d
--- /dev/null
+++ b/frontend/static/js/stats-reset.js
@@ -0,0 +1,80 @@
+/**
+ * Stats Reset Handler
+ * Provides a unified way to handle stats reset operations
+ */
+
+document.addEventListener('DOMContentLoaded', function() {
+ // Find the reset button on the home page
+ const resetButton = document.getElementById('reset-stats');
+
+ if (resetButton) {
+ console.log('Stats reset button found, attaching handler');
+
+ resetButton.addEventListener('click', function(e) {
+ e.preventDefault();
+
+ // Prevent double-clicks
+ if (this.disabled) return;
+
+ // First update the UI immediately for responsive feedback
+ resetStatsUI();
+
+ // Then make the API call to persist the changes
+ resetStatsAPI()
+ .then(response => {
+ console.log('Stats reset response:', response);
+ if (!response.success) {
+ console.warn('Server reported an error with stats reset:', response.error);
+ }
+ })
+ .catch(error => {
+ console.error('Error during stats reset:', error);
+ });
+ });
+ }
+});
+
+/**
+ * Reset the stats UI immediately for responsive feedback
+ */
+function resetStatsUI() {
+ // Find all stat counters and reset them to 0
+ const statCounters = document.querySelectorAll('.stat-number');
+ statCounters.forEach(counter => {
+ if (counter && counter.textContent) {
+ counter.textContent = '0';
+ }
+ });
+
+ // Show success notification if available
+ if (window.huntarrUI && typeof window.huntarrUI.showNotification === 'function') {
+ window.huntarrUI.showNotification('Statistics reset successfully', 'success');
+ }
+}
+
+/**
+ * Make the API call to reset stats on the server
+ * @param {string|null} appType - Optional specific app to reset
+ * @returns {Promise} - Promise resolving to the API response
+ */
+function resetStatsAPI(appType = null) {
+ const requestBody = appType ? { app_type: appType } : {};
+
+ // Use the public endpoint that doesn't require authentication
+ return fetch('/api/stats/reset_public', {
+ method: 'POST',
+ headers: {
+ 'Content-Type': 'application/json'
+ },
+ body: JSON.stringify(requestBody)
+ })
+ .then(response => {
+ if (!response.ok) {
+ throw new Error('Server responded with status: ' + response.status);
+ }
+ return response.json();
+ });
+}
+
+// Make resetStatsAPI available globally so other scripts can use it
+window.resetStatsAPI = resetStatsAPI;
diff --git a/frontend/templates/index.html b/frontend/templates/index.html
index 51a6a3f0..811661ef 100644
--- a/frontend/templates/index.html
+++ b/frontend/templates/index.html
@@ -26,11 +26,6 @@
{% include 'components/settings_section.html' %}
-
-
-
@@ -43,8 +38,8 @@
-
-
+
+