Initial commit

This commit is contained in:
iulian 2025-12-26 00:52:56 +00:00
commit 983cee0320
322 changed files with 57174 additions and 0 deletions

View file

@ -0,0 +1,752 @@
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
:root {
--primary: #5b5fc7;
--primary-dark: #4338ca;
--success: #10b981;
--danger: #ef4444;
--glass-bg: rgba(255, 255, 255, 0.08);
--glass-border: rgba(255, 255, 255, 0.15);
--text-primary: #ffffff;
--text-secondary: rgba(255, 255, 255, 0.8);
}
body {
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
background: linear-gradient(135deg, #4c1d95 0%, #3b0764 100%);
min-height: 100vh;
color: var(--text-primary);
line-height: 1.6;
}
.alert {
position: fixed !important;
top: 80px !important;
right: 20px !important;
left: auto !important;
max-width: 350px !important;
width: auto !important;
padding: 1rem 1.5rem !important;
margin: 0 !important;
border-radius: 15px !important;
box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5) !important;
z-index: 9999 !important;
animation: slideIn 0.3s ease-out !important;
}
@keyframes slideIn {
from { transform: translateX(400px); opacity: 0; }
to { transform: translateX(0); opacity: 1; }
}
@keyframes slideOut {
from { transform: translateX(0); opacity: 1; }
to { transform: translateX(400px); opacity: 0; }
}
.alert.hiding { animation: slideOut 0.3s ease-in forwards !important; }
.alert-success { background: rgba(16, 185, 129, 0.25) !important; border: 1px solid var(--success) !important; }
.alert-error { background: rgba(239, 68, 68, 0.25) !important; border: 1px solid var(--danger) !important; }
.alert-info { background: rgba(99, 102, 241, 0.25) !important; border: 1px solid var(--primary) !important; }
.glass-card {
background: var(--glass-bg);
backdrop-filter: blur(20px);
-webkit-backdrop-filter: blur(20px);
border: 1px solid var(--glass-border);
border-radius: 20px;
padding: 2rem;
box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
}
.container { max-width: 1200px; margin: 0 auto; padding: 2rem 1rem; }
.auth-container { display: flex; justify-content: center; align-items: center; min-height: 80vh; }
.auth-card { max-width: 500px; width: 100%; }
.auth-card h1 { font-size: 2rem; margin-bottom: 0.5rem; text-align: center; }
.subtitle { text-align: center; color: var(--text-secondary); margin-bottom: 2rem; }
.auth-form { display: flex; flex-direction: column; gap: 1.5rem; }
.form-group { display: flex; flex-direction: column; }
.form-group label { margin-bottom: 0.5rem; font-weight: 500; color: var(--text-primary); }
.form-group input {
padding: 0.75rem;
border: 1px solid var(--glass-border);
border-radius: 10px;
background: rgba(255, 255, 255, 0.12);
color: var(--text-primary);
font-size: 1rem;
}
.form-group input:focus { outline: none; border-color: var(--primary); background: rgba(255, 255, 255, 0.18); }
.btn {
padding: 0.75rem 1.5rem;
border: none;
border-radius: 10px;
font-size: 1rem;
font-weight: 600;
cursor: pointer;
transition: all 0.3s;
text-decoration: none;
display: inline-block;
text-align: center;
text-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
}
.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover { background: var(--primary-dark); transform: translateY(-2px); box-shadow: 0 4px 12px rgba(99, 102, 241, 0.5); }
.btn-secondary { background: rgba(255, 255, 255, 0.12); color: var(--text-primary); border: 1px solid var(--glass-border); }
.btn-secondary:hover { background: rgba(255, 255, 255, 0.2); }
.btn-danger { background: var(--danger); color: white; }
.btn-danger:hover { background: #dc2626; }
.btn-small { padding: 0.5rem 1rem; font-size: 0.875rem; }
.auth-link { text-align: center; margin-top: 1rem; color: var(--text-secondary); }
.auth-link a { color: #a5b4fc; text-decoration: none; }
.empty-state { text-align: center; padding: 3rem 2rem; }
.empty-state h2 { margin-bottom: 1rem; }
.empty-state p { color: var(--text-secondary); margin-bottom: 1.5rem; }
.stats-container {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
gap: 1.5rem;
margin-bottom: 2rem;
}
.stat-card { text-align: center; }
.stat-card h3 { color: var(--text-secondary); font-size: 1rem; margin-bottom: 0.5rem; }
.stat-value { font-size: 2rem; font-weight: bold; }
.glass-nav {
background: rgba(59, 7, 100, 0.5);
backdrop-filter: blur(20px);
-webkit-backdrop-filter: blur(20px);
border-bottom: 1px solid var(--glass-border);
padding: 1rem 0;
margin-bottom: 2rem;
}
.nav-container {
max-width: 1400px;
margin: 0 auto;
padding: 0 1rem;
display: flex;
justify-content: space-between;
align-items: center;
gap: 1.5rem;
}
.nav-brand {
font-size: 1.5rem;
font-weight: bold;
color: var(--text-primary);
text-decoration: none;
display: flex;
align-items: center;
gap: 0.5rem;
flex-shrink: 0;
}
.nav-logo {
width: 32px;
height: 32px;
}
/* Navigation Search */
.nav-search {
flex: 0 1 400px;
min-width: 200px;
}
.nav-search-form {
display: flex;
gap: 0.5rem;
}
.nav-search-input {
flex: 1;
padding: 0.5rem 1rem;
background: rgba(255, 255, 255, 0.05);
border: 1px solid rgba(255, 255, 255, 0.1);
border-radius: 24px;
color: var(--text-primary);
font-size: 0.9rem;
transition: all 0.3s;
}
.nav-search-input:focus {
outline: none;
background: rgba(255, 255, 255, 0.08);
border-color: rgba(102, 126, 234, 0.5);
box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}
.nav-search-input::placeholder {
color: var(--text-secondary);
}
.nav-search-btn {
padding: 0.5rem 1rem;
background: transparent;
border: none;
color: var(--text-primary);
cursor: pointer;
font-size: 1rem;
transition: opacity 0.3s;
}
.nav-search-btn:hover {
opacity: 0.7;
}
.nav-links {
display: flex;
gap: 1.5rem;
flex-wrap: wrap;
align-items: center;
}
.nav-links a {
color: var(--text-primary);
text-decoration: none;
transition: opacity 0.3s;
font-weight: 500;
white-space: nowrap;
}
.nav-links a:hover { opacity: 0.7; }
.metrics-section {
padding: 2rem;
margin-top: 0;
margin-bottom: 2rem;
max-height: 550px !important;
overflow: hidden !important;
}
.metrics-header {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 1.5rem;
flex-wrap: wrap;
gap: 1rem;
}
.metrics-header h2 { margin: 0; }
.metrics-controls { display: flex; gap: 1rem; }
.metric-select {
padding: 0.75rem 1rem;
border: 1px solid var(--glass-border);
border-radius: 10px;
background: rgba(255, 255, 255, 0.12);
color: var(--text-primary);
font-size: 1rem;
cursor: pointer;
min-width: 150px;
font-weight: 500;
}
.metric-select:focus { outline: none; border-color: var(--primary); background: rgba(255, 255, 255, 0.18); }
.metric-select option { background: #3b0764; color: white; }
.charts-container {
display: grid;
grid-template-columns: 320px 1fr;
gap: 1.5rem;
margin-top: 1rem;
height: 380px !important;
max-height: 380px !important;
}
.chart-box {
background: rgba(255, 255, 255, 0.06);
padding: 1rem;
border-radius: 15px;
border: 1px solid var(--glass-border);
height: 380px !important;
max-height: 380px !important;
overflow: hidden !important;
display: flex;
flex-direction: column;
}
.chart-box h3 { margin: 0 0 1rem 0; font-size: 1rem; text-align: center; flex-shrink: 0; }
.chart-box canvas { max-width: 100% !important; max-height: 320px !important; height: 320px !important; }
.chart-box-wide { height: 380px !important; max-height: 380px !important; }
.categories-grid {
display: grid;
grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
gap: 1.5rem;
margin-top: 2rem;
}
.category-card { text-decoration: none; color: inherit; cursor: pointer; transition: all 0.3s ease; display: block; }
.category-card:hover { transform: translateY(-5px); box-shadow: 0 12px 40px rgba(0, 0, 0, 0.4); }
.category-content h3 { margin-bottom: 0.5rem; font-size: 1.3rem; }
.category-description { color: var(--text-secondary); font-size: 0.9rem; margin: 0.5rem 0 1rem; }
.category-amount { font-size: 2rem; font-weight: bold; color: var(--success); margin: 1rem 0; }
.category-info { color: var(--text-secondary); font-size: 0.85rem; }
.section-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 1.5rem; }
.form-group textarea { padding: 0.75rem; border: 1px solid var(--glass-border); border-radius: 10px; background: rgba(255, 255, 255, 0.12); color: var(--text-primary); font-size: 1rem; font-family: inherit; resize: vertical; }
.form-group textarea:focus { outline: none; border-color: var(--primary); background: rgba(255, 255, 255, 0.18); }
.form-group input[type="color"] { height: 50px; cursor: pointer; }
.form-actions { display: flex; gap: 1rem; justify-content: flex-end; margin-top: 1rem; }
input[type="file"] { padding: 0.5rem; background: rgba(255, 255, 255, 0.12); border: 1px solid var(--glass-border); border-radius: 10px; color: var(--text-primary); }
@media (max-width: 1024px) {
.charts-container { grid-template-columns: 1fr; height: auto !important; }
.chart-box { height: 350px !important; }
.metrics-controls { flex-direction: column; width: 100%; }
.metric-select { width: 100%; }
.nav-container { flex-direction: column; gap: 1rem; }
}
/* SETTINGS PAGE */
.settings-container {
max-width: 1000px;
margin: 0 auto;
}
.settings-container h1 {
margin-bottom: 2rem;
font-size: 2rem;
}
.settings-tabs {
display: flex;
gap: 0.5rem;
margin-bottom: 2rem;
border-bottom: 2px solid var(--glass-border);
flex-wrap: wrap;
}
.tab-btn {
padding: 1rem 1.5rem;
background: transparent;
border: none;
color: var(--text-secondary);
cursor: pointer;
font-size: 1rem;
font-weight: 500;
border-bottom: 3px solid transparent;
transition: all 0.3s;
}
.tab-btn:hover {
color: var(--text-primary);
background: rgba(255, 255, 255, 0.05);
}
.tab-btn.active {
color: var(--text-primary);
border-bottom-color: var(--primary);
}
.tab-content {
display: none;
}
.tab-content.active {
display: block;
}
.tags-grid {
display: grid;
grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
gap: 1rem;
margin-top: 1.5rem;
}
.tag-item {
padding: 1rem;
display: flex;
justify-content: space-between;
align-items: center;
}
.tag-name {
font-weight: 500;
font-size: 1.1rem;
}
.empty-message {
color: var(--text-secondary);
text-align: center;
padding: 2rem;
}
.users-table {
width: 100%;
border-collapse: collapse;
margin-top: 1.5rem;
}
.users-table th,
.users-table td {
padding: 1rem;
text-align: left;
border-bottom: 1px solid var(--glass-border);
}
.users-table th {
font-weight: 600;
color: var(--text-secondary);
}
.users-table tr:hover {
background: rgba(255, 255, 255, 0.05);
}
.form-container {
max-width: 600px;
margin: 0 auto;
}
.form-card h1 {
margin-bottom: 2rem;
font-size: 1.8rem;
}
.form-group small {
display: block;
margin-top: 0.25rem;
color: var(--text-secondary);
font-size: 0.875rem;
}
input[type="checkbox"] {
width: auto;
margin-right: 0.5rem;
}
@media (max-width: 768px) {
.settings-tabs {
flex-direction: column;
}
.tab-btn {
width: 100%;
text-align: left;
}
.users-table {
font-size: 0.875rem;
}
.users-table th,
.users-table td {
padding: 0.5rem;
}
}
/* FINA Logo Styling */
.nav-logo {
height: 32px;
width: 32px;
margin-right: 0.5rem;
border-radius: 50%;
object-fit: cover;
vertical-align: middle;
}
.nav-brand {
display: flex;
align-items: center;
gap: 0.5rem;
}
.nav-brand span {
font-size: 1.5rem;
font-weight: bold;
}
/* Language Switcher */
.language-switcher {
position: relative;
display: inline-block;
z-index: 9999;
}
.language-btn {
background: transparent;
border: none;
font-size: 1.5rem;
cursor: pointer;
padding: 0.5rem;
transition: transform 0.2s;
}
.language-btn:hover {
transform: scale(1.1);
}
.language-menu {
display: none;
position: absolute;
top: 100%;
right: 0;
margin-top: 0.5rem;
background: var(--glass-bg);
backdrop-filter: blur(20px);
-webkit-backdrop-filter: blur(20px);
border: 1px solid var(--glass-border);
border-radius: 10px;
min-width: 150px;
box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
z-index: 9999;
overflow: hidden;
}
.language-menu.show {
display: block;
animation: fadeIn 0.2s ease-out;
}
@keyframes fadeIn {
from { opacity: 0; transform: translateY(-10px); }
to { opacity: 1; transform: translateY(0); }
}
.language-option {
display: block;
padding: 0.75rem 1rem;
color: var(--text-primary);
text-decoration: none;
transition: background 0.2s;
}
.language-option:hover {
background: rgba(255, 255, 255, 0.1);
}
/* PWA Install Prompt Styles */
.pwa-prompt {
position: fixed;
bottom: 20px;
left: 50%;
transform: translateX(-50%);
max-width: 500px;
width: calc(100% - 40px);
z-index: 10000;
animation: slideUp 0.3s ease-out;
}
@keyframes slideUp {
from { transform: translateX(-50%) translateY(100px); opacity: 0; }
to { transform: translateX(-50%) translateY(0); opacity: 1; }
}
.pwa-prompt-content {
display: flex;
align-items: center;
gap: 1rem;
flex-wrap: wrap;
}
.pwa-icon {
width: 48px;
height: 48px;
border-radius: 12px;
}
.pwa-prompt-text {
flex: 1;
min-width: 150px;
}
.pwa-prompt-text h3 {
margin: 0;
font-size: 1.1rem;
color: var(--text-primary);
}
.pwa-prompt-text p {
margin: 0.25rem 0 0 0;
font-size: 0.9rem;
color: var(--text-secondary);
}
.pwa-prompt-actions {
display: flex;
gap: 0.5rem;
margin-left: auto;
}
.pwa-prompt-actions .btn {
padding: 0.5rem 1rem;
font-size: 0.9rem;
}
@media (max-width: 600px) {
.pwa-prompt-content {
flex-direction: column;
text-align: center;
}
.pwa-prompt-actions {
margin-left: 0;
width: 100%;
}
.pwa-prompt-actions .btn {
flex: 1;
}
}
/* Enhanced Mobile Responsiveness for PWA */
@media (max-width: 768px) {
/* Larger touch targets for mobile */
.btn {
min-height: 44px;
padding: 0.875rem 1.5rem;
font-size: 1rem;
}
.btn-small {
min-height: 40px;
padding: 0.625rem 1.25rem;
}
/* Stack header actions vertically on mobile */
.page-header {
flex-direction: column;
gap: 1rem;
align-items: stretch !important;
}
.header-actions {
display: flex;
flex-direction: column;
gap: 0.75rem;
width: 100%;
}
.header-actions .btn,
.header-actions form {
width: 100%;
}
.header-actions form button {
width: 100%;
}
/* Navigation adjustments for mobile */
.nav-container {
flex-wrap: wrap;
gap: 1rem;
}
.nav-brand {
font-size: 1.2rem;
}
.nav-logo {
width: 28px;
height: 28px;
}
.nav-search {
order: 3;
flex: 1 1 100%;
max-width: 100%;
}
.nav-search-input {
padding: 0.625rem 1rem;
min-height: 44px;
}
.nav-links {
gap: 0.75rem;
font-size: 0.9rem;
}
.nav-links a {
padding: 0.5rem 0.75rem;
background: rgba(255, 255, 255, 0.05);
border-radius: 8px;
min-height: 40px;
display: flex;
align-items: center;
}
/* Better mobile navigation */
.nav-links {
flex-wrap: wrap;
gap: 0.75rem;
justify-content: center;
}
.nav-links a {
padding: 0.5rem 0.75rem;
background: rgba(255, 255, 255, 0.1);
border-radius: 8px;
min-height: 40px;
display: flex;
align-items: center;
}
/* Subscription cards mobile-friendly */
.subscription-item {
flex-direction: column !important;
align-items: flex-start !important;
gap: 1rem;
}
.subscription-info {
width: 100%;
}
.subscription-actions {
width: 100%;
display: flex;
gap: 0.5rem;
}
.subscription-actions .btn,
.subscription-actions form {
flex: 1;
}
/* Stats grid mobile */
.stats-container {
grid-template-columns: 1fr;
gap: 1rem;
}
/* Form improvements */
.form-group input,
.form-group select,
.form-group textarea {
font-size: 16px; /* Prevents iOS zoom */
min-height: 44px;
}
/* Categories grid mobile */
.categories-grid {
grid-template-columns: 1fr;
gap: 1rem;
}
/* Suggestion cards mobile */
.suggestion-details {
grid-template-columns: 1fr 1fr !important;
gap: 0.75rem !important;
}
.suggestion-actions {
flex-direction: column !important;
width: 100%;
}
.suggestion-actions .btn,
.suggestion-actions form {
width: 100% !important;
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 863 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 863 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 863 KiB

File diff suppressed because one or more lines are too long

View file

@ -0,0 +1,187 @@
// PWA Service Worker Registration
if ('serviceWorker' in navigator) {
window.addEventListener('load', () => {
navigator.serviceWorker.register('/static/js/service-worker.js')
.then(registration => {
console.log('[PWA] Service Worker registered successfully:', registration.scope);
// Check for updates
registration.addEventListener('updatefound', () => {
const newWorker = registration.installing;
newWorker.addEventListener('statechange', () => {
if (newWorker.state === 'installed' && navigator.serviceWorker.controller) {
console.log('[PWA] New version available! Refresh to update.');
// Optionally show a notification to the user
if (confirm('A new version of FINA is available. Reload to update?')) {
newWorker.postMessage({ type: 'SKIP_WAITING' });
window.location.reload();
}
}
});
});
})
.catch(error => {
console.log('[PWA] Service Worker registration failed:', error);
});
});
}
// PWA Install Prompt
let deferredPrompt;
const installPrompt = document.getElementById('pwa-install-prompt');
const installBtn = document.getElementById('pwa-install-btn');
const dismissBtn = document.getElementById('pwa-dismiss-btn');
// Check if already installed (standalone mode)
const isInstalled = () => {
return window.matchMedia('(display-mode: standalone)').matches ||
window.navigator.standalone === true ||
document.referrer.includes('android-app://');
};
// Detect iOS
const isIOS = () => {
return /iPad|iPhone|iPod/.test(navigator.userAgent) && !window.MSStream;
};
// Show iOS install instructions
function showIOSInstallPrompt() {
if (installPrompt) {
const promptText = installPrompt.querySelector('.pwa-prompt-text p');
if (promptText && isIOS() && !window.navigator.standalone) {
promptText.textContent = 'Tap Share button and then "Add to Home Screen"';
installBtn.style.display = 'none'; // Hide install button on iOS
}
}
}
window.addEventListener('beforeinstallprompt', (e) => {
// Prevent the default mini-infobar
e.preventDefault();
// Store the event for later use
deferredPrompt = e;
// Don't show if already installed
if (isInstalled()) {
return;
}
// Show custom install prompt if not dismissed
const dismissed = localStorage.getItem('pwa-install-dismissed');
const dismissedUntil = parseInt(dismissed || '0');
if (Date.now() > dismissedUntil && installPrompt) {
installPrompt.style.display = 'block';
}
});
// Handle iOS separately
if (isIOS() && !isInstalled()) {
const dismissed = localStorage.getItem('pwa-install-dismissed');
const dismissedUntil = parseInt(dismissed || '0');
if (Date.now() > dismissedUntil && installPrompt) {
setTimeout(() => {
installPrompt.style.display = 'block';
showIOSInstallPrompt();
}, 2000); // Show after 2 seconds
}
}
if (installBtn) {
installBtn.addEventListener('click', async () => {
if (!deferredPrompt) {
return;
}
// Show the install prompt
deferredPrompt.prompt();
// Wait for the user's response
const { outcome } = await deferredPrompt.userChoice;
console.log(`[PWA] User response: ${outcome}`);
// Clear the saved prompt since it can't be used again
deferredPrompt = null;
// Hide the prompt
installPrompt.style.display = 'none';
});
}
if (dismissBtn) {
dismissBtn.addEventListener('click', () => {
installPrompt.style.display = 'none';
// Remember dismissal for 7 days
localStorage.setItem('pwa-install-dismissed', Date.now() + (7 * 24 * 60 * 60 * 1000));
});
}
// Check if app is installed
window.addEventListener('appinstalled', () => {
console.log('[PWA] App installed successfully');
if (installPrompt) {
installPrompt.style.display = 'none';
}
localStorage.removeItem('pwa-install-dismissed');
});
// Online/Offline status
window.addEventListener('online', () => {
console.log('[PWA] Back online');
// Show notification or update UI
showToast('Connection restored', 'success');
});
window.addEventListener('offline', () => {
console.log('[PWA] Gone offline');
showToast('You are offline. Some features may be limited.', 'info');
});
// Toast notification function
function showToast(message, type = 'info') {
const toast = document.createElement('div');
toast.className = `alert alert-${type} glass-card`;
toast.textContent = message;
document.body.appendChild(toast);
setTimeout(() => {
toast.classList.add('hiding');
setTimeout(() => toast.remove(), 300);
}, 3000);
}
// Language menu toggle
function toggleLanguageMenu() {
const menu = document.getElementById('language-menu');
menu.classList.toggle('show');
}
// Close language menu when clicking outside
document.addEventListener('click', function(event) {
const switcher = document.querySelector('.language-switcher');
const menu = document.getElementById('language-menu');
if (menu && switcher && !switcher.contains(event.target)) {
menu.classList.remove('show');
}
});
document.addEventListener('DOMContentLoaded', function() {
console.log('Finance Tracker loaded');
// Auto-hide flash messages after 2 seconds
const alerts = document.querySelectorAll('.alert');
alerts.forEach(function(alert) {
// Add hiding animation after 2 seconds
setTimeout(function() {
alert.classList.add('hiding');
// Remove from DOM after animation completes
setTimeout(function() {
alert.remove();
}, 300); // Wait for animation to finish
}, 2000); // Show for 2 seconds
});
});

View file

@ -0,0 +1,161 @@
const CACHE_NAME = 'fina-v1';
const STATIC_CACHE = 'fina-static-v1';
const DYNAMIC_CACHE = 'fina-dynamic-v1';
// Assets to cache on install
const STATIC_ASSETS = [
'/',
'/static/css/style.css',
'/static/js/script.js',
'/static/js/chart.min.js',
'/static/images/fina-logo.png'
];
// Install event - cache static assets
self.addEventListener('install', event => {
console.log('[Service Worker] Installing...');
event.waitUntil(
caches.open(STATIC_CACHE)
.then(cache => {
console.log('[Service Worker] Caching static assets');
return cache.addAll(STATIC_ASSETS);
})
.then(() => self.skipWaiting())
);
});
// Activate event - clean up old caches
self.addEventListener('activate', event => {
console.log('[Service Worker] Activating...');
event.waitUntil(
caches.keys().then(cacheNames => {
return Promise.all(
cacheNames
.filter(name => name !== STATIC_CACHE && name !== DYNAMIC_CACHE)
.map(name => caches.delete(name))
);
}).then(() => self.clients.claim())
);
});
// Fetch event - network first, then cache
self.addEventListener('fetch', event => {
const { request } = event;
// Skip non-GET requests
if (request.method !== 'GET') {
return;
}
// Skip chrome extension and other non-http(s) requests
if (!request.url.startsWith('http')) {
return;
}
// API requests - network first, cache fallback
if (request.url.includes('/api/')) {
event.respondWith(
fetch(request)
.then(response => {
const responseClone = response.clone();
caches.open(DYNAMIC_CACHE).then(cache => {
cache.put(request, responseClone);
});
return response;
})
.catch(() => caches.match(request))
);
return;
}
// Static assets - cache first, network fallback
if (
request.url.includes('/static/') ||
request.url.endsWith('.css') ||
request.url.endsWith('.js') ||
request.url.endsWith('.png') ||
request.url.endsWith('.jpg') ||
request.url.endsWith('.jpeg') ||
request.url.endsWith('.gif') ||
request.url.endsWith('.svg')
) {
event.respondWith(
caches.match(request)
.then(cachedResponse => {
if (cachedResponse) {
return cachedResponse;
}
return fetch(request).then(response => {
const responseClone = response.clone();
caches.open(STATIC_CACHE).then(cache => {
cache.put(request, responseClone);
});
return response;
});
})
);
return;
}
// HTML pages - network first, cache fallback
event.respondWith(
fetch(request)
.then(response => {
const responseClone = response.clone();
caches.open(DYNAMIC_CACHE).then(cache => {
cache.put(request, responseClone);
});
return response;
})
.catch(() => {
return caches.match(request).then(cachedResponse => {
if (cachedResponse) {
return cachedResponse;
}
// Return offline page if available
return caches.match('/');
});
})
);
});
// Handle messages from clients
self.addEventListener('message', event => {
if (event.data && event.data.type === 'SKIP_WAITING') {
self.skipWaiting();
}
});
// Background sync for offline form submissions
self.addEventListener('sync', event => {
if (event.tag === 'sync-expenses') {
event.waitUntil(syncExpenses());
}
});
async function syncExpenses() {
// Placeholder for syncing offline data
console.log('[Service Worker] Syncing expenses...');
}
// Push notifications support (for future feature)
self.addEventListener('push', event => {
const options = {
body: event.data ? event.data.text() : 'New notification from FINA',
icon: '/static/images/fina-logo.png',
badge: '/static/images/fina-logo.png',
vibrate: [200, 100, 200]
};
event.waitUntil(
self.registration.showNotification('FINA', options)
);
});
// Notification click handler
self.addEventListener('notificationclick', event => {
event.notification.close();
event.waitUntil(
clients.openWindow('/')
);
});

View file

@ -0,0 +1,49 @@
{
"name": "FINA - Personal Finance Tracker",
"short_name": "FINA",
"description": "Track your expenses, manage categories, and visualize spending patterns",
"start_url": "/",
"display": "standalone",
"background_color": "#3b0764",
"theme_color": "#5b5fc7",
"orientation": "portrait-primary",
"categories": ["finance", "productivity"],
"icons": [
{
"src": "/static/images/fina-logo.png",
"sizes": "192x192",
"type": "image/png",
"purpose": "any maskable"
},
{
"src": "/static/images/fina-logo.png",
"sizes": "512x512",
"type": "image/png",
"purpose": "any maskable"
}
],
"shortcuts": [
{
"name": "Dashboard",
"short_name": "Dashboard",
"description": "View your expense dashboard",
"url": "/dashboard",
"icons": [{ "src": "/static/images/fina-logo.png", "sizes": "96x96" }]
},
{
"name": "New Category",
"short_name": "Category",
"description": "Create a new expense category",
"url": "/create-category",
"icons": [{ "src": "/static/images/fina-logo.png", "sizes": "96x96" }]
},
{
"name": "Subscriptions",
"short_name": "Subscriptions",
"description": "Manage recurring expenses",
"url": "/subscriptions",
"icons": [{ "src": "/static/images/fina-logo.png", "sizes": "96x96" }]
}
],
"screenshots": []
}