MikeH222222's picture
want the front end to search our .pdf quick fix guides
154b83f verified
Raw History Blame Contribute Delete
11.3 kB
document.addEventListener('DOMContentLoaded', function() {
const form = document.getElementById('troubleshootForm');
const resultsContainer = document.getElementById('resultsContainer');
const solutionsList = document.getElementById('solutionsList');
// Database of solutions and PDF documents
const solutionsDatabase = {
"pdf": [
{
title: "User Manual",
description: "Complete user manual for your coffee machine",
pdfUrl: "/manuals/user-manual.pdf",
difficulty: "Easy",
time: "Varies"
},
{
title: "Installation Guide",
description: "Step-by-step installation instructions",
pdfUrl: "/manuals/installation-guide.pdf",
difficulty: "Medium",
time: "30 minutes"
},
{
title: "Troubleshooting Guide",
description: "Comprehensive troubleshooting reference",
pdfUrl: "/manuals/troubleshooting-guide.pdf",
difficulty: "Easy",
time: "Varies"
},
{
title: "Cleaning Instructions",
description: "Detailed cleaning and maintenance procedures",
pdfUrl: "/manuals/cleaning-instructions.pdf",
difficulty: "Medium",
time: "20 minutes"
}
],
"no power": [
{
title: "Check Power Connection",
description: "Ensure the machine is properly plugged into a working power outlet. Try a different outlet to rule out electrical issues.",
steps: [
"Unplug the machine from the power source",
"Check the power cord for any visible damage",
"Plug into a different outlet",
"Try turning the machine on again"
],
difficulty: "Easy",
time: "2 minutes"
},
{
title: "Reset Circuit Breaker",
description: "The machine may have tripped an internal circuit breaker. Locate and reset the breaker switch.",
steps: [
"Locate the circuit breaker (usually at the back or bottom of the machine)",
"Press the reset button if available",
"Wait 30 seconds before turning the machine back on"
],
difficulty: "Medium",
time: "5 minutes"
}
],
"no water flow": [
{
title: "Check Water Tank",
description: "Ensure the water tank is properly seated and filled with fresh water.",
steps: [
"Remove and reinsert the water tank",
"Fill with fresh, cold water",
"Ensure tank is properly seated in its position"
],
difficulty: "Easy",
time: "1 minute"
},
{
title: "Descale the Machine",
description: "Mineral buildup may be blocking water flow. Perform a descaling cycle.",
steps: [
"Prepare descaling solution as per manufacturer instructions",
"Run descaling cycle",
"Rinse thoroughly with fresh water"
],
difficulty: "Medium",
time: "20 minutes"
}
],
"weak coffee": [
{
title: "Adjust Grind Size",
description: "If using fresh beans, try a finer grind setting for stronger extraction.",
steps: [
"Access grind settings (consult your manual for location)",
"Adjust to a finer setting",
"Brew a test shot and adjust further if needed"
],
difficulty: "Easy",
time: "3 minutes"
},
{
title: "Clean Brew Group",
description: "Coffee oils and residue can affect flavor. Clean the brew group thoroughly.",
steps: [
"Remove brew group according to manual instructions",
"Clean with warm water and soft brush",
"Dry completely before reinserting"
],
difficulty: "Medium",
time: "10 minutes"
}
]
};
form.addEventListener('submit', function(e) {
e.preventDefault();
const machineModel = document.getElementById('machineModel').value;
const issueDescription = document.getElementById('issueDescription').value.toLowerCase();
// Simple keyword matching (in a real app, this would be more sophisticated)
let matchedSolutions = [];
if (issueDescription.includes('power') || issueDescription.includes('turn on')) {
matchedSolutions = matchedSolutions.concat(solutionsDatabase['no power']);
}
if (issueDescription.includes('water') || issueDescription.includes('flow')) {
matchedSolutions = matchedSolutions.concat(solutionsDatabase['no water flow']);
}
if (issueDescription.includes('weak') || issueDescription.includes('taste') || issueDescription.includes('flavor')) {
matchedSolutions = matchedSolutions.concat(solutionsDatabase['weak coffee']);
}
// Enhanced PDF guide search
const pdfKeywords = ['manual', 'guide', 'document', 'pdf', 'instructions', 'reference', 'tutorial',
'quick fix', 'troubleshoot', 'how to', 'help', 'support', 'fix', 'solution'];
if (pdfKeywords.some(keyword => issueDescription.includes(keyword))) {
matchedSolutions = matchedSolutions.concat(solutionsDatabase['pdf']);
} else {
// Also show PDF guides for any technical issue
const technicalKeywords = ['power', 'water', 'flow', 'weak', 'taste', 'flavor', 'leak', 'noise',
'error', 'code', 'not working', 'broken', 'issue', 'problem'];
if (technicalKeywords.some(keyword => issueDescription.includes(keyword))) {
matchedSolutions = matchedSolutions.concat(solutionsDatabase['pdf'].filter(pdf =>
pdf.title.toLowerCase().includes('troubleshooting') ||
pdf.title.toLowerCase().includes('guide')
));
}
}
// If no matches, show a generic message
if (matchedSolutions.length === 0) {
matchedSolutions.push({
title: "No Exact Match Found",
description: "We couldn't find an exact match for your issue, but here are some general troubleshooting steps:",
steps: [
"Turn the machine off and unplug it for 2 minutes, then restart",
"Check all connections and water reservoirs",
"Consult your user manual for model-specific guidance",
"Contact our support team for further assistance"
],
difficulty: "Varies",
time: "Varies"
});
}
// Display solutions
displaySolutions(matchedSolutions);
});
function displaySolutions(solutions) {
solutionsList.innerHTML = '';
solutions.forEach((solution, index) => {
const solutionElement = document.createElement('div');
solutionElement.className = `solution-card bg-gray-50 rounded-lg p-6 border border-gray-200`;
solutionElement.style.animationDelay = `${index * 0.1}s`;
solutionElement.innerHTML = `
<div class="flex justify-between items-start mb-4">
<h3 class="text-xl font-semibold text-gray-800">${solution.title}</h3>
<div class="flex items-center space-x-2">
<span class="px-2 py-1 text-xs font-medium rounded-full ${solution.difficulty === 'Easy' ? 'bg-green-100 text-green-800' : 'bg-yellow-100 text-yellow-800'}">
${solution.difficulty}
</span>
<span class="px-2 py-1 text-xs font-medium rounded-full bg-blue-100 text-blue-800">
${solution.time}
</span>
</div>
</div>
<p class="text-gray-600 mb-4">${solution.description}</p>
<div class="space-y-2">
<h4 class="font-medium text-gray-700">Steps:</h4>
<ol class="list-decimal list-inside space-y-1 text-gray-600">
${solution.steps.map(step => `<li>${step}</li>`).join('')}
</ol>
</div>
${solution.pdfUrl ? `
<div class="mt-4">
<h4 class="font-medium text-gray-700 mb-2">Quick Fix Guide:</h4>
<div class="flex items-center mb-3">
<i data-feather="file-text" class="text-blue-500 mr-2"></i>
<span class="text-sm text-gray-600">${solution.title}</span>
</div>
<pdf-viewer></pdf-viewer>
<div class="mt-3 flex space-x-3">
<a href="${solution.pdfUrl}" target="_blank" class="inline-flex items-center px-3 py-2 border border-transparent text-sm leading-4 font-medium rounded-md text-white bg-blue-600 hover:bg-blue-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-blue-500">
<i data-feather="external-link" class="mr-1 w-4 h-4"></i>
Open Full Screen
</a>
<a href="${solution.pdfUrl}" download class="inline-flex items-center px-3 py-2 border border-gray-300 text-sm leading-4 font-medium rounded-md text-gray-700 bg-white hover:bg-gray-50 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-blue-500">
<i data-feather="download" class="mr-1 w-4 h-4"></i>
Download
</a>
</div>
<script>
// Load the PDF after the element is rendered
setTimeout(() => {
const viewer = document.querySelector('#solution-${index} pdf-viewer');
if (viewer) viewer.loadPdf('${solution.pdfUrl}');
}, 100);
</script>
</div>
` : ''}
${index < solutions.length - 1 ? '<div class="border-t border-gray-200 mt-6 pt-6"></div>' : ''}
`;
solutionsList.appendChild(solutionElement);
});
resultsContainer.classList.remove('hidden');
resultsContainer.scrollIntoView({ behavior: 'smooth' });
}
});