Prepare Specs UI for Windows review
This commit is contained in:
+110
-12
@@ -11,7 +11,7 @@ from typing import Optional
|
||||
from app.database import get_db
|
||||
from app.services.resource_allocation_service import ResourceAllocationService
|
||||
from app.services.procurement_flow_service import ProcurementFlowService
|
||||
from app.models import Project, System, Guardian, Module, Resource, ResourceAllocation, Specification, Purchase
|
||||
from app.models import Project, System, Guardian, Module, Resource, ResourceAllocation, Specification, Purchase, SystemModule, SpecificationItem, PurchaseItem, Contract, PurchaseSpecification
|
||||
|
||||
router = APIRouter(prefix="/ui", tags=["UI"])
|
||||
templates = Jinja2Templates(directory="app/templates")
|
||||
@@ -75,9 +75,9 @@ async def project_detail(request: Request, project_id: int, db: Session = Depend
|
||||
if not project:
|
||||
raise HTTPException(status_code=404, detail="Project not found")
|
||||
|
||||
customers = db.query(Project).filter(Project.id == project_id).first().customers
|
||||
customers = project.customers
|
||||
systems = db.query(System).filter(System.project_id == project_id).all()
|
||||
contracts = db.query(Project).filter(Project.id == project_id).first().contracts
|
||||
contracts = db.query(Contract).filter(Contract.project_id == project_id).all()
|
||||
resources = db.query(Resource).filter(Resource.project_id == project_id).all()
|
||||
purchases = db.query(Purchase).filter(Purchase.project_id == project_id).all()
|
||||
|
||||
@@ -118,8 +118,8 @@ async def system_detail(request: Request, system_id: int, db: Session = Depends(
|
||||
if not system:
|
||||
raise HTTPException(status_code=404, detail="System not found")
|
||||
|
||||
# Get Common part (guardian_id = NULL)
|
||||
common_modules = db.query(SystemModule).filter(
|
||||
# Get Common part (guardian_id = NULL) with joined loading
|
||||
common_modules = db.query(SystemModule).join(Module, SystemModule.module_id == Module.id).filter(
|
||||
SystemModule.system_id == system_id,
|
||||
SystemModule.guardian_id == None
|
||||
).all()
|
||||
@@ -129,13 +129,13 @@ async def system_detail(request: Request, system_id: int, db: Session = Depends(
|
||||
|
||||
guardian_data = []
|
||||
for guardian in guardians:
|
||||
core = db.query(SystemModule).filter(
|
||||
core = db.query(SystemModule).join(Module, SystemModule.module_id == Module.id).filter(
|
||||
SystemModule.system_id == system_id,
|
||||
SystemModule.guardian_id == guardian.id,
|
||||
Module.name == "Core"
|
||||
).first()
|
||||
|
||||
other_modules = db.query(SystemModule).filter(
|
||||
other_modules = db.query(SystemModule).join(Module, SystemModule.module_id == Module.id).filter(
|
||||
SystemModule.system_id == system_id,
|
||||
SystemModule.guardian_id == guardian.id
|
||||
).all()
|
||||
@@ -164,12 +164,12 @@ async def guardian_detail(request: Request, guardian_id: int, db: Session = Depe
|
||||
if not guardian:
|
||||
raise HTTPException(status_code=404, detail="Guardian not found")
|
||||
|
||||
core = db.query(SystemModule).filter(
|
||||
core = db.query(SystemModule).join(Module, SystemModule.module_id == Module.id).filter(
|
||||
SystemModule.guardian_id == guardian_id,
|
||||
Module.name == "Core"
|
||||
).first()
|
||||
|
||||
modules = db.query(SystemModule).filter(
|
||||
modules = db.query(SystemModule).join(Module, SystemModule.module_id == Module.id).filter(
|
||||
SystemModule.guardian_id == guardian_id
|
||||
).all()
|
||||
|
||||
@@ -205,6 +205,9 @@ async def resource_detail(request: Request, resource_id: int, db: Session = Depe
|
||||
if not resource:
|
||||
raise HTTPException(status_code=404, detail="Resource not found")
|
||||
|
||||
# Get systems for this project
|
||||
systems = db.query(System).filter(System.project_id == resource.project_id).all()
|
||||
|
||||
# Get allocations for this resource
|
||||
allocations = db.query(ResourceAllocation).filter(
|
||||
ResourceAllocation.resource_id == resource_id
|
||||
@@ -233,7 +236,8 @@ async def resource_detail(request: Request, resource_id: int, db: Session = Depe
|
||||
"request": request,
|
||||
"resource": resource,
|
||||
"allocations": allocation_details,
|
||||
"remaining": remaining
|
||||
"remaining": remaining,
|
||||
"systems": systems
|
||||
}
|
||||
)
|
||||
|
||||
@@ -297,7 +301,7 @@ async def specification_detail(request: Request, specification_id: int, db: Sess
|
||||
if not specification:
|
||||
raise HTTPException(status_code=404, detail="Specification not found")
|
||||
|
||||
items = db.query(SpecificationItem).filter(
|
||||
items = db.query(SpecificationItem).join(Module, SpecificationItem.module_id == Module.id).filter(
|
||||
SpecificationItem.specification_id == specification_id
|
||||
).all()
|
||||
|
||||
@@ -327,7 +331,7 @@ async def purchases_list(request: Request, project_id: Optional[int] = None, db:
|
||||
|
||||
@router.get("/purchases/{purchase_id}")
|
||||
async def purchase_detail(request: Request, purchase_id: int, db: Session = Depends(get_db)):
|
||||
"""Purchase detail page."""
|
||||
"Purchase detail page."
|
||||
purchase = db.query(Purchase).filter(Purchase.id == purchase_id).first()
|
||||
if not purchase:
|
||||
raise HTTPException(status_code=404, detail="Purchase not found")
|
||||
@@ -355,9 +359,103 @@ async def purchase_detail(request: Request, purchase_id: int, db: Session = Depe
|
||||
)
|
||||
|
||||
|
||||
@router.get("/projects")
|
||||
async def projects_list(request: Request, db: Session = Depends(get_db)):
|
||||
"""List all projects."""
|
||||
projects = db.query(Project).all()
|
||||
return templates.TemplateResponse(
|
||||
"projects/list.html",
|
||||
{"request": request, "projects": projects}
|
||||
)
|
||||
async def project_systems_list(request: Request, project_id: int, db: Session = Depends(get_db)):
|
||||
"""Systems list for project."""
|
||||
project = db.query(Project).filter(Project.id == project_id).first()
|
||||
if not project:
|
||||
raise HTTPException(status_code=404, detail="Project not found")
|
||||
|
||||
systems = db.query(System).filter(System.project_id == project_id).all()
|
||||
return templates.TemplateResponse(
|
||||
"systems/list.html",
|
||||
{"request": request, "systems": systems, "project_id": project_id}
|
||||
)
|
||||
|
||||
|
||||
@router.get("/projects/{project_id}/resources")
|
||||
async def project_resources_list(request: Request, project_id: int, db: Session = Depends(get_db)):
|
||||
"""Resources list for project."""
|
||||
project = db.query(Project).filter(Project.id == project_id).first()
|
||||
if not project:
|
||||
raise HTTPException(status_code=404, detail="Project not found")
|
||||
|
||||
resources = db.query(Resource).filter(Resource.project_id == project_id).all()
|
||||
return templates.TemplateResponse(
|
||||
"resources/list.html",
|
||||
{"request": request, "resources": resources, "project_id": project_id}
|
||||
)
|
||||
|
||||
|
||||
@router.get("/projects/{project_id}/specifications")
|
||||
async def project_specifications_list(request: Request, project_id: int, db: Session = Depends(get_db)):
|
||||
"""Specifications list for project."""
|
||||
project = db.query(Project).filter(Project.id == project_id).first()
|
||||
if not project:
|
||||
raise HTTPException(status_code=404, detail="Project not found")
|
||||
|
||||
specifications = db.query(Specification).filter(Specification.project_id == project_id).all()
|
||||
return templates.TemplateResponse(
|
||||
"specifications/list.html",
|
||||
{"request": request, "specifications": specifications, "project_id": project_id}
|
||||
)
|
||||
|
||||
|
||||
@router.get("/projects/{project_id}/purchases")
|
||||
async def project_purchases_list(request: Request, project_id: int, db: Session = Depends(get_db)):
|
||||
"""Purchases list for project."""
|
||||
project = db.query(Project).filter(Project.id == project_id).first()
|
||||
if not project:
|
||||
raise HTTPException(status_code=404, detail="Project not found")
|
||||
|
||||
purchases = db.query(Purchase).filter(Purchase.project_id == project_id).all()
|
||||
return templates.TemplateResponse(
|
||||
"purchases/list.html",
|
||||
{"request": request, "purchases": purchases, "project_id": project_id}
|
||||
)
|
||||
|
||||
|
||||
@router.get("/seed")
|
||||
async def seed_demo_data(db: Session = Depends(get_db)):
|
||||
"""Seed demo data endpoint."""
|
||||
from app.utils.seed_data import seed_demo_data
|
||||
seed_demo_data(db)
|
||||
return {"message": "Demo data seeded successfully"}
|
||||
|
||||
|
||||
@router.get("/resources/{resource_id}/allocate")
|
||||
async def allocate_resource(request: Request, resource_id: int, system_id: int = Query(...), guardian_id: Optional[int] = Query(None), quantity: int = Query(...), db: Session = Depends(get_db)):
|
||||
"""Allocate resource to system/guardian."""
|
||||
# Use ResourceAllocationService for business logic
|
||||
service = ResourceAllocationService(db)
|
||||
|
||||
result = service.allocate_resource(resource_id, system_id, guardian_id, quantity)
|
||||
|
||||
if result['success']:
|
||||
return templates.TemplateResponse(
|
||||
"resources/allocated.html",
|
||||
{
|
||||
"request": request,
|
||||
"allocation": result['allocation'],
|
||||
"resource": result['resource'],
|
||||
"system": result['system'],
|
||||
"guardian": result.get('guardian')
|
||||
}
|
||||
)
|
||||
else:
|
||||
return templates.TemplateResponse(
|
||||
"resources/allocate_error.html",
|
||||
{
|
||||
"request": request,
|
||||
"error": result['error'],
|
||||
"resource": result.get('resource'),
|
||||
"resource_id": resource_id
|
||||
}
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user