adds status and server time indicators. fixes checkboxes

This commit is contained in:
2025-02-10 18:22:06 +01:00
parent 2b6aebdab4
commit 0340dea4f8
6 changed files with 96 additions and 36 deletions

View File

@@ -9,52 +9,26 @@ class ScraperApp {
}
init() {
this.checkScrapingStatus();
this.checkScrapingStatusIndex();
this.addEventListeners();
}
async checkScrapingStatus() {
async checkScrapingStatusIndex() {
try {
const response = await fetch('/scraping_status');
const data = await response.json();
if (data.scraping_active) {
this.startButton.disabled = true;
this.stopButton.disabled = false;
this.activityIndicator.classList.remove('text-bg-danger');
this.activityIndicator.classList.add('text-bg-success');
this.activityIndicator.textContent = 'Active';
this.endTimeElement.classList.remove('d-none');
this.endTimeElement.textContent = data.end_time;
await this.fetchEndTime();
} else {
this.startButton.disabled = false;
this.stopButton.disabled = true;
this.activityIndicator.classList.remove('text-bg-success');
this.activityIndicator.classList.add('text-bg-danger');
this.activityIndicator.textContent = 'Inactive';
this.endTimeElement.textContent = '';
this.endTimeElement.classList.add('d-none');
}
} catch (error) {
console.error('Error checking scraping status:', error);
}
}
async fetchEndTime() {
try {
const response = await fetch('/scraping_get_end_time');
const data = await response.json();
if (data.end_time) {
this.endTimeElement.textContent = `Track until: ${data.end_time}`;
}
} catch (error) {
this.endTimeElement.textContent = 'Error fetching end time';
console.error('Error fetching end time:', error);
}
}
async startScraping(event) {
event.preventDefault(); // Prevent the default form submission
const formData = new FormData(this.form);
@@ -65,7 +39,7 @@ class ScraperApp {
});
const data = await response.json();
if (data.status === "Scraping started") {
this.checkScrapingStatus();
this.checkScrapingStatusIndex();
}
} catch (error) {
console.error('Error starting scraping:', error);
@@ -79,7 +53,7 @@ class ScraperApp {
});
const data = await response.json();
if (data.status === "Scraping stopped") {
this.checkScrapingStatus();
this.checkScrapingStatusIndex();
}
} catch (error) {
console.error('Error stopping scraping:', error);
@@ -93,4 +67,6 @@ class ScraperApp {
}
// Initialize the application when DOM is fully loaded
document.addEventListener('DOMContentLoaded', () => new ScraperApp());
document.addEventListener('DOMContentLoaded', () => {
new ScraperApp();
});