Before refactor
This commit is contained in:
+80
-9
@@ -1868,7 +1868,7 @@
|
||||
|
||||
try {
|
||||
// Load PPR departures, local flight departures, and airport departures simultaneously
|
||||
const [pprResponse, localBookedOutResponse, localOutGroundResponse, localLocalResponse, localCircuitResponse, depBookedOutResponse, depOutGroundResponse, depLocalResponse] = await Promise.all([
|
||||
const [pprResponse, localBookedOutResponse, localOutGroundResponse, localLocalResponse, localCircuitResponse, depBookedOutResponse, depOutGroundResponse, depLocalResponse, arrLocalResponse, arrCircuitResponse] = await Promise.all([
|
||||
authenticatedFetch('/api/v1/pprs/?limit=1000'),
|
||||
authenticatedFetch('/api/v1/local-flights/?status=BOOKED_OUT&limit=1000'),
|
||||
authenticatedFetch('/api/v1/local-flights/?status=GROUND&limit=1000'),
|
||||
@@ -1876,7 +1876,9 @@
|
||||
authenticatedFetch('/api/v1/local-flights/?status=CIRCUIT&limit=1000'),
|
||||
authenticatedFetch('/api/v1/departures/?status=BOOKED_OUT&limit=1000'),
|
||||
authenticatedFetch('/api/v1/departures/?status=GROUND&limit=1000'),
|
||||
authenticatedFetch('/api/v1/departures/?status=LOCAL&limit=1000')
|
||||
authenticatedFetch('/api/v1/departures/?status=LOCAL&limit=1000'),
|
||||
authenticatedFetch('/api/v1/arrivals/?status=LOCAL&limit=1000'),
|
||||
authenticatedFetch('/api/v1/arrivals/?status=CIRCUIT&limit=1000')
|
||||
]);
|
||||
|
||||
if (!pprResponse.ok) {
|
||||
@@ -1891,6 +1893,8 @@
|
||||
const depBookedOut = depBookedOutResponse.ok ? await depBookedOutResponse.json() : [];
|
||||
const depOutGround = depOutGroundResponse.ok ? await depOutGroundResponse.json() : [];
|
||||
const depLocal = depLocalResponse.ok ? await depLocalResponse.json() : [];
|
||||
const arrLocal = arrLocalResponse.ok ? await arrLocalResponse.json() : [];
|
||||
const arrCircuit = arrCircuitResponse.ok ? await arrCircuitResponse.json() : [];
|
||||
|
||||
// Combine local flights
|
||||
const allLocalFlights = [...localBookedOut, ...localOutGround, ...localLocal, ...localCircuit];
|
||||
@@ -1929,6 +1933,20 @@
|
||||
}));
|
||||
departures.push(...depDepartures);
|
||||
|
||||
// Add arrivals in LOCAL status
|
||||
const arrDepartures = arrLocal.map(flight => ({
|
||||
...flight,
|
||||
isArrival: true // Flag to distinguish from PPR
|
||||
}));
|
||||
departures.push(...arrDepartures);
|
||||
|
||||
// Add arrivals in CIRCUIT status
|
||||
const arrCircuitDepartures = arrCircuit.map(flight => ({
|
||||
...flight,
|
||||
isArrival: true // Flag to distinguish from PPR
|
||||
}));
|
||||
departures.push(...arrCircuitDepartures);
|
||||
|
||||
displayDepartures(departures);
|
||||
} catch (error) {
|
||||
console.error('Error loading departures:', error);
|
||||
@@ -2557,6 +2575,7 @@
|
||||
const row = document.createElement('tr');
|
||||
const isLocal = flight.isLocalFlight;
|
||||
const isDeparture = flight.isDeparture;
|
||||
const isArrival = flight.isArrival;
|
||||
|
||||
// Click handler that routes to correct modal
|
||||
row.onclick = () => {
|
||||
@@ -2564,6 +2583,8 @@
|
||||
openLocalFlightEditModal(flight.id);
|
||||
} else if (isDeparture) {
|
||||
openDepartureEditModal(flight.id);
|
||||
} else if (isArrival) {
|
||||
openArrivalEditModal(flight.id);
|
||||
} else {
|
||||
openPPRModal(flight.id);
|
||||
}
|
||||
@@ -2682,6 +2703,42 @@
|
||||
} else {
|
||||
actionButtons = '<span style="color: #999;">-</span>';
|
||||
}
|
||||
} else if (isArrival) {
|
||||
// Arrival display
|
||||
if (flight.callsign && flight.callsign.trim()) {
|
||||
aircraftDisplay = `<strong>${flight.callsign}</strong><br><span style="font-size: 0.8em; color: #666; font-style: italic;">${flight.registration}</span>`;
|
||||
} else {
|
||||
aircraftDisplay = `<strong>${flight.registration}</strong>`;
|
||||
}
|
||||
typeIcon = '<span style="color: #228b22; font-weight: bold; font-size: 0.9em;" title="Arrival">A</span>';
|
||||
toDisplay = `<i>Arrival from ${flight.in_from || '?'}</i>`;
|
||||
etd = flight.eta ? formatTimeOnly(flight.eta) : (flight.created_dt ? formatTimeOnly(flight.created_dt) : '-');
|
||||
pob = flight.pob || '-';
|
||||
fuel = '-';
|
||||
landedDt = flight.arrived_dt ? formatTimeOnly(flight.arrived_dt) : '-';
|
||||
|
||||
// Action buttons for arrival
|
||||
if (flight.status === 'LOCAL') {
|
||||
actionButtons = `
|
||||
<button class="btn btn-info btn-icon" onclick="event.stopPropagation(); currentArrivalId = ${flight.id}; updateArrivalStatusFromTable(${flight.id}, 'CIRCUIT')" title="Rejoin Circuit">
|
||||
REJOIN
|
||||
</button>
|
||||
`;
|
||||
} else if (flight.status === 'CIRCUIT') {
|
||||
actionButtons = `
|
||||
<button class="btn btn-warning btn-icon" onclick="event.stopPropagation(); currentArrivalId = ${flight.id}; updateArrivalStatusFromTable(${flight.id}, 'LOCAL')" title="Move to Local Area">
|
||||
LOCAL
|
||||
</button>
|
||||
<button class="btn btn-info btn-icon" onclick="event.stopPropagation(); currentArrivalId = ${flight.id}; showCircuitModal(null, ${flight.id})" title="Record Touch & Go">
|
||||
T&G
|
||||
</button>
|
||||
<button class="btn btn-success btn-icon" onclick="event.stopPropagation(); currentArrivalId = ${flight.id}; updateArrivalStatusFromTable(${flight.id}, 'LANDED')" title="Mark as Landed">
|
||||
LAND
|
||||
</button>
|
||||
`;
|
||||
} else {
|
||||
actionButtons = '<span style="color: #999;">-</span>';
|
||||
}
|
||||
} else {
|
||||
// PPR display
|
||||
if (flight.ac_call && flight.ac_call.trim()) {
|
||||
@@ -3043,8 +3100,12 @@
|
||||
}
|
||||
|
||||
// Circuit modal functions
|
||||
function showCircuitModal() {
|
||||
if (!currentLocalFlightId) return;
|
||||
function showCircuitModal(localFlightId = null, arrivalId = null) {
|
||||
if (!localFlightId && !arrivalId) return;
|
||||
|
||||
// Set the current IDs
|
||||
currentLocalFlightId = localFlightId;
|
||||
currentArrivalId = arrivalId;
|
||||
|
||||
// Set default timestamp to current time
|
||||
const now = new Date();
|
||||
@@ -3061,13 +3122,15 @@
|
||||
function closeCircuitModal() {
|
||||
document.getElementById('circuitModal').style.display = 'none';
|
||||
document.getElementById('circuit-form').reset();
|
||||
currentLocalFlightId = null;
|
||||
currentArrivalId = null;
|
||||
}
|
||||
|
||||
// Circuit form submission
|
||||
document.getElementById('circuit-form').addEventListener('submit', async function(e) {
|
||||
e.preventDefault();
|
||||
|
||||
if (!currentLocalFlightId || !accessToken) return;
|
||||
if ((!currentLocalFlightId && !currentArrivalId) || !accessToken) return;
|
||||
|
||||
const circuitTimestampInput = document.getElementById('circuit-timestamp').value;
|
||||
if (!circuitTimestampInput) {
|
||||
@@ -3080,15 +3143,23 @@
|
||||
const localDate = new Date(circuitTimestampInput);
|
||||
const circuitTimestamp = localDate.toISOString();
|
||||
|
||||
const requestBody = {
|
||||
circuit_timestamp: circuitTimestamp
|
||||
};
|
||||
|
||||
// Add the appropriate ID based on what we're tracking
|
||||
if (currentLocalFlightId) {
|
||||
requestBody.local_flight_id = currentLocalFlightId;
|
||||
} else if (currentArrivalId) {
|
||||
requestBody.arrival_id = currentArrivalId;
|
||||
}
|
||||
|
||||
const response = await authenticatedFetch('/api/v1/circuits/', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
body: JSON.stringify({
|
||||
local_flight_id: currentLocalFlightId,
|
||||
circuit_timestamp: circuitTimestamp
|
||||
})
|
||||
body: JSON.stringify(requestBody)
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
|
||||
Reference in New Issue
Block a user