Solution Database Dashboard

Add New Solution

Customize Solution Categories

Enter categories separated by commas. This will update the category dropdowns.

No solutions found matching your criteria.

'; return; } filtered.forEach(s => { const card = document.createElement('div'); card.className = 'sdd-solution-card'; card.innerHTML = `

${s.title}

${s.category}

${s.problem.substring(0, 100)}${s.problem.length > 100 ? '...' : ''}

`; grid.appendChild(card); }); } function populateCategoryDropdowns() { const selects = [document.getElementById('sdd-category-filter'), document.getElementById('sdd-category')]; selects.forEach(sel => { const currentVal = sel.value; sel.innerHTML = (sel.id === 'sdd-category-filter') ? '' : ''; config.categories.forEach(cat => { sel.innerHTML += ``; }); sel.value = currentVal; }); } // --- EVENT HANDLERS & HELPERS --- window.editSolution = (id) => { const solution = solutions.find(s => s.id === id); if (!solution) return; document.getElementById('sdd-form-title').textContent = 'Edit Solution'; document.getElementById('sdd-add-edit-tab-btn').textContent = 'Edit Solution'; document.getElementById('sdd-solution-id').value = solution.id; document.getElementById('sdd-title').value = solution.title; document.getElementById('sdd-category').value = solution.category; document.getElementById('sdd-keywords').value = solution.keywords; document.getElementById('sdd-problem').value = solution.problem; document.getElementById('sdd-solution').value = solution.solution; document.getElementById('sdd-add-edit-tab-btn').click(); }; window.sdd_cancelEdit = () => { document.getElementById('sdd-solution-form').reset(); document.getElementById('sdd-solution-id').value = ''; document.getElementById('sdd-form-title').textContent = 'Add New Solution'; document.getElementById('sdd-add-edit-tab-btn').textContent = 'Add Solution'; document.querySelector('.sdd-tab-button[onclick*="sdd-dashboard"]').click(); }; window.deleteSolution = (id) => { const index = solutions.findIndex(s => s.id === id); if(index !== -1 && confirm(`Are you sure you want to delete "${solutions[index].title}"?`)){ solutions.splice(index, 1); renderSolutions(); } }; function handleFormSubmit(e) { e.preventDefault(); const id = parseInt(document.getElementById('sdd-solution-id').value); const solutionData = { title: document.getElementById('sdd-title').value, category: document.getElementById('sdd-category').value, keywords: document.getElementById('sdd-keywords').value, problem: document.getElementById('sdd-problem').value, solution: document.getElementById('sdd-solution').value, }; if (id) { // Editing const index = solutions.findIndex(s => s.id === id); solutions[index] = { ...solutions[index], ...solutionData }; } else { // Adding solutionData.id = nextSolutionId++; solutions.unshift(solutionData); } sdd_cancelEdit(); // Reset form and switch tab renderSolutions(); } function saveConfig() { config.categories = document.getElementById('sdd-config-categories').value.split(',').map(s => s.trim()).filter(Boolean); populateCategoryDropdowns(); alert('Categories saved!'); } window.downloadSolution = (id) => { const solution = solutions.find(s => s.id === id); if (!solution) return; const { jsPDF } = window.jspdf; const pdf = new jsPDF('p', 'pt', 'a4'); const pageHeight = pdf.internal.pageSize.getHeight(); let y = 60; const margin = 40; const maxWidth = pdf.internal.pageSize.getWidth() - (margin * 2); const addText = (text, size, style, spaceAfter = 10) => { if (y > pageHeight - 50) { pdf.addPage(); y = 60; } pdf.setFontSize(size).setFont(undefined, style); const lines = pdf.splitTextToSize(text, maxWidth); pdf.text(lines, margin, y); y += (lines.length * size * 0.7) + spaceAfter; } addText(solution.title, 22, 'bold', 20); addText(`Category: ${solution.category}`, 10, 'italic', 25); addText('Problem Description', 14, 'bold', 15); addText(solution.problem, 11, 'normal', 25); addText('Solution / Resolution', 14, 'bold', 15); addText(solution.solution, 11, 'normal', 25); pdf.save(`Solution_${solution.id}_${solution.title.replace(/\s+/g, '_')}.pdf`); }; // --- INITIALIZATION --- function init() { document.getElementById('sdd-config-categories').value = config.categories.join(', '); populateCategoryDropdowns(); renderSolutions(); // Add event listeners document.getElementById('sdd-solution-form').addEventListener('submit', handleFormSubmit); document.getElementById('sdd-save-config').addEventListener('click', saveConfig); document.getElementById('sdd-search-box').addEventListener('input', renderSolutions); document.getElementById('sdd-category-filter').addEventListener('change', renderSolutions); } init(); });
Scroll to Top