diff --git a/services/presentation/app/static/now.js b/services/presentation/app/static/now.js new file mode 100644 index 0000000..b46d86d --- /dev/null +++ b/services/presentation/app/static/now.js @@ -0,0 +1,43 @@ +// „Tu i teraz": uzupełnia datę/godzinę/strefę z przeglądarki oraz — jeśli to +// możliwe — lokalizację (lat/lon). +// +// UWAGA: geolokalizacja przeglądarki działa tylko w "secure context" +// (https:// lub localhost). Na http:// przeglądarka NIE pyta o zgodę, +// tylko po cichu odmawia — dlatego pokazujemy jawny komunikat w #geoNote. +document.addEventListener('DOMContentLoaded', function () { + const btn = document.getElementById('nowBtn'); + if (!btn) return; + + const note = document.getElementById('geoNote'); + const say = msg => { if (note) note.textContent = msg; }; + + btn.addEventListener('click', function () { + const d = new Date(); + const pad = n => String(n).padStart(2, '0'); + document.querySelector('input[name=date]').value = + d.getFullYear() + '-' + pad(d.getMonth() + 1) + '-' + pad(d.getDate()); + document.querySelector('input[name=time]').value = pad(d.getHours()) + ':' + pad(d.getMinutes()); + document.querySelector('input[name=tz_offset]').value = (-d.getTimezoneOffset() / 60); + + if (!('geolocation' in navigator)) { + say('Ta przeglądarka nie udostępnia geolokalizacji — wpisz lat/lon ręcznie.'); + return; + } + if (!window.isSecureContext) { + say('Lokalizacja z przeglądarki wymaga HTTPS lub localhost (otwarto przez http://) — wpisz lat/lon ręcznie.'); + return; + } + say('Pobieram lokalizację…'); + navigator.geolocation.getCurrentPosition( + function (pos) { + document.querySelector('input[name=lat]').value = pos.coords.latitude.toFixed(4); + document.querySelector('input[name=lon]').value = pos.coords.longitude.toFixed(4); + say('Lokalizacja pobrana ✓'); + }, + function (err) { + say('Nie udało się pobrać lokalizacji: ' + (err && err.message ? err.message : 'odmowa dostępu')); + }, + { timeout: 8000 } + ); + }); +}); diff --git a/services/presentation/app/templates/chart.html b/services/presentation/app/templates/chart.html index 01a49d9..050bd97 100644 --- a/services/presentation/app/templates/chart.html +++ b/services/presentation/app/templates/chart.html @@ -36,6 +36,7 @@
+
@@ -110,22 +111,5 @@ {% endif %} {% endif %} - + {% endblock %} diff --git a/services/presentation/app/templates/interpret.html b/services/presentation/app/templates/interpret.html index 6fa24e9..b428ad8 100644 --- a/services/presentation/app/templates/interpret.html +++ b/services/presentation/app/templates/interpret.html @@ -29,6 +29,7 @@
+
@@ -82,21 +83,5 @@ {% endfor %} {% endif %} - + {% endblock %}