/** * Main scraper dashboard initialization and coordination */ class ScraperDashboard { constructor(config = {}) { this.config = { maxVolume: config.maxVolume || 1000, volumeConfig: config.volumeConfig || 100, currentTimeRange: 24, }; this.initComponents(); this.setupCallbacks(); this.initializeData(); } /** * Initialize all dashboard components */ initComponents() { // Initialize chart this.activityChart = new ActivityChart("activityChart"); // Initialize scraper controller this.scraperController = new ScraperController({ maxVolume: this.config.maxVolume, volumeConfig: this.config.volumeConfig, }); // Initialize paper processor this.paperProcessor = new PaperProcessor(); // Initialize activity monitor this.activityMonitor = new ActivityMonitor(); } /** * Setup callbacks between components */ setupCallbacks() { // Set up activity refresh callbacks const activityRefreshCallback = () => this.activityMonitor.loadRecentActivity(); this.scraperController.setActivityRefreshCallback(activityRefreshCallback); this.paperProcessor.setActivityRefreshCallback(activityRefreshCallback); // Set up chart refresh callbacks const chartRefreshCallback = (timeRange = this.config.currentTimeRange) => { this.config.currentTimeRange = timeRange; this.activityChart.loadData(timeRange); }; this.scraperController.setChartRefreshCallback(chartRefreshCallback); this.paperProcessor.setChartRefreshCallback(chartRefreshCallback); this.activityMonitor.setChartRefreshCallback(chartRefreshCallback); } /** * Initialize data on page load */ initializeData() { // Load recent activity this.activityMonitor.loadRecentActivity(); // Load chart data after a short delay to ensure Chart.js is loaded setTimeout(() => { this.activityChart.loadData(this.config.currentTimeRange); }, 100); } /** * Refresh all dashboard data */ refreshAll() { this.activityMonitor.loadRecentActivity(); this.activityChart.loadData(this.config.currentTimeRange); this.scraperController.updateStatus(); } } /** * Initialize the scraper dashboard * @param {Object} config - Configuration object with Jinja variables */ function initScraperDashboard(config = {}) { return new ScraperDashboard(config); }