Positionsupdate und NAvigations Deeplink in mobilen Views
This commit is contained in:
1 parent
d312442e62
commit
91ff49b688
6 files changed
+395
-16
No files matched your search
+17
-10
@@ -542,28 +542,35 @@ class WebSocketBroker:
|
|||||||
# manipulierbare Client-Zeitangaben verfälscht wird.
|
# manipulierbare Client-Zeitangaben verfälscht wird.
|
||||||
pos_at = datetime.now(timezone.utc).strftime('%Y-%m-%d %H:%M:%S')
|
pos_at = datetime.now(timezone.utc).strftime('%Y-%m-%d %H:%M:%S')
|
||||||
ts_ms = int(time.time() * 1000)
|
ts_ms = int(time.time() * 1000)
|
||||||
|
automatic = payload.get('automatic') is True
|
||||||
|
|
||||||
db.execute(
|
db.execute(
|
||||||
'UPDATE groups SET last_lat = ?, last_lon = ?, last_pos_at = ?, '
|
'UPDATE groups SET last_lat = ?, last_lon = ?, last_pos_at = ?, '
|
||||||
'updated_at = CURRENT_TIMESTAMP WHERE id = ? AND tenant_id = ?',
|
'updated_at = CURRENT_TIMESTAMP WHERE id = ? AND tenant_id = ?',
|
||||||
(lat, lon, pos_at, group_id, tenant_id)
|
(lat, lon, pos_at, group_id, tenant_id)
|
||||||
)
|
)
|
||||||
db.execute(
|
# Automatische Positionsmeldungen der Gruppen-View aktualisieren nur
|
||||||
'''INSERT INTO group_state_history
|
# die Live-Position. Die Historie und das Transaktionslog bleiben
|
||||||
(tenant_id, group_id, from_state, to_state, last_lat, last_lon,
|
# manuellen Positionsänderungen vorbehalten, damit sie nicht durch
|
||||||
last_pos_at, actor_account_id)
|
# regelmäßige Telemetrie geflutet werden.
|
||||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?)''',
|
if not automatic:
|
||||||
(tenant_id, group_id, group['state'], group['state'],
|
db.execute(
|
||||||
lat, lon, pos_at, sender['id'])
|
'''INSERT INTO group_state_history
|
||||||
)
|
(tenant_id, group_id, from_state, to_state, last_lat, last_lon,
|
||||||
|
last_pos_at, actor_account_id)
|
||||||
|
VALUES (?, ?, ?, ?, ?, ?, ?, ?)''',
|
||||||
|
(tenant_id, group_id, group['state'], group['state'],
|
||||||
|
lat, lon, pos_at, sender['id'])
|
||||||
|
)
|
||||||
db.commit()
|
db.commit()
|
||||||
GroupsService.update_cache_entry(tenant_id, group_id, {
|
GroupsService.update_cache_entry(tenant_id, group_id, {
|
||||||
'last_lat': lat,
|
'last_lat': lat,
|
||||||
'last_lon': lon,
|
'last_lon': lon,
|
||||||
'last_pos_at': pos_at
|
'last_pos_at': pos_at
|
||||||
})
|
})
|
||||||
self._log_business(tenant_id, sender['id'], 'group.position_change', 'group',
|
if not automatic:
|
||||||
group_id, {'lat': lat, 'lon': lon})
|
self._log_business(tenant_id, sender['id'], 'group.position_change', 'group',
|
||||||
|
group_id, {'lat': lat, 'lon': lon})
|
||||||
|
|
||||||
message.receiver_id = group_id
|
message.receiver_id = group_id
|
||||||
# Auch der Nachrichten-Zeitstempel wird serverseitig gesetzt, damit
|
# Auch der Nachrichten-Zeitstempel wird serverseitig gesetzt, damit
|
||||||
|
|||||||
@@ -183,6 +183,67 @@ body.mobile-page main.container {
|
|||||||
z-index: 1000;
|
z-index: 1000;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.mobile-position-btn {
|
||||||
|
position: absolute;
|
||||||
|
top: 0.75rem;
|
||||||
|
left: 0.75rem;
|
||||||
|
width: auto;
|
||||||
|
margin: 0;
|
||||||
|
padding: 0.5rem 0.9rem;
|
||||||
|
border-radius: 999px;
|
||||||
|
border: 1px solid var(--mobile-accent);
|
||||||
|
background: var(--mobile-accent);
|
||||||
|
color: #fff;
|
||||||
|
box-shadow: 0 8px 24px rgba(37, 99, 235, 0.3);
|
||||||
|
font-size: 0.85rem;
|
||||||
|
font-weight: 600;
|
||||||
|
z-index: 900;
|
||||||
|
}
|
||||||
|
|
||||||
|
.mobile-position-btn:hover,
|
||||||
|
.mobile-position-btn:focus-visible {
|
||||||
|
border-color: var(--mobile-accent);
|
||||||
|
background: var(--mobile-accent);
|
||||||
|
color: #fff;
|
||||||
|
filter: brightness(1.06);
|
||||||
|
}
|
||||||
|
|
||||||
|
.mobile-nav-btn {
|
||||||
|
position: absolute;
|
||||||
|
top: 0.75rem;
|
||||||
|
right: 0.7rem;
|
||||||
|
width: 3rem;
|
||||||
|
height: 3rem;
|
||||||
|
border-radius: 50%;
|
||||||
|
border: none;
|
||||||
|
background: var(--mobile-accent);
|
||||||
|
color: #fff;
|
||||||
|
display: none;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
margin: 0;
|
||||||
|
padding: 0;
|
||||||
|
box-shadow: 0 8px 24px rgba(37, 99, 235, 0.35);
|
||||||
|
z-index: 1000;
|
||||||
|
}
|
||||||
|
|
||||||
|
.mobile-nav-btn:not([hidden]) {
|
||||||
|
display: flex;
|
||||||
|
}
|
||||||
|
|
||||||
|
.mobile-nav-btn:hover,
|
||||||
|
.mobile-nav-btn:focus-visible {
|
||||||
|
border-color: var(--mobile-accent);
|
||||||
|
background: var(--mobile-accent);
|
||||||
|
color: #fff;
|
||||||
|
filter: brightness(1.06);
|
||||||
|
}
|
||||||
|
|
||||||
|
.mobile-nav-btn svg {
|
||||||
|
width: 1.35rem;
|
||||||
|
height: 1.35rem;
|
||||||
|
}
|
||||||
|
|
||||||
.mobile-chat-messages {
|
.mobile-chat-messages {
|
||||||
flex: 1 1 auto;
|
flex: 1 1 auto;
|
||||||
min-height: 0;
|
min-height: 0;
|
||||||
@@ -299,6 +360,11 @@ html[data-theme="dark"] .mobile-chat-card.own {
|
|||||||
font-size: 0.85rem;
|
font-size: 0.85rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.mobile-settings-row input[role="switch"] {
|
||||||
|
flex: 0 0 auto;
|
||||||
|
margin: 0;
|
||||||
|
}
|
||||||
|
|
||||||
.mobile-settings-button.is-active {
|
.mobile-settings-button.is-active {
|
||||||
background: var(--mobile-accent);
|
background: var(--mobile-accent);
|
||||||
border-color: var(--mobile-accent);
|
border-color: var(--mobile-accent);
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
* damit er sowohl die mobilen Views als auch die statischen Assets
|
* damit er sowohl die mobilen Views als auch die statischen Assets
|
||||||
* kontrolliert. Der Cache-Name wird pro App-Wurzel gebildet.
|
* kontrolliert. Der Cache-Name wird pro App-Wurzel gebildet.
|
||||||
*/
|
*/
|
||||||
const VERSION = 'cmbnet-pwa-v4';
|
const VERSION = 'cmbnet-pwa-v6';
|
||||||
const BASE = new URL('./', self.location).href;
|
const BASE = new URL('./', self.location).href;
|
||||||
const SHELL_CACHE = `${VERSION}-shell`;
|
const SHELL_CACHE = `${VERSION}-shell`;
|
||||||
const TILE_CACHE = `${VERSION}-tiles`;
|
const TILE_CACHE = `${VERSION}-tiles`;
|
||||||
|
|||||||
@@ -14,9 +14,14 @@ const appTitle = window.CMBNET_APP_TITLE || '20*C+M+B+27';
|
|||||||
const DEFAULT_SETTINGS = {
|
const DEFAULT_SETTINGS = {
|
||||||
opacity: 0.7,
|
opacity: 0.7,
|
||||||
weight: 20,
|
weight: 20,
|
||||||
baseLayer: 'osm'
|
baseLayer: 'osm',
|
||||||
|
autoSendPosition: true
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const AUTO_POSITION_INTERVAL_MS = 30000;
|
||||||
|
const NAVIGATION_MAX_AGE_MS = 30 * 60 * 1000;
|
||||||
|
const NAVIGATION_REFRESH_MS = 15000;
|
||||||
|
|
||||||
const STREET_STATES = ['unbearbeitet', 'zugewiesen', 'erledigt'];
|
const STREET_STATES = ['unbearbeitet', 'zugewiesen', 'erledigt'];
|
||||||
const STREET_COLORS = {
|
const STREET_COLORS = {
|
||||||
unbearbeitet: '#1f6feb',
|
unbearbeitet: '#1f6feb',
|
||||||
@@ -45,7 +50,11 @@ const state = {
|
|||||||
chatKeys: new Set(),
|
chatKeys: new Set(),
|
||||||
userMarker: null,
|
userMarker: null,
|
||||||
userArrow: null,
|
userArrow: null,
|
||||||
watchId: null
|
watchId: null,
|
||||||
|
positionSendTimerId: null,
|
||||||
|
navigationTimerId: null,
|
||||||
|
lastKnownPosition: null,
|
||||||
|
lastPositionSentAt: 0
|
||||||
};
|
};
|
||||||
|
|
||||||
const AudioContext = window.AudioContext || window.webkitAudioContext;
|
const AudioContext = window.AudioContext || window.webkitAudioContext;
|
||||||
@@ -108,11 +117,18 @@ async function initMobile() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
startGeolocation();
|
startGeolocation();
|
||||||
|
startNavigationButtonWatcher();
|
||||||
connectWebSocket();
|
connectWebSocket();
|
||||||
window.addEventListener('beforeunload', () => {
|
window.addEventListener('beforeunload', () => {
|
||||||
if (state.watchId !== null && navigator.geolocation) {
|
if (state.watchId !== null && navigator.geolocation) {
|
||||||
navigator.geolocation.clearWatch(state.watchId);
|
navigator.geolocation.clearWatch(state.watchId);
|
||||||
}
|
}
|
||||||
|
if (state.positionSendTimerId !== null) {
|
||||||
|
clearInterval(state.positionSendTimerId);
|
||||||
|
}
|
||||||
|
if (state.navigationTimerId !== null) {
|
||||||
|
clearInterval(state.navigationTimerId);
|
||||||
|
}
|
||||||
if (state.ws) state.ws.close();
|
if (state.ws) state.ws.close();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -269,6 +285,7 @@ function loadSettings() {
|
|||||||
state.settings.opacity = typeof saved.opacity === 'number' ? saved.opacity : DEFAULT_SETTINGS.opacity;
|
state.settings.opacity = typeof saved.opacity === 'number' ? saved.opacity : DEFAULT_SETTINGS.opacity;
|
||||||
state.settings.weight = typeof saved.weight === 'number' ? saved.weight : DEFAULT_SETTINGS.weight;
|
state.settings.weight = typeof saved.weight === 'number' ? saved.weight : DEFAULT_SETTINGS.weight;
|
||||||
state.settings.baseLayer = saved.baseLayer === 'aerial' ? 'aerial' : 'osm';
|
state.settings.baseLayer = saved.baseLayer === 'aerial' ? 'aerial' : 'osm';
|
||||||
|
state.settings.autoSendPosition = saved.autoSendPosition !== false;
|
||||||
}
|
}
|
||||||
} catch(e) {}
|
} catch(e) {}
|
||||||
}
|
}
|
||||||
@@ -279,6 +296,105 @@ function saveSettings() {
|
|||||||
} catch(e) {}
|
} catch(e) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function updatePositionSharingUi() {
|
||||||
|
if (viewMode !== 'mobile_group') return;
|
||||||
|
|
||||||
|
const toggle = document.getElementById('mobileAutoPositionToggle');
|
||||||
|
if (toggle) toggle.checked = state.settings.autoSendPosition;
|
||||||
|
|
||||||
|
const button = document.getElementById('mobileSendPositionBtn');
|
||||||
|
if (!button) return;
|
||||||
|
button.hidden = state.settings.autoSendPosition;
|
||||||
|
button.disabled = false;
|
||||||
|
button.textContent = 'Position senden';
|
||||||
|
}
|
||||||
|
|
||||||
|
function sendOwnPosition(lat, lon, automatic = false) {
|
||||||
|
if (viewMode !== 'mobile_group' || currentRole !== 'Gruppe') return false;
|
||||||
|
if (!state.currentGroupId) return false;
|
||||||
|
if (!Number.isFinite(lat) || !Number.isFinite(lon)) return false;
|
||||||
|
if (!state.ws || state.ws.readyState !== WebSocket.OPEN || !state.authenticated) return false;
|
||||||
|
|
||||||
|
state.ws.send(JSON.stringify({
|
||||||
|
code: 300,
|
||||||
|
msg: JSON.stringify({
|
||||||
|
group_id: state.currentGroupId,
|
||||||
|
lat,
|
||||||
|
lon,
|
||||||
|
ts: Date.now(),
|
||||||
|
actor: currentAccountId,
|
||||||
|
automatic: automatic === true
|
||||||
|
})
|
||||||
|
}));
|
||||||
|
state.lastPositionSentAt = Date.now();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
function sendAutomaticPosition(force = false) {
|
||||||
|
if (viewMode !== 'mobile_group' || !state.settings.autoSendPosition) return false;
|
||||||
|
if (!state.lastKnownPosition) return false;
|
||||||
|
if (!force && Date.now() - state.lastPositionSentAt < AUTO_POSITION_INTERVAL_MS) return false;
|
||||||
|
return sendOwnPosition(
|
||||||
|
state.lastKnownPosition.lat,
|
||||||
|
state.lastKnownPosition.lon,
|
||||||
|
true
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function sendPositionNow() {
|
||||||
|
if (viewMode !== 'mobile_group' || state.settings.autoSendPosition) return;
|
||||||
|
|
||||||
|
const button = document.getElementById('mobileSendPositionBtn');
|
||||||
|
if (!navigator.geolocation) {
|
||||||
|
alert('Eigenposition ist auf diesem Gerät nicht verfügbar.');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (button) {
|
||||||
|
button.disabled = true;
|
||||||
|
button.textContent = 'Sende …';
|
||||||
|
}
|
||||||
|
|
||||||
|
navigator.geolocation.getCurrentPosition((position) => {
|
||||||
|
const lat = Number(position.coords.latitude);
|
||||||
|
const lon = Number(position.coords.longitude);
|
||||||
|
state.lastKnownPosition = {
|
||||||
|
lat,
|
||||||
|
lon,
|
||||||
|
accuracy: position.coords.accuracy
|
||||||
|
};
|
||||||
|
updateOwnPositionMarker(lat, lon);
|
||||||
|
|
||||||
|
const sent = sendOwnPosition(lat, lon, false);
|
||||||
|
if (button) {
|
||||||
|
button.disabled = false;
|
||||||
|
button.textContent = sent ? 'Gesendet' : 'Position senden';
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!sent) {
|
||||||
|
alert('Eigenposition konnte nicht gesendet werden. Keine Verbindung zum Server.');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
setTimeout(() => {
|
||||||
|
if (button && !button.hidden) button.textContent = 'Position senden';
|
||||||
|
}, 2000);
|
||||||
|
}, (error) => {
|
||||||
|
console.warn(error);
|
||||||
|
if (button) {
|
||||||
|
button.disabled = false;
|
||||||
|
button.textContent = 'Position senden';
|
||||||
|
}
|
||||||
|
alert('Eigenposition konnte nicht ermittelt werden.');
|
||||||
|
}, {enableHighAccuracy: true, maximumAge: 0, timeout: 10000});
|
||||||
|
}
|
||||||
|
|
||||||
|
function updateOwnPositionMarker(lat, lon) {
|
||||||
|
if (state.userMarker && Number.isFinite(lat) && Number.isFinite(lon)) {
|
||||||
|
state.userMarker.setLatLng([lat, lon]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function initMap() {
|
function initMap() {
|
||||||
map = L.map('mobileMap', {zoomControl: false, preferCanvas: true});
|
map = L.map('mobileMap', {zoomControl: false, preferCanvas: true});
|
||||||
map.setView([51.0, 10.0], 6);
|
map.setView([51.0, 10.0], 6);
|
||||||
@@ -327,6 +443,9 @@ function bindButtons() {
|
|||||||
|
|
||||||
const workBtn = document.getElementById('mobileWorkBtn');
|
const workBtn = document.getElementById('mobileWorkBtn');
|
||||||
if (workBtn) workBtn.addEventListener('click', openStreetStateDialog);
|
if (workBtn) workBtn.addEventListener('click', openStreetStateDialog);
|
||||||
|
|
||||||
|
const navigateBtn = document.getElementById('mobileNavigateBtn');
|
||||||
|
if (navigateBtn) navigateBtn.addEventListener('click', openGroupNavigation);
|
||||||
|
|
||||||
const chatForm = document.getElementById('mobileChatForm');
|
const chatForm = document.getElementById('mobileChatForm');
|
||||||
if (chatForm) {
|
if (chatForm) {
|
||||||
@@ -368,12 +487,30 @@ function bindButtons() {
|
|||||||
if (baseSel) {
|
if (baseSel) {
|
||||||
baseSel.addEventListener('change', (e) => setBaseLayer(e.target.value));
|
baseSel.addEventListener('change', (e) => setBaseLayer(e.target.value));
|
||||||
}
|
}
|
||||||
|
const autoPositionToggle = document.getElementById('mobileAutoPositionToggle');
|
||||||
|
if (autoPositionToggle) {
|
||||||
|
autoPositionToggle.addEventListener('change', () => {
|
||||||
|
state.settings.autoSendPosition = autoPositionToggle.checked;
|
||||||
|
saveSettings();
|
||||||
|
updatePositionSharingUi();
|
||||||
|
if (state.settings.autoSendPosition && state.lastKnownPosition) {
|
||||||
|
state.lastPositionSentAt = 0;
|
||||||
|
sendAutomaticPosition();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
const sendPositionBtn = document.getElementById('mobileSendPositionBtn');
|
||||||
|
if (sendPositionBtn) {
|
||||||
|
sendPositionBtn.addEventListener('click', sendPositionNow);
|
||||||
|
}
|
||||||
|
updatePositionSharingUi();
|
||||||
}
|
}
|
||||||
|
|
||||||
function indexGroups() {
|
function indexGroups() {
|
||||||
state.groupById.clear();
|
state.groupById.clear();
|
||||||
state.groups.forEach(g => {
|
state.groups.forEach(g => {
|
||||||
g.id = Number(g.id);
|
g.id = Number(g.id);
|
||||||
|
g.last_pos_ts = parseFlexibleTimestamp(g.last_pos_at);
|
||||||
state.groupById.set(g.id, g);
|
state.groupById.set(g.id, g);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -522,6 +659,7 @@ async function loadGroupData(groupId) {
|
|||||||
state.currentGroupId = groupId;
|
state.currentGroupId = groupId;
|
||||||
const sel = document.getElementById('mobileGroupSelect');
|
const sel = document.getElementById('mobileGroupSelect');
|
||||||
if (sel && viewMode === 'mobile_dispatcher') sel.value = String(groupId);
|
if (sel && viewMode === 'mobile_dispatcher') sel.value = String(groupId);
|
||||||
|
updateNavigationButton();
|
||||||
|
|
||||||
clearPolylines();
|
clearPolylines();
|
||||||
if (state.currentPolyline) {
|
if (state.currentPolyline) {
|
||||||
@@ -741,6 +879,7 @@ function saveMobileStreetState() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function openSettingsDialog() {
|
function openSettingsDialog() {
|
||||||
|
updatePositionSharingUi();
|
||||||
const opacitySlider = document.getElementById('mobileOpacitySlider');
|
const opacitySlider = document.getElementById('mobileOpacitySlider');
|
||||||
const weightSlider = document.getElementById('mobileWeightSlider');
|
const weightSlider = document.getElementById('mobileWeightSlider');
|
||||||
if (opacitySlider) { opacitySlider.value = state.settings.opacity; document.getElementById('mobileOpacityValue').textContent = state.settings.opacity.toFixed(2); }
|
if (opacitySlider) { opacitySlider.value = state.settings.opacity; document.getElementById('mobileOpacityValue').textContent = state.settings.opacity.toFixed(2); }
|
||||||
@@ -777,11 +916,30 @@ function startGeolocation() {
|
|||||||
state.userArrow = document.getElementById('mobileUserArrow');
|
state.userArrow = document.getElementById('mobileUserArrow');
|
||||||
|
|
||||||
state.watchId = navigator.geolocation.watchPosition((pos) => {
|
state.watchId = navigator.geolocation.watchPosition((pos) => {
|
||||||
const latlng = [pos.coords.latitude, pos.coords.longitude];
|
const lat = Number(pos.coords.latitude);
|
||||||
state.userMarker.setLatLng(latlng);
|
const lon = Number(pos.coords.longitude);
|
||||||
|
state.lastKnownPosition = {
|
||||||
|
lat,
|
||||||
|
lon,
|
||||||
|
accuracy: pos.coords.accuracy
|
||||||
|
};
|
||||||
|
updateOwnPositionMarker(lat, lon);
|
||||||
|
|
||||||
|
if (viewMode === 'mobile_group') {
|
||||||
|
sendAutomaticPosition();
|
||||||
|
}
|
||||||
}, (err) => {
|
}, (err) => {
|
||||||
console.warn(err);
|
console.warn(err);
|
||||||
}, {enableHighAccuracy: true, maximumAge: 2000, timeout: 10000});
|
}, {enableHighAccuracy: true, maximumAge: 2000, timeout: 10000});
|
||||||
|
|
||||||
|
// Auch bei einem stehengebliebenen Gerät regelmäßig die zuletzt bekannte
|
||||||
|
// Position senden, damit die Anzeige im Dispatcher nicht veraltet.
|
||||||
|
if (viewMode === 'mobile_group') {
|
||||||
|
state.positionSendTimerId = setInterval(
|
||||||
|
() => sendAutomaticPosition(),
|
||||||
|
AUTO_POSITION_INTERVAL_MS
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
if (window.DeviceOrientationEvent) {
|
if (window.DeviceOrientationEvent) {
|
||||||
window.addEventListener('deviceorientationabsolute', handleOrientation, true);
|
window.addEventListener('deviceorientationabsolute', handleOrientation, true);
|
||||||
@@ -821,6 +979,8 @@ function showAllGroupPositions() {
|
|||||||
state.groupMarkers.set(group.id, marker);
|
state.groupMarkers.set(group.id, marker);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
updateNavigationButton();
|
||||||
}
|
}
|
||||||
|
|
||||||
function getGroupColor(id) {
|
function getGroupColor(id) {
|
||||||
@@ -828,6 +988,116 @@ function getGroupColor(id) {
|
|||||||
return `hsl(${hue}, 72%, 45%)`;
|
return `hsl(${hue}, 72%, 45%)`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getGroupCoordinates(group) {
|
||||||
|
if (!group) return null;
|
||||||
|
const hasLat = group.last_lat !== null && group.last_lat !== undefined && String(group.last_lat).trim() !== '';
|
||||||
|
const hasLon = group.last_lon !== null && group.last_lon !== undefined && String(group.last_lon).trim() !== '';
|
||||||
|
if (!hasLat || !hasLon) return null;
|
||||||
|
|
||||||
|
const lat = Number(group.last_lat);
|
||||||
|
const lon = Number(group.last_lon);
|
||||||
|
if (!Number.isFinite(lat) || !Number.isFinite(lon)) return null;
|
||||||
|
return {lat, lon};
|
||||||
|
}
|
||||||
|
|
||||||
|
function getGroupPositionTimestamp(group) {
|
||||||
|
if (!group) return null;
|
||||||
|
|
||||||
|
const parsed = parseFlexibleTimestamp(group.last_pos_at);
|
||||||
|
if (parsed) {
|
||||||
|
group.last_pos_ts = parsed;
|
||||||
|
return parsed;
|
||||||
|
}
|
||||||
|
|
||||||
|
return Number.isFinite(group.last_pos_ts) && group.last_pos_ts > 0
|
||||||
|
? group.last_pos_ts
|
||||||
|
: null;
|
||||||
|
}
|
||||||
|
|
||||||
|
function isGroupPositionFresh(group, now = Date.now()) {
|
||||||
|
if (!getGroupCoordinates(group)) return false;
|
||||||
|
const timestamp = getGroupPositionTimestamp(group);
|
||||||
|
if (!timestamp) return false;
|
||||||
|
return Math.max(0, now - timestamp) < NAVIGATION_MAX_AGE_MS;
|
||||||
|
}
|
||||||
|
|
||||||
|
function updateNavigationButton() {
|
||||||
|
if (viewMode !== 'mobile_dispatcher') return;
|
||||||
|
|
||||||
|
const button = document.getElementById('mobileNavigateBtn');
|
||||||
|
if (!button) return;
|
||||||
|
|
||||||
|
const group = state.groupById.get(Number(state.currentGroupId));
|
||||||
|
const visible = isGroupPositionFresh(group);
|
||||||
|
button.hidden = !visible;
|
||||||
|
|
||||||
|
if (visible) {
|
||||||
|
const name = groupDisplayName(group);
|
||||||
|
const label = name === 'Gruppe'
|
||||||
|
? 'Navigation starten'
|
||||||
|
: `Navigation zu ${name} starten`;
|
||||||
|
button.title = label;
|
||||||
|
button.setAttribute('aria-label', label);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function startNavigationButtonWatcher() {
|
||||||
|
if (viewMode !== 'mobile_dispatcher') return;
|
||||||
|
|
||||||
|
const button = document.getElementById('mobileNavigateBtn');
|
||||||
|
if (!button) return;
|
||||||
|
|
||||||
|
updateNavigationButton();
|
||||||
|
if (state.navigationTimerId !== null) {
|
||||||
|
clearInterval(state.navigationTimerId);
|
||||||
|
}
|
||||||
|
state.navigationTimerId = setInterval(updateNavigationButton, NAVIGATION_REFRESH_MS);
|
||||||
|
|
||||||
|
document.addEventListener('visibilitychange', () => {
|
||||||
|
if (!document.hidden) updateNavigationButton();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function detectNavigationPlatform() {
|
||||||
|
const userAgent = navigator.userAgent || '';
|
||||||
|
const platform = navigator.platform || '';
|
||||||
|
const maxTouchPoints = Number(navigator.maxTouchPoints) || 0;
|
||||||
|
const isIpadOs = platform === 'MacIntel' && maxTouchPoints > 1;
|
||||||
|
|
||||||
|
if (/iPad|iPhone|iPod/i.test(userAgent) || isIpadOs) return 'ios';
|
||||||
|
if (/Android/i.test(userAgent)) return 'android';
|
||||||
|
return 'other';
|
||||||
|
}
|
||||||
|
|
||||||
|
function buildNavigationUrl(lat, lon) {
|
||||||
|
const coordinates = `${lat},${lon}`;
|
||||||
|
const platform = detectNavigationPlatform();
|
||||||
|
|
||||||
|
if (platform === 'ios') {
|
||||||
|
return `https://maps.apple.com/?daddr=${coordinates}&dirflg=d`;
|
||||||
|
}
|
||||||
|
if (platform === 'android') {
|
||||||
|
return `https://www.google.com/maps/dir/?api=1&destination=${coordinates}&travelmode=driving`;
|
||||||
|
}
|
||||||
|
return `geo:${coordinates}?q=${coordinates}(Zielort)`;
|
||||||
|
}
|
||||||
|
|
||||||
|
function openGroupNavigation() {
|
||||||
|
const group = state.groupById.get(Number(state.currentGroupId));
|
||||||
|
if (!isGroupPositionFresh(group)) {
|
||||||
|
updateNavigationButton();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const coordinates = getGroupCoordinates(group);
|
||||||
|
if (!coordinates) {
|
||||||
|
updateNavigationButton();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
window.location.href = buildNavigationUrl(coordinates.lat, coordinates.lon);
|
||||||
|
}
|
||||||
|
|
||||||
function connectWebSocket() {
|
function connectWebSocket() {
|
||||||
if (state.ws && (state.ws.readyState === WebSocket.OPEN || state.ws.readyState === WebSocket.CONNECTING)) return;
|
if (state.ws && (state.ws.readyState === WebSocket.OPEN || state.ws.readyState === WebSocket.CONNECTING)) return;
|
||||||
fetchJson(`${apiBase}/auth/ws-token`).then(res => {
|
fetchJson(`${apiBase}/auth/ws-token`).then(res => {
|
||||||
@@ -977,6 +1247,22 @@ function normalizeTs(value) {
|
|||||||
return number < 1e12 ? number * 1000 : number;
|
return number < 1e12 ? number * 1000 : number;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function parseFlexibleTimestamp(value) {
|
||||||
|
if (value === null || value === undefined || value === '') return null;
|
||||||
|
if (typeof value === 'number') return normalizeTs(value);
|
||||||
|
|
||||||
|
const text = String(value).trim();
|
||||||
|
if (/^\d+(?:\.\d+)?$/.test(text)) return normalizeTs(Number(text));
|
||||||
|
|
||||||
|
let iso = text.replace(' ', 'T');
|
||||||
|
if (!/[zZ]|[+-]\d{2}:?\d{2}$/.test(iso)) {
|
||||||
|
iso += 'Z';
|
||||||
|
}
|
||||||
|
|
||||||
|
const parsed = Date.parse(iso);
|
||||||
|
return Number.isNaN(parsed) ? null : parsed;
|
||||||
|
}
|
||||||
|
|
||||||
function handleWs(event) {
|
function handleWs(event) {
|
||||||
let message;
|
let message;
|
||||||
try { message = JSON.parse(event.data); } catch(e) { return; }
|
try { message = JSON.parse(event.data); } catch(e) { return; }
|
||||||
@@ -1019,7 +1305,10 @@ function handleWs(event) {
|
|||||||
const gid = Number(p.group_id || message.receiver_id);
|
const gid = Number(p.group_id || message.receiver_id);
|
||||||
const g = state.groupById.get(gid);
|
const g = state.groupById.get(gid);
|
||||||
if (g && p.lat && p.lon) {
|
if (g && p.lat && p.lon) {
|
||||||
g.last_lat = p.lat; g.last_lon = p.lon;
|
g.last_lat = p.lat;
|
||||||
|
g.last_lon = p.lon;
|
||||||
|
g.last_pos_ts = parseFlexibleTimestamp(p.ts) || Date.now();
|
||||||
|
g.last_pos_at = new Date(g.last_pos_ts).toISOString();
|
||||||
if (viewMode === 'mobile_dispatcher') showAllGroupPositions();
|
if (viewMode === 'mobile_dispatcher') showAllGroupPositions();
|
||||||
}
|
}
|
||||||
} catch(e) {}
|
} catch(e) {}
|
||||||
|
|||||||
@@ -38,6 +38,12 @@
|
|||||||
<main class="mobile-main">
|
<main class="mobile-main">
|
||||||
<section id="tab-map" class="mobile-tab-panel active" role="tabpanel">
|
<section id="tab-map" class="mobile-tab-panel active" role="tabpanel">
|
||||||
<div id="mobileMap" class="mobile-map"></div>
|
<div id="mobileMap" class="mobile-map"></div>
|
||||||
|
<button type="button" id="mobileNavigateBtn" class="mobile-nav-btn"
|
||||||
|
title="Navigation zur Gruppe starten" aria-label="Navigation zur Gruppe starten" hidden>
|
||||||
|
<svg viewBox="0 0 24 24" width="22" height="22" aria-hidden="true" focusable="false">
|
||||||
|
<path fill="currentColor" d="M21.71 2.29a1 1 0 0 0-1.05-.24l-18 7a1 1 0 0 0 .06 1.87l7.16 2.2 2.2 7.16a1 1 0 0 0 1.87.06l7-18a1 1 0 0 0-.24-1.05Z"/>
|
||||||
|
</svg>
|
||||||
|
</button>
|
||||||
<button type="button" id="mobileTodoBtn" class="mobile-fab" title="ToDo-Liste" aria-label="ToDo-Liste">📋</button>
|
<button type="button" id="mobileTodoBtn" class="mobile-fab" title="ToDo-Liste" aria-label="ToDo-Liste">📋</button>
|
||||||
<button type="button" id="mobileSettingsBtn" class="mobile-fab mobile-fab-secondary" title="Einstellungen" aria-label="Einstellungen">⚙</button>
|
<button type="button" id="mobileSettingsBtn" class="mobile-fab mobile-fab-secondary" title="Einstellungen" aria-label="Einstellungen">⚙</button>
|
||||||
<button type="button" id="mobileWorkBtn" class="mobile-work-btn" title="Straße bearbeiten" aria-label="Straße bearbeiten">Bearbeiten</button>
|
<button type="button" id="mobileWorkBtn" class="mobile-work-btn" title="Straße bearbeiten" aria-label="Straße bearbeiten">Bearbeiten</button>
|
||||||
|
|||||||
@@ -38,6 +38,8 @@
|
|||||||
<main class="mobile-main">
|
<main class="mobile-main">
|
||||||
<section id="tab-map" class="mobile-tab-panel active" role="tabpanel">
|
<section id="tab-map" class="mobile-tab-panel active" role="tabpanel">
|
||||||
<div id="mobileMap" class="mobile-map"></div>
|
<div id="mobileMap" class="mobile-map"></div>
|
||||||
|
<button type="button" id="mobileSendPositionBtn" class="mobile-position-btn"
|
||||||
|
title="Eigenposition jetzt senden" aria-label="Eigenposition jetzt senden" hidden>Position senden</button>
|
||||||
<button type="button" id="mobileTodoBtn" class="mobile-fab" title="ToDo-Liste" aria-label="ToDo-Liste">📋</button>
|
<button type="button" id="mobileTodoBtn" class="mobile-fab" title="ToDo-Liste" aria-label="ToDo-Liste">📋</button>
|
||||||
<button type="button" id="mobileSettingsBtn" class="mobile-fab mobile-fab-secondary" title="Einstellungen" aria-label="Einstellungen">⚙</button>
|
<button type="button" id="mobileSettingsBtn" class="mobile-fab mobile-fab-secondary" title="Einstellungen" aria-label="Einstellungen">⚙</button>
|
||||||
<button type="button" id="mobileWorkBtn" class="mobile-work-btn" title="Straße bearbeiten" aria-label="Straße bearbeiten">Bearbeiten</button>
|
<button type="button" id="mobileWorkBtn" class="mobile-work-btn" title="Straße bearbeiten" aria-label="Straße bearbeiten">Bearbeiten</button>
|
||||||
@@ -110,6 +112,15 @@
|
|||||||
<option value="aerial">Luftbild</option>
|
<option value="aerial">Luftbild</option>
|
||||||
</select>
|
</select>
|
||||||
</label>
|
</label>
|
||||||
|
<div class="mobile-settings-row">
|
||||||
|
<span>Eigenposition automatisch senden</span>
|
||||||
|
<input type="checkbox" id="mobileAutoPositionToggle" role="switch"
|
||||||
|
aria-label="Eigenposition automatisch senden" checked>
|
||||||
|
</div>
|
||||||
|
<p class="mobile-dialog-hint">
|
||||||
|
Ist die automatische Versendung deaktiviert, kann die Position
|
||||||
|
über den Button in der Karte einmalig gesendet werden.
|
||||||
|
</p>
|
||||||
<div class="mobile-settings-row">
|
<div class="mobile-settings-row">
|
||||||
<span>Benachrichtigungen</span>
|
<span>Benachrichtigungen</span>
|
||||||
<button type="button" id="mobileNotifyBtn" class="secondary mobile-settings-button">Aktivieren</button>
|
<button type="button" id="mobileNotifyBtn" class="secondary mobile-settings-button">Aktivieren</button>
|
||||||
|
|||||||
Reference in new issue
Block a user