450ae37f42
- server/routes/weather.js: OpenWeatherMap-Proxy (aktuelles Wetter + 3-Tage-Forecast, 30-min-Cache, graceful fallback wenn kein API-Key gesetzt) - public/pages/dashboard.js: Weather-Widget parallel mit Dashboard-Daten laden - public/styles/dashboard.css: Weather-Widget-Styles (Gradient, Forecast-Strip) - server/services/recurrence.js: RRULE-Parser (FREQ=DAILY/WEEKLY/MONTHLY, BYDAY, INTERVAL, UNTIL) + nextOccurrence()-Funktion - server/routes/tasks.js: Bei PATCH /:id/status = done → nächste Instanz wiederkehrender Aufgaben automatisch anlegen - public/pages/tasks.js: Kanban-Ansicht (3 Spalten: Offen/In Bearbeitung/Erledigt) mit HTML5 Drag & Drop, View-Toggle (Liste/Kanban) - public/styles/tasks.css: Kanban-Board-Styles (Spalten, Cards, Drag-over-Highlight) - public/sw.js: Cache-Version auf v2, alle Modul-CSS-Dateien im APP_SHELL-Cache Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
86 lines
2.3 KiB
JavaScript
86 lines
2.3 KiB
JavaScript
/**
|
|
* Modul: Service Worker
|
|
* Zweck: Offline-Fähigkeit (App-Shell-Caching), Hintergrund-Sync
|
|
* Abhängigkeiten: keine
|
|
*/
|
|
|
|
const CACHE_NAME = 'oikos-v2';
|
|
|
|
// App-Shell-Ressourcen, die offline verfügbar sein sollen
|
|
const APP_SHELL = [
|
|
'/',
|
|
'/index.html',
|
|
'/api.js',
|
|
'/router.js',
|
|
'/styles/tokens.css',
|
|
'/styles/reset.css',
|
|
'/styles/layout.css',
|
|
'/styles/login.css',
|
|
'/styles/dashboard.css',
|
|
'/styles/tasks.css',
|
|
'/styles/shopping.css',
|
|
'/styles/meals.css',
|
|
'/styles/calendar.css',
|
|
'/styles/notes.css',
|
|
'/styles/contacts.css',
|
|
'/styles/budget.css',
|
|
'/manifest.json',
|
|
];
|
|
|
|
// --------------------------------------------------------
|
|
// Install: App-Shell cachen
|
|
// --------------------------------------------------------
|
|
self.addEventListener('install', (event) => {
|
|
event.waitUntil(
|
|
caches.open(CACHE_NAME).then((cache) => cache.addAll(APP_SHELL))
|
|
);
|
|
self.skipWaiting();
|
|
});
|
|
|
|
// --------------------------------------------------------
|
|
// Activate: Alte Caches löschen
|
|
// --------------------------------------------------------
|
|
self.addEventListener('activate', (event) => {
|
|
event.waitUntil(
|
|
caches.keys().then((keys) =>
|
|
Promise.all(
|
|
keys.filter((key) => key !== CACHE_NAME).map((key) => caches.delete(key))
|
|
)
|
|
)
|
|
);
|
|
self.clients.claim();
|
|
});
|
|
|
|
// --------------------------------------------------------
|
|
// Fetch: Netzwerk-First für API, Cache-First für App-Shell
|
|
// --------------------------------------------------------
|
|
self.addEventListener('fetch', (event) => {
|
|
const { request } = event;
|
|
const url = new URL(request.url);
|
|
|
|
// API-Requests: immer Netzwerk (kein Caching von Nutzerdaten)
|
|
if (url.pathname.startsWith('/api/')) {
|
|
return; // Browser übernimmt
|
|
}
|
|
|
|
// App-Shell: Cache-First, Fallback Netzwerk
|
|
event.respondWith(
|
|
caches.match(request).then((cached) => {
|
|
if (cached) return cached;
|
|
|
|
return fetch(request).then((response) => {
|
|
if (response.ok && response.type === 'basic') {
|
|
const copy = response.clone();
|
|
caches.open(CACHE_NAME).then((cache) => cache.put(request, copy));
|
|
}
|
|
return response;
|
|
}).catch(() => {
|
|
// Offline-Fallback für Seiten-Navigation
|
|
if (request.mode === 'navigate') {
|
|
return caches.match('/index.html');
|
|
}
|
|
});
|
|
})
|
|
);
|
|
});
|