Wellness Program Participation Dashboard

Wellness Program Participation

Total Participants

0

Participation Rate

0%

Total Activities Logged

0

Most Popular Activity

N/A

Participation Over Time

Participation by Activity

Recent Activity Log

No participation data to display.

`; } renderTimeChart(metrics.activitiesByDate); renderActivityChart(metrics.activitiesByType); }; const renderTimeChart = (activitiesByDate) => { const ctx = elements.timeChartCanvas?.getContext('2d'); if (!ctx) return; const sortedDates = Object.keys(activitiesByDate).sort((a, b) => new Date(a) - new Date(b)); const chartData = sortedDates.map(date => activitiesByDate[date]); if (timeChart) timeChart.destroy(); timeChart = new Chart(ctx, { type: 'line', data: { labels: sortedDates, datasets: [{ label: 'Activities', data: chartData, borderColor: '#7e22ce', backgroundColor: 'rgba(126, 34, 206, 0.1)', fill: true, tension: 0.3 }] }, options: { responsive: true, maintainAspectRatio: true } }); }; const renderActivityChart = (activitiesByType) => { const ctx = elements.activityChartCanvas?.getContext('2d'); if (!ctx) return; const labels = Object.keys(activitiesByType); const data = Object.values(activitiesByType); if (activityChart) activityChart.destroy(); activityChart = new Chart(ctx, { type: 'pie', data: { labels, datasets: [{ label: 'Activities', data, backgroundColor: ['#8b5cf6', '#3b82f6', '#10b981', '#f59e0b', '#ef4444'], hoverOffset: 4 }] }, options: { responsive: true, maintainAspectRatio: true, plugins: { legend: { position: 'top' } } } }); }; const renderConfigPanel = () => { const container = elements.editableList; if (!container) return; container.innerHTML = ''; participationData.forEach(d => { const card = document.createElement('div'); card.className = 'grid grid-cols-1 md:grid-cols-4 gap-4 items-center bg-white p-3 rounded-lg border'; card.innerHTML = `
`; container.appendChild(card); }); }; const handleAddLog = (e) => { e.preventDefault(); try { const newLog = { id: participationData.length > 0 ? Math.max(...participationData.map(d => d.id)) + 1 : 1, name: document.getElementById('participantName').value, activity: document.getElementById('activity').value, date: document.getElementById('activityDate').value, }; participationData.push(newLog); elements.addForm.reset(); renderAll(); showToast('Record added!'); } catch (error) { console.error("Error adding record:", error); showToast("Error: Could not add record."); } }; const handleConfigListClick = (e) => { const target = e.target.closest('button'); if (!target) return; const action = target.dataset.action; const id = parseInt(target.dataset.id, 10); if (action === 'update') { const index = participationData.findIndex(d => d.id === id); if (index === -1) return; const inputs = target.closest('.grid').querySelectorAll('input'); inputs.forEach(input => { participationData[index][input.dataset.field] = input.value; }); } else if (action === 'delete') { participationData = participationData.filter(d => d.id !== id); } renderAll(); showToast(`Record ${action}d successfully!`); }; const handleGeneratePDF = () => { try { const { jsPDF } = window.jspdf; const doc = new jsPDF(); const metrics = calculateMetrics(); doc.setFontSize(20); doc.text("Wellness Program Participation Report", 105, 20, null, null, 'center'); doc.setFontSize(10); doc.text(`Generated on: ${new Date().toLocaleDateString()}`, 105, 26, null, null, 'center'); doc.autoTable({ startY: 35, head: [['Metric', 'Value']], body: [ ['Total Participants', metrics.participants], ['Participation Rate', `${metrics.rate.toFixed(1)}%`], ['Total Activities Logged', metrics.totalActivities], ['Most Popular Activity', metrics.topActivity] ], theme: 'grid' }); let finalY = doc.lastAutoTable.finalY || 60; doc.setFontSize(14); doc.text("Participation Over Time", 14, finalY + 15); doc.addImage(elements.timeChartCanvas.toDataURL('image/png', 1.0), 'PNG', 14, finalY + 20, 180, 80); finalY += 95; doc.setFontSize(14); doc.text("Activity Log", 14, finalY); const sortedData = [...participationData].sort((a, b) => new Date(b.date) - new Date(a.date)); const tableBody = sortedData.slice(0, 20).map(d => [d.name, d.activity, new Date(d.date).toLocaleDateString()]); doc.autoTable({ head: [['Participant', 'Activity', 'Date']], body: tableBody, startY: finalY + 5, theme: 'striped', headStyles: { fillColor: [126, 34, 206] } }); doc.save('Wellness-Participation-Report.pdf'); } catch (error) { console.error("Failed to generate PDF:", error); showToast("Error: Could not generate PDF."); } }; const switchTab = (tabName) => { currentTab = tabName; Object.values(elements.tabs).forEach(tab => tab.classList.add('hidden')); Object.values(elements.tabButtons).forEach(btn => btn.classList.remove('active')); elements.tabs[tabName].classList.remove('hidden'); elements.tabButtons[tabName].classList.add('active'); updateNavButtons(); }; const navigateTabs = (direction) => { const currentIndex = tabOrder.indexOf(currentTab); const newIndex = direction === 'next' ? Math.min(currentIndex + 1, tabOrder.length - 1) : Math.max(currentIndex - 1, 0); if (newIndex !== currentIndex) switchTab(tabOrder[newIndex]); }; const updateNavButtons = () => { const currentIndex = tabOrder.indexOf(currentTab); elements.navButtons.prev.disabled = currentIndex === 0; elements.navButtons.next.disabled = currentIndex === tabOrder.length - 1; }; const showToast = (message) => { if (!elements.toast) return; elements.toast.textContent = message; elements.toast.classList.add('show'); setTimeout(() => { elements.toast.classList.remove('show'); }, 3000); } elements.addForm.addEventListener('submit', handleAddLog); elements.editableList.addEventListener('click', handleConfigListClick); elements.pdfButton.addEventListener('click', handleGeneratePDF); elements.tabButtons.dashboard.addEventListener('click', () => switchTab('dashboard')); elements.tabButtons.config.addEventListener('click', () => switchTab('config')); elements.navButtons.prev.addEventListener('click', () => navigateTabs('prev')); elements.navButtons.next.addEventListener('click', () => navigateTabs('next')); renderAll(); updateNavButtons(); });
Scroll to Top