Circuits handling
This commit is contained in:
117
web/admin.html
117
web/admin.html
@@ -797,6 +797,32 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Circuit Modal for recording touch-and-go events -->
|
||||
<div id="circuitModal" class="modal">
|
||||
<div class="modal-content" style="max-width: 400px;">
|
||||
<div class="modal-header">
|
||||
<h2>Record Circuit (Touch & Go)</h2>
|
||||
<button class="close" onclick="closeCircuitModal()">×</button>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<form id="circuit-form">
|
||||
<div class="form-group">
|
||||
<label for="circuit-timestamp">Circuit Time (Local Time) *</label>
|
||||
<input type="datetime-local" id="circuit-timestamp" name="timestamp" required>
|
||||
</div>
|
||||
<div class="form-actions">
|
||||
<button type="button" class="btn btn-primary" onclick="closeCircuitModal()">
|
||||
Cancel
|
||||
</button>
|
||||
<button type="submit" class="btn btn-success">
|
||||
Record Circuit
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
let currentUser = null;
|
||||
let accessToken = null;
|
||||
@@ -1074,6 +1100,13 @@
|
||||
return;
|
||||
}
|
||||
|
||||
// Press 'Escape' to close circuit modal if it's open (allow even when typing in inputs)
|
||||
if (e.key === 'Escape' && document.getElementById('circuitModal').style.display === 'block') {
|
||||
e.preventDefault();
|
||||
closeCircuitModal();
|
||||
return;
|
||||
}
|
||||
|
||||
// Press 'Escape' to close Book Out modal if it's open (allow even when typing in inputs)
|
||||
if (e.key === 'Escape' && document.getElementById('localFlightModal').style.display === 'block') {
|
||||
e.preventDefault();
|
||||
@@ -1852,7 +1885,17 @@
|
||||
eta = flight.departure_dt ? formatTimeOnly(flight.departure_dt) : '-';
|
||||
pob = flight.pob || '-';
|
||||
fuel = '-';
|
||||
|
||||
// For circuits, add a circuit 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">
|
||||
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>
|
||||
@@ -2004,7 +2047,15 @@
|
||||
</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">
|
||||
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>
|
||||
@@ -2382,6 +2433,72 @@
|
||||
document.getElementById('timestamp-form').reset();
|
||||
}
|
||||
|
||||
// Circuit modal functions
|
||||
function showCircuitModal() {
|
||||
if (!currentLocalFlightId) return;
|
||||
|
||||
// Set default timestamp to current time
|
||||
const now = new Date();
|
||||
const year = now.getFullYear();
|
||||
const month = String(now.getMonth() + 1).padStart(2, '0');
|
||||
const day = String(now.getDate()).padStart(2, '0');
|
||||
const hours = String(now.getHours()).padStart(2, '0');
|
||||
const minutes = String(now.getMinutes()).padStart(2, '0');
|
||||
document.getElementById('circuit-timestamp').value = `${year}-${month}-${day}T${hours}:${minutes}`;
|
||||
|
||||
document.getElementById('circuitModal').style.display = 'block';
|
||||
}
|
||||
|
||||
function closeCircuitModal() {
|
||||
document.getElementById('circuitModal').style.display = 'none';
|
||||
document.getElementById('circuit-form').reset();
|
||||
}
|
||||
|
||||
// Circuit form submission
|
||||
document.getElementById('circuit-form').addEventListener('submit', async function(e) {
|
||||
e.preventDefault();
|
||||
|
||||
if (!currentLocalFlightId || !accessToken) return;
|
||||
|
||||
const circuitTimestampInput = document.getElementById('circuit-timestamp').value;
|
||||
if (!circuitTimestampInput) {
|
||||
showNotification('Please select a circuit time', true);
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
// Convert local datetime to UTC ISO format
|
||||
const localDate = new Date(circuitTimestampInput);
|
||||
const circuitTimestamp = localDate.toISOString();
|
||||
|
||||
const response = await authenticatedFetch('/api/v1/circuits/', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
body: JSON.stringify({
|
||||
local_flight_id: currentLocalFlightId,
|
||||
circuit_timestamp: circuitTimestamp
|
||||
})
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
const error = await response.json();
|
||||
throw new Error(error.detail || 'Failed to record circuit');
|
||||
}
|
||||
|
||||
const circuit = await response.json();
|
||||
showNotification(`✈️ Circuit recorded at ${formatTimeOnly(circuit.circuit_timestamp)}`);
|
||||
closeCircuitModal();
|
||||
|
||||
// Refresh departures to show updated circuit count
|
||||
loadDepartures();
|
||||
} catch (error) {
|
||||
console.error('Error recording circuit:', error);
|
||||
showNotification('Error recording circuit: ' + error.message, true);
|
||||
}
|
||||
});
|
||||
|
||||
// Timestamp form submission
|
||||
document.getElementById('timestamp-form').addEventListener('submit', async function(e) {
|
||||
e.preventDefault();
|
||||
|
||||
Reference in New Issue
Block a user