Certification Dashboard
No certifications expiring soon.
';
} else {
expiryContainer.innerHTML = expiringSoon.sort((a,b) => new Date(a.ExpiryDate) - new Date(b.ExpiryDate)).map(c => {
const daysLeft = Math.ceil((new Date(c.ExpiryDate) - today) / (1000 * 60 * 60 * 24));
return `
${c.Name}
Holder: ${c.Holder}
${daysLeft} days
`;
}).join('');
}
renderStatusChart();
}
function renderStatusChart() {
const statusCounts = certsData.reduce((acc, c) => { acc[c.Status] = (acc[c.Status] || 0) + 1; return acc; }, {});
const ctx = document.getElementById('cd-status-chart').getContext('2d');
if(statusChart) statusChart.destroy();
statusChart = new Chart(ctx, {
type: 'doughnut',
data: {
labels: Object.keys(statusCounts),
datasets: [{
data: Object.values(statusCounts),
backgroundColor: ['#16a34a', '#dc2626', '#f59e0b', '#64748b']
}]
},
options: { responsive: true, maintainAspectRatio: false, plugins: { legend: { position: 'bottom' } } }
});
}
function renderCertsTable() {
const table = document.getElementById('certs-table');
table.innerHTML = `
| Holder | Certification Name | Issuing Body | Status | Expiry Date | Actions |
${certsData.map(c => `
|
|
|
|
|
|
`).join('')}
`;
}
function addCert() {
certsData.push({ id: Date.now(), Name: 'New Certification', Body: '', Holder: 'New Employee', Status: 'In Progress', ExpiryDate: null });
processAndRenderAll();
}
function handleTableEvents(e) {
const target = e.target; if (!target) return;
const id = parseInt(target.closest('tr')?.dataset.id); if (!id) return;
if (target.classList.contains('remove-cert-btn')) {
certsData = certsData.filter(c => c.id !== id);
} else if (target.tagName === 'INPUT' || target.tagName === 'SELECT') {
const key = target.dataset.key;
const item = certsData.find(c => c.id === id);
if (item) item[key] = target.value;
}
processAndRenderAll();
}
document.getElementById('cd-add-cert-btn').addEventListener('click', addCert);
const certsTable = document.getElementById('certs-table');
certsTable.addEventListener('change', handleTableEvents);
certsTable.addEventListener('click', handleTableEvents);
function initialize() {
const createDate = (offsetDays) => { const d = new Date("2025-07-12"); d.setDate(d.getDate() + offsetDays); return d.toISOString().split('T')[0]; };
certsData = [
{ id: 1, Name: 'Project Management Professional (PMP)', Body: 'PMI', Holder: 'John Smith', Status: 'Active', ExpiryDate: createDate(85) },
{ id: 2, Name: 'AWS Certified Solutions Architect', Body: 'Amazon Web Services', Holder: 'Jane Doe', Status: 'Active', ExpiryDate: createDate(45) },
{ id: 3, Name: 'CompTIA Security+', Body: 'CompTIA', Holder: 'Alex Ray', Status: 'Expired', ExpiryDate: '2025-01-15' },
{ id: 4, Name: 'Certified ScrumMaster (CSM)', Body: 'Scrum Alliance', Holder: 'Brenda Miller', Status: 'Active', ExpiryDate: '2026-05-20' },
{ id: 5, Name: 'Google Analytics IQ', Body: 'Google', Holder: 'Samantha Chen', Status: 'In Progress', ExpiryDate: null },
];
processAndRenderAll();
}
initialize();
});