- Mount static files on /static endpoint - Configure Jinja2Templates with directory structure - Create base template with Pico.css, HTMX, Chart.js - Create all template subdirectories (auth, dashboard, keys, tokens, profile, components) - Create initial CSS and JS files - Add tests for static files and templates configuration Tests: 12 passing Coverage: 100% on new configuration code
50 lines
1.4 KiB
JavaScript
50 lines
1.4 KiB
JavaScript
// OpenRouter Monitor - Main JavaScript
|
|
|
|
// HTMX Configuration
|
|
document.addEventListener('DOMContentLoaded', function() {
|
|
// Configure HTMX to include CSRF token in requests
|
|
document.body.addEventListener('htmx:configRequest', function(evt) {
|
|
const csrfToken = document.querySelector('meta[name="csrf-token"]');
|
|
if (csrfToken) {
|
|
evt.detail.headers['X-CSRF-Token'] = csrfToken.content;
|
|
}
|
|
});
|
|
|
|
// Auto-hide alerts after 5 seconds
|
|
const alerts = document.querySelectorAll('.alert:not(.alert-permanent)');
|
|
alerts.forEach(function(alert) {
|
|
setTimeout(function() {
|
|
alert.style.opacity = '0';
|
|
setTimeout(function() {
|
|
alert.remove();
|
|
}, 300);
|
|
}, 5000);
|
|
});
|
|
});
|
|
|
|
// Utility function to format currency
|
|
function formatCurrency(amount) {
|
|
return new Intl.NumberFormat('en-US', {
|
|
style: 'currency',
|
|
currency: 'USD'
|
|
}).format(amount);
|
|
}
|
|
|
|
// Utility function to format date
|
|
function formatDate(dateString) {
|
|
return new Intl.DateTimeFormat('en-US', {
|
|
year: 'numeric',
|
|
month: 'short',
|
|
day: 'numeric',
|
|
hour: '2-digit',
|
|
minute: '2-digit'
|
|
}).format(new Date(dateString));
|
|
}
|
|
|
|
// Confirmation dialog for destructive actions
|
|
function confirmAction(message, callback) {
|
|
if (confirm(message)) {
|
|
callback();
|
|
}
|
|
}
|