Major refactor WIP

This commit is contained in:
2026-04-03 11:13:44 -04:00
parent dee58e0aae
commit 7b2de645db
25 changed files with 5841 additions and 7760 deletions
+67
View File
@@ -0,0 +1,67 @@
"""Add movements table
Revision ID: 006_movements
Revises: 005_flight_states
Create Date: 2026-04-03 12:00:00.000000
"""
from alembic import op
import sqlalchemy as sa
from sqlalchemy import Enum
# revision identifiers, used by Alembic.
revision = '006_movements'
down_revision = '005_flight_states'
branch_labels = None
depends_on = None
def upgrade() -> None:
# Create movements table
op.create_table('movements',
sa.Column('id', sa.BigInteger(), autoincrement=True, nullable=False),
sa.Column('movement_type', sa.Enum('TAKEOFF', 'LANDING', 'OVERFLIGHT', 'GO_AROUND', 'TOUCH_AND_GO', name='movementtype'), nullable=False),
sa.Column('aircraft_registration', sa.String(length=16), nullable=False),
sa.Column('aircraft_type', sa.String(length=32), nullable=True),
sa.Column('callsign', sa.String(length=16), nullable=True),
sa.Column('timestamp', sa.DateTime(), nullable=False),
sa.Column('entity_type', sa.String(length=50), nullable=False),
sa.Column('entity_id', sa.BigInteger(), nullable=False),
sa.Column('to_location', sa.String(length=64), nullable=True),
sa.Column('from_location', sa.String(length=64), nullable=True),
sa.Column('runway', sa.String(length=10), nullable=True),
sa.Column('wind', sa.String(length=20), nullable=True),
sa.Column('pressure_setting', sa.String(length=20), nullable=True),
sa.Column('created_by', sa.String(length=16), nullable=True),
sa.Column('ip_address', sa.String(length=45), nullable=True),
sa.Column('notes', sa.String(length=255), nullable=True),
sa.Column('created_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP'), nullable=False),
sa.PrimaryKeyConstraint('id')
)
# Create indexes
op.create_index('idx_movement_lookup', 'movements', ['entity_type', 'entity_id'], unique=False)
op.create_index('idx_movement_time', 'movements', ['timestamp', 'movement_type'], unique=False)
op.create_index('ix_movements_movement_type', 'movements', ['movement_type'], unique=False)
op.create_index('ix_movements_aircraft_registration', 'movements', ['aircraft_registration'], unique=False)
op.create_index('ix_movements_timestamp', 'movements', ['timestamp'], unique=False)
op.create_index('ix_movements_entity_type', 'movements', ['entity_type'], unique=False)
op.create_index('ix_movements_created_by', 'movements', ['created_by'], unique=False)
def downgrade() -> None:
# Drop indexes
op.drop_index('ix_movements_created_by', table_name='movements')
op.drop_index('ix_movements_entity_type', table_name='movements')
op.drop_index('ix_movements_timestamp', table_name='movements')
op.drop_index('ix_movements_aircraft_registration', table_name='movements')
op.drop_index('ix_movements_movement_type', table_name='movements')
op.drop_index('idx_movement_time', table_name='movements')
op.drop_index('idx_movement_lookup', table_name='movements')
# Drop table
op.drop_table('movements')
# Drop enum
op.execute("DROP TYPE IF EXISTS movementtype")
@@ -0,0 +1,58 @@
"""Add ACTIVATED status to PPR, PENDING status to departures, arrival_id FK on departures
Revision ID: 007_ppr_activated_status
Revises: 006_movements
Create Date: 2026-04-03 12:00:00.000000
"""
from alembic import op
import sqlalchemy as sa
revision = '007_ppr_activated_status'
down_revision = '006_movements'
branch_labels = None
depends_on = None
def upgrade() -> None:
# Add ACTIVATED to PPR status enum
op.execute(
"ALTER TABLE submitted MODIFY COLUMN status "
"ENUM('NEW','CONFIRMED','CANCELED','LANDED','DELETED','DEPARTED','ACTIVATED') NOT NULL"
)
# Add PENDING to departures status enum
op.execute(
"ALTER TABLE departures MODIFY COLUMN status "
"ENUM('BOOKED_OUT','GROUND','DEPARTED','LOCAL','CANCELLED','PENDING') NOT NULL"
)
# Add arrival_id FK column to departures (nullable - only set for PPR-activated departures)
op.add_column('departures', sa.Column('arrival_id', sa.BigInteger(), nullable=True))
op.create_foreign_key(
'fk_departures_arrival_id', 'departures', 'arrivals',
['arrival_id'], ['id'], ondelete='SET NULL'
)
op.create_index('idx_departures_arrival_id', 'departures', ['arrival_id'])
def downgrade() -> None:
op.drop_index('idx_departures_arrival_id', table_name='departures')
op.drop_constraint('fk_departures_arrival_id', 'departures', type_='foreignkey')
op.drop_column('departures', 'arrival_id')
op.execute(
"UPDATE departures SET status = 'CANCELLED' WHERE status = 'PENDING'"
)
op.execute(
"ALTER TABLE departures MODIFY COLUMN status "
"ENUM('BOOKED_OUT','GROUND','DEPARTED','LOCAL','CANCELLED') NOT NULL"
)
op.execute(
"UPDATE submitted SET status = 'CONFIRMED' WHERE status = 'ACTIVATED'"
)
op.execute(
"ALTER TABLE submitted MODIFY COLUMN status "
"ENUM('NEW','CONFIRMED','CANCELED','LANDED','DELETED','DEPARTED') NOT NULL"
)
+2 -1
View File
@@ -1,5 +1,5 @@
from fastapi import APIRouter
from app.api.endpoints import auth, pprs, public, aircraft, airport, local_flights, departures, arrivals, circuits, journal, overflights, public_book
from app.api.endpoints import auth, pprs, public, aircraft, airport, local_flights, departures, arrivals, circuits, journal, overflights, public_book, movements
api_router = APIRouter()
@@ -11,6 +11,7 @@ api_router.include_router(arrivals.router, prefix="/arrivals", tags=["arrivals"]
api_router.include_router(overflights.router, prefix="/overflights", tags=["overflights"])
api_router.include_router(circuits.router, prefix="/circuits", tags=["circuits"])
api_router.include_router(journal.router, prefix="/journal", tags=["journal"])
api_router.include_router(movements.router, prefix="/movements", tags=["movements"])
api_router.include_router(public.router, prefix="/public", tags=["public"])
api_router.include_router(public_book.router, prefix="/public-book", tags=["public_booking"])
api_router.include_router(aircraft.router, prefix="/aircraft", tags=["aircraft"])
+48
View File
@@ -0,0 +1,48 @@
from typing import List, Optional
from fastapi import APIRouter, Depends, HTTPException, status
from sqlalchemy.orm import Session
from datetime import date
from app.api.deps import get_db, get_current_read_user
from app.crud.crud_movement import movement as crud_movement
from app.schemas.movement import Movement
from app.models.ppr import User
from app.models.movement import MovementType
router = APIRouter()
@router.get("/", response_model=List[Movement])
async def get_movements(
skip: int = 0,
limit: int = 100,
movement_type: Optional[MovementType] = None,
aircraft_registration: Optional[str] = None,
date_from: Optional[date] = None,
date_to: Optional[date] = None,
entity_type: Optional[str] = None,
db: Session = Depends(get_db),
current_user: User = Depends(get_current_read_user)
):
"""Get movement records with optional filtering"""
movements = crud_movement.get_multi(
db, skip=skip, limit=limit, movement_type=movement_type,
aircraft_registration=aircraft_registration, date_from=date_from,
date_to=date_to, entity_type=entity_type
)
return movements
@router.get("/{movement_id}", response_model=Movement)
async def get_movement(
movement_id: int,
db: Session = Depends(get_db),
current_user: User = Depends(get_current_read_user)
):
"""Get a specific movement record"""
movement = crud_movement.get(db, movement_id=movement_id)
if not movement:
raise HTTPException(
status_code=status.HTTP_404_NOT_FOUND,
detail="Movement record not found"
)
return movement
+78
View File
@@ -5,7 +5,11 @@ from datetime import date
from app.api.deps import get_db, get_current_read_user, get_current_operator_user
from app.crud.crud_ppr import ppr as crud_ppr
from app.crud.crud_journal import journal as crud_journal
from app.crud.crud_arrival import arrival as crud_arrival
from app.crud.crud_departure import departure as crud_departure
from app.schemas.ppr import PPR, PPRCreate, PPRUpdate, PPRStatus, PPRStatusUpdate, Journal
from app.schemas.arrival import ArrivalCreate
from app.schemas.departure import DepartureCreate
from app.models.ppr import User
from app.core.utils import get_client_ip
from app.core.email import email_service
@@ -374,3 +378,77 @@ async def get_ppr_journal(
)
return crud_journal.get_by_ppr_id(db, ppr_id=ppr_id)
@router.post("/{ppr_id}/activate")
async def activate_ppr(
request: Request,
ppr_id: int,
db: Session = Depends(get_db),
current_user: User = Depends(get_current_operator_user)
):
"""Activate a PPR by creating BOOKED_IN arrival and (if out_to set) BOOKED_OUT departure records."""
db_ppr = crud_ppr.get(db, ppr_id=ppr_id)
if not db_ppr:
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail="PPR record not found")
if db_ppr.status not in (PPRStatus.NEW, PPRStatus.CONFIRMED):
raise HTTPException(
status_code=status.HTTP_400_BAD_REQUEST,
detail=f"PPR cannot be activated in its current state ({db_ppr.status.value})"
)
client_ip = get_client_ip(request)
username = current_user.username
# Create INBOUND arrival (ADMIN submitted_via sets status to INBOUND)
in_from = (db_ppr.in_from or "ZZZZ")[:4].upper()
arrival_in = ArrivalCreate(
registration=db_ppr.ac_reg,
type=db_ppr.ac_type,
callsign=db_ppr.ac_call,
pob=db_ppr.pob_in,
in_from=in_from,
eta=db_ppr.eta,
notes=db_ppr.notes,
submitted_via="ADMIN"
)
new_arrival = crud_arrival.create(db, obj_in=arrival_in, created_by=username, submitted_via="ADMIN", user_ip=client_ip)
# Create PENDING departure linked to this arrival (only visible once arrival lands)
new_departure = None
if db_ppr.out_to:
departure_in = DepartureCreate(
registration=db_ppr.ac_reg,
type=db_ppr.ac_type,
callsign=db_ppr.ac_call,
pob=db_ppr.pob_out if db_ppr.pob_out else db_ppr.pob_in,
out_to=db_ppr.out_to,
etd=db_ppr.etd,
notes=db_ppr.notes,
arrival_id=new_arrival.id,
)
new_departure = crud_departure.create(db, obj_in=departure_in, created_by=username, submitted_via="ADMIN", user_ip=client_ip)
# Mark PPR as ACTIVATED — removes it from Today's PPR and pending arrivals displays
crud_ppr.update_status(db, ppr_id=ppr_id, status=PPRStatus.ACTIVATED, user=username, user_ip=client_ip)
# Broadcast WebSocket update
if hasattr(request.app.state, 'connection_manager'):
await request.app.state.connection_manager.broadcast({
"type": "ppr_activated",
"data": {
"ppr_id": ppr_id,
"arrival_id": new_arrival.id,
"departure_id": new_departure.id if new_departure else None
}
})
return {
"arrival_id": new_arrival.id,
"departure_id": new_departure.id if new_departure else None,
"message": (
f"PPR activated: arrival #{new_arrival.id} created"
+ (f", departure #{new_departure.id} queued (will appear when aircraft lands)" if new_departure else "")
)
}
+38
View File
@@ -6,6 +6,9 @@ from app.models.arrival import Arrival, ArrivalStatus
from app.schemas.arrival import ArrivalCreate, ArrivalUpdate, ArrivalStatusUpdate
from app.models.journal import EntityType
from app.crud.crud_journal import journal
from app.crud.crud_movement import movement as movement_crud
from app.schemas.movement import MovementCreate
from app.models.movement import MovementType
class CRUDArrival:
@@ -155,6 +158,41 @@ class CRUDArrival:
db.commit()
db.refresh(db_obj)
# Create movement record if applicable
if status == ArrivalStatus.LANDED and db_obj.landed_dt:
movement_data = MovementCreate(
movement_type=MovementType.LANDING,
aircraft_registration=db_obj.registration,
aircraft_type=db_obj.type,
callsign=db_obj.callsign,
timestamp=db_obj.landed_dt,
entity_type="ARRIVAL",
entity_id=arrival_id,
from_location=db_obj.in_from,
created_by=user,
ip_address=user_ip
)
movement_crud.create(db, movement_data)
# Promote any PENDING departure linked to this arrival to BOOKED_OUT
from app.models.departure import Departure as DepartureModel, DepartureStatus as DepStatus
pending_dep = db.query(DepartureModel).filter(
DepartureModel.arrival_id == arrival_id,
DepartureModel.status == DepStatus.PENDING
).first()
if pending_dep:
pending_dep.status = DepStatus.BOOKED_OUT
db.add(pending_dep)
db.commit()
journal.log_change(
db,
EntityType.ARRIVAL,
arrival_id,
f"Linked departure #{pending_dep.id} promoted to BOOKED_OUT on landing",
user,
user_ip
)
# Log status change in journal
journal.log_change(
db,
+38
View File
@@ -6,6 +6,11 @@ from app.models.circuit import Circuit
from app.schemas.circuit import CircuitCreate, CircuitUpdate
from app.models.journal import EntityType
from app.crud.crud_journal import journal
from app.crud.crud_movement import movement as movement_crud
from app.schemas.movement import MovementCreate
from app.models.movement import MovementType
from app.crud.crud_local_flight import local_flight as crud_local_flight
from app.crud.crud_arrival import arrival as crud_arrival
class CRUDCircuit:
@@ -56,6 +61,39 @@ class CRUDCircuit:
user_ip
)
# Create TOUCH_AND_GO movement
if obj_in.local_flight_id:
flight = crud_local_flight.get(db, obj_in.local_flight_id)
if flight:
movement_data = MovementCreate(
movement_type=MovementType.TOUCH_AND_GO,
aircraft_registration=flight.registration,
aircraft_type=flight.type,
callsign=flight.callsign,
timestamp=obj_in.circuit_timestamp,
entity_type="LOCAL_FLIGHT",
entity_id=obj_in.local_flight_id,
created_by=user,
ip_address=user_ip
)
movement_crud.create(db, movement_data)
elif obj_in.arrival_id:
arrival = crud_arrival.get(db, obj_in.arrival_id)
if arrival:
movement_data = MovementCreate(
movement_type=MovementType.TOUCH_AND_GO,
aircraft_registration=arrival.registration,
aircraft_type=arrival.type,
callsign=arrival.callsign,
timestamp=obj_in.circuit_timestamp,
entity_type="ARRIVAL",
entity_id=obj_in.arrival_id,
from_location=arrival.in_from,
created_by=user,
ip_address=user_ip
)
movement_crud.create(db, movement_data)
return db_obj
def update(self, db: Session, db_obj: Circuit, obj_in: CircuitUpdate, user: str = "system", user_ip: Optional[str] = None) -> Circuit:
+29 -1
View File
@@ -6,6 +6,9 @@ from app.models.departure import Departure, DepartureStatus
from app.schemas.departure import DepartureCreate, DepartureUpdate, DepartureStatusUpdate
from app.models.journal import EntityType
from app.crud.crud_journal import journal
from app.crud.crud_movement import movement as movement_crud
from app.schemas.movement import MovementCreate
from app.models.movement import MovementType
class CRUDDeparture:
@@ -58,8 +61,17 @@ class CRUDDeparture:
initial_status = DepartureStatus.GROUND
contact_dt = func.now() # Set contact_dt to creation time for admin submissions
obj_data = obj_in.dict()
arrival_id = obj_data.pop('arrival_id', None)
# If arrival_id is provided this is a PPR-linked departure — stay PENDING until arrival lands
if arrival_id is not None:
initial_status = DepartureStatus.PENDING
contact_dt = None
db_obj = Departure(
**obj_in.dict(),
**obj_data,
arrival_id=arrival_id,
created_by=created_by,
status=initial_status,
contact_dt=contact_dt,
@@ -149,6 +161,22 @@ class CRUDDeparture:
db.commit()
db.refresh(db_obj)
# Create movement record if applicable
if db_obj.takeoff_dt and status == DepartureStatus.LOCAL:
movement_data = MovementCreate(
movement_type=MovementType.TAKEOFF,
aircraft_registration=db_obj.registration,
aircraft_type=db_obj.type,
callsign=db_obj.callsign,
timestamp=db_obj.takeoff_dt,
entity_type="DEPARTURE",
entity_id=departure_id,
to_location=db_obj.out_to,
created_by=user,
ip_address=user_ip
)
movement_crud.create(db, movement_data)
# Log status change in journal
journal.log_change(
db,
+36 -3
View File
@@ -7,6 +7,9 @@ from app.schemas.local_flight import LocalFlightCreate, LocalFlightUpdate, Local
from app.models.journal import EntityType
from app.models.circuit import Circuit
from app.crud.crud_journal import journal
from app.crud.crud_movement import movement as movement_crud
from app.schemas.movement import MovementCreate
from app.models.movement import MovementType
class CRUDLocalFlight:
@@ -186,9 +189,7 @@ class CRUDLocalFlight:
db_obj.contact_dt = current_time
elif status == LocalFlightStatus.DEPARTED:
db_obj.departed_dt = current_time
elif status == LocalFlightStatus.LOCAL:
db_obj.takeoff_dt = current_time
elif status == LocalFlightStatus.LANDED:
elif status == LocalFlightStatus.LANDED and not db_obj.landed_dt:
db_obj.landed_dt = current_time
# Count circuits from the circuits table and populate the circuits column
circuit_count = db.query(func.count(Circuit.id)).filter(
@@ -196,10 +197,42 @@ class CRUDLocalFlight:
).scalar()
db_obj.circuits = circuit_count
# Takeoff: happens once when transitioning away from GROUND
if old_status == LocalFlightStatus.GROUND and status in (LocalFlightStatus.DEPARTED, LocalFlightStatus.LOCAL, LocalFlightStatus.CIRCUIT) and not db_obj.takeoff_dt:
db_obj.takeoff_dt = current_time
db.add(db_obj)
db.commit()
db.refresh(db_obj)
# Create movement record if applicable
if db_obj.takeoff_dt and old_status == LocalFlightStatus.GROUND and status in (LocalFlightStatus.DEPARTED, LocalFlightStatus.LOCAL, LocalFlightStatus.CIRCUIT):
movement_data = MovementCreate(
movement_type=MovementType.TAKEOFF,
aircraft_registration=db_obj.registration,
aircraft_type=db_obj.type,
callsign=db_obj.callsign,
timestamp=db_obj.takeoff_dt,
entity_type="LOCAL_FLIGHT",
entity_id=flight_id,
created_by=user,
ip_address=user_ip
)
movement_crud.create(db, movement_data)
if db_obj.landed_dt and status == LocalFlightStatus.LANDED:
movement_data = MovementCreate(
movement_type=MovementType.LANDING,
aircraft_registration=db_obj.registration,
aircraft_type=db_obj.type,
callsign=db_obj.callsign,
timestamp=db_obj.landed_dt,
entity_type="LOCAL_FLIGHT",
entity_id=flight_id,
created_by=user,
ip_address=user_ip
)
movement_crud.create(db, movement_data)
# Log status change in journal
journal.log_change(
db,
+61
View File
@@ -0,0 +1,61 @@
from typing import List, Optional
from sqlalchemy.orm import Session
from sqlalchemy import and_, func
from datetime import date, datetime
from app.models.movement import Movement, MovementType
from app.schemas.movement import MovementCreate
class CRUDMovement:
def get(self, db: Session, movement_id: int) -> Optional[Movement]:
return db.query(Movement).filter(Movement.id == movement_id).first()
def get_multi(
self,
db: Session,
skip: int = 0,
limit: int = 100,
movement_type: Optional[MovementType] = None,
aircraft_registration: Optional[str] = None,
date_from: Optional[date] = None,
date_to: Optional[date] = None,
entity_type: Optional[str] = None
) -> List[Movement]:
query = db.query(Movement)
if movement_type:
query = query.filter(Movement.movement_type == movement_type)
if aircraft_registration:
query = query.filter(Movement.aircraft_registration.ilike(f"%{aircraft_registration}%"))
if date_from:
query = query.filter(func.date(Movement.timestamp) >= date_from)
if date_to:
query = query.filter(func.date(Movement.timestamp) <= date_to)
if entity_type:
query = query.filter(Movement.entity_type == entity_type)
return query.order_by(Movement.timestamp.desc()).offset(skip).limit(limit).all()
def create(self, db: Session, obj_in: MovementCreate) -> Movement:
db_obj = Movement(**obj_in.dict())
db.add(db_obj)
db.commit()
db.refresh(db_obj)
return db_obj
def get_movements_by_entity(self, db: Session, entity_type: str, entity_id: int) -> List[Movement]:
return db.query(Movement).filter(
and_(Movement.entity_type == entity_type, Movement.entity_id == entity_id)
).order_by(Movement.timestamp).all()
def get_daily_movements(self, db: Session, target_date: date) -> List[Movement]:
return db.query(Movement).filter(
func.date(Movement.timestamp) == target_date
).order_by(Movement.timestamp).all()
movement = CRUDMovement()
+18
View File
@@ -6,6 +6,9 @@ from app.models.overflight import Overflight, OverflightStatus
from app.schemas.overflight import OverflightCreate, OverflightUpdate, OverflightStatusUpdate
from app.models.journal import EntityType
from app.crud.crud_journal import journal
from app.crud.crud_movement import movement as movement_crud
from app.schemas.movement import MovementCreate
from app.models.movement import MovementType
class CRUDOverflight:
@@ -57,6 +60,21 @@ class CRUDOverflight:
db.commit()
db.refresh(db_obj)
# Create OVERFLIGHT movement if call_dt is set
if db_obj.call_dt:
movement_data = MovementCreate(
movement_type=MovementType.OVERFLIGHT,
aircraft_registration=db_obj.registration,
aircraft_type=db_obj.type,
timestamp=db_obj.call_dt,
entity_type="OVERFLIGHT",
entity_id=db_obj.id,
from_location=db_obj.departure_airfield,
to_location=db_obj.destination_airfield,
created_by=created_by
)
movement_crud.create(db, movement_data)
# Log creation in journal
journal.log_change(
db,
+1
View File
@@ -15,6 +15,7 @@ from app.models.local_flight import LocalFlight
from app.models.departure import Departure
from app.models.arrival import Arrival
from app.models.circuit import Circuit
from app.models.movement import Movement
# Set up logging
logging.basicConfig(level=logging.INFO)
+2
View File
@@ -17,6 +17,7 @@ class DepartureStatus(str, Enum):
DEPARTED = "DEPARTED"
LOCAL = "LOCAL"
CANCELLED = "CANCELLED"
PENDING = "PENDING"
class Departure(Base):
@@ -38,4 +39,5 @@ class Departure(Base):
created_by = Column(String(16), nullable=True, index=True)
submitted_via = Column(SQLEnum(SubmissionSource), nullable=False, default=SubmissionSource.ADMIN, index=True)
pilot_email = Column(String(128), nullable=True) # For public submissions
arrival_id = Column(BigInteger, nullable=True) # Linked arrival for PPR-activated departures
updated_at = Column(DateTime, server_default=func.now(), onupdate=func.now(), nullable=False)
+37
View File
@@ -0,0 +1,37 @@
from sqlalchemy import Column, BigInteger, String, DateTime, Enum as SQLEnum, func, Index
from enum import Enum
from app.db.session import Base
class MovementType(str, Enum):
TAKEOFF = "TAKEOFF" # Aircraft becomes airborne
LANDING = "LANDING" # Aircraft touches down
OVERFLIGHT = "OVERFLIGHT" # Aircraft passes through airspace (e.g., on call or QSY)
GO_AROUND = "GO_AROUND" # Aircraft aborts landing and goes around
TOUCH_AND_GO = "TOUCH_AND_GO" # Aircraft lands and immediately takes off again
class Movement(Base):
__tablename__ = "movements"
id = Column(BigInteger, primary_key=True, autoincrement=True)
movement_type = Column(SQLEnum(MovementType), nullable=False, index=True)
aircraft_registration = Column(String(16), nullable=False, index=True)
aircraft_type = Column(String(32), nullable=True)
callsign = Column(String(16), nullable=True)
timestamp = Column(DateTime, nullable=False, index=True) # Exact time of movement
entity_type = Column(String(50), nullable=False, index=True) # PPR, LOCAL_FLIGHT, ARRIVAL, DEPARTURE, OVERFLIGHT
entity_id = Column(BigInteger, nullable=False, index=True) # ID of the associated flight record
to_location = Column(String(64), nullable=True) # Destination (TO) - populated based on movement type
from_location = Column(String(64), nullable=True) # Origin (FROM) - populated based on movement type
runway = Column(String(10), nullable=True) # Runway used (e.g., "10", "28", "04", "22")
wind = Column(String(20), nullable=True) # Wind speed/direction (e.g., "280/25")
pressure_setting = Column(String(20), nullable=True) # Pressure setting (e.g., "QNH1024", "QFE1013")
created_by = Column(String(16), nullable=True, index=True) # User who triggered the movement
ip_address = Column(String(45), nullable=True) # For audit
notes = Column(String(255), nullable=True) # Optional context (e.g., runway used)
created_at = Column(DateTime, nullable=False, server_default=func.current_timestamp())
# Composite index for efficient queries
__table_args__ = (
Index('idx_movement_lookup', 'entity_type', 'entity_id'),
Index('idx_movement_time', 'timestamp', 'movement_type'),
)
+1
View File
@@ -11,6 +11,7 @@ class PPRStatus(str, Enum):
LANDED = "LANDED"
DELETED = "DELETED"
DEPARTED = "DEPARTED"
ACTIVATED = "ACTIVATED"
class UserRole(str, Enum):
+3 -1
View File
@@ -10,6 +10,7 @@ class DepartureStatus(str, Enum):
DEPARTED = "DEPARTED"
LOCAL = "LOCAL"
CANCELLED = "CANCELLED"
PENDING = "PENDING"
class SubmissionSource(str, Enum):
@@ -46,7 +47,7 @@ class DepartureBase(BaseModel):
class DepartureCreate(DepartureBase):
pass
arrival_id: Optional[int] = None
class DepartureUpdate(BaseModel):
@@ -79,6 +80,7 @@ class Departure(DepartureBase):
updated_at: datetime
submitted_via: Optional[SubmissionSource] = None
pilot_email: Optional[str] = None
arrival_id: Optional[int] = None
class Config:
from_attributes = True
+1
View File
@@ -75,6 +75,7 @@ class LocalFlightUpdate(BaseModel):
contact_dt: Optional[datetime] = None
departed_dt: Optional[datetime] = None
takeoff_dt: Optional[datetime] = None
landed_dt: Optional[datetime] = None
circuits: Optional[int] = None
notes: Optional[str] = None
+34
View File
@@ -0,0 +1,34 @@
from typing import Optional
from pydantic import BaseModel
from datetime import datetime
from app.models.movement import MovementType
class MovementBase(BaseModel):
movement_type: MovementType
aircraft_registration: str
aircraft_type: Optional[str] = None
callsign: Optional[str] = None
timestamp: datetime
entity_type: str
entity_id: int
to_location: Optional[str] = None
from_location: Optional[str] = None
runway: Optional[str] = None
wind: Optional[str] = None
pressure_setting: Optional[str] = None
created_by: Optional[str] = None
ip_address: Optional[str] = None
notes: Optional[str] = None
class MovementCreate(MovementBase):
pass
class Movement(MovementBase):
id: int
created_at: datetime
class Config:
from_attributes = True
+1
View File
@@ -11,6 +11,7 @@ class PPRStatus(str, Enum):
LANDED = "LANDED"
DELETED = "DELETED"
DEPARTED = "DEPARTED"
ACTIVATED = "ACTIVATED"
class UserRole(str, Enum):
+2
View File
@@ -39,11 +39,13 @@ http {
# Serve HTML files without .html extension (e.g., /admin -> admin.html)
location ~ ^/([a-zA-Z0-9_-]+)$ {
ssi on;
try_files /$1.html =404;
}
# Serve static files
location / {
ssi on;
try_files $uri $uri/ =404;
# Apply X-Frame-Options to other files
add_header X-Frame-Options "SAMEORIGIN" always;
+31 -3871
View File
File diff suppressed because it is too large Load Diff
+35 -3880
View File
File diff suppressed because it is too large Load Diff
+1277
View File
File diff suppressed because it is too large Load Diff
+927
View File
@@ -0,0 +1,927 @@
<!-- Login Modal -->
<div id="loginModal" class="modal" style="display: none;">
<div class="modal-content" style="max-width: 400px;">
<div class="modal-header">
<h2>PPR Admin Login</h2>
</div>
<div class="modal-body">
<form id="login-form">
<div class="form-group">
<label for="login-username">Username:</label>
<input type="text" id="login-username" name="username" required autofocus>
</div>
<div class="form-group">
<label for="login-password">Password:</label>
<input type="password" id="login-password" name="password" required>
</div>
<div id="login-error" style="color: #dc3545; margin: 1rem 0; display: none;"></div>
<div class="form-actions" style="border-top: none; padding-top: 0;">
<button type="submit" class="btn btn-success" id="login-btn">
🔐 Login
</button>
</div>
</form>
</div>
</div>
</div>
<!-- PPR Detail/Edit Modal -->
<div id="pprModal" class="modal">
<div class="modal-content">
<div class="modal-header">
<h2 id="modal-title">PPR Details</h2>
<button class="close" onclick="closePPRModal()">&times;</button>
</div>
<div class="modal-body">
<div class="quick-actions">
<button id="btn-landed" class="btn btn-warning btn-sm" onclick="showTimestampModal('LANDED')">
🛬 Land
</button>
<button id="btn-departed" class="btn btn-primary btn-sm" onclick="showTimestampModal('DEPARTED')">
🛫 Depart
</button>
</div>
<form id="ppr-form">
<input type="hidden" id="ppr-id" name="id">
<div class="form-grid">
<div class="form-group">
<label for="ac_reg">Aircraft Registration *</label>
<input type="text" id="ac_reg" name="ac_reg" required oninput="handleAircraftLookup(this.value)">
<div id="aircraft-lookup-results"></div>
</div>
<div class="form-group">
<label for="ac_type">Aircraft Type *</label>
<input type="text" id="ac_type" name="ac_type" required tabindex="-1">
</div>
<div class="form-group">
<label for="ac_call">Callsign</label>
<input type="text" id="ac_call" name="ac_call" placeholder="If different from registration" tabindex="-1">
</div>
<div class="form-group">
<label for="captain">Captain *</label>
<input type="text" id="captain" name="captain" required>
</div>
<div class="form-group">
<label for="in_from">Arriving From *</label>
<input type="text" id="in_from" name="in_from" required placeholder="ICAO Code or Airport Name" oninput="handleArrivalAirportLookup(this.value)">
<div id="arrival-airport-lookup-results"></div>
</div>
<div class="form-group">
<label for="eta">ETA (Local Time) *</label>
<div style="display: flex; gap: 0.5rem;">
<input type="date" id="eta-date" name="eta-date" required style="flex: 1;">
<select id="eta-time" name="eta-time" required style="flex: 1;">
<option value="">Select Time</option>
</select>
</div>
</div>
<div class="form-group">
<label for="pob_in">POB Inbound *</label>
<input type="number" id="pob_in" name="pob_in" required min="1">
</div>
<div class="form-group">
<label for="fuel">Fuel Required</label>
<select id="fuel" name="fuel" tabindex="-1">
<option value="">None</option>
<option value="100LL">100LL</option>
<option value="JET A1">JET A1</option>
</select>
</div>
<div class="form-group">
<label for="out_to">Departing To</label>
<input type="text" id="out_to" name="out_to" placeholder="ICAO Code or Airport Name" oninput="handleDepartureAirportLookup(this.value)" tabindex="-1">
<div id="departure-airport-lookup-results"></div>
</div>
<div class="form-group">
<label for="etd">ETD (Local Time)</label>
<div style="display: flex; gap: 0.5rem;">
<input type="date" id="etd-date" name="etd-date" tabindex="-1" style="flex: 1;">
<select id="etd-time" name="etd-time" tabindex="-1" style="flex: 1;">
<option value="">Select Time</option>
</select>
</div>
</div>
<div class="form-group">
<label for="pob_out">POB Outbound</label>
<input type="number" id="pob_out" name="pob_out" min="1" tabindex="-1">
</div>
<div class="form-group">
<label for="email">Email</label>
<input type="email" id="email" name="email" tabindex="-1">
</div>
<div class="form-group">
<label for="phone">Phone</label>
<input type="tel" id="phone" name="phone" tabindex="-1">
</div>
<div class="form-group full-width">
<label for="notes">Notes</label>
<textarea id="notes" name="notes" rows="3" tabindex="-1"></textarea>
</div>
</div>
<div class="form-actions">
<button type="button" class="btn btn-info" onclick="closePPRModal()">
Close
</button>
<button type="button" class="btn btn-danger" id="btn-cancel" onclick="updateStatus('CANCELED')">
❌ Cancel PPR
</button>
<button type="submit" class="btn btn-success">
💾 Save Changes
</button>
</div>
</form>
<div class="journal-section" id="journal-section">
<h3>Activity Journal</h3>
<div id="journal-entries" class="journal-entries">
Loading journal...
</div>
</div>
</div>
</div>
</div>
<!-- Local Flight (Book Out) Modal -->
<div id="localFlightModal" class="modal">
<div class="modal-content">
<div class="modal-header">
<h2 id="local-flight-modal-title">Book Out</h2>
<button class="close" onclick="closeModal('localFlightModal')">&times;</button>
</div>
<div class="modal-body">
<form id="local-flight-form">
<input type="hidden" id="local-flight-id" name="id">
<div class="form-grid">
<div class="form-group">
<label for="local_registration">Aircraft Registration *</label>
<input type="text" id="local_registration" name="registration" required oninput="handleLocalAircraftLookup(this.value)" tabindex="1">
<div id="local-aircraft-lookup-results"></div>
</div>
<div class="form-group">
<label for="local_type">Aircraft Type</label>
<input type="text" id="local_type" name="type" tabindex="4" placeholder="e.g., C172, PA34, AA5">
</div>
<div class="form-group">
<label for="local_callsign">Callsign (optional)</label>
<input type="text" id="local_callsign" name="callsign" placeholder="If different from registration" tabindex="6">
</div>
<div class="form-group">
<label for="local_pob">Persons on Board *</label>
<input type="number" id="local_pob" name="pob" required min="1" tabindex="2">
</div>
<div class="form-group">
<label for="local_flight_type">Flight Type *</label>
<select id="local_flight_type" name="flight_type" required tabindex="5" onchange="handleFlightTypeChange(this.value)">
<option value="LOCAL">Local Flight</option>
<option value="CIRCUITS">Circuits</option>
<option value="DEPARTURE">Departure to Other Airport</option>
</select>
</div>
<div class="form-group">
<label for="local_duration">Duration (minutes)</label>
<input type="number" id="local_duration" name="duration" min="5" max="480" value="45" placeholder="Duration in minutes" tabindex="7">
</div>
<div class="form-group" id="departure-destination-group" style="display: none;">
<label for="local_out_to" id="departure-destination-label">Destination Airport</label>
<input type="text" id="local_out_to" name="out_to" placeholder="ICAO Code or Airport Name" oninput="handleLocalOutToAirportLookup(this.value)" tabindex="3">
<div id="local-out-to-lookup-results"></div>
</div>
<div class="form-group">
<label for="local_etd_time">ETD (Estimated Time of Departure) *</label>
<select id="local_etd_time" name="etd_time" required>
<option value="">Select Time</option>
</select>
</div>
<div class="form-group full-width">
<label for="local_notes">Notes</label>
<textarea id="local_notes" name="notes" rows="3" placeholder="e.g., destination, any special requirements"></textarea>
</div>
</div>
<div class="form-actions">
<button type="button" class="btn btn-info" onclick="closeModal('localFlightModal')">
Close
</button>
<button type="submit" class="btn btn-success">
🛫 Book Out
</button>
</div>
</form>
</div>
</div>
</div>
<!-- Local Flight Edit Modal -->
<div id="localFlightEditModal" class="modal">
<div class="modal-content">
<div class="modal-header">
<h2 id="local-flight-edit-title">Local Flight Details</h2>
<button class="close" onclick="closeLocalFlightEditModal()">&times;</button>
</div>
<div class="modal-body">
<div class="quick-actions">
<button id="local-btn-departed" class="btn btn-primary btn-sm" onclick="updateLocalFlightStatus('DEPARTED')" style="display: none;">
🛫 Mark Departed
</button>
<button id="local-btn-landed" class="btn btn-warning btn-sm" onclick="updateLocalFlightStatus('LANDED')" style="display: none;">
🛬 Land
</button>
<button id="local-btn-cancel" class="btn btn-danger btn-sm" onclick="updateLocalFlightStatus('CANCELLED')" style="display: none;">
❌ Cancel Flight
</button>
</div>
<form id="local-flight-edit-form">
<input type="hidden" id="local-edit-flight-id" name="id">
<div class="form-grid">
<div class="form-group">
<label for="local_edit_registration">Aircraft Registration</label>
<input type="text" id="local_edit_registration" name="registration">
</div>
<div class="form-group">
<label for="local_edit_type">Aircraft Type</label>
<input type="text" id="local_edit_type" name="type">
</div>
<div class="form-group">
<label for="local_edit_callsign">Callsign</label>
<input type="text" id="local_edit_callsign" name="callsign">
</div>
<div class="form-group">
<label for="local_edit_pob">POB</label>
<input type="number" id="local_edit_pob" name="pob" min="1">
</div>
<div class="form-group">
<label for="local_edit_flight_type">Flight Type</label>
<select id="local_edit_flight_type" name="flight_type">
<option value="LOCAL">Local Flight</option>
<option value="CIRCUITS">Circuits</option>
<option value="DEPARTURE">Departure</option>
</select>
</div>
<div class="form-group">
<label for="local_edit_duration">Duration (minutes)</label>
<input type="number" id="local_edit_duration" name="duration" min="5" max="480">
</div>
<div class="form-group">
<label for="local_edit_takeoff_dt">Takeoff Time</label>
<div style="display: flex; gap: 0.5rem;">
<input type="date" id="local_edit_departure_date" name="departure_date" style="flex: 1;">
<input type="time" id="local_edit_departure_time" name="departure_time" style="flex: 1;">
</div>
</div>
<div class="form-group" id="local-edit-landing-group">
<label for="local_edit_landed_dt">Landing Time</label>
<div style="display: flex; gap: 0.5rem;">
<input type="date" id="local_edit_landed_date" name="landed_date" style="flex: 1;">
<input type="time" id="local_edit_landed_time" name="landed_time" style="flex: 1;">
</div>
</div>
<div class="form-group full-width">
<label for="local_edit_notes">Notes</label>
<textarea id="local_edit_notes" name="notes" rows="3"></textarea>
</div>
</div>
<div class="form-actions">
<button type="button" class="btn btn-info" onclick="closeLocalFlightEditModal()">
Close
</button>
<button type="submit" class="btn btn-success">
💾 Save Changes
</button>
</div>
</form>
<!-- Touch & Go Records Section (for all local flight types) -->
<div id="circuits-section" style="display: none; margin-top: 2rem; border-top: 1px solid #ddd; padding-top: 1rem;">
<h3>✈️ Touch & Go Records</h3>
<div id="circuits-list" style="margin-top: 1rem;">
<p style="color: #666; font-style: italic;">Loading circuits...</p>
</div>
</div>
<!-- Journal Section -->
<div id="local-flight-journal-section" style="margin-top: 2rem; border-top: 1px solid #ddd; padding-top: 1rem;">
<h3>📋 Activity Journal</h3>
<div id="local-flight-journal-entries" class="journal-entries">
Loading journal...
</div>
</div>
</div>
</div>
</div>
<!-- Book In Modal -->
<div id="bookInModal" class="modal">
<div class="modal-content">
<div class="modal-header">
<h2>Book In</h2>
<button class="close" onclick="closeModal('bookInModal')">&times;</button>
</div>
<div class="modal-body">
<form id="book-in-form">
<input type="hidden" id="book-in-id" name="id">
<div class="form-grid">
<div class="form-group">
<label for="book_in_registration">Aircraft Registration *</label>
<input type="text" id="book_in_registration" name="registration" required oninput="handleBookInAircraftLookup(this.value)" tabindex="1">
<div id="book-in-aircraft-lookup-results"></div>
</div>
<div class="form-group">
<label for="book_in_type">Aircraft Type</label>
<input type="text" id="book_in_type" name="type" tabindex="4" placeholder="e.g., C172, PA34, AA5">
</div>
<div class="form-group">
<label for="book_in_callsign">Callsign (optional)</label>
<input type="text" id="book_in_callsign" name="callsign" placeholder="If different from registration" tabindex="5">
</div>
<div class="form-group">
<label for="book_in_pob">Persons on Board *</label>
<input type="number" id="book_in_pob" name="pob" required min="1" tabindex="2">
</div>
<div class="form-group">
<label for="book_in_from">Coming From (Airport) *</label>
<input type="text" id="book_in_from" name="in_from" placeholder="ICAO Code or Airport Name" required oninput="handleBookInArrivalAirportLookup(this.value)" tabindex="3">
<div id="book-in-arrival-airport-lookup-results"></div>
</div>
<div class="form-group">
<label for="book_in_eta_time">ETA (Estimated Time of Arrival) *</label>
<select id="book_in_eta_time" name="eta_time" required>
<option value="">Select Time</option>
</select>
</div>
<div class="form-group full-width">
<label for="book_in_notes">Notes</label>
<textarea id="book_in_notes" name="notes" rows="3" placeholder="e.g., any special requirements"></textarea>
</div>
</div>
<div class="form-actions">
<button type="button" class="btn btn-info" onclick="closeModal('bookInModal')">
Close
</button>
<button type="submit" class="btn btn-success">
🛬 Book In
</button>
</div>
</form>
</div>
</div>
</div>
<!-- Overflight Modal -->
<div id="overflightModal" class="modal">
<div class="modal-content">
<div class="modal-header">
<h2>Register Overflight</h2>
<button class="close" onclick="closeModal('overflightModal')">&times;</button>
</div>
<div class="modal-body">
<form id="overflight-form">
<input type="hidden" id="overflight-id" name="id">
<div class="form-grid">
<div class="form-group">
<label for="overflight_registration">Callsign/Registration *</label>
<input type="text" id="overflight_registration" name="registration" required oninput="handleOverflightAircraftLookup(this.value)" tabindex="1">
<div id="overflight-aircraft-lookup-results"></div>
</div>
<div class="form-group">
<label for="overflight_type">Aircraft Type</label>
<input type="text" id="overflight_type" name="type" placeholder="e.g., C172, PA34, AA5" tabindex="2">
</div>
<div class="form-group">
<label for="overflight_pob">Persons on Board</label>
<input type="number" id="overflight_pob" name="pob" min="1" tabindex="3">
</div>
<div class="form-group">
<label for="overflight_departure_airfield">Departure Airfield</label>
<input type="text" id="overflight_departure_airfield" name="departure_airfield" placeholder="ICAO Code or Airport Name" oninput="handleOverflightDepartureAirportLookup(this.value)" tabindex="4">
<div id="overflight-departure-airport-lookup-results"></div>
</div>
<div class="form-group">
<label for="overflight_destination_airfield">Destination Airfield</label>
<input type="text" id="overflight_destination_airfield" name="destination_airfield" placeholder="ICAO Code or Airport Name" oninput="handleOverflightDestinationAirportLookup(this.value)" tabindex="5">
<div id="overflight-destination-airport-lookup-results"></div>
</div>
<div class="form-group">
<label for="overflight_call_dt">Time of Call *</label>
<input type="datetime-local" id="overflight_call_dt" name="call_dt" required tabindex="6">
</div>
<div class="form-group full-width">
<label for="overflight_notes">Notes</label>
<textarea id="overflight_notes" name="notes" rows="3" placeholder="e.g., flight plan, special remarks" tabindex="7"></textarea>
</div>
</div>
<div class="form-actions">
<button type="button" class="btn btn-info" onclick="closeModal('overflightModal')">
Close
</button>
<button type="submit" class="btn btn-success">
🔄 Register Overflight
</button>
</div>
</form>
</div>
</div>
</div>
<!-- Overflight Edit Modal -->
<div id="overflightEditModal" class="modal">
<div class="modal-content">
<div class="modal-header">
<h2 id="overflight-edit-title">Overflight Details</h2>
<button class="close" onclick="closeModal('overflightEditModal')">&times;</button>
</div>
<div class="modal-body">
<div class="quick-actions">
<button id="overflight-btn-qsy" class="btn btn-primary btn-sm" onclick="showOverflightQSYModal()" style="display: none;">
📡 Mark QSY
</button>
<button id="overflight-btn-cancel" class="btn btn-danger btn-sm" onclick="confirmCancelOverflight()" style="display: none;">
❌ Cancel
</button>
</div>
<form id="overflight-edit-form">
<input type="hidden" id="overflight-edit-id" name="id">
<div class="form-grid">
<div class="form-group">
<label for="overflight_edit_registration">Callsign/Registration</label>
<input type="text" id="overflight_edit_registration" name="registration" readonly>
</div>
<div class="form-group">
<label for="overflight_edit_type">Aircraft Type</label>
<input type="text" id="overflight_edit_type" name="type">
</div>
<div class="form-group">
<label for="overflight_edit_pob">Persons on Board</label>
<input type="number" id="overflight_edit_pob" name="pob" min="1">
</div>
<div class="form-group">
<label for="overflight_edit_departure_airfield">Departure Airfield</label>
<input type="text" id="overflight_edit_departure_airfield" name="departure_airfield">
</div>
<div class="form-group">
<label for="overflight_edit_destination_airfield">Destination Airfield</label>
<input type="text" id="overflight_edit_destination_airfield" name="destination_airfield">
</div>
<div class="form-group">
<label for="overflight_edit_call_dt">Time of Call</label>
<input type="datetime-local" id="overflight_edit_call_dt" name="call_dt">
</div>
<div class="form-group">
<label for="overflight_edit_status">Status</label>
<input type="text" id="overflight_edit_status" name="status" readonly>
</div>
<div class="form-group">
<label for="overflight_edit_qsy_dt">QSY Time</label>
<input type="datetime-local" id="overflight_edit_qsy_dt" name="qsy_dt">
</div>
<div class="form-group full-width">
<label for="overflight_edit_notes">Notes</label>
<textarea id="overflight_edit_notes" name="notes" rows="3"></textarea>
</div>
</div>
<div class="form-actions">
<button type="button" class="btn btn-info" onclick="closeModal('overflightEditModal')">
Close
</button>
<button type="submit" class="btn btn-success">
Save Changes
</button>
</div>
</form>
</div>
</div>
</div>
<!-- Departure Edit Modal -->
<div id="departureEditModal" class="modal">
<div class="modal-content">
<div class="modal-header">
<h2 id="departure-edit-title">Departure Details</h2>
<button class="close" onclick="closeDepartureEditModal()">&times;</button>
</div>
<div class="modal-body">
<div class="quick-actions">
<button id="departure-btn-departed" class="btn btn-primary btn-sm" onclick="updateDepartureStatus('DEPARTED')" style="display: none;">
🛫 Mark Departed
</button>
<button id="departure-btn-cancel" class="btn btn-danger btn-sm" onclick="updateDepartureStatus('CANCELLED')" style="display: none;">
❌ Cancel Departure
</button>
</div>
<form id="departure-edit-form">
<input type="hidden" id="departure-edit-id" name="id">
<div class="form-grid">
<div class="form-group">
<label for="departure_edit_registration">Aircraft Registration</label>
<input type="text" id="departure_edit_registration" name="registration">
</div>
<div class="form-group">
<label for="departure_edit_type">Aircraft Type</label>
<input type="text" id="departure_edit_type" name="type">
</div>
<div class="form-group">
<label for="departure_edit_callsign">Callsign</label>
<input type="text" id="departure_edit_callsign" name="callsign">
</div>
<div class="form-group">
<label for="departure_edit_pob">Persons on Board</label>
<input type="number" id="departure_edit_pob" name="pob" min="1">
</div>
<div class="form-group">
<label for="departure_edit_out_to">Destination</label>
<input type="text" id="departure_edit_out_to" name="out_to">
</div>
<div class="form-group">
<label for="departure_edit_etd">ETD (UTC)</label>
<div style="display: flex; gap: 0.5rem;">
<input type="date" id="departure_edit_etd_date" name="etd_date" style="flex: 1;">
<input type="time" id="departure_edit_etd_time" name="etd_time" style="flex: 1;">
</div>
</div>
<div class="form-group">
<label>Takeoff Time (UTC)</label>
<div style="display: flex; gap: 0.5rem;">
<input type="date" id="departure_edit_takeoff_date" name="takeoff_date" style="flex: 1;">
<input type="time" id="departure_edit_takeoff_time" name="takeoff_time" style="flex: 1;">
</div>
</div>
<div class="form-group full-width">
<label for="departure_edit_notes">Notes</label>
<textarea id="departure_edit_notes" name="notes" rows="3"></textarea>
</div>
</div>
<div class="form-actions">
<button type="button" class="btn btn-info" onclick="closeDepartureEditModal()">
Close
</button>
<button type="submit" class="btn btn-success">
Save Changes
</button>
</div>
</form>
<!-- Journal Section -->
<div id="departure-journal-section" style="margin-top: 2rem; border-top: 1px solid #ddd; padding-top: 1rem;">
<h3>📋 Activity Journal</h3>
<div id="departure-journal-entries" class="journal-entries">
Loading journal...
</div>
</div>
</div>
</div>
</div>
<!-- Arrival Edit Modal -->
<div id="arrivalEditModal" class="modal">
<div class="modal-content">
<div class="modal-header">
<h2 id="arrival-edit-title">Arrival Details</h2>
<button class="close" onclick="closeArrivalEditModal()">&times;</button>
</div>
<div class="modal-body">
<div class="quick-actions">
<button id="arrival-btn-landed" class="btn btn-primary btn-sm" onclick="updateArrivalStatus('LANDED')" style="display: none;">
🛬 Mark Landed
</button>
<button id="arrival-btn-cancel" class="btn btn-danger btn-sm" onclick="updateArrivalStatus('CANCELLED')" style="display: none;">
❌ Cancel Arrival
</button>
</div>
<form id="arrival-edit-form">
<input type="hidden" id="arrival-edit-id" name="id">
<div class="form-grid">
<div class="form-group">
<label for="arrival_edit_registration">Aircraft Registration</label>
<input type="text" id="arrival_edit_registration" name="registration">
</div>
<div class="form-group">
<label for="arrival_edit_type">Aircraft Type</label>
<input type="text" id="arrival_edit_type" name="type">
</div>
<div class="form-group">
<label for="arrival_edit_callsign">Callsign</label>
<input type="text" id="arrival_edit_callsign" name="callsign">
</div>
<div class="form-group">
<label for="arrival_edit_in_from">Origin Airport</label>
<input type="text" id="arrival_edit_in_from" name="in_from">
</div>
<div class="form-group">
<label for="arrival_edit_pob">POB (Persons on Board)</label>
<input type="number" id="arrival_edit_pob" name="pob" min="1">
</div>
<div class="form-group full-width">
<label for="arrival_edit_notes">Notes</label>
<textarea id="arrival_edit_notes" name="notes" rows="3"></textarea>
</div>
</div>
<div class="form-actions">
<button type="button" class="btn btn-info" onclick="closeArrivalEditModal()">
Close
</button>
<button type="submit" class="btn btn-success">
Save Changes
</button>
</div>
</form>
<!-- Journal Section -->
<div id="arrival-journal-section" style="margin-top: 2rem; border-top: 1px solid #ddd; padding-top: 1rem;">
<h3>📋 Activity Journal</h3>
<div id="arrival-journal-entries" class="journal-entries">
Loading journal...
</div>
</div>
</div>
</div>
</div>
<!-- Table Help Modal -->
<div id="tableHelpModal" class="modal">
<div class="modal-content">
<div class="modal-header">
<h2>Table Information</h2>
<button class="close" onclick="closeModal('tableHelpModal')">&times;</button>
</div>
<div class="modal-body" id="tableHelpContent">
<!-- Content will be populated by JavaScript -->
</div>
<div class="modal-footer">
<button class="btn btn-info" onclick="closeModal('tableHelpModal')">Close</button>
</div>
</div>
</div>
<!-- User Management Modal -->
<div id="userManagementModal" class="modal">
<div class="modal-content">
<div class="modal-header">
<h2>User Management</h2>
<button class="close" onclick="closeModal('userManagementModal')">&times;</button>
</div>
<div class="modal-body">
<div class="quick-actions" style="margin-bottom: 1rem;">
<button class="btn btn-success" onclick="openUserCreateModal()">
Create New User
</button>
</div>
<div id="users-loading" class="loading">
<div class="spinner"></div>
Loading users...
</div>
<div id="users-table-content" style="display: none;">
<table>
<thead>
<tr>
<th>Username</th>
<th>Role</th>
<th>Created</th>
<th>Actions</th>
</tr>
</thead>
<tbody id="users-table-body">
</tbody>
</table>
</div>
<div id="users-no-data" class="no-data" style="display: none;">
<h3>No users found</h3>
<p>No users are configured in the system.</p>
</div>
</div>
</div>
</div>
<!-- User Create/Edit Modal -->
<div id="userModal" class="modal">
<div class="modal-content" style="max-width: 500px;">
<div class="modal-header">
<h2 id="user-modal-title">Create User</h2>
<button class="close" onclick="closeUserModal()">&times;</button>
</div>
<div class="modal-body">
<form id="user-form">
<input type="hidden" id="user-id" name="id">
<div class="form-grid">
<div class="form-group full-width">
<label for="user-username">Username *</label>
<input type="text" id="user-username" name="username" required>
</div>
<div class="form-group full-width">
<label for="user-password">Password *</label>
<input type="password" id="user-password" name="password" required>
<small style="color: #666; font-size: 0.8rem;">Leave blank when editing to keep current password</small>
</div>
<div class="form-group full-width">
<label for="user-role">Role *</label>
<select id="user-role" name="role" required>
<option value="READ_ONLY">Read Only - View only access</option>
<option value="OPERATOR">Operator - PPR management access</option>
<option value="ADMINISTRATOR">Administrator - Full access</option>
</select>
</div>
</div>
<div class="form-actions">
<button type="button" class="btn btn-info" onclick="closeUserModal()">
Close
</button>
<button type="submit" class="btn btn-success">
💾 Save User
</button>
</div>
</form>
</div>
</div>
</div>
<!-- Change User Password Modal -->
<div id="changePasswordModal" class="modal">
<div class="modal-content" style="max-width: 500px;">
<div class="modal-header">
<h2 id="change-password-title">Change User Password</h2>
<button class="close" onclick="closeChangePasswordModal()">&times;</button>
</div>
<div class="modal-body">
<form id="change-password-form">
<div class="form-group full-width">
<label for="change-password-username" style="font-weight: bold;">Username</label>
<input type="text" id="change-password-username" name="username" readonly style="background-color: #f5f5f5; cursor: not-allowed;">
</div>
<div class="form-group full-width">
<label for="change-password-new">New Password *</label>
<input type="password" id="change-password-new" name="new_password" required>
</div>
<div class="form-group full-width">
<label for="change-password-confirm">Confirm New Password *</label>
<input type="password" id="change-password-confirm" name="confirm_password" required>
</div>
<div class="form-actions">
<button type="button" class="btn btn-info" onclick="closeChangePasswordModal()">
Close
</button>
<button type="submit" class="btn btn-warning">
🔐 Change Password
</button>
</div>
</form>
</div>
</div>
</div>
<!-- Success Notification -->
<div id="notification" class="notification"></div>
<!-- User Aircraft Management Modal -->
<div id="userAircraftModal" class="modal">
<div class="modal-content" style="max-width: 1000px;">
<div class="modal-header">
<h2>User Aircraft Management</h2>
<button class="close" onclick="closeModal('userAircraftModal')">&times;</button>
</div>
<div class="modal-body">
<div class="quick-actions" style="margin-bottom: 1rem;">
<div class="form-group" style="display: inline-block; margin-right: 1rem;">
<label for="user-aircraft-search" style="display: inline; margin-right: 0.5rem;">Search:</label>
<input type="text" id="user-aircraft-search" placeholder="Filter by registration or type..." style="width: 250px;">
</div>
<button class="btn btn-info" onclick="loadUserAircraft()">
🔄 Refresh
</button>
</div>
<div id="user-aircraft-loading" class="loading">
<div class="spinner"></div>
Loading user aircraft...
</div>
<div id="user-aircraft-table-content" style="display: none;">
<table>
<thead>
<tr>
<th>Registration</th>
<th>Type</th>
<th>Added By</th>
<th>Created</th>
<th>Actions</th>
</tr>
</thead>
<tbody id="user-aircraft-table-body">
</tbody>
</table>
</div>
<div id="user-aircraft-no-data" class="no-data" style="display: none;">
<h3>No user aircraft found</h3>
<p>No custom aircraft types have been saved yet.</p>
</div>
</div>
</div>
</div>
<!-- User Aircraft Edit Modal -->
<div id="userAircraftEditModal" class="modal">
<div class="modal-content" style="max-width: 500px;">
<div class="modal-header">
<h2 id="user-aircraft-edit-title">Edit User Aircraft</h2>
<button class="close" onclick="closeModal('userAircraftEditModal')">&times;</button>
</div>
<div class="modal-body">
<form id="user-aircraft-edit-form">
<div class="form-group full-width">
<label for="edit-aircraft-registration">Registration *</label>
<input type="text" id="edit-aircraft-registration" name="registration" required readonly style="background-color: #f5f5f5;">
</div>
<div class="form-group full-width">
<label for="edit-aircraft-type">Aircraft Type *</label>
<input type="text" id="edit-aircraft-type" name="type_code" required>
</div>
<div class="form-actions">
<button type="button" class="btn btn-info" onclick="closeModal('userAircraftEditModal')">
Cancel
</button>
<button type="submit" class="btn btn-warning">
💾 Save Changes
</button>
<button type="button" class="btn btn-danger" onclick="deleteUserAircraft()">
🗑️ Delete
</button>
</div>
</form>
</div>
</div>
</div>
<!-- Timestamp Modal for Landing/Departure -->
<div id="timestampModal" class="modal">
<div class="modal-content" style="max-width: 400px;">
<div class="modal-header">
<h2 id="timestamp-modal-title">Confirm Landing Time</h2>
<button class="close" onclick="closeTimestampModal()">&times;</button>
</div>
<div class="modal-body">
<form id="timestamp-form">
<div class="form-group">
<label for="event-timestamp">Event Time (UTC) *</label>
<input type="datetime-local" id="event-timestamp" name="timestamp" required>
</div>
<div class="form-actions">
<button type="button" class="btn btn-info" onclick="closeTimestampModal()">
Close
</button>
<button type="submit" class="btn btn-success" id="timestamp-submit-btn">
Confirm
</button>
</div>
</form>
</div>
</div>
</div>
<!-- Circuit Modal for recording touch-and-go events -->
<div id="circuitModal" class="modal">
<div class="modal-content" style="max-width: 400px;">
<div class="modal-header">
<h2>Record Circuit (Touch & Go)</h2>
<button class="close" onclick="closeCircuitModal()">&times;</button>
</div>
<div class="modal-body">
<form id="circuit-form">
<div class="form-group">
<label for="circuit-timestamp">Circuit Time (UTC) *</label>
<input type="datetime-local" id="circuit-timestamp" name="timestamp" required>
</div>
<div class="form-actions">
<button type="button" class="btn btn-info" onclick="closeCircuitModal()">
Close
</button>
<button type="submit" class="btn btn-success">
Record Circuit
</button>
</div>
</form>
</div>
</div>
</div>
+3013
View File
File diff suppressed because it is too large Load Diff