feat: implement Bari bounds validation and update UI components for admin panel

This commit is contained in:
gabdevele
2026-06-15 13:00:22 +02:00 Unverified
parent 8bf6f29561
commit d6eb7d3e9b
13 changed files with 108 additions and 34 deletions
+28 -10
View File
@@ -2,6 +2,7 @@
import type { Category, CreateReportRequest } from '~/types/api'
import type { LeafletMouseEvent, Map as LeafletMap, Marker as LeafletMarker } from 'leaflet'
import { onMounted, onUnmounted, ref, watch } from 'vue'
import { BARI_BOUNDS, BARI_CENTER, isWithinBariBounds } from '~/utils/bari'
interface Props {
isLoading?: boolean
@@ -65,18 +66,28 @@ const initMap = async () => {
const L = await loadLeaflet()
if (!mapContainer.value || map) return
// Centro Italia default
const defaultLat = 41.8719
const defaultLng = 12.5674
const zoom = 5
const bariBounds = L.latLngBounds(
[BARI_BOUNDS.south, BARI_BOUNDS.west],
[BARI_BOUNDS.north, BARI_BOUNDS.east]
)
map = L.map(mapContainer.value).setView([defaultLat, defaultLng], zoom)
map = L.map(mapContainer.value, {
maxBounds: bariBounds,
maxBoundsViscosity: 1,
minZoom: 12
}).setView(BARI_CENTER, 12)
L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
attribution: '© OpenStreetMap contributors'
}).addTo(map)
map.fitBounds(bariBounds)
map.on('click', (e: LeafletMouseEvent) => {
if (!isWithinBariBounds(e.latlng.lat, e.latlng.lng)) {
errors.value.location = 'Puoi inserire segnalazioni solo nel Comune di Bari.'
return
}
updateLocation(e.latlng.lat, e.latlng.lng)
})
@@ -87,6 +98,11 @@ const initMap = async () => {
}
const updateLocation = (lat: number, lng: number, zoomTo = false) => {
if (!isWithinBariBounds(lat, lng)) {
errors.value.location = 'Puoi inserire segnalazioni solo nel Comune di Bari.'
return
}
form.value.latitude = Number(lat.toFixed(6))
form.value.longitude = Number(lng.toFixed(6))
@@ -125,6 +141,8 @@ const validateForm = (): boolean => {
}
if (!form.value.latitude || !form.value.longitude) {
errors.value.location = 'Imposta la posizione sulla mappa'
} else if (!isWithinBariBounds(form.value.latitude, form.value.longitude)) {
errors.value.location = 'La posizione deve essere nel Comune di Bari'
}
if (!form.value.address?.trim()) {
errors.value.address = 'Inserisci l\'indirizzo'
@@ -186,7 +204,7 @@ const resetForm = () => {
if (marker && map) {
map.removeLayer(marker)
marker = null
map.setView([41.8719, 12.5674], 5)
map.setView(BARI_CENTER, 12)
}
}
@@ -246,6 +264,7 @@ watch([() => form.value.latitude, () => form.value.longitude], ([newLat, newLng]
<BIIcon name="it-map-marker-circle" size="sm" color="primary" class="me-2" />
Posizione *
</label>
<p class="small text-muted mb-2">Le segnalazioni sono abilitate solo entro confini del Comune di Bari.</p>
<button
type="button"
@@ -275,7 +294,7 @@ watch([() => form.value.latitude, () => form.value.longitude], ([newLat, newLng]
step="0.000001"
class="form-control form-control-sm"
:class="{ 'is-invalid': errors.location }"
placeholder="Latitudine (es. 45.5)"
placeholder="Latitudine (Bari)"
required
/>
</div>
@@ -286,7 +305,7 @@ watch([() => form.value.latitude, () => form.value.longitude], ([newLat, newLng]
step="0.000001"
class="form-control form-control-sm"
:class="{ 'is-invalid': errors.location }"
placeholder="Longitudine (es. 10.2)"
placeholder="Longitudine (Bari)"
required
/>
</div>
@@ -307,7 +326,7 @@ watch([() => form.value.latitude, () => form.value.longitude], ([newLat, newLng]
type="text"
class="form-control"
:class="{ 'is-invalid': errors.address }"
placeholder="Es. Via Roma 123, Milano"
placeholder="Es. Via Sparano 12, Bari"
required
/>
<div v-if="errors.address" class="invalid-feedback">
@@ -393,4 +412,3 @@ textarea {
</style>