From 95486c67372227fa298c85c774644dc3879ecbe8 Mon Sep 17 00:00:00 2001 From: Thomas Date: Tue, 3 Nov 2026 17:19:25 +0100 Subject: [PATCH] Mobiles UI verbessert --- CMBNet/static/css/mobile.css | 7 ++ CMBNet/static/js/sw.js | 2 +- CMBNet/static/js/views/mobile.js | 76 +++++++++++++++---- .../_mobile_notification_dialog.html | 14 ++++ CMBNet/templates/dispatcher_mobil.html | 10 ++- CMBNet/templates/gruppen.html | 10 ++- 6 files changed, 101 insertions(+), 18 deletions(-) create mode 100644 CMBNet/templates/_mobile_notification_dialog.html diff --git a/CMBNet/static/css/mobile.css b/CMBNet/static/css/mobile.css index 015997f..20e2980 100644 --- a/CMBNet/static/css/mobile.css +++ b/CMBNet/static/css/mobile.css @@ -413,6 +413,13 @@ html[data-theme="dark"] .mobile-chat-card.own { font-size: 0.85rem; } +.mobile-notification-text { + margin: 0; + font-size: 1rem; + white-space: pre-wrap; + overflow-wrap: anywhere; +} + .mobile-settings-row { display: flex; align-items: center; diff --git a/CMBNet/static/js/sw.js b/CMBNet/static/js/sw.js index 9914c07..281de43 100644 --- a/CMBNet/static/js/sw.js +++ b/CMBNet/static/js/sw.js @@ -5,7 +5,7 @@ * damit er sowohl die mobilen Views als auch die statischen Assets * kontrolliert. Der Cache-Name wird pro App-Wurzel gebildet. */ -const VERSION = 'cmbnet-pwa-v11'; +const VERSION = 'cmbnet-pwa-v12'; const BASE = new URL('./', self.location).href; const SHELL_CACHE = `${VERSION}-shell`; const TILE_CACHE = `${VERSION}-tiles`; diff --git a/CMBNet/static/js/views/mobile.js b/CMBNet/static/js/views/mobile.js index 7d77136..423f72b 100644 --- a/CMBNet/static/js/views/mobile.js +++ b/CMBNet/static/js/views/mobile.js @@ -788,9 +788,23 @@ function loadStreetPolyline(name) { const fragments = getStreetFragments(); const segments = fragments[name]; if (!Array.isArray(segments)) return; - const latlngs = []; + const street = state.streetById.get(Number(state.currentStreetId)); + const color = STREET_COLORS[street?.state] || STREET_COLORS.unbearbeitet; + const style = { + color, + opacity: state.settings.opacity, + weight: state.settings.weight, + lineCap: 'round', + lineJoin: 'round' + }; + + // Jedes Segment wird als eigene Polyline gezeichnet. Eine gemeinsame + // LatLng-Liste würde die Segmentgrenzen mit einer zusätzlichen Linie + // verbinden, die im Straßenverlauf nicht existiert. + const group = L.featureGroup(); segments.forEach(seg => { if (!Array.isArray(seg)) return; + const latlngs = []; seg.forEach(pt => { if (!Array.isArray(pt) || pt.length < 2) return; // try lat,lng or lng,lat @@ -799,13 +813,12 @@ function loadStreetPolyline(name) { if (Math.abs(a) <= 90 && Math.abs(b) <= 180) latlngs.push([a,b]); else if (Math.abs(b) <= 90 && Math.abs(a) <= 180) latlngs.push([b,a]); }); + if (latlngs.length >= 2) { + L.polyline(latlngs, style).addTo(group); + } }); - if (latlngs.length < 2) return; - const street = state.streetById.get(Number(state.currentStreetId)); - const color = STREET_COLORS[street?.state] || STREET_COLORS.unbearbeitet; - state.currentPolyline = L.polyline(latlngs, { - color, opacity: state.settings.opacity, weight: state.settings.weight, lineCap: 'round', lineJoin: 'round' - }).addTo(map); + if (!group.getLayers().length) return; + state.currentPolyline = group.addTo(map); } function clearPolylines() { @@ -824,10 +837,12 @@ function updateAllPolylineStyles() { function fitToPositionAndPolyline() { const bounds = L.latLngBounds([]); if (state.currentPolyline) { - state.currentPolyline.getLatLngs().forEach(ll => { - if (Array.isArray(ll)) ll.forEach(p => bounds.extend(p)); - else bounds.extend(ll); - }); + // Seit der segmentweisen Darstellung ist currentPolyline eine + // FeatureGroup; getBounds() umfasst alle Teilpolylines. + const polylineBounds = typeof state.currentPolyline.getBounds === 'function' + ? state.currentPolyline.getBounds() + : null; + if (polylineBounds && polylineBounds.isValid()) bounds.extend(polylineBounds); } if (state.userMarker) { bounds.extend(state.userMarker.getLatLng()); @@ -1146,7 +1161,7 @@ function setMobileWsStatus(label, status) { const element = document.getElementById('mobileWsStatus'); if (!element) return; - element.textContent = `WS: ${label}`; + element.textContent = `CMB ${label}`; element.title = `WebSocket: ${label}`; element.classList.remove('is-connected', 'is-connecting', 'is-disconnected', 'is-error'); element.classList.add(`is-${status}`); @@ -1332,6 +1347,32 @@ async function showChatPopup(text, senderName) { } } +function showIncomingChatDialog(text, senderName) { + const dialog = document.getElementById('mobileNotificationDialog'); + if (!dialog) return; + + const title = document.getElementById('mobileNotificationTitle'); + const body = document.getElementById('mobileNotificationText'); + if (title) title.textContent = senderName || 'Neue Nachricht'; + if (body) body.textContent = text || ''; + + if (!dialog.open) { + if (typeof dialog.showModal === 'function') dialog.showModal(); + else if (typeof dialog.show === 'function') dialog.show(); + } +} + +function closeMobileNotification() { + const dialog = document.getElementById('mobileNotificationDialog'); + if (dialog && dialog.open) dialog.close(); +} + +function openMobileChatFromNotification() { + closeMobileNotification(); + const chatTab = document.querySelector('.mobile-tab[data-tab="chat"]'); + if (chatTab) chatTab.click(); +} + function extractText(msg) { if (!msg) return ''; if (typeof msg === 'object') { @@ -1551,7 +1592,7 @@ function handleWs(event) { console.warn('[WS] Code 300: Gruppe nicht im lokalen Zustand', p); } } catch(e) {} - } else if (message.code === 2000 || message.code === 1000 || message.code === 1100) { + } else if (Number(message.code) >= 1000) { // Chat messages const payload = parseMessagePayload(message.msg); const text = extractText(payload ?? message.msg); @@ -1565,18 +1606,21 @@ function handleWs(event) { } } + const senderName = getSenderName(message, payload); addChatEntry({ sender_id: message.sender_id, code: message.code, ts: normalizeTs(message.ts) || Date.now(), text, - fromName: getSenderName(message, payload), + fromName: senderName, toName: getReceiverName(message, payload) }); if (Number(message.sender_id) !== currentAccountId) { playSound(); - showChatPopup(text, getSenderName(message, payload)); + // In-App-Dialog und, sofern erlaubt, Systembenachrichtigung. + showIncomingChatDialog(text, senderName); + showChatPopup(text, senderName); } } } @@ -1587,3 +1631,5 @@ window.closeMobileStreetState = closeMobileStreetState; window.saveMobileStreetState = saveMobileStreetState; window.closeMobileSettings = closeMobileSettings; window.closeMobileInstall = closeMobileInstall; +window.closeMobileNotification = closeMobileNotification; +window.openMobileChatFromNotification = openMobileChatFromNotification; diff --git a/CMBNet/templates/_mobile_notification_dialog.html b/CMBNet/templates/_mobile_notification_dialog.html new file mode 100644 index 0000000..cdaf9ee --- /dev/null +++ b/CMBNet/templates/_mobile_notification_dialog.html @@ -0,0 +1,14 @@ + +
+
+

Neue Nachricht

+
+
+

+
+
+ + +
+
+
diff --git a/CMBNet/templates/dispatcher_mobil.html b/CMBNet/templates/dispatcher_mobil.html index bae25f9..00d3ce7 100644 --- a/CMBNet/templates/dispatcher_mobil.html +++ b/CMBNet/templates/dispatcher_mobil.html @@ -46,7 +46,14 @@ - + @@ -128,6 +135,7 @@ +{% include "_mobile_notification_dialog.html" %} {% include "_pwa_install_dialog.html" %} {% endblock %} diff --git a/CMBNet/templates/gruppen.html b/CMBNet/templates/gruppen.html index 6cf5820..0e24688 100644 --- a/CMBNet/templates/gruppen.html +++ b/CMBNet/templates/gruppen.html @@ -42,7 +42,14 @@
- + @@ -133,6 +140,7 @@ +{% include "_mobile_notification_dialog.html" %} {% include "_pwa_install_dialog.html" %} {% endblock %}