adds activity indicators in header (ugly af)

This commit is contained in:
2025-02-11 01:58:06 +01:00
parent 0340dea4f8
commit 57e969a647
7 changed files with 234 additions and 92 deletions

View File

@@ -1,64 +1,22 @@
import { ScraperUtils } from './scraper_utils.js';
class Common {
constructor() {
this.activityIndicator = document.getElementById('activity_indicator');
this.endTimeElement = document.getElementById('end_time');
this.serverTimeElement = document.getElementById('server_time');
this.init();
this.utils = new ScraperUtils();
this.addEventListeners();
this.scheduleUpdates();
}
init() {
this.updateServerTime();
setInterval(() => this.updateServerTime(), 60000); // Update every minute
this.checkScrapingStatus();
scheduleUpdates() {
// Ensure server time updates every minute but only after initial fetch
setTimeout(() => {
setInterval(() => this.utils.updateServerTime(), 60000);
}, 5000); // Delay first scheduled update to prevent duplicate initial request
}
async fetchEndTime() {
try {
const response = await fetch('/scraping_get_end_time');
const data = await response.json();
if (data.end_time) {
const endTime = new Date(data.end_time);
const localEndTime = endTime.toLocaleString();
this.endTimeElement.textContent = `End Time: ${endTime} TCT`;
}
} catch (error) {
this.endTimeElement.textContent = 'Error fetching end time';
console.error('Error fetching end time:', error);
}
}
async updateServerTime() {
try {
const response = await fetch('/server_time');
const data = await response.json();
this.serverTimeElement.textContent = `Server Time (UTC): ${data.server_time}`;
} catch (error) {
console.error('Error fetching server time:', error);
}
}
async checkScrapingStatus() {
try {
const response = await fetch('/scraping_status');
const data = await response.json();
if (data.scraping_active) {
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.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);
addEventListeners() {
if (this.utils.stopButton) {
this.utils.stopButton.addEventListener('click', () => this.utils.checkScrapingStatus());
}
}
}
@@ -67,10 +25,14 @@ document.addEventListener('DOMContentLoaded', () => {
new Common();
});
function checkAllCheckboxes(tableId, checkAllCheckboxId) {
const table = document.getElementById(tableId);
const checkboxes = table.querySelectorAll('input[type="checkbox"]:not(:disabled)');
const checkAllCheckbox = document.getElementById(checkAllCheckboxId);
window.checkAllCheckboxes = function(tableId, checkAllId) {
var table = document.getElementById(tableId);
var checkAll = document.getElementById(checkAllId);
var checkboxes = table.querySelectorAll('input[type="checkbox"]');
checkboxes.forEach(checkbox => checkbox.checked = checkAllCheckbox.checked);
}
checkboxes.forEach(function(checkbox) {
if (!checkbox.disabled) {
checkbox.checked = checkAll.checked;
}
});
};