- Implemented a modal for renaming units with validation and confirmation prompts. - Added JavaScript functions to handle opening, closing, and submitting the rename unit form. - Enhanced the back navigation in the SLM detail page to check referrer history. - Updated breadcrumb navigation in the legacy dashboard to accommodate NRL locations. - Improved the sound level meters page with a more informative header and device list. - Introduced a live measurement chart with WebSocket support for real-time data streaming. - Added functionality to manage active devices and projects with auto-refresh capabilities.
75 lines
2.5 KiB
Python
75 lines
2.5 KiB
Python
from fastapi import APIRouter, Depends, HTTPException
|
|
from sqlalchemy.orm import Session
|
|
from datetime import datetime
|
|
from typing import Dict, Any
|
|
|
|
from backend.database import get_db
|
|
from backend.services.snapshot import emit_status_snapshot
|
|
from backend.models import RosterUnit
|
|
|
|
router = APIRouter(prefix="/api", tags=["units"])
|
|
|
|
|
|
@router.get("/unit/{unit_id}")
|
|
def get_unit_detail(unit_id: str, db: Session = Depends(get_db)):
|
|
"""
|
|
Returns detailed data for a single unit.
|
|
"""
|
|
snapshot = emit_status_snapshot()
|
|
|
|
if unit_id not in snapshot["units"]:
|
|
raise HTTPException(status_code=404, detail=f"Unit {unit_id} not found")
|
|
|
|
unit_data = snapshot["units"][unit_id]
|
|
|
|
# Mock coordinates for now (will be replaced with real data)
|
|
mock_coords = {
|
|
"BE1234": {"lat": 37.7749, "lon": -122.4194, "location": "San Francisco, CA"},
|
|
"BE5678": {"lat": 34.0522, "lon": -118.2437, "location": "Los Angeles, CA"},
|
|
"BE9012": {"lat": 40.7128, "lon": -74.0060, "location": "New York, NY"},
|
|
"BE3456": {"lat": 41.8781, "lon": -87.6298, "location": "Chicago, IL"},
|
|
"BE7890": {"lat": 29.7604, "lon": -95.3698, "location": "Houston, TX"},
|
|
}
|
|
|
|
coords = mock_coords.get(unit_id, {"lat": 39.8283, "lon": -98.5795, "location": "Unknown"})
|
|
|
|
return {
|
|
"id": unit_id,
|
|
"status": unit_data["status"],
|
|
"age": unit_data["age"],
|
|
"last_seen": unit_data["last"],
|
|
"last_file": unit_data.get("fname", ""),
|
|
"deployed": unit_data["deployed"],
|
|
"note": unit_data.get("note", ""),
|
|
"coordinates": coords
|
|
}
|
|
|
|
|
|
@router.get("/units/{unit_id}")
|
|
def get_unit_by_id(unit_id: str, db: Session = Depends(get_db)):
|
|
"""
|
|
Get unit data directly from the roster (for settings/configuration).
|
|
"""
|
|
unit = db.query(RosterUnit).filter_by(id=unit_id).first()
|
|
|
|
if not unit:
|
|
raise HTTPException(status_code=404, detail=f"Unit {unit_id} not found")
|
|
|
|
return {
|
|
"id": unit.id,
|
|
"unit_type": unit.unit_type,
|
|
"device_type": unit.device_type,
|
|
"deployed": unit.deployed,
|
|
"retired": unit.retired,
|
|
"note": unit.note,
|
|
"location": unit.location,
|
|
"address": unit.address,
|
|
"coordinates": unit.coordinates,
|
|
"slm_host": unit.slm_host,
|
|
"slm_tcp_port": unit.slm_tcp_port,
|
|
"slm_ftp_port": unit.slm_ftp_port,
|
|
"slm_model": unit.slm_model,
|
|
"slm_serial_number": unit.slm_serial_number,
|
|
"deployed_with_modem_id": unit.deployed_with_modem_id
|
|
}
|