feat: Refactor project creation and management to support modular project types
- Updated project creation modal to allow selection of optional modules (Sound and Vibration Monitoring). - Modified project dashboard and header to display active modules and provide options to add/remove them. - Enhanced project detail view to dynamically adjust UI based on enabled modules. - Implemented a new migration script to create a `project_modules` table and seed it based on existing project types. - Adjusted form submissions to handle module selections and ensure proper API interactions for module management.
This commit is contained in:
@@ -24,6 +24,7 @@ from backend.database import get_db
|
||||
from backend.models import (
|
||||
Project,
|
||||
ProjectType,
|
||||
ProjectModule,
|
||||
MonitoringLocation,
|
||||
UnitAssignment,
|
||||
RosterUnit,
|
||||
@@ -40,12 +41,17 @@ router = APIRouter(prefix="/api/projects/{project_id}", tags=["project-locations
|
||||
# Shared helpers
|
||||
# ============================================================================
|
||||
|
||||
def _require_sound_project(project) -> None:
|
||||
"""Raise 400 if the project is not a sound_monitoring project."""
|
||||
if not project or project.project_type_id != "sound_monitoring":
|
||||
def _require_module(project, module_type: str, db: Session) -> None:
|
||||
"""Raise 400 if the project does not have the given module enabled."""
|
||||
if not project:
|
||||
raise HTTPException(status_code=404, detail="Project not found.")
|
||||
exists = db.query(ProjectModule).filter_by(
|
||||
project_id=project.id, module_type=module_type, enabled=True
|
||||
).first()
|
||||
if not exists:
|
||||
raise HTTPException(
|
||||
status_code=400,
|
||||
detail="This feature is only available for Sound Monitoring projects.",
|
||||
detail=f"This project does not have the {module_type.replace('_', ' ').title()} module enabled.",
|
||||
)
|
||||
|
||||
|
||||
@@ -762,7 +768,7 @@ async def upload_nrl_data(
|
||||
|
||||
# Verify project and location exist
|
||||
project = db.query(Project).filter_by(id=project_id).first()
|
||||
_require_sound_project(project)
|
||||
_require_module(project, "sound_monitoring", db)
|
||||
|
||||
location = db.query(MonitoringLocation).filter_by(
|
||||
id=location_id, project_id=project_id
|
||||
@@ -955,7 +961,7 @@ async def get_nrl_live_status(
|
||||
import os
|
||||
import httpx
|
||||
|
||||
_require_sound_project(db.query(Project).filter_by(id=project_id).first())
|
||||
_require_module(db.query(Project).filter_by(id=project_id).first(), "sound_monitoring", db)
|
||||
|
||||
# Find the assigned unit (active = assigned_until IS NULL)
|
||||
assignment = db.query(UnitAssignment).filter(
|
||||
|
||||
Reference in New Issue
Block a user