Pilot self-bookout
This commit is contained in:
82
backend/alembic/versions/003_public_booking.py
Normal file
82
backend/alembic/versions/003_public_booking.py
Normal file
@@ -0,0 +1,82 @@
|
||||
"""Add public booking support with submitted_via and pilot_email columns
|
||||
|
||||
Revision ID: 003_public_booking
|
||||
Revises: 002_local_flights
|
||||
Create Date: 2026-02-20 12:00:00.000000
|
||||
|
||||
This migration adds support for public flight booking by adding:
|
||||
- submitted_via enum field to track ADMIN vs PUBLIC submissions
|
||||
- pilot_email field to store contact info for public submissions
|
||||
- Indexes on submitted_via for filtering queries
|
||||
|
||||
"""
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision = '003_public_booking'
|
||||
down_revision = '002_local_flights'
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
"""
|
||||
Add public booking support columns to local_flights, departures, and arrivals tables.
|
||||
"""
|
||||
|
||||
# Create the SubmissionSource enum type
|
||||
submission_source_enum = sa.Enum('ADMIN', 'PUBLIC', name='submissionsource')
|
||||
|
||||
# Add submitted_via and pilot_email to local_flights table
|
||||
op.add_column('local_flights', sa.Column('submitted_via', submission_source_enum, nullable=False, server_default='ADMIN'))
|
||||
op.add_column('local_flights', sa.Column('pilot_email', sa.String(length=128), nullable=True))
|
||||
|
||||
# Add indexes for submitted_via and pilot_email on local_flights
|
||||
op.create_index('idx_lf_submitted_via', 'local_flights', ['submitted_via'])
|
||||
op.create_index('idx_lf_pilot_email', 'local_flights', ['pilot_email'])
|
||||
|
||||
# Add submitted_via and pilot_email to departures table
|
||||
op.add_column('departures', sa.Column('submitted_via', submission_source_enum, nullable=False, server_default='ADMIN'))
|
||||
op.add_column('departures', sa.Column('pilot_email', sa.String(length=128), nullable=True))
|
||||
|
||||
# Add indexes for submitted_via and pilot_email on departures
|
||||
op.create_index('idx_dep_submitted_via', 'departures', ['submitted_via'])
|
||||
op.create_index('idx_dep_pilot_email', 'departures', ['pilot_email'])
|
||||
|
||||
# Add submitted_via and pilot_email to arrivals table
|
||||
op.add_column('arrivals', sa.Column('submitted_via', submission_source_enum, nullable=False, server_default='ADMIN'))
|
||||
op.add_column('arrivals', sa.Column('pilot_email', sa.String(length=128), nullable=True))
|
||||
|
||||
# Add indexes for submitted_via and pilot_email on arrivals
|
||||
op.create_index('idx_arr_submitted_via', 'arrivals', ['submitted_via'])
|
||||
op.create_index('idx_arr_pilot_email', 'arrivals', ['pilot_email'])
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
"""
|
||||
Remove the submitted_via and pilot_email columns from local_flights, departures, and arrivals tables.
|
||||
"""
|
||||
|
||||
# Drop indexes first
|
||||
op.drop_index('idx_lf_submitted_via', table_name='local_flights')
|
||||
op.drop_index('idx_lf_pilot_email', table_name='local_flights')
|
||||
op.drop_index('idx_dep_submitted_via', table_name='departures')
|
||||
op.drop_index('idx_dep_pilot_email', table_name='departures')
|
||||
op.drop_index('idx_arr_submitted_via', table_name='arrivals')
|
||||
op.drop_index('idx_arr_pilot_email', table_name='arrivals')
|
||||
|
||||
# Drop columns from local_flights
|
||||
op.drop_column('local_flights', 'pilot_email')
|
||||
op.drop_column('local_flights', 'submitted_via')
|
||||
|
||||
# Drop columns from departures
|
||||
op.drop_column('departures', 'pilot_email')
|
||||
op.drop_column('departures', 'submitted_via')
|
||||
|
||||
# Drop columns from arrivals
|
||||
op.drop_column('arrivals', 'pilot_email')
|
||||
op.drop_column('arrivals', 'submitted_via')
|
||||
|
||||
# Drop the enum type
|
||||
op.execute('DROP TYPE IF EXISTS submissionsource')
|
||||
@@ -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
|
||||
from app.api.endpoints import auth, pprs, public, aircraft, airport, local_flights, departures, arrivals, circuits, journal, overflights, public_book
|
||||
|
||||
api_router = APIRouter()
|
||||
|
||||
@@ -12,5 +12,6 @@ api_router.include_router(overflights.router, prefix="/overflights", tags=["over
|
||||
api_router.include_router(circuits.router, prefix="/circuits", tags=["circuits"])
|
||||
api_router.include_router(journal.router, prefix="/journal", tags=["journal"])
|
||||
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"])
|
||||
api_router.include_router(airport.router, prefix="/airport", tags=["airport"])
|
||||
207
backend/app/api/endpoints/public_book.py
Normal file
207
backend/app/api/endpoints/public_book.py
Normal file
@@ -0,0 +1,207 @@
|
||||
from typing import List
|
||||
from fastapi import APIRouter, Depends, HTTPException, status, Request
|
||||
from sqlalchemy.orm import Session
|
||||
from app.api.deps import get_db
|
||||
from app.core.config import settings
|
||||
from app.schemas.public_book import (
|
||||
PublicLocalFlightCreate,
|
||||
PublicCircuitCreate,
|
||||
PublicDepartureCreate,
|
||||
PublicArrivalCreate,
|
||||
)
|
||||
from app.schemas.local_flight import LocalFlight as LocalFlightSchema
|
||||
from app.schemas.circuit import Circuit as CircuitSchema
|
||||
from app.schemas.departure import Departure as DepartureSchema
|
||||
from app.schemas.arrival import Arrival as ArrivalSchema
|
||||
from app.crud.crud_local_flight import local_flight as crud_local_flight
|
||||
from app.crud.crud_circuit import crud_circuit
|
||||
from app.crud.crud_departure import departure as crud_departure
|
||||
from app.crud.crud_arrival import arrival as crud_arrival
|
||||
from app.models.local_flight import SubmissionSource
|
||||
from app.models.departure import SubmissionSource as DepartureSubmissionSource
|
||||
from app.models.arrival import SubmissionSource as ArrivalSubmissionSource
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
|
||||
def check_public_booking_enabled():
|
||||
"""Check if public booking is enabled"""
|
||||
if not settings.allow_public_booking:
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_403_FORBIDDEN,
|
||||
detail="Public booking is currently disabled"
|
||||
)
|
||||
|
||||
|
||||
@router.post("/local-flights", response_model=LocalFlightSchema)
|
||||
async def public_book_local_flight(
|
||||
request: Request,
|
||||
flight_in: PublicLocalFlightCreate,
|
||||
db: Session = Depends(get_db),
|
||||
):
|
||||
"""Book a local flight via public portal"""
|
||||
check_public_booking_enabled()
|
||||
|
||||
# Create the flight with public submission source
|
||||
from app.schemas.local_flight import LocalFlightCreate
|
||||
|
||||
flight_create = LocalFlightCreate(
|
||||
registration=flight_in.registration,
|
||||
type=flight_in.type,
|
||||
callsign=flight_in.callsign,
|
||||
pob=flight_in.pob,
|
||||
flight_type=flight_in.flight_type,
|
||||
duration=flight_in.duration,
|
||||
etd=flight_in.etd,
|
||||
notes=flight_in.notes,
|
||||
)
|
||||
|
||||
flight = crud_local_flight.create(db, obj_in=flight_create, created_by="PUBLIC_PILOT")
|
||||
|
||||
# Update with submission source and pilot email
|
||||
db.query(type(flight)).filter(type(flight).id == flight.id).update({
|
||||
type(flight).submitted_via: SubmissionSource.PUBLIC,
|
||||
type(flight).pilot_email: flight_in.pilot_email,
|
||||
})
|
||||
db.commit()
|
||||
db.refresh(flight)
|
||||
|
||||
# Send real-time update via WebSocket if available
|
||||
if hasattr(request.app.state, 'connection_manager'):
|
||||
await request.app.state.connection_manager.broadcast({
|
||||
"type": "local_flight_booked_out",
|
||||
"data": {
|
||||
"id": flight.id,
|
||||
"registration": flight.registration,
|
||||
"flight_type": flight.flight_type.value,
|
||||
"status": flight.status.value,
|
||||
"submitted_via": "PUBLIC"
|
||||
}
|
||||
})
|
||||
|
||||
return flight
|
||||
|
||||
|
||||
@router.post("/circuits", response_model=CircuitSchema)
|
||||
async def public_record_circuit(
|
||||
request: Request,
|
||||
circuit_in: PublicCircuitCreate,
|
||||
db: Session = Depends(get_db),
|
||||
):
|
||||
"""Record a circuit (touch and go) via public portal"""
|
||||
check_public_booking_enabled()
|
||||
|
||||
from app.schemas.circuit import CircuitCreate
|
||||
|
||||
circuit_create = CircuitCreate(
|
||||
local_flight_id=circuit_in.local_flight_id,
|
||||
circuit_timestamp=circuit_in.circuit_timestamp,
|
||||
)
|
||||
|
||||
circuit = crud_circuit.create(db, obj_in=circuit_create)
|
||||
|
||||
# Send real-time update via WebSocket
|
||||
if hasattr(request.app.state, 'connection_manager'):
|
||||
await request.app.state.connection_manager.broadcast({
|
||||
"type": "circuit_recorded",
|
||||
"data": {
|
||||
"id": circuit.id,
|
||||
"local_flight_id": circuit.local_flight_id,
|
||||
"circuit_timestamp": circuit.circuit_timestamp.isoformat(),
|
||||
"submitted_via": "PUBLIC"
|
||||
}
|
||||
})
|
||||
|
||||
return circuit
|
||||
|
||||
|
||||
@router.post("/departures", response_model=DepartureSchema)
|
||||
async def public_book_departure(
|
||||
request: Request,
|
||||
departure_in: PublicDepartureCreate,
|
||||
db: Session = Depends(get_db),
|
||||
):
|
||||
"""Book a departure via public portal"""
|
||||
check_public_booking_enabled()
|
||||
|
||||
from app.schemas.departure import DepartureCreate
|
||||
|
||||
departure_create = DepartureCreate(
|
||||
registration=departure_in.registration,
|
||||
type=departure_in.type,
|
||||
callsign=departure_in.callsign,
|
||||
pob=departure_in.pob,
|
||||
out_to=departure_in.out_to,
|
||||
etd=departure_in.etd,
|
||||
notes=departure_in.notes,
|
||||
)
|
||||
|
||||
departure = crud_departure.create(db, obj_in=departure_create, created_by="PUBLIC_PILOT")
|
||||
|
||||
# Update with submission source and pilot email
|
||||
db.query(type(departure)).filter(type(departure).id == departure.id).update({
|
||||
type(departure).submitted_via: DepartureSubmissionSource.PUBLIC,
|
||||
type(departure).pilot_email: departure_in.pilot_email,
|
||||
})
|
||||
db.commit()
|
||||
db.refresh(departure)
|
||||
|
||||
# Send real-time update via WebSocket
|
||||
if hasattr(request.app.state, 'connection_manager'):
|
||||
await request.app.state.connection_manager.broadcast({
|
||||
"type": "departure_booked_out",
|
||||
"data": {
|
||||
"id": departure.id,
|
||||
"registration": departure.registration,
|
||||
"status": departure.status.value,
|
||||
"submitted_via": "PUBLIC"
|
||||
}
|
||||
})
|
||||
|
||||
return departure
|
||||
|
||||
|
||||
@router.post("/arrivals", response_model=ArrivalSchema)
|
||||
async def public_book_arrival(
|
||||
request: Request,
|
||||
arrival_in: PublicArrivalCreate,
|
||||
db: Session = Depends(get_db),
|
||||
):
|
||||
"""Book an arrival via public portal"""
|
||||
check_public_booking_enabled()
|
||||
|
||||
from app.schemas.arrival import ArrivalCreate
|
||||
|
||||
arrival_create = ArrivalCreate(
|
||||
registration=arrival_in.registration,
|
||||
type=arrival_in.type,
|
||||
callsign=arrival_in.callsign,
|
||||
pob=arrival_in.pob,
|
||||
in_from=arrival_in.in_from,
|
||||
eta=arrival_in.eta,
|
||||
notes=arrival_in.notes,
|
||||
)
|
||||
|
||||
arrival = crud_arrival.create(db, obj_in=arrival_create, created_by="PUBLIC_PILOT")
|
||||
|
||||
# Update with submission source and pilot email
|
||||
db.query(type(arrival)).filter(type(arrival).id == arrival.id).update({
|
||||
type(arrival).submitted_via: ArrivalSubmissionSource.PUBLIC,
|
||||
type(arrival).pilot_email: arrival_in.pilot_email,
|
||||
})
|
||||
db.commit()
|
||||
db.refresh(arrival)
|
||||
|
||||
# Send real-time update via WebSocket
|
||||
if hasattr(request.app.state, 'connection_manager'):
|
||||
await request.app.state.connection_manager.broadcast({
|
||||
"type": "arrival_booked_in",
|
||||
"data": {
|
||||
"id": arrival.id,
|
||||
"registration": arrival.registration,
|
||||
"status": arrival.status.value,
|
||||
"submitted_via": "PUBLIC"
|
||||
}
|
||||
})
|
||||
|
||||
return arrival
|
||||
@@ -33,6 +33,9 @@ class Settings(BaseSettings):
|
||||
top_bar_base_color: str = "#2c3e50"
|
||||
environment: str = "production" # production, development, staging, etc.
|
||||
|
||||
# Public booking settings
|
||||
allow_public_booking: bool = False # Enable/disable public flight booking
|
||||
|
||||
# Redis settings (for future use)
|
||||
redis_url: Optional[str] = None
|
||||
|
||||
|
||||
@@ -6,6 +6,11 @@ from datetime import datetime
|
||||
Base = declarative_base()
|
||||
|
||||
|
||||
class SubmissionSource(str, Enum):
|
||||
ADMIN = "ADMIN"
|
||||
PUBLIC = "PUBLIC"
|
||||
|
||||
|
||||
class ArrivalStatus(str, Enum):
|
||||
BOOKED_IN = "BOOKED_IN"
|
||||
LANDED = "LANDED"
|
||||
@@ -27,4 +32,6 @@ class Arrival(Base):
|
||||
eta = Column(DateTime, nullable=True, index=True)
|
||||
landed_dt = Column(DateTime, nullable=True)
|
||||
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
|
||||
updated_at = Column(DateTime, server_default=func.now(), onupdate=func.now(), nullable=False)
|
||||
|
||||
@@ -6,6 +6,11 @@ from datetime import datetime
|
||||
Base = declarative_base()
|
||||
|
||||
|
||||
class SubmissionSource(str, Enum):
|
||||
ADMIN = "ADMIN"
|
||||
PUBLIC = "PUBLIC"
|
||||
|
||||
|
||||
class DepartureStatus(str, Enum):
|
||||
BOOKED_OUT = "BOOKED_OUT"
|
||||
DEPARTED = "DEPARTED"
|
||||
@@ -27,4 +32,6 @@ class Departure(Base):
|
||||
etd = Column(DateTime, nullable=True, index=True) # Estimated Time of Departure
|
||||
departed_dt = Column(DateTime, nullable=True) # Actual departure time
|
||||
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
|
||||
updated_at = Column(DateTime, server_default=func.now(), onupdate=func.now(), nullable=False)
|
||||
|
||||
@@ -4,6 +4,11 @@ from enum import Enum
|
||||
from app.db.session import Base
|
||||
|
||||
|
||||
class SubmissionSource(str, Enum):
|
||||
ADMIN = "ADMIN"
|
||||
PUBLIC = "PUBLIC"
|
||||
|
||||
|
||||
class LocalFlightType(str, Enum):
|
||||
LOCAL = "LOCAL"
|
||||
CIRCUITS = "CIRCUITS"
|
||||
@@ -35,4 +40,6 @@ class LocalFlight(Base):
|
||||
departed_dt = Column(DateTime, nullable=True) # Actual takeoff time
|
||||
landed_dt = Column(DateTime, nullable=True)
|
||||
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
|
||||
updated_at = Column(DateTime, nullable=False, server_default=func.current_timestamp(), onupdate=func.current_timestamp())
|
||||
|
||||
@@ -10,6 +10,11 @@ class ArrivalStatus(str, Enum):
|
||||
CANCELLED = "CANCELLED"
|
||||
|
||||
|
||||
class SubmissionSource(str, Enum):
|
||||
ADMIN = "ADMIN"
|
||||
PUBLIC = "PUBLIC"
|
||||
|
||||
|
||||
class ArrivalBase(BaseModel):
|
||||
registration: str
|
||||
type: Optional[str] = None
|
||||
@@ -63,6 +68,8 @@ class Arrival(ArrivalBase):
|
||||
landed_dt: Optional[datetime] = None
|
||||
created_by: Optional[str] = None
|
||||
updated_at: datetime
|
||||
submitted_via: Optional[SubmissionSource] = None
|
||||
pilot_email: Optional[str] = None
|
||||
|
||||
class Config:
|
||||
from_attributes = True
|
||||
|
||||
@@ -10,6 +10,11 @@ class DepartureStatus(str, Enum):
|
||||
CANCELLED = "CANCELLED"
|
||||
|
||||
|
||||
class SubmissionSource(str, Enum):
|
||||
ADMIN = "ADMIN"
|
||||
PUBLIC = "PUBLIC"
|
||||
|
||||
|
||||
class DepartureBase(BaseModel):
|
||||
registration: str
|
||||
type: Optional[str] = None
|
||||
@@ -63,3 +68,9 @@ class Departure(DepartureBase):
|
||||
created_dt: datetime
|
||||
etd: Optional[datetime] = None
|
||||
departed_dt: Optional[datetime] = None
|
||||
updated_at: datetime
|
||||
submitted_via: Optional[SubmissionSource] = None
|
||||
pilot_email: Optional[str] = None
|
||||
|
||||
class Config:
|
||||
from_attributes = True
|
||||
|
||||
@@ -17,6 +17,11 @@ class LocalFlightStatus(str, Enum):
|
||||
CANCELLED = "CANCELLED"
|
||||
|
||||
|
||||
class SubmissionSource(str, Enum):
|
||||
ADMIN = "ADMIN"
|
||||
PUBLIC = "PUBLIC"
|
||||
|
||||
|
||||
class LocalFlightBase(BaseModel):
|
||||
registration: str
|
||||
type: Optional[str] = None # Aircraft type - optional, can be looked up later
|
||||
@@ -81,6 +86,8 @@ class LocalFlightInDBBase(LocalFlightBase):
|
||||
circuits: Optional[int] = None
|
||||
created_by: Optional[str] = None
|
||||
updated_at: datetime
|
||||
submitted_via: Optional[SubmissionSource] = None
|
||||
pilot_email: Optional[str] = None
|
||||
|
||||
class Config:
|
||||
from_attributes = True
|
||||
|
||||
129
backend/app/schemas/public_book.py
Normal file
129
backend/app/schemas/public_book.py
Normal file
@@ -0,0 +1,129 @@
|
||||
from pydantic import BaseModel, validator, EmailStr
|
||||
from datetime import datetime
|
||||
from typing import Optional
|
||||
from enum import Enum
|
||||
|
||||
|
||||
class LocalFlightType(str, Enum):
|
||||
LOCAL = "LOCAL"
|
||||
CIRCUITS = "CIRCUITS"
|
||||
DEPARTURE = "DEPARTURE"
|
||||
|
||||
|
||||
class PublicLocalFlightCreate(BaseModel):
|
||||
"""Schema for public local flight booking"""
|
||||
registration: str
|
||||
type: Optional[str] = None # Aircraft type - optional
|
||||
callsign: Optional[str] = None
|
||||
pob: int
|
||||
flight_type: LocalFlightType
|
||||
duration: Optional[int] = 45 # Duration in minutes, default 45
|
||||
etd: Optional[datetime] = None # Estimated Time of Departure
|
||||
notes: Optional[str] = None
|
||||
pilot_email: Optional[str] = None # Pilot's email for contact (optional)
|
||||
pilot_name: Optional[str] = None # Pilot's name
|
||||
|
||||
@validator('registration')
|
||||
def validate_registration(cls, v):
|
||||
if not v or len(v.strip()) == 0:
|
||||
raise ValueError('Aircraft registration is required')
|
||||
return v.strip().upper()
|
||||
|
||||
@validator('pob')
|
||||
def validate_pob(cls, v):
|
||||
if v is not None and v < 1:
|
||||
raise ValueError('Persons on board must be at least 1')
|
||||
return v
|
||||
|
||||
@validator('pilot_email', pre=True, always=False)
|
||||
def validate_pilot_email(cls, v):
|
||||
if v is None or v == '':
|
||||
return None
|
||||
return v.strip().lower()
|
||||
|
||||
|
||||
class PublicCircuitCreate(BaseModel):
|
||||
"""Schema for public circuit (touch and go) recording"""
|
||||
local_flight_id: int
|
||||
circuit_timestamp: datetime
|
||||
pilot_email: Optional[str] = None
|
||||
|
||||
@validator('pilot_email', pre=True, always=False)
|
||||
def validate_pilot_email(cls, v):
|
||||
if v is None or v == '':
|
||||
return None
|
||||
return v.strip().lower()
|
||||
|
||||
|
||||
class PublicDepartureCreate(BaseModel):
|
||||
"""Schema for public departure booking"""
|
||||
registration: str
|
||||
type: Optional[str] = None
|
||||
callsign: Optional[str] = None
|
||||
pob: int
|
||||
out_to: str
|
||||
etd: Optional[datetime] = None # Estimated Time of Departure
|
||||
notes: Optional[str] = None
|
||||
pilot_email: Optional[str] = None
|
||||
pilot_name: Optional[str] = None
|
||||
|
||||
@validator('registration')
|
||||
def validate_registration(cls, v):
|
||||
if not v or len(v.strip()) == 0:
|
||||
raise ValueError('Aircraft registration is required')
|
||||
return v.strip().upper()
|
||||
|
||||
@validator('out_to')
|
||||
def validate_out_to(cls, v):
|
||||
if not v or len(v.strip()) == 0:
|
||||
raise ValueError('Destination airport is required')
|
||||
return v.strip()
|
||||
|
||||
@validator('pob')
|
||||
def validate_pob(cls, v):
|
||||
if v is not None and v < 1:
|
||||
raise ValueError('Persons on board must be at least 1')
|
||||
return v
|
||||
|
||||
@validator('pilot_email', pre=True, always=False)
|
||||
def validate_pilot_email(cls, v):
|
||||
if v is None or v == '':
|
||||
return None
|
||||
return v.strip().lower()
|
||||
|
||||
|
||||
class PublicArrivalCreate(BaseModel):
|
||||
"""Schema for public arrival booking"""
|
||||
registration: str
|
||||
type: Optional[str] = None
|
||||
callsign: Optional[str] = None
|
||||
pob: int
|
||||
in_from: str
|
||||
eta: Optional[datetime] = None
|
||||
notes: Optional[str] = None
|
||||
pilot_email: Optional[str] = None
|
||||
pilot_name: Optional[str] = None
|
||||
|
||||
@validator('registration')
|
||||
def validate_registration(cls, v):
|
||||
if not v or len(v.strip()) == 0:
|
||||
raise ValueError('Aircraft registration is required')
|
||||
return v.strip().upper()
|
||||
|
||||
@validator('in_from')
|
||||
def validate_in_from(cls, v):
|
||||
if not v or len(v.strip()) == 0:
|
||||
raise ValueError('Origin airport is required')
|
||||
return v.strip()
|
||||
|
||||
@validator('pob')
|
||||
def validate_pob(cls, v):
|
||||
if v is not None and v < 1:
|
||||
raise ValueError('Persons on board must be at least 1')
|
||||
return v
|
||||
|
||||
@validator('pilot_email', pre=True, always=False)
|
||||
def validate_pilot_email(cls, v):
|
||||
if v is None or v == '':
|
||||
return None
|
||||
return v.strip().lower()
|
||||
@@ -28,6 +28,7 @@ services:
|
||||
REDIS_URL: ${REDIS_URL}
|
||||
TAG: ${TAG}
|
||||
TOP_BAR_BASE_COLOR: ${TOP_BAR_BASE_COLOR}
|
||||
ALLOW_PUBLIC_BOOKING: ${ALLOW_PUBLIC_BOOKING}
|
||||
ENVIRONMENT: production
|
||||
WORKERS: "4"
|
||||
ports:
|
||||
|
||||
@@ -562,7 +562,7 @@
|
||||
</div>
|
||||
</form>
|
||||
|
||||
<!-- Circuits Section (for CIRCUITS flights only) -->
|
||||
<!-- 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;">
|
||||
@@ -2019,7 +2019,7 @@
|
||||
if (isLocal) {
|
||||
row.innerHTML = `
|
||||
<td style="padding: 0.3rem 0.4rem !important; font-size: 0.85rem !important;">${flight.registration || '-'}</td>
|
||||
<td style="padding: 0.3rem 0.4rem !important; font-size: 0.85rem !important; text-align: center; width: 30px;"></td>
|
||||
<td style="padding: 0.3rem 0.4rem !important; font-size: 0.85rem !important; text-align: center; width: 30px;">${flight.submitted_via === 'PUBLIC' ? '<span style="color: #b8860b; font-weight: bold;" title="Submitted by Pilot Online">O</span>' : ''}</td>
|
||||
<td style="padding: 0.3rem 0.4rem !important; font-size: 0.85rem !important;">${flight.callsign || '-'}</td>
|
||||
<td style="padding: 0.3rem 0.4rem !important; font-size: 0.85rem !important;">-</td>
|
||||
<td style="padding: 0.3rem 0.4rem !important; font-size: 0.85rem !important;">${formatTimeOnly(flight.departed_dt)}</td>
|
||||
@@ -2027,7 +2027,7 @@
|
||||
} else if (isDeparture) {
|
||||
row.innerHTML = `
|
||||
<td style="padding: 0.3rem 0.4rem !important; font-size: 0.85rem !important;">${flight.registration || '-'}</td>
|
||||
<td style="padding: 0.3rem 0.4rem !important; font-size: 0.85rem !important; text-align: center; width: 30px;"></td>
|
||||
<td style="padding: 0.3rem 0.4rem !important; font-size: 0.85rem !important; text-align: center; width: 30px;">${flight.submitted_via === 'PUBLIC' ? '<span style="color: #b8860b; font-weight: bold;" title="Submitted by Pilot Online">O</span>' : ''}</td>
|
||||
<td style="padding: 0.3rem 0.4rem !important; font-size: 0.85rem !important;">${flight.callsign || '-'}</td>
|
||||
<td style="padding: 0.3rem 0.4rem !important; font-size: 0.85rem !important;">${flight.out_to || '-'}</td>
|
||||
<td style="padding: 0.3rem 0.4rem !important; font-size: 0.85rem !important;">${formatTimeOnly(flight.departed_dt)}</td>
|
||||
@@ -2336,7 +2336,7 @@
|
||||
aircraftDisplay = `<strong>${flight.registration}</strong>`;
|
||||
}
|
||||
acType = flight.type;
|
||||
typeIcon = '';
|
||||
typeIcon = flight.submitted_via === 'PUBLIC' ? '<span style="color: #b8860b; font-weight: bold; font-size: 0.9em;" title="Submitted by Pilot Online">O</span>' : '';
|
||||
fromDisplay = `<i>${flight.flight_type === 'CIRCUITS' ? 'Circuits' : flight.flight_type === 'LOCAL' ? 'Local Flight' : 'Departure'}</i>`;
|
||||
|
||||
// Calculate ETA: use departed_dt (actual departure) if available, otherwise etd (planned departure)
|
||||
@@ -2351,22 +2351,17 @@
|
||||
pob = flight.pob || '-';
|
||||
fuel = '-';
|
||||
|
||||
// For circuits, add a circuit button
|
||||
// Allow touch and go for all local flight types
|
||||
let circuitButton = '';
|
||||
if (flight.flight_type === 'CIRCUITS') {
|
||||
circuitButton = `<button class="btn btn-info btn-icon" onclick="event.stopPropagation(); currentLocalFlightId = ${flight.id}; showCircuitModal()" title="Record Touch & Go">
|
||||
T&G
|
||||
</button>`;
|
||||
}
|
||||
|
||||
actionButtons = `
|
||||
${circuitButton}
|
||||
<button class="btn btn-success btn-icon" onclick="event.stopPropagation(); currentLocalFlightId = ${flight.id}; showTimestampModal('LANDED', ${flight.id}, true)" title="Mark as Landed">
|
||||
LAND
|
||||
</button>
|
||||
<button class="btn btn-danger btn-icon" onclick="event.stopPropagation(); updateLocalFlightStatusFromTable(${flight.id}, 'CANCELLED')" title="Cancel Flight">
|
||||
CANCEL
|
||||
</button>
|
||||
`;
|
||||
} else if (isBookedIn) {
|
||||
// Booked-in arrival display
|
||||
@@ -2376,7 +2371,7 @@
|
||||
aircraftDisplay = `<strong>${flight.registration}</strong>`;
|
||||
}
|
||||
acType = flight.type;
|
||||
typeIcon = '';
|
||||
typeIcon = flight.submitted_via === 'PUBLIC' ? '<span style="color: #b8860b; font-weight: bold; font-size: 0.9em;" title="Submitted by Pilot Online">O</span>' : '';
|
||||
|
||||
// Lookup airport name for in_from
|
||||
let fromDisplay_temp = flight.in_from;
|
||||
@@ -2421,9 +2416,6 @@
|
||||
<button class="btn btn-warning btn-icon" onclick="event.stopPropagation(); showTimestampModal('LANDED', ${flight.id})" title="Mark as Landed">
|
||||
LAND
|
||||
</button>
|
||||
<button class="btn btn-danger btn-icon" onclick="event.stopPropagation(); updateStatusFromTable(${flight.id}, 'CANCELED')" title="Cancel Arrival">
|
||||
CANCEL
|
||||
</button>
|
||||
`;
|
||||
}
|
||||
|
||||
@@ -2495,7 +2487,7 @@
|
||||
} else {
|
||||
aircraftDisplay = `<strong>${flight.registration}</strong>`;
|
||||
}
|
||||
typeIcon = '';
|
||||
typeIcon = flight.submitted_via === 'PUBLIC' ? '<span style="color: #b8860b; font-weight: bold; font-size: 0.9em;" title="Submitted by Pilot Online">O</span>' : '';
|
||||
toDisplay = `<i>${flight.flight_type === 'CIRCUITS' ? 'Circuits' : flight.flight_type === 'LOCAL' ? 'Local Flight' : 'Departure'}</i>`;
|
||||
etd = flight.etd ? formatTimeOnly(flight.etd) : (flight.created_dt ? formatTimeOnly(flight.created_dt) : '-');
|
||||
pob = flight.pob || '-';
|
||||
@@ -2508,26 +2500,17 @@
|
||||
<button class="btn btn-primary btn-icon" onclick="event.stopPropagation(); currentLocalFlightId = ${flight.id}; showTimestampModal('DEPARTED', ${flight.id}, true)" title="Mark as Departed">
|
||||
TAKE OFF
|
||||
</button>
|
||||
<button class="btn btn-danger btn-icon" onclick="event.stopPropagation(); updateLocalFlightStatusFromTable(${flight.id}, 'CANCELLED')" title="Cancel Flight">
|
||||
CANCEL
|
||||
</button>
|
||||
`;
|
||||
} else if (flight.status === 'DEPARTED') {
|
||||
// For circuits, add a circuit button; for other flights, just show land button
|
||||
let circuitButton = '';
|
||||
if (flight.flight_type === 'CIRCUITS') {
|
||||
circuitButton = `<button class="btn btn-info btn-icon" onclick="event.stopPropagation(); currentLocalFlightId = ${flight.id}; showCircuitModal()" title="Record Touch & Go">
|
||||
// Allow touch and go for all local flight types
|
||||
let circuitButton = `<button class="btn btn-info btn-icon" onclick="event.stopPropagation(); currentLocalFlightId = ${flight.id}; showCircuitModal()" title="Record Touch & Go">
|
||||
T&G
|
||||
</button>`;
|
||||
}
|
||||
actionButtons = `
|
||||
${circuitButton}
|
||||
<button class="btn btn-success btn-icon" onclick="event.stopPropagation(); currentLocalFlightId = ${flight.id}; showTimestampModal('LANDED', ${flight.id}, true)" title="Mark as Landed">
|
||||
LAND
|
||||
</button>
|
||||
<button class="btn btn-danger btn-icon" onclick="event.stopPropagation(); updateLocalFlightStatusFromTable(${flight.id}, 'CANCELLED')" title="Cancel Flight">
|
||||
CANCEL
|
||||
</button>
|
||||
`;
|
||||
} else {
|
||||
actionButtons = '<span style="color: #999;">-</span>';
|
||||
@@ -2539,7 +2522,7 @@
|
||||
} else {
|
||||
aircraftDisplay = `<strong>${flight.registration}</strong>`;
|
||||
}
|
||||
typeIcon = '';
|
||||
typeIcon = flight.submitted_via === 'PUBLIC' ? '<span style="color: #b8860b; font-weight: bold; font-size: 0.9em;" title="Submitted by Pilot Online">O</span>' : '';
|
||||
toDisplay = flight.out_to || '-';
|
||||
if (flight.out_to && flight.out_to.length === 4 && /^[A-Z]{4}$/.test(flight.out_to)) {
|
||||
toDisplay = await getAirportDisplay(flight.out_to);
|
||||
@@ -2555,9 +2538,6 @@
|
||||
<button class="btn btn-primary btn-icon" onclick="event.stopPropagation(); currentDepartureId = ${flight.id}; showTimestampModal('DEPARTED', ${flight.id}, false, true)" title="Mark as Departed">
|
||||
TAKE OFF
|
||||
</button>
|
||||
<button class="btn btn-danger btn-icon" onclick="event.stopPropagation(); updateDepartureStatusFromTable(${flight.id}, 'CANCELLED')" title="Cancel">
|
||||
CANCEL
|
||||
</button>
|
||||
`;
|
||||
} else if (flight.status === 'DEPARTED') {
|
||||
actionButtons = '<span style="color: #999;">Departed</span>';
|
||||
@@ -2585,9 +2565,6 @@
|
||||
<button class="btn btn-primary btn-icon" onclick="event.stopPropagation(); showTimestampModal('DEPARTED', ${flight.id})" title="Mark as Departed">
|
||||
TAKE OFF
|
||||
</button>
|
||||
<button class="btn btn-danger btn-icon" onclick="event.stopPropagation(); updateStatusFromTable(${flight.id}, 'CANCELED')" title="Cancel Departure">
|
||||
CANCEL
|
||||
</button>
|
||||
`;
|
||||
}
|
||||
|
||||
@@ -3994,14 +3971,10 @@
|
||||
|
||||
document.getElementById('local-flight-edit-title').textContent = `${flight.registration} - ${flight.flight_type}`;
|
||||
|
||||
// Load and display circuits if this is a CIRCUITS flight
|
||||
// Load and display circuits for all local flight types
|
||||
const circuitsSection = document.getElementById('circuits-section');
|
||||
if (flight.flight_type === 'CIRCUITS') {
|
||||
circuitsSection.style.display = 'block';
|
||||
loadCircuitsDisplay(flight.id);
|
||||
} else {
|
||||
circuitsSection.style.display = 'none';
|
||||
}
|
||||
|
||||
document.getElementById('localFlightEditModal').style.display = 'block';
|
||||
|
||||
|
||||
866
web/book.html
Normal file
866
web/book.html
Normal file
@@ -0,0 +1,866 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Flight Booking - Pilot Portal</title>
|
||||
<style>
|
||||
* {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
body {
|
||||
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
|
||||
background: #f5f5f5;
|
||||
padding: 10px;
|
||||
color: #333;
|
||||
}
|
||||
|
||||
.container {
|
||||
max-width: 600px;
|
||||
margin: 0 auto;
|
||||
background: white;
|
||||
border-radius: 8px;
|
||||
padding: 20px;
|
||||
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
|
||||
}
|
||||
|
||||
.header {
|
||||
background: linear-gradient(135deg, #2c3e50 0%, #3498db 100%);
|
||||
color: white;
|
||||
padding: 20px;
|
||||
margin: -20px -20px 20px -20px;
|
||||
border-radius: 8px 8px 0 0;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.header h1 {
|
||||
font-size: 24px;
|
||||
margin-bottom: 5px;
|
||||
}
|
||||
|
||||
.header p {
|
||||
font-size: 14px;
|
||||
opacity: 0.9;
|
||||
}
|
||||
|
||||
.tabs {
|
||||
display: flex;
|
||||
gap: 10px;
|
||||
margin-bottom: 20px;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
|
||||
.tab-btn {
|
||||
flex: 1;
|
||||
padding: 12px;
|
||||
border: 2px solid #ddd;
|
||||
background: white;
|
||||
color: #333;
|
||||
border-radius: 6px;
|
||||
cursor: pointer;
|
||||
font-size: 14px;
|
||||
font-weight: 600;
|
||||
transition: all 0.3s ease;
|
||||
min-width: 120px;
|
||||
}
|
||||
|
||||
.tab-btn.active {
|
||||
background: #3498db;
|
||||
color: white;
|
||||
border-color: #3498db;
|
||||
}
|
||||
|
||||
.tab-content {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.tab-content.active {
|
||||
display: block;
|
||||
}
|
||||
|
||||
.form-group {
|
||||
margin-bottom: 15px;
|
||||
}
|
||||
|
||||
label {
|
||||
display: block;
|
||||
margin-bottom: 5px;
|
||||
font-weight: 600;
|
||||
font-size: 14px;
|
||||
color: #2c3e50;
|
||||
}
|
||||
|
||||
input, select, textarea {
|
||||
width: 100%;
|
||||
padding: 12px;
|
||||
border: 1px solid #ddd;
|
||||
border-radius: 6px;
|
||||
font-size: 14px;
|
||||
font-family: inherit;
|
||||
}
|
||||
|
||||
input:focus, select:focus, textarea:focus {
|
||||
outline: none;
|
||||
border-color: #3498db;
|
||||
box-shadow: 0 0 0 3px rgba(52, 152, 219, 0.1);
|
||||
}
|
||||
|
||||
textarea {
|
||||
resize: vertical;
|
||||
min-height: 80px;
|
||||
}
|
||||
|
||||
.form-row {
|
||||
display: grid;
|
||||
grid-template-columns: 1fr 1fr;
|
||||
gap: 10px;
|
||||
}
|
||||
|
||||
.btn-submit {
|
||||
width: 100%;
|
||||
padding: 14px;
|
||||
background: #27ae60;
|
||||
color: white;
|
||||
border: none;
|
||||
border-radius: 6px;
|
||||
font-size: 16px;
|
||||
font-weight: 600;
|
||||
cursor: pointer;
|
||||
transition: all 0.3s ease;
|
||||
}
|
||||
|
||||
.btn-submit:hover {
|
||||
background: #229954;
|
||||
}
|
||||
|
||||
.btn-submit:active {
|
||||
transform: scale(0.98);
|
||||
}
|
||||
|
||||
.btn-submit:disabled {
|
||||
background: #bdc3c7;
|
||||
cursor: not-allowed;
|
||||
}
|
||||
|
||||
.success-message {
|
||||
display: none;
|
||||
background: #d4edda;
|
||||
color: #155724;
|
||||
padding: 15px;
|
||||
border-radius: 6px;
|
||||
margin-bottom: 15px;
|
||||
border-left: 4px solid #28a745;
|
||||
}
|
||||
|
||||
.error-message {
|
||||
display: none;
|
||||
background: #f8d7da;
|
||||
color: #721c24;
|
||||
padding: 15px;
|
||||
border-radius: 6px;
|
||||
margin-bottom: 15px;
|
||||
border-left: 4px solid #f5c6cb;
|
||||
}
|
||||
|
||||
.info-box {
|
||||
background: #e3f2fd;
|
||||
border-left: 4px solid #2196f3;
|
||||
padding: 12px;
|
||||
border-radius: 4px;
|
||||
font-size: 13px;
|
||||
margin-bottom: 15px;
|
||||
color: #1565c0;
|
||||
}
|
||||
|
||||
.required {
|
||||
color: #e74c3c;
|
||||
}
|
||||
|
||||
.loading {
|
||||
display: none;
|
||||
text-align: center;
|
||||
padding: 20px;
|
||||
}
|
||||
|
||||
.spinner {
|
||||
border: 4px solid #f3f3f3;
|
||||
border-top: 4px solid #3498db;
|
||||
border-radius: 50%;
|
||||
width: 40px;
|
||||
height: 40px;
|
||||
animation: spin 1s linear infinite;
|
||||
margin: 0 auto;
|
||||
}
|
||||
|
||||
@keyframes spin {
|
||||
0% { transform: rotate(0deg); }
|
||||
100% { transform: rotate(360deg); }
|
||||
}
|
||||
|
||||
.footer {
|
||||
text-align: center;
|
||||
margin-top: 20px;
|
||||
padding-top: 20px;
|
||||
border-top: 1px solid #eee;
|
||||
font-size: 13px;
|
||||
color: #666;
|
||||
}
|
||||
|
||||
.aircraft-lookup-results {
|
||||
margin-top: 5px;
|
||||
padding: 5px;
|
||||
background-color: #f8f9fa;
|
||||
border-radius: 4px;
|
||||
font-size: 13px;
|
||||
min-height: 20px;
|
||||
border: 1px solid #e9ecef;
|
||||
}
|
||||
|
||||
.airport-lookup-results {
|
||||
margin-top: 5px;
|
||||
padding: 5px;
|
||||
background-color: #f8f9fa;
|
||||
border-radius: 4px;
|
||||
font-size: 13px;
|
||||
min-height: 20px;
|
||||
border: 1px solid #e9ecef;
|
||||
}
|
||||
|
||||
.lookup-match {
|
||||
padding: 3px;
|
||||
background-color: #e8f5e8;
|
||||
border: 1px solid #c3e6c3;
|
||||
border-radius: 4px;
|
||||
font-family: 'Courier New', monospace;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
.lookup-no-match {
|
||||
color: #6c757d;
|
||||
font-style: italic;
|
||||
}
|
||||
|
||||
.lookup-searching {
|
||||
color: #007bff;
|
||||
}
|
||||
|
||||
.aircraft-list {
|
||||
max-height: 200px;
|
||||
overflow-y: auto;
|
||||
border: 1px solid #dee2e6;
|
||||
border-radius: 4px;
|
||||
background-color: white;
|
||||
}
|
||||
|
||||
.aircraft-option {
|
||||
padding: 5px;
|
||||
border-bottom: 1px solid #f0f0f0;
|
||||
cursor: pointer;
|
||||
transition: background-color 0.2s ease;
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.aircraft-option:hover {
|
||||
background-color: #f8f9fa;
|
||||
}
|
||||
|
||||
.aircraft-option:last-child {
|
||||
border-bottom: none;
|
||||
}
|
||||
|
||||
.aircraft-code {
|
||||
font-family: 'Courier New', monospace;
|
||||
font-weight: bold;
|
||||
color: #495057;
|
||||
}
|
||||
|
||||
.aircraft-details {
|
||||
color: #6c757d;
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
@media (max-width: 480px) {
|
||||
.container {
|
||||
padding: 15px;
|
||||
}
|
||||
|
||||
.header {
|
||||
margin: -15px -15px 15px -15px;
|
||||
padding: 15px;
|
||||
}
|
||||
|
||||
.form-row {
|
||||
grid-template-columns: 1fr;
|
||||
}
|
||||
|
||||
.tabs {
|
||||
gap: 5px;
|
||||
}
|
||||
|
||||
.tab-btn {
|
||||
font-size: 12px;
|
||||
padding: 10px;
|
||||
min-width: 100px;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="container">
|
||||
<div class="header">
|
||||
<h1>Swansea - Book Out</h1>
|
||||
</div>
|
||||
|
||||
<div id="successMessage" class="success-message"></div>
|
||||
<div id="errorMessage" class="error-message"></div>
|
||||
|
||||
<div class="info-box">
|
||||
Booking out really helps our volunteers in the tower, thank you!
|
||||
</div>
|
||||
|
||||
<div class="tabs">
|
||||
<button class="tab-btn active" onclick="switchTab(this, 'local')">Local</button>
|
||||
<button class="tab-btn" onclick="switchTab(this, 'circuits')">Circuits</button>
|
||||
<button class="tab-btn" onclick="switchTab(this, 'departure')">Departure</button>
|
||||
<button class="tab-btn" onclick="switchTab(this, 'arrival')">Arrival</button>
|
||||
</div>
|
||||
|
||||
<!-- Local Flight Form -->
|
||||
<div id="local" class="tab-content active">
|
||||
|
||||
<form id="localFlightForm" onsubmit="handleSubmit(event, 'local')">
|
||||
<div class="form-group">
|
||||
<label for="localReg">Aircraft Registration <span class="required">*</span></label>
|
||||
<input type="text" id="localReg" name="registration" placeholder="e.g gbamc" required oninput="handleAircraftLookup(this.value, 'local')">
|
||||
<div id="localReg-lookup-results" class="aircraft-lookup-results"></div>
|
||||
</div>
|
||||
|
||||
<div class="form-row">
|
||||
<div class="form-group">
|
||||
<label for="localType">Aircraft Type</label>
|
||||
<input type="text" id="localType" name="type" placeholder="e.g., Cessna 172">
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="localCallsign">Callsign</label>
|
||||
<input type="text" id="localCallsign" name="callsign" placeholder="Optional">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-row">
|
||||
<div class="form-group">
|
||||
<label for="localPOB">Persons on Board <span class="required">*</span></label>
|
||||
<input type="number" id="localPOB" name="pob" value="1" min="1" required>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="localDuration">Est. Duration (minutes)</label>
|
||||
<input type="number" id="localDuration" name="duration" value="45" min="5">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="localETD">Est. Takeoff Time</label>
|
||||
<input type="time" id="localETD" name="etd">
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="localNotes">Notes</label>
|
||||
<textarea id="localNotes" name="notes" placeholder="Any additional information..."></textarea>
|
||||
</div>
|
||||
|
||||
<button type="submit" class="btn-submit">📋 Book Local Flight</button>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<!-- Circuit Form -->
|
||||
<div id="circuits" class="tab-content">
|
||||
<form id="circuitForm" onsubmit="handleSubmit(event, 'circuits')">
|
||||
<div class="form-group">
|
||||
<label for="circuitReg">Aircraft Registration <span class="required">*</span></label>
|
||||
<input type="text" id="circuitReg" name="registration" placeholder="e.g., G-BAMC" required oninput="handleAircraftLookup(this.value, 'circuits')">
|
||||
<div id="circuitReg-lookup-results" class="aircraft-lookup-results"></div>
|
||||
</div>
|
||||
|
||||
<div class="form-row">
|
||||
<div class="form-group">
|
||||
<label for="circuitType">Aircraft Type</label>
|
||||
<input type="text" id="circuitType" name="type" placeholder="e.g., Cessna 172">
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="circuitCallsign">Callsign</label>
|
||||
<input type="text" id="circuitCallsign" name="callsign" placeholder="Optional">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-row">
|
||||
<div class="form-group">
|
||||
<label for="circuitPOB">Persons on Board <span class="required">*</span></label>
|
||||
<input type="number" id="circuitPOB" name="pob" value="1" min="1" required>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="circuitDuration">Est. Duration (minutes)</label>
|
||||
<input type="number" id="circuitDuration" name="duration" value="30" min="5">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="circuitETD">Est. Takeoff Time</label>
|
||||
<input type="time" id="circuitETD" name="etd">
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="circuitNotes">Notes</label>
|
||||
<textarea id="circuitNotes" name="notes" placeholder="Any additional information..."></textarea>
|
||||
</div>
|
||||
|
||||
<button type="submit" class="btn-submit">✈️ Book Circuits</button>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<!-- Departure Form -->
|
||||
<div id="departure" class="tab-content">
|
||||
<div class="info-box">
|
||||
➡️ Book a flight departing to another airport (email optional)
|
||||
</div>
|
||||
<form id="departureForm" onsubmit="handleSubmit(event, 'departure')">
|
||||
<div class="form-group">
|
||||
<label for="depReg">Aircraft Registration <span class="required">*</span></label>
|
||||
<input type="text" id="depReg" name="registration" placeholder="e.g., N12345" required oninput="handleAircraftLookup(this.value, 'departure')">
|
||||
<div id="depReg-lookup-results" class="aircraft-lookup-results"></div>
|
||||
</div>
|
||||
|
||||
<div class="form-row">
|
||||
<div class="form-group">
|
||||
<label for="depType">Aircraft Type</label>
|
||||
<input type="text" id="depType" name="type" placeholder="e.g., Cessna 172">
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="depCallsign">Callsign</label>
|
||||
<input type="text" id="depCallsign" name="callsign" placeholder="Optional">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-row">
|
||||
<div class="form-group">
|
||||
<label for="depPOB">Persons on Board <span class="required">*</span></label>
|
||||
<input type="number" id="depPOB" name="pob" value="1" min="1" required>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="depTo">Destination (ICAO) <span class="required">*</span></label>
|
||||
<input type="text" id="depTo" name="out_to" placeholder="e.g., KJFK" required oninput="handleAirportLookup(this.value, 'depTo')">
|
||||
<div id="depTo-lookup-results" class="airport-lookup-results"></div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="depETD">Takeoff Time</label>
|
||||
<input type="time" id="depETD" name="etd">
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="depNotes">Notes</label>
|
||||
<textarea id="depNotes" name="notes" placeholder="Any additional information..."></textarea>
|
||||
</div>
|
||||
|
||||
<div class="form-row">
|
||||
<div class="form-group">
|
||||
<label for="depEmail">Pilot Email</label>
|
||||
<input type="email" id="depEmail" name="pilot_email">
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="depName">Pilot Name</label>
|
||||
<input type="text" id="depName" name="pilot_name" placeholder="Optional">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<button type="submit" class="btn-submit">✈️ Book Departure</button>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<!-- Arrival Form -->
|
||||
<div id="arrival" class="tab-content">
|
||||
<div class="info-box">
|
||||
⬅️ Book an arrival from another airport (email optional)
|
||||
</div>
|
||||
<form id="arrivalForm" onsubmit="handleSubmit(event, 'arrival')">
|
||||
<div class="form-group">
|
||||
<label for="arrReg">Aircraft Registration <span class="required">*</span></label>
|
||||
<input type="text" id="arrReg" name="registration" placeholder="e.g., N12345" required oninput="handleAircraftLookup(this.value, 'arrival')">
|
||||
<div id="arrReg-lookup-results" class="aircraft-lookup-results"></div>
|
||||
</div>
|
||||
|
||||
<div class="form-row">
|
||||
<div class="form-group">
|
||||
<label for="arrType">Aircraft Type</label>
|
||||
<input type="text" id="arrType" name="type" placeholder="e.g., Cessna 172">
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="arrCallsign">Callsign</label>
|
||||
<input type="text" id="arrCallsign" name="callsign" placeholder="Optional">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-row">
|
||||
<div class="form-group">
|
||||
<label for="arrPOB">Persons on Board <span class="required">*</span></label>
|
||||
<input type="number" id="arrPOB" name="pob" value="1" min="1" required>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="arrFrom">Origin (ICAO) <span class="required">*</span></label>
|
||||
<input type="text" id="arrFrom" name="in_from" placeholder="e.g., KJFK" required oninput="handleAirportLookup(this.value, 'arrFrom')">
|
||||
<div id="arrFrom-lookup-results" class="airport-lookup-results"></div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="arrETA">Arrival Time</label>
|
||||
<input type="time" id="arrETA" name="eta">
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="arrNotes">Notes</label>
|
||||
<textarea id="arrNotes" name="notes" placeholder="Any additional information..."></textarea>
|
||||
</div>
|
||||
|
||||
<div class="form-row">
|
||||
<div class="form-group">
|
||||
<label for="arrEmail">Pilot Email</label>
|
||||
<input type="email" id="arrEmail" name="pilot_email">
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="arrName">Pilot Name</label>
|
||||
<input type="text" id="arrName" name="pilot_name" placeholder="Optional">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<button type="submit" class="btn-submit">✈️ Book Arrival</button>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<div class="loading" id="loading">
|
||||
<div class="spinner"></div>
|
||||
<p style="margin-top: 15px; color: #666;">Processing...</p>
|
||||
</div>
|
||||
|
||||
<div class="footer">
|
||||
<p>📞 Questions? Contact the airfield operations team</p>
|
||||
<p style="margin-top: 10px; font-size: 12px; color: #999;">Version 1.0</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
const API_BASE = window.location.origin + '/api/v1';
|
||||
|
||||
function switchTab(button, tabName) {
|
||||
// Hide all tabs
|
||||
document.querySelectorAll('.tab-content').forEach(tab => {
|
||||
tab.classList.remove('active');
|
||||
});
|
||||
document.querySelectorAll('.tab-btn').forEach(btn => {
|
||||
btn.classList.remove('active');
|
||||
});
|
||||
|
||||
// Show selected tab and activate button
|
||||
document.getElementById(tabName).classList.add('active');
|
||||
button.classList.add('active');
|
||||
}
|
||||
|
||||
function showMessage(message, isError = false) {
|
||||
const successEl = document.getElementById('successMessage');
|
||||
const errorEl = document.getElementById('errorMessage');
|
||||
|
||||
if (isError) {
|
||||
errorEl.textContent = message;
|
||||
errorEl.style.display = 'block';
|
||||
successEl.style.display = 'none';
|
||||
} else {
|
||||
successEl.textContent = message;
|
||||
successEl.style.display = 'block';
|
||||
errorEl.style.display = 'none';
|
||||
}
|
||||
|
||||
// Auto-hide after 5 seconds
|
||||
setTimeout(() => {
|
||||
successEl.style.display = 'none';
|
||||
errorEl.style.display = 'none';
|
||||
}, 5000);
|
||||
}
|
||||
|
||||
async function handleSubmit(event, formType) {
|
||||
event.preventDefault();
|
||||
|
||||
const form = event.target;
|
||||
const formData = new FormData(form);
|
||||
const data = Object.fromEntries(formData);
|
||||
|
||||
// Set flight_type based on form type
|
||||
if (formType === 'local' && !data.flight_type) {
|
||||
data.flight_type = 'LOCAL';
|
||||
} else if (formType === 'circuits' && !data.flight_type) {
|
||||
data.flight_type = 'CIRCUITS';
|
||||
}
|
||||
|
||||
// Convert time inputs to ISO datetime (combine with today's date)
|
||||
const today = new Date().toISOString().split('T')[0];
|
||||
const timeFields = ['etd', 'circuit_timestamp', 'eta'];
|
||||
timeFields.forEach(field => {
|
||||
if (data[field]) {
|
||||
// data[field] is in HH:MM format (time input)
|
||||
const datetime = new Date(`${today}T${data[field]}:00`);
|
||||
data[field] = datetime.toISOString();
|
||||
}
|
||||
});
|
||||
|
||||
let endpoint = '';
|
||||
switch(formType) {
|
||||
case 'local':
|
||||
endpoint = '/public-book/local-flights';
|
||||
break;
|
||||
case 'circuits':
|
||||
endpoint = '/public-book/local-flights';
|
||||
break;
|
||||
case 'departure':
|
||||
endpoint = '/public-book/departures';
|
||||
break;
|
||||
case 'arrival':
|
||||
endpoint = '/public-book/arrivals';
|
||||
break;
|
||||
}
|
||||
|
||||
document.getElementById('loading').style.display = 'block';
|
||||
|
||||
try {
|
||||
const response = await fetch(`${API_BASE}${endpoint}`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
body: JSON.stringify(data)
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
const error = await response.json();
|
||||
throw new Error(error.detail || `Error: ${response.status}`);
|
||||
}
|
||||
|
||||
const result = await response.json();
|
||||
showMessage(`✅ Success! Your booking has been submitted. Booking ID: ${result.id}`);
|
||||
form.reset();
|
||||
} catch (error) {
|
||||
console.error('Error:', error);
|
||||
showMessage(`❌ Error: ${error.message}`, true);
|
||||
} finally {
|
||||
document.getElementById('loading').style.display = 'none';
|
||||
}
|
||||
}
|
||||
|
||||
// Set current time as default for time inputs
|
||||
function setDefaultTimes() {
|
||||
const now = new Date();
|
||||
const hours = String(now.getHours()).padStart(2, '0');
|
||||
const minutes = String(now.getMinutes()).padStart(2, '0');
|
||||
const timeValue = `${hours}:${minutes}`;
|
||||
|
||||
document.querySelectorAll('input[type="time"]').forEach(input => {
|
||||
if (!input.value) {
|
||||
input.value = timeValue;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// Aircraft lookup functionality
|
||||
let aircraftLookupTimeouts = {};
|
||||
|
||||
async function handleAircraftLookup(registration, formType) {
|
||||
if (aircraftLookupTimeouts[formType]) {
|
||||
clearTimeout(aircraftLookupTimeouts[formType]);
|
||||
}
|
||||
|
||||
const registerIdMap = {
|
||||
'local': 'localReg',
|
||||
'circuits': 'circuitReg',
|
||||
'departure': 'depReg',
|
||||
'arrival': 'arrReg'
|
||||
};
|
||||
|
||||
const typeIdMap = {
|
||||
'local': 'localType',
|
||||
'circuits': 'circuitType',
|
||||
'departure': 'depType',
|
||||
'arrival': 'arrType'
|
||||
};
|
||||
|
||||
const regId = registerIdMap[formType];
|
||||
const typeId = typeIdMap[formType];
|
||||
const resultsDiv = document.getElementById(`${regId}-lookup-results`);
|
||||
|
||||
if (!registration || registration.length < 4) {
|
||||
resultsDiv.innerHTML = '';
|
||||
return;
|
||||
}
|
||||
|
||||
resultsDiv.innerHTML = '<span class="lookup-searching">Searching...</span>';
|
||||
|
||||
aircraftLookupTimeouts[formType] = setTimeout(async () => {
|
||||
try {
|
||||
const response = await fetch(`${API_BASE}/aircraft/public/lookup/${registration.toUpperCase()}`);
|
||||
if (response.ok) {
|
||||
const data = await response.json();
|
||||
if (data && data.length > 0) {
|
||||
if (data.length === 1) {
|
||||
const aircraft = data[0];
|
||||
document.getElementById(regId).value = aircraft.registration || registration.toUpperCase();
|
||||
resultsDiv.innerHTML = `
|
||||
<div class="lookup-match">
|
||||
${aircraft.registration || registration.toUpperCase()} - ${aircraft.type_code || 'Unknown'} ${aircraft.model ? `(${aircraft.model})` : ''}
|
||||
</div>
|
||||
`;
|
||||
if (!document.getElementById(typeId).value) {
|
||||
document.getElementById(typeId).value = aircraft.type_code || '';
|
||||
}
|
||||
} else if (data.length <= 10) {
|
||||
resultsDiv.innerHTML = `
|
||||
<div class="aircraft-list">
|
||||
${data.map(aircraft => `
|
||||
<div class="aircraft-option" onclick="selectAircraft('${formType}', '${aircraft.registration || registration.toUpperCase()}', '${aircraft.type_code || ''}')">
|
||||
<div class="aircraft-code">${aircraft.registration || registration.toUpperCase()}</div>
|
||||
<div class="aircraft-details">${aircraft.type_code || 'Unknown'} ${aircraft.model ? `(${aircraft.model})` : ''}</div>
|
||||
</div>
|
||||
`).join('')}
|
||||
</div>
|
||||
`;
|
||||
} else {
|
||||
resultsDiv.innerHTML = '<span class="lookup-no-match">Too many matches, please be more specific</span>';
|
||||
}
|
||||
} else {
|
||||
resultsDiv.innerHTML = '<span class="lookup-no-match">No aircraft found</span>';
|
||||
}
|
||||
} else {
|
||||
resultsDiv.innerHTML = '';
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Aircraft lookup error:', error);
|
||||
resultsDiv.innerHTML = '';
|
||||
}
|
||||
}, 500);
|
||||
}
|
||||
|
||||
function selectAircraft(formType, registration, typeCode) {
|
||||
const registerIdMap = {
|
||||
'local': 'localReg',
|
||||
'circuits': 'circuitReg',
|
||||
'departure': 'depReg',
|
||||
'arrival': 'arrReg'
|
||||
};
|
||||
|
||||
const typeIdMap = {
|
||||
'local': 'localType',
|
||||
'circuits': 'circuitType',
|
||||
'departure': 'depType',
|
||||
'arrival': 'arrType'
|
||||
};
|
||||
|
||||
const regId = registerIdMap[formType];
|
||||
const typeId = typeIdMap[formType];
|
||||
|
||||
document.getElementById(regId).value = registration;
|
||||
document.getElementById(typeId).value = typeCode;
|
||||
document.getElementById(`${regId}-lookup-results`).innerHTML = '';
|
||||
document.getElementById(regId).blur();
|
||||
}
|
||||
|
||||
// Airport lookup functionality
|
||||
let airportLookupTimeouts = {};
|
||||
|
||||
async function handleAirportLookup(query, fieldType) {
|
||||
if (airportLookupTimeouts[fieldType]) {
|
||||
clearTimeout(airportLookupTimeouts[fieldType]);
|
||||
}
|
||||
|
||||
const fieldIdMap = {
|
||||
'depTo': 'depTo',
|
||||
'arrFrom': 'arrFrom'
|
||||
};
|
||||
|
||||
const fieldId = fieldIdMap[fieldType];
|
||||
const resultsDiv = document.getElementById(`${fieldId}-lookup-results`);
|
||||
|
||||
if (!query || query.length < 2) {
|
||||
resultsDiv.innerHTML = '';
|
||||
return;
|
||||
}
|
||||
|
||||
resultsDiv.innerHTML = '<span class="lookup-searching">Searching...</span>';
|
||||
|
||||
airportLookupTimeouts[fieldType] = setTimeout(async () => {
|
||||
try {
|
||||
const response = await fetch(`${API_BASE}/airport/public/lookup/${query.toUpperCase()}`);
|
||||
if (response.ok) {
|
||||
const data = await response.json();
|
||||
if (data && data.length > 0) {
|
||||
if (data.length === 1) {
|
||||
const airport = data[0];
|
||||
resultsDiv.innerHTML = `
|
||||
<div class="aircraft-list">
|
||||
<div class="aircraft-option" onclick="selectAirport('${fieldId}', '${airport.icao}')">
|
||||
<div class="aircraft-code">${airport.icao}/${airport.iata || ''}</div>
|
||||
<div class="aircraft-details">${airport.name}, ${airport.country}</div>
|
||||
</div>
|
||||
</div>
|
||||
`;
|
||||
} else if (data.length <= 10) {
|
||||
resultsDiv.innerHTML = `
|
||||
<div class="aircraft-list">
|
||||
${data.map(airport => `
|
||||
<div class="aircraft-option" onclick="selectAirport('${fieldId}', '${airport.icao}')">
|
||||
<div class="aircraft-code">${airport.icao}/${airport.iata || ''}</div>
|
||||
<div class="aircraft-details">${airport.name}, ${airport.country}</div>
|
||||
</div>
|
||||
`).join('')}
|
||||
</div>
|
||||
`;
|
||||
} else {
|
||||
resultsDiv.innerHTML = '<span class="lookup-no-match">Too many matches, please be more specific</span>';
|
||||
}
|
||||
} else {
|
||||
resultsDiv.innerHTML = '<span class="lookup-no-match">No airport found</span>';
|
||||
}
|
||||
} else {
|
||||
resultsDiv.innerHTML = '';
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Airport lookup error:', error);
|
||||
resultsDiv.innerHTML = '';
|
||||
}
|
||||
}, 500);
|
||||
}
|
||||
|
||||
function selectAirport(fieldId, icaoCode) {
|
||||
document.getElementById(fieldId).value = icaoCode;
|
||||
document.getElementById(`${fieldId}-lookup-results`).innerHTML = '';
|
||||
document.getElementById(fieldId).blur();
|
||||
}
|
||||
|
||||
// Clear lookup results on blur
|
||||
document.addEventListener('DOMContentLoaded', function() {
|
||||
['localReg', 'depReg', 'arrReg', 'depTo', 'arrFrom'].forEach(fieldId => {
|
||||
const field = document.getElementById(fieldId);
|
||||
if (field) {
|
||||
field.addEventListener('blur', function() {
|
||||
setTimeout(() => {
|
||||
document.getElementById(`${fieldId}-lookup-results`).innerHTML = '';
|
||||
}, 150);
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
// Initialize on page load
|
||||
document.addEventListener('DOMContentLoaded', setDefaultTimes);
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user