Server Maintenance Checklist Generator

Server Maintenance Checklist Generator

Your generated checklist will appear here. Go to the "Checklist Configuration" tab to select your tasks.

Daily Tasks

Weekly Tasks

Monthly Tasks

Quarterly Tasks

Error: Could not load PDF generation libraries. Please check console.

'; pdfBtnContainer.style.display = 'block'; } } // Element selection const tabs = document.querySelectorAll('.smc-tool-container .smc-tab-button'); const contents = document.querySelectorAll('.smc-tool-container .smc-tab-content'); const nextBtn = document.getElementById('smc-prev-tab'); const prevBtn = document.getElementById('smc-next-tab'); const generateBtn = document.getElementById('smc-generate-checklist'); const downloadPdfBtn = document.getElementById('smc-download-pdf'); const outputDiv = document.getElementById('smc-checklist-output'); const placeholder = document.getElementById('smc-dashboard-placeholder'); const pdfBtnContainer = document.getElementById('smc-pdf-btn-container'); const customTaskButtons = document.querySelectorAll('.smc-tool-container .smc-custom-task button'); let currentTabIndex = 0; // --- Tab Navigation Function --- function showSmcTab(tabIndex) { // Guard clause if (tabIndex < 0 || tabIndex >= tabs.length) { return; } currentTabIndex = tabIndex; // Update tab buttons tabs.forEach((tab, index) => { if (index === tabIndex) { tab.classList.add('active'); } else { tab.classList.remove('active'); } }); // Show/hide content contents.forEach((content, index) => { if (index === tabIndex) { content.classList.add('active'); } else { content.classList.remove('active'); } }); // Update Nav Buttons if (prevBtn) { prevBtn.disabled = currentTabIndex === 0; } if (nextBtn) { nextBtn.disabled = currentTabIndex === tabs.length - 1; } } // --- Add Custom Task Function --- function addSmcCustomTask(frequency) { const input = document.getElementById(`smc-custom-task-${frequency}`); const list = document.getElementById(`smc-task-list-${frequency}`); // Null checks if (!input || !list) { console.error('SMC Tool: Could not find custom task elements for', frequency); return; } const taskText = input.value.trim(); if (taskText === "") { alert('Please enter a task description.'); return; } const taskId = `smc-custom-${frequency}-${Date.now()}`; // Create new task item const taskItem = document.createElement('div'); taskItem.className = 'smc-task-item'; taskItem.innerHTML = ` `; list.appendChild(taskItem); input.value = ''; // Clear input } // --- Generate Checklist Function --- function generateSmcChecklist() { if (!outputDiv || !placeholder || !pdfBtnContainer) { console.error('SMC Tool: Output elements not found.'); return; } let html = ''; let taskCount = 0; const frequencies = [ { id: 'daily', title: 'Daily Tasks' }, { id: 'weekly', title: 'Weekly Tasks' }, { id: 'monthly', title: 'Monthly Tasks' }, { id: 'quarterly', title: 'Quarterly Tasks' } ]; frequencies.forEach(freq => { const listContainer = document.getElementById(`smc-task-list-${freq.id}`); if (!listContainer) return; const checkedTasks = listContainer.querySelectorAll('input[type="checkbox"]:checked'); if (checkedTasks.length > 0) { html += `

${freq.title}

    `; checkedTasks.forEach(task => { // Get text from the associated label let label = document.querySelector(`label[for="${task.id}"]`); let taskText = label ? label.textContent : task.value; // Fallback to value html += `
  • ${taskText}
  • `; taskCount++; }); html += `
`; } }); // Update dashboard if (taskCount > 0) { outputDiv.innerHTML = html; placeholder.style.display = 'none'; outputDiv.style.display = 'block'; pdfBtnContainer.style.display = 'block'; } else { outputDiv.innerHTML = ''; outputDiv.style.display = 'none'; placeholder.style.display = 'block'; placeholder.textContent = 'No tasks were selected. Please select tasks in the Configuration tab.'; pdfBtnContainer.style.display = 'none'; } // Switch to Dashboard tab showSmcTab(0); } // --- PDF Download Function --- function downloadSmcPdf() { // Check for libraries again if (typeof jspdf === 'undefined' || typeof html2canvas === 'undefined') { alert('Error: PDF generation libraries are not loaded. Cannot download PDF.'); return; } const { jsPDF } = window.jspdf; const checklistOutput = document.getElementById('smc-checklist-output'); if (!checklistOutput || checklistOutput.innerHTML.trim() === "") { alert('No checklist content to download.'); return; } // Create a temporary, styled element for PDF output // This ensures consistent styling and excludes non-PDF elements const pdfContent = document.createElement('div'); pdfContent.className = 'smc-pdf-content'; pdfContent.innerHTML = '

Server Maintenance Checklist

' + checklistOutput.innerHTML; // Append to body temporarily for rendering, but make it invisible pdfContent.style.position = 'absolute'; pdfContent.style.left = '-9999px'; pdfContent.style.width = '800px'; // Set a fixed width for consistent rendering document.body.appendChild(pdfContent); html2canvas(pdfContent, { scale: 2 // Improve resolution }).then(canvas => { // Remove the temporary element document.body.removeChild(pdfContent); const imgData = canvas.toDataURL('image/png'); const pdf = new jsPDF('p', 'mm', 'a4'); const pdfWidth = pdf.internal.pageSize.getWidth(); const pdfHeight = pdf.internal.pageSize.getHeight(); const canvasWidth = canvas.width; const canvasHeight = canvas.height; const ratio = canvasWidth / canvasHeight; const imgWidth = pdfWidth - 20; // A4 width with 10mm margins const imgHeight = imgWidth / ratio; let heightLeft = imgHeight; let position = 10; // Top margin pdf.addImage(imgData, 'PNG', 10, position, imgWidth, imgHeight); heightLeft -= pdfHeight; while (heightLeft >= 0) { position = heightLeft - imgHeight + 10; // 10mm margin pdf.addPage(); pdf.addImage(imgData, 'PNG', 10, position, imgWidth, imgHeight); heightLeft -= pdfHeight; } pdf.save('server-maintenance-checklist.pdf'); }).catch(err => { console.error('SMC Tool: PDF generation failed.', err); alert('An error occurred while generating the PDF.'); // Ensure removal of temp element on error if (document.body.contains(pdfContent)) { document.body.removeChild(pdfContent); } }); } // --- Event Listeners --- // Tab buttons tabs.forEach((tab, index) => { tab.addEventListener('click', () => showSmcTab(index)); }); // Next/Prev buttons if (prevBtn) { prevBtn.addEventListener('click', () => showSmcTab(currentTabIndex - 1)); } if (nextBtn) { nextBtn.addEventListener('click', () => showSmcTab(currentTabIndex + 1)); } // Custom Task buttons customTaskButtons.forEach(button => { button.addEventListener('click', () => { const frequency = button.getAttribute('data-frequency'); if (frequency) { addSmcCustomTask(frequency); } }); }); // Generate button if (generateBtn) { generateBtn.addEventListener('click', generateSmcChecklist); } // PDF Download button if (downloadPdfBtn) { downloadPdfBtn.addEventListener('click', downloadSmcPdf); } // Initialize showSmcTab(0); // Show the first tab (Dashboard) by default });
Scroll to Top