pump-doctor-pro / script.js
MavinGC's picture
Create an app that resolves all kinds of centrifugal pump problems, diagnoses, and more based on optimizations by the use of calculations with inputs and results. It should also have the ability to display pump & motor details inputs.
2140345 verified
Raw History Blame Contribute Delete
1.83 kB
// Shared functions across the application
// Load recent calculations on homepage
document.addEventListener('DOMContentLoaded', function() {
if (document.getElementById('recentCalculations')) {
loadRecentCalculations();
}
});
function loadRecentCalculations() {
const calculations = JSON.parse(localStorage.getItem('pumpCalculations') || '[]');
const tableBody = document.getElementById('recentCalculations');
if (calculations.length === 0) {
tableBody.innerHTML = '<tr><td colspan="6" class="py-4 text-center text-gray-400">No recent calculations found</td></tr>';
return;
}
tableBody.innerHTML = calculations.slice(0, 5).map(calc => `
<tr class="border-b border-slate-700 hover:bg-slate-700 transition-colors">
<td class="py-3">${calc.date}</td>
<td>${calc.type.charAt(0).toUpperCase() + calc.type.slice(1)}</td>
<td>${calc.flowRate} m³/h</td>
<td>${calc.head} m</td>
<td>${calc.efficiency}</td>
<td>
<a href="calculator.html" class="text-primary hover:text-red-400 transition-colors">
<i data-feather="repeat" class="w-4 h-4"></i>
</a>
</td>
</tr>
`).join('');
feather.replace();
}
// Theme toggle functionality
function toggleDarkMode() {
const html = document.documentElement;
html.classList.toggle('dark');
localStorage.setItem('darkMode', html.classList.contains('dark'));
}
// Check for saved theme preference
if (localStorage.getItem('darkMode') === 'false') {
document.documentElement.classList.remove('dark');
}
// Format numbers with units
function formatNumber(value, unit) {
if (isNaN(value)) return '-';
return `${parseFloat(value.toFixed(2))} ${unit}`;
}