Info display tweaks
This commit is contained in:
@@ -3,19 +3,19 @@ from fastapi import APIRouter, Depends
|
|||||||
from sqlalchemy.orm import Session
|
from sqlalchemy.orm import Session
|
||||||
from app.api.deps import get_db
|
from app.api.deps import get_db
|
||||||
from app.crud.crud_ppr import ppr as crud_ppr
|
from app.crud.crud_ppr import ppr as crud_ppr
|
||||||
from app.schemas.ppr import PPR
|
from app.schemas.ppr import PPRPublic
|
||||||
|
|
||||||
router = APIRouter()
|
router = APIRouter()
|
||||||
|
|
||||||
|
|
||||||
@router.get("/arrivals", response_model=List[PPR])
|
@router.get("/arrivals", response_model=List[PPRPublic])
|
||||||
async def get_public_arrivals(db: Session = Depends(get_db)):
|
async def get_public_arrivals(db: Session = Depends(get_db)):
|
||||||
"""Get today's arrivals for public display"""
|
"""Get today's arrivals for public display"""
|
||||||
arrivals = crud_ppr.get_arrivals_today(db)
|
arrivals = crud_ppr.get_arrivals_today(db)
|
||||||
return arrivals
|
return arrivals
|
||||||
|
|
||||||
|
|
||||||
@router.get("/departures", response_model=List[PPR])
|
@router.get("/departures", response_model=List[PPRPublic])
|
||||||
async def get_public_departures(db: Session = Depends(get_db)):
|
async def get_public_departures(db: Session = Depends(get_db)):
|
||||||
"""Get today's departures for public display"""
|
"""Get today's departures for public display"""
|
||||||
departures = crud_ppr.get_departures_today(db)
|
departures = crud_ppr.get_departures_today(db)
|
||||||
|
|||||||
@@ -48,7 +48,7 @@ class CRUDPPR:
|
|||||||
return query.order_by(desc(PPRRecord.submitted_dt)).offset(skip).limit(limit).all()
|
return query.order_by(desc(PPRRecord.submitted_dt)).offset(skip).limit(limit).all()
|
||||||
|
|
||||||
def get_arrivals_today(self, db: Session) -> List[PPRRecord]:
|
def get_arrivals_today(self, db: Session) -> List[PPRRecord]:
|
||||||
"""Get today's arrivals"""
|
"""Get today's arrivals - includes aircraft that have arrived and may have departed"""
|
||||||
today = date.today()
|
today = date.today()
|
||||||
return db.query(PPRRecord).filter(
|
return db.query(PPRRecord).filter(
|
||||||
and_(
|
and_(
|
||||||
@@ -56,7 +56,8 @@ class CRUDPPR:
|
|||||||
or_(
|
or_(
|
||||||
PPRRecord.status == PPRStatus.NEW,
|
PPRRecord.status == PPRStatus.NEW,
|
||||||
PPRRecord.status == PPRStatus.CONFIRMED,
|
PPRRecord.status == PPRStatus.CONFIRMED,
|
||||||
PPRRecord.status == PPRStatus.LANDED
|
PPRRecord.status == PPRStatus.LANDED,
|
||||||
|
PPRRecord.status == PPRStatus.DEPARTED
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
).order_by(PPRRecord.eta).all()
|
).order_by(PPRRecord.eta).all()
|
||||||
|
|||||||
@@ -96,6 +96,25 @@ class PPR(PPRInDBBase):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
class PPRPublic(BaseModel):
|
||||||
|
"""Public schema for arrivals/departures board - excludes sensitive data"""
|
||||||
|
id: int
|
||||||
|
status: PPRStatus
|
||||||
|
ac_reg: str
|
||||||
|
ac_type: str
|
||||||
|
ac_call: Optional[str] = None
|
||||||
|
in_from: str
|
||||||
|
eta: datetime
|
||||||
|
out_to: Optional[str] = None
|
||||||
|
etd: Optional[datetime] = None
|
||||||
|
landed_dt: Optional[datetime] = None
|
||||||
|
departed_dt: Optional[datetime] = None
|
||||||
|
submitted_dt: datetime
|
||||||
|
|
||||||
|
class Config:
|
||||||
|
from_attributes = True
|
||||||
|
|
||||||
|
|
||||||
class PPRInDB(PPRInDBBase):
|
class PPRInDB(PPRInDBBase):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|||||||
@@ -564,7 +564,7 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="menu-buttons">
|
<div class="menu-buttons">
|
||||||
<button class="btn btn-success" onclick="openNewPPRModal()">
|
<button class="btn btn-success" onclick="openNewPPRModal()">
|
||||||
➕ New PPR Entry
|
➕ New PPR
|
||||||
</button>
|
</button>
|
||||||
<button class="btn btn-primary" onclick="window.open('reports.html', '_blank')">
|
<button class="btn btn-primary" onclick="window.open('reports.html', '_blank')">
|
||||||
📊 Reports
|
📊 Reports
|
||||||
@@ -587,7 +587,7 @@
|
|||||||
<!-- Arrivals Table -->
|
<!-- Arrivals Table -->
|
||||||
<div class="ppr-table">
|
<div class="ppr-table">
|
||||||
<div class="table-header">
|
<div class="table-header">
|
||||||
🛬 Today's Arrivals - <span id="arrivals-count">0</span> entries
|
🛬 Pending Arrivals - <span id="arrivals-count">0</span>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div id="arrivals-loading" class="loading">
|
<div id="arrivals-loading" class="loading">
|
||||||
@@ -614,15 +614,14 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div id="arrivals-no-data" class="no-data" style="display: none;">
|
<div id="arrivals-no-data" class="no-data" style="display: none;">
|
||||||
<h3>No arrivals for today</h3>
|
<h3>No Pending Arrivals</h3>
|
||||||
<p>No NEW or CONFIRMED arrivals scheduled for today.</p>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- Departures Table -->
|
<!-- Departures Table -->
|
||||||
<div class="ppr-table" style="margin-top: 2rem;">
|
<div class="ppr-table" style="margin-top: 2rem;">
|
||||||
<div class="table-header">
|
<div class="table-header">
|
||||||
🛫 Today's Departures - <span id="departures-count">0</span> entries
|
🛫 Pending Departures - <span id="departures-count">0</span>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div id="departures-loading" class="loading">
|
<div id="departures-loading" class="loading">
|
||||||
@@ -650,7 +649,7 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div id="departures-no-data" class="no-data" style="display: none;">
|
<div id="departures-no-data" class="no-data" style="display: none;">
|
||||||
<h3>No departures for today</h3>
|
<h3>No Pending Departures</h3>
|
||||||
<p>No aircraft currently landed and ready to depart.</p>
|
<p>No aircraft currently landed and ready to depart.</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -1324,22 +1323,26 @@
|
|||||||
document.getElementById('arrivals-no-data').style.display = 'none';
|
document.getElementById('arrivals-no-data').style.display = 'none';
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// Always load today's date
|
// Load all PPRs and filter client-side for today's arrivals
|
||||||
const today = new Date().toISOString().split('T')[0];
|
// We filter by ETA date (not ETD) and NEW/CONFIRMED status
|
||||||
let url = `/api/v1/pprs/?limit=1000&date_from=${today}&date_to=${today}`;
|
const response = await authenticatedFetch('/api/v1/pprs/?limit=1000');
|
||||||
|
|
||||||
const response = await authenticatedFetch(url);
|
|
||||||
|
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
throw new Error('Failed to fetch arrivals');
|
throw new Error('Failed to fetch arrivals');
|
||||||
}
|
}
|
||||||
|
|
||||||
const allPPRs = await response.json();
|
const allPPRs = await response.json();
|
||||||
|
const today = new Date().toISOString().split('T')[0];
|
||||||
|
|
||||||
// Filter for arrivals (NEW and CONFIRMED with ETA only)
|
// Filter for arrivals with ETA today and NEW or CONFIRMED status
|
||||||
const arrivals = allPPRs.filter(ppr =>
|
const arrivals = allPPRs.filter(ppr => {
|
||||||
(ppr.status === 'NEW' || ppr.status === 'CONFIRMED') && ppr.eta
|
if (!ppr.eta || (ppr.status !== 'NEW' && ppr.status !== 'CONFIRMED')) {
|
||||||
);
|
return false;
|
||||||
|
}
|
||||||
|
// Extract date from ETA (UTC)
|
||||||
|
const etaDate = ppr.eta.split('T')[0];
|
||||||
|
return etaDate === today;
|
||||||
|
});
|
||||||
|
|
||||||
displayArrivals(arrivals);
|
displayArrivals(arrivals);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@@ -1359,20 +1362,26 @@
|
|||||||
document.getElementById('departures-no-data').style.display = 'none';
|
document.getElementById('departures-no-data').style.display = 'none';
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// Always load today's date
|
// Load all PPRs and filter client-side for today's departures
|
||||||
const today = new Date().toISOString().split('T')[0];
|
// We filter by ETD date and LANDED status only (exclude DEPARTED)
|
||||||
let url = `/api/v1/pprs/?limit=1000&date_from=${today}&date_to=${today}`;
|
const response = await authenticatedFetch('/api/v1/pprs/?limit=1000');
|
||||||
|
|
||||||
const response = await authenticatedFetch(url);
|
|
||||||
|
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
throw new Error('Failed to fetch departures');
|
throw new Error('Failed to fetch departures');
|
||||||
}
|
}
|
||||||
|
|
||||||
const allPPRs = await response.json();
|
const allPPRs = await response.json();
|
||||||
|
const today = new Date().toISOString().split('T')[0];
|
||||||
|
|
||||||
// Filter for departures (LANDED status only)
|
// Filter for departures with ETD today and LANDED status only
|
||||||
const departures = allPPRs.filter(ppr => ppr.status === 'LANDED');
|
const departures = allPPRs.filter(ppr => {
|
||||||
|
if (!ppr.etd || ppr.status !== 'LANDED') {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
// Extract date from ETD (UTC)
|
||||||
|
const etdDate = ppr.etd.split('T')[0];
|
||||||
|
return etdDate === today;
|
||||||
|
});
|
||||||
|
|
||||||
displayDepartures(departures);
|
displayDepartures(departures);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@@ -1548,7 +1557,7 @@
|
|||||||
isNewPPR = true;
|
isNewPPR = true;
|
||||||
currentPPRId = null;
|
currentPPRId = null;
|
||||||
etdManuallyEdited = false; // Reset the manual edit flag for new PPR
|
etdManuallyEdited = false; // Reset the manual edit flag for new PPR
|
||||||
document.getElementById('modal-title').textContent = 'New PPR Entry';
|
document.getElementById('modal-title').textContent = 'New PPR';
|
||||||
document.getElementById('delete-btn').style.display = 'none';
|
document.getElementById('delete-btn').style.display = 'none';
|
||||||
document.getElementById('journal-section').style.display = 'none';
|
document.getElementById('journal-section').style.display = 'none';
|
||||||
document.querySelector('.quick-actions').style.display = 'none';
|
document.querySelector('.quick-actions').style.display = 'none';
|
||||||
|
|||||||
@@ -309,7 +309,7 @@
|
|||||||
|
|
||||||
// Show landed time if available, otherwise ETA
|
// Show landed time if available, otherwise ETA
|
||||||
let timeDisplay;
|
let timeDisplay;
|
||||||
if (arrival.status === 'LANDED' && arrival.landed_dt) {
|
if ((arrival.status === 'LANDED' || arrival.status === 'DEPARTED') && arrival.landed_dt) {
|
||||||
const time = convertToLocalTime(arrival.landed_dt);
|
const time = convertToLocalTime(arrival.landed_dt);
|
||||||
timeDisplay = `<div style="display: flex; align-items: center; gap: 8px;"><span style="color: #27ae60; font-weight: bold;">${time}</span><span style="font-size: 0.7em; background: #27ae60; color: white; padding: 2px 4px; border-radius: 3px; white-space: nowrap;">LANDED</span></div>`;
|
timeDisplay = `<div style="display: flex; align-items: center; gap: 8px;"><span style="color: #27ae60; font-weight: bold;">${time}</span><span style="font-size: 0.7em; background: #27ae60; color: white; padding: 2px 4px; border-radius: 3px; white-space: nowrap;">LANDED</span></div>`;
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
47
web/ppr.html
47
web/ppr.html
@@ -454,6 +454,41 @@
|
|||||||
console.log('Source:', window.PPR_CONFIG?.apiBase ? 'config.js' : 'fallback');
|
console.log('Source:', window.PPR_CONFIG?.apiBase ? 'config.js' : 'fallback');
|
||||||
console.log('=======================');
|
console.log('=======================');
|
||||||
|
|
||||||
|
// Track if user has manually edited ETD
|
||||||
|
let etdManuallyEdited = false;
|
||||||
|
|
||||||
|
// Function to update ETD based on ETA (2 hours later)
|
||||||
|
function updateETDFromETA() {
|
||||||
|
// Only auto-update if user hasn't manually edited ETD
|
||||||
|
if (etdManuallyEdited) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const etaDate = document.getElementById('eta-date').value;
|
||||||
|
const etaTime = document.getElementById('eta-time').value;
|
||||||
|
|
||||||
|
if (etaDate && etaTime) {
|
||||||
|
// Parse ETA
|
||||||
|
const eta = new Date(`${etaDate}T${etaTime}`);
|
||||||
|
|
||||||
|
// Calculate ETD (2 hours after ETA)
|
||||||
|
const etd = new Date(eta.getTime() + 2 * 60 * 60 * 1000);
|
||||||
|
|
||||||
|
// Format ETD
|
||||||
|
const etdDateStr = `${etd.getFullYear()}-${String(etd.getMonth() + 1).padStart(2, '0')}-${String(etd.getDate()).padStart(2, '0')}`;
|
||||||
|
const etdTimeStr = `${String(etd.getHours()).padStart(2, '0')}:${String(etd.getMinutes()).padStart(2, '0')}`;
|
||||||
|
|
||||||
|
// Update ETD fields
|
||||||
|
document.getElementById('etd-date').value = etdDateStr;
|
||||||
|
document.getElementById('etd-time').value = etdTimeStr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Function to mark ETD as manually edited
|
||||||
|
function markETDAsManuallyEdited() {
|
||||||
|
etdManuallyEdited = true;
|
||||||
|
}
|
||||||
|
|
||||||
// Iframe resizing functionality
|
// Iframe resizing functionality
|
||||||
function sendHeightToParent() {
|
function sendHeightToParent() {
|
||||||
const height = document.body.scrollHeight || document.documentElement.scrollHeight;
|
const height = document.body.scrollHeight || document.documentElement.scrollHeight;
|
||||||
@@ -814,9 +849,9 @@
|
|||||||
const nextHour = new Date(now);
|
const nextHour = new Date(now);
|
||||||
nextHour.setHours(now.getHours() + 1, 0, 0, 0);
|
nextHour.setHours(now.getHours() + 1, 0, 0, 0);
|
||||||
|
|
||||||
// ETD is 1 hour after ETA
|
// ETD is 2 hours after ETA
|
||||||
const etd = new Date(nextHour);
|
const etd = new Date(nextHour);
|
||||||
etd.setHours(nextHour.getHours() + 1);
|
etd.setHours(nextHour.getHours() + 2);
|
||||||
|
|
||||||
// Format date and time for separate inputs
|
// Format date and time for separate inputs
|
||||||
function formatDate(date) {
|
function formatDate(date) {
|
||||||
@@ -845,6 +880,14 @@
|
|||||||
document.addEventListener('DOMContentLoaded', function() {
|
document.addEventListener('DOMContentLoaded', function() {
|
||||||
initializeTimeDropdowns();
|
initializeTimeDropdowns();
|
||||||
setDefaultDateTime();
|
setDefaultDateTime();
|
||||||
|
|
||||||
|
// Add event listeners to ETA fields to auto-update ETD
|
||||||
|
document.getElementById('eta-date').addEventListener('change', updateETDFromETA);
|
||||||
|
document.getElementById('eta-time').addEventListener('change', updateETDFromETA);
|
||||||
|
|
||||||
|
// Add event listeners to ETD fields to mark as manually edited
|
||||||
|
document.getElementById('etd-date').addEventListener('change', markETDAsManuallyEdited);
|
||||||
|
document.getElementById('etd-time').addEventListener('change', markETDAsManuallyEdited);
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
|
|||||||
Reference in New Issue
Block a user