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) {
|
||||
|
||||
+67
-59
@@ -3009,8 +3009,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();
|
||||
@@ -3027,13 +3031,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) {
|
||||
@@ -3046,15 +3052,21 @@
|
||||
const localDate = new Date(circuitTimestampInput);
|
||||
const circuitTimestamp = localDate.toISOString();
|
||||
|
||||
const requestBody = {
|
||||
circuit_timestamp: circuitTimestamp
|
||||
};
|
||||
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) {
|
||||
@@ -4602,41 +4614,10 @@
|
||||
}
|
||||
}
|
||||
|
||||
// Update status from table for departures
|
||||
async function updateDepartureStatusFromTable(departureId, status) {
|
||||
if (!accessToken) return;
|
||||
|
||||
try {
|
||||
const response = await fetch(`/api/v1/departures/${departureId}/status`, {
|
||||
method: 'PATCH',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'Authorization': `Bearer ${accessToken}`
|
||||
},
|
||||
body: JSON.stringify({ status: status })
|
||||
});
|
||||
|
||||
if (!response.ok) throw new Error('Failed to update status');
|
||||
|
||||
loadPPRs(); // Refresh display
|
||||
showNotification(`Departure marked as ${status.toLowerCase()}`);
|
||||
} catch (error) {
|
||||
console.error('Error updating status:', error);
|
||||
showNotification('Error updating departure status', true);
|
||||
}
|
||||
}
|
||||
|
||||
// Update status from table for booked-in arrivals
|
||||
// Update status from table for arrivals
|
||||
async function updateArrivalStatusFromTable(arrivalId, status) {
|
||||
if (!accessToken) return;
|
||||
|
||||
// Show confirmation for cancel actions
|
||||
if (status === 'CANCELLED') {
|
||||
if (!confirm('Are you sure you want to cancel this arrival? This action cannot be easily undone.')) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
const response = await fetch(`/api/v1/arrivals/${arrivalId}/status`, {
|
||||
method: 'PATCH',
|
||||
@@ -4649,7 +4630,7 @@
|
||||
|
||||
if (!response.ok) throw new Error('Failed to update status');
|
||||
|
||||
loadArrivals(); // Refresh arrivals table
|
||||
loadATCAircraft(); // Refresh display
|
||||
showNotification(`Arrival marked as ${status.toLowerCase()}`);
|
||||
} catch (error) {
|
||||
console.error('Error updating status:', error);
|
||||
@@ -5230,12 +5211,14 @@
|
||||
try {
|
||||
const response = await Promise.all([
|
||||
authenticatedFetch('/api/v1/local-flights/?status=LOCAL&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')
|
||||
]);
|
||||
|
||||
let locals = [];
|
||||
if (response[0].ok) locals = (await response[0].json()).map(l => ({ ...l, isLocalFlight: true }));
|
||||
if (response[1].ok) locals = locals.concat((await response[1].json()).map(d => ({ ...d, isDeparture: true })));
|
||||
if (response[2].ok) locals = locals.concat((await response[2].json()).map(a => ({ ...a, isArrival: true })));
|
||||
|
||||
displayLocalAircraft(locals);
|
||||
} catch (error) {
|
||||
@@ -5264,9 +5247,9 @@
|
||||
if (isDeparture) {
|
||||
// Departure in LOCAL status - show QSY button
|
||||
buttons = `<button class="status-btn" onclick="event.stopPropagation(); currentDepartureId = '${ac.id}'; showTimestampModal('DEPARTED', ${ac.id}, false, true)">QSY</button>`;
|
||||
} else if (ac.isLocalFlight) {
|
||||
// Local flight in LOCAL status - show REJOIN button
|
||||
buttons = `<button class="status-btn" onclick="event.stopPropagation(); updateLocalFlightStatusFromTable('${ac.id}', 'CIRCUIT')">REJOIN</button>`;
|
||||
} else if (ac.isLocalFlight || ac.isArrival) {
|
||||
// Local flight or arrival in LOCAL status - show REJOIN button
|
||||
buttons = `<button class="status-btn" onclick="event.stopPropagation(); ${ac.isArrival ? `updateArrivalStatusFromTable('${ac.id}', 'CIRCUIT')` : `updateLocalFlightStatusFromTable('${ac.id}', 'CIRCUIT')`}">REJOIN</button>`;
|
||||
}
|
||||
|
||||
return `
|
||||
@@ -5322,6 +5305,12 @@
|
||||
const from = ac.in_from;
|
||||
const eta = ac.eta;
|
||||
|
||||
let buttons = '';
|
||||
if (ac.isArrival) {
|
||||
// Arrival in BOOKED_IN status - show CONTACT button
|
||||
buttons = `<button class="status-btn" onclick="event.stopPropagation(); updateArrivalStatusFromTable('${ac.id}', 'LOCAL')">CONTACT</button>`;
|
||||
}
|
||||
|
||||
return `
|
||||
<div class="aircraft-item" onclick="handleATCClick('${ac.id}', '${ac.isArrival ? 'arrival' : 'ppr'}')">
|
||||
<div class="aircraft-info">
|
||||
@@ -5329,7 +5318,7 @@
|
||||
<div class="aircraft-details">${type} from ${from || '?'}</div>
|
||||
<div class="aircraft-time">${eta ? formatTimeOnly(eta) : ''}</div>
|
||||
</div>
|
||||
<div class="aircraft-status status-inbound">IB</div>
|
||||
${buttons ? `<div style="display: flex; gap: 0.5rem;">${buttons}</div>` : '<div class="aircraft-status status-inbound">IB</div>'}
|
||||
</div>
|
||||
`;
|
||||
}).join('');
|
||||
@@ -5340,12 +5329,14 @@
|
||||
try {
|
||||
const response = await Promise.all([
|
||||
authenticatedFetch('/api/v1/local-flights/?status=DEPARTED&limit=1000&flight_type=CIRCUITS'),
|
||||
authenticatedFetch('/api/v1/local-flights/?status=CIRCUIT&limit=1000')
|
||||
authenticatedFetch('/api/v1/local-flights/?status=CIRCUIT&limit=1000'),
|
||||
authenticatedFetch('/api/v1/arrivals/?status=CIRCUIT&limit=1000')
|
||||
]);
|
||||
|
||||
let circuits = [];
|
||||
if (response[0].ok) circuits = await response[0].json();
|
||||
if (response[1].ok) circuits = circuits.concat(await response[1].json());
|
||||
if (response[2].ok) circuits = circuits.concat((await response[2].json()).map(a => ({ ...a, isArrival: true })));
|
||||
|
||||
displayCircuitAircraft(circuits);
|
||||
} catch (error) {
|
||||
@@ -5364,20 +5355,37 @@
|
||||
return;
|
||||
}
|
||||
|
||||
container.innerHTML = aircraft.map(ac => `
|
||||
<div class="aircraft-item" onclick="handleATCClick('${ac.id}', 'local')">
|
||||
<div class="aircraft-info">
|
||||
<div class="aircraft-reg">${ac.registration}</div>
|
||||
<div class="aircraft-details">${ac.type}</div>
|
||||
<div class="aircraft-time">${formatTimeOnly(ac.created_dt)}</div>
|
||||
container.innerHTML = aircraft.map(ac => {
|
||||
const isArrival = ac.isArrival;
|
||||
const entityType = isArrival ? 'arrival' : 'local';
|
||||
const updateFunction = isArrival ? 'updateArrivalStatusFromTable' : 'updateLocalFlightStatusFromTable';
|
||||
const landFunction = isArrival ? `${updateFunction}('${ac.id}', 'LANDED')` : `showTimestampModal('LANDED', ${ac.id}, true)`;
|
||||
|
||||
let buttons = `
|
||||
<button class="status-btn" onclick="event.stopPropagation(); ${updateFunction}('${ac.id}', 'LOCAL')">LOCAL</button>
|
||||
`;
|
||||
|
||||
// Show T&G for both local flights and arrivals
|
||||
const tgFunction = isArrival
|
||||
? `currentArrivalId = '${ac.id}'; showCircuitModal(null, '${ac.id}')`
|
||||
: `currentLocalFlightId = '${ac.id}'; showCircuitModal('${ac.id}')`;
|
||||
buttons += `<button class="status-btn" onclick="event.stopPropagation(); ${tgFunction}">T&G</button>`;
|
||||
|
||||
buttons += `<button class="status-btn" onclick="event.stopPropagation(); ${landFunction}">LAND</button>`;
|
||||
|
||||
return `
|
||||
<div class="aircraft-item" onclick="handleATCClick('${ac.id}', '${entityType}')">
|
||||
<div class="aircraft-info">
|
||||
<div class="aircraft-reg">${ac.registration}</div>
|
||||
<div class="aircraft-details">${ac.type}</div>
|
||||
<div class="aircraft-time">${formatTimeOnly(ac.created_dt)}</div>
|
||||
</div>
|
||||
<div style="display: flex; gap: 0.5rem;">
|
||||
${buttons}
|
||||
</div>
|
||||
</div>
|
||||
<div style="display: flex; gap: 0.5rem;">
|
||||
<button class="status-btn" onclick="event.stopPropagation(); updateLocalFlightStatusFromTable('${ac.id}', 'LOCAL')">LOCAL</button>
|
||||
<button class="status-btn" onclick="event.stopPropagation(); currentLocalFlightId = '${ac.id}'; showCircuitModal()">T&G</button>
|
||||
<button class="status-btn" onclick="event.stopPropagation(); currentLocalFlightId = '${ac.id}'; showTimestampModal('LANDED', ${ac.id}, true)">LAND</button>
|
||||
</div>
|
||||
</div>
|
||||
`).join('');
|
||||
`;
|
||||
}).join('');
|
||||
}
|
||||
|
||||
// Load pending PPRs
|
||||
|
||||
Reference in New Issue
Block a user