T6 Map Page Improvements: geolocation fallback, location coordinates, friendly error messages
- Improved geolocation error messages (maps error codes to friendly text: Location blocked, GPS unavailable, GPS timed out) - Added location data to list_assets API (location_latitude, longitude, address, building_name, building_number, name) via LEFT JOIN - Map pins now use location coordinates as direct fallback when asset lacks own lat/lng - GeocodeAndPin now falls back to location address fields when asset address is empty - All 96 map-related tests pass (66 API + 30 frontend)
This commit is contained in:
@@ -958,16 +958,30 @@ def list_assets(
|
||||
if assigned_to is not None:
|
||||
conditions.append("assigned_to = ?")
|
||||
params.append(assigned_to)
|
||||
# Build conditions with table prefix for JOIN safety
|
||||
if q:
|
||||
conditions.append("(name LIKE ? OR machine_id LIKE ? OR description LIKE ?)")
|
||||
conditions.append("(a.name LIKE ? OR a.machine_id LIKE ? OR a.description LIKE ?)")
|
||||
like = f"%{q}%"
|
||||
params.extend([like, like, like])
|
||||
|
||||
where = " AND ".join(conditions)
|
||||
sql = "SELECT * FROM assets"
|
||||
where = " AND ".join(
|
||||
f"a.{c}" if not c.startswith("(") else c
|
||||
for c in conditions
|
||||
) if conditions else ""
|
||||
sql = (
|
||||
"SELECT a.*,"
|
||||
" l.latitude AS location_latitude,"
|
||||
" l.longitude AS location_longitude,"
|
||||
" l.address AS location_address,"
|
||||
" l.building_name AS location_building_name,"
|
||||
" l.building_number AS location_building_number,"
|
||||
" l.name AS location_name"
|
||||
" FROM assets a"
|
||||
" LEFT JOIN locations l ON a.location_id = l.id"
|
||||
)
|
||||
if where:
|
||||
sql += f" WHERE {where}"
|
||||
sql += " ORDER BY created_at DESC LIMIT ? OFFSET ?"
|
||||
sql += " ORDER BY a.created_at DESC LIMIT ? OFFSET ?"
|
||||
params.extend([limit, offset])
|
||||
|
||||
rows = conn.execute(sql, params).fetchall()
|
||||
|
||||
Reference in New Issue
Block a user