local-flights #5

Merged
jamesp merged 37 commits from local-flights into main 2025-12-20 12:29:32 -05:00
Showing only changes of commit 97517777df - Show all commits

View File

@@ -394,14 +394,11 @@
<input type="text" id="local_out_to" name="out_to" placeholder="ICAO Code or Airport Name" oninput="handleLocalOutToAirportLookup(this.value)" tabindex="3"> <input type="text" id="local_out_to" name="out_to" placeholder="ICAO Code or Airport Name" oninput="handleLocalOutToAirportLookup(this.value)" tabindex="3">
<div id="local-out-to-lookup-results"></div> <div id="local-out-to-lookup-results"></div>
</div> </div>
<div class="form-group" id="local-etd-group" style="display: none;"> <div class="form-group">
<label for="local_etd">ETD (Estimated Time of Departure)</label> <label for="local_etd_time">ETD (Estimated Time of Departure) *</label>
<div style="display: flex; gap: 0.5rem;"> <select id="local_etd_time" name="etd_time" required>
<input type="date" id="local_etd_date" name="etd_date" style="flex: 1;"> <option value="">Select Time</option>
<select id="local_etd_time" name="etd_time" style="flex: 1;"> </select>
<option value="">Select Time</option>
</select>
</div>
</div> </div>
<div class="form-group full-width"> <div class="form-group full-width">
<label for="local_notes">Notes</label> <label for="local_notes">Notes</label>
@@ -2662,82 +2659,74 @@
const destGroup = document.getElementById('departure-destination-group'); const destGroup = document.getElementById('departure-destination-group');
const destInput = document.getElementById('local_out_to'); const destInput = document.getElementById('local_out_to');
const destLabel = document.getElementById('departure-destination-label'); const destLabel = document.getElementById('departure-destination-label');
const etdGroup = document.getElementById('local-etd-group');
if (flightType === 'DEPARTURE') { if (flightType === 'DEPARTURE') {
destGroup.style.display = 'block'; destGroup.style.display = 'block';
destInput.required = true; destInput.required = true;
destLabel.textContent = 'Destination Airport *'; destLabel.textContent = 'Destination Airport *';
etdGroup.style.display = 'block';
} else { } else {
destGroup.style.display = 'none'; destGroup.style.display = 'none';
destInput.required = false; destInput.required = false;
destInput.value = ''; destInput.value = '';
destLabel.textContent = 'Destination Airport'; destLabel.textContent = 'Destination Airport';
etdGroup.style.display = 'none';
document.getElementById('local_etd_date').value = '';
document.getElementById('local_etd_time').value = '';
} }
// Populate ETD time slots // Populate ETD time slots for all flight types
populateETDTimeSlots(); populateETDTimeSlots();
} }
function getNearest15MinSlot() { function getNext10MinuteSlot() {
const now = new Date(); const now = new Date();
const minutes = now.getMinutes(); const minutes = now.getMinutes();
const remainder = minutes % 15; const remainder = minutes % 10;
const roundedMinutes = remainder >= 7.5 ? minutes + (15 - remainder) : minutes - remainder;
const future = new Date(now); const next = new Date(now);
future.setMinutes(roundedMinutes === 60 ? 0 : roundedMinutes); if (remainder === 0) {
if (roundedMinutes === 60) { // Already on a 10-minute boundary, use this time
future.setHours(future.getHours() + 1); next.setSeconds(0);
} else {
// Round up to next 10-minute boundary
next.setMinutes(minutes + (10 - remainder));
next.setSeconds(0);
} }
return future; return next;
} }
function populateETDTimeSlots() { function populateETDTimeSlots() {
const timeSelect = document.getElementById('local_etd_time'); const timeSelect = document.getElementById('local_etd_time');
const dateInput = document.getElementById('local_etd_date');
// Get the selected date or use today
let selectedDate = dateInput.value;
if (!selectedDate) {
const today = new Date();
const year = today.getFullYear();
const month = String(today.getMonth() + 1).padStart(2, '0');
const day = String(today.getDate()).padStart(2, '0');
selectedDate = `${year}-${month}-${day}`;
dateInput.value = selectedDate;
}
// Clear and repopulate // Clear and repopulate
timeSelect.innerHTML = '<option value="">Select Time</option>'; timeSelect.innerHTML = '<option value="">Select Time</option>';
const future = getNearest15MinSlot(); // Get the next 10-minute slot
const selectedDateTime = new Date(selectedDate + 'T00:00:00'); const defaultTime = getNext10MinuteSlot();
const defaultHour = defaultTime.getHours();
const defaultMinute = defaultTime.getMinutes();
// If selected date is today, start from nearest 15-min slot; otherwise start from 06:00 // Generate 10-minute slots from next slot to 22:00
let startHour = selectedDateTime.toDateString() === new Date().toDateString() ? future.getHours() : 6; let currentHour = defaultHour;
let startMinute = selectedDateTime.toDateString() === new Date().toDateString() ? future.getMinutes() : 0; let currentMinute = defaultMinute;
// Generate 15-minute slots from start time to 22:00 // Generate 10-minute slots from start time to 22:00
for (let hour = startHour; hour < 24; hour++) { while (currentHour < 24) {
for (let minute = (hour === startHour ? startMinute : 0); minute < 60; minute += 15) { const timeStr = `${String(currentHour).padStart(2, '0')}:${String(currentMinute).padStart(2, '0')}`;
const timeStr = `${String(hour).padStart(2, '0')}:${String(minute).padStart(2, '0')}`; const option = document.createElement('option');
const option = document.createElement('option'); option.value = timeStr;
option.value = timeStr; option.textContent = timeStr;
option.textContent = timeStr;
// Auto-select the nearest slot for today // Auto-select the next 10-minute slot
if (selectedDateTime.toDateString() === new Date().toDateString() && if (currentHour === defaultHour && currentMinute === defaultMinute) {
hour === future.getHours() && minute === future.getMinutes()) { option.selected = true;
option.selected = true; }
}
timeSelect.appendChild(option); timeSelect.appendChild(option);
// Move to next 10-minute interval
currentMinute += 10;
if (currentMinute >= 60) {
currentMinute -= 60;
currentHour += 1;
} }
} }
} }
@@ -2943,12 +2932,15 @@
// Skip the hidden id field and empty values // Skip the hidden id field and empty values
if (key === 'id') return; if (key === 'id') return;
// Handle date/time combination for ETD (departures) // Handle time-only ETD (always today)
if (key === 'etd_date' || key === 'etd_time') { if (key === 'etd_time') {
if (!flightData.etd && formData.get('etd_date') && formData.get('etd_time')) { if (value.trim()) {
const dateStr = formData.get('etd_date'); const today = new Date();
const timeStr = formData.get('etd_time'); const year = today.getFullYear();
flightData.etd = new Date(`${dateStr}T${timeStr}`).toISOString(); const month = String(today.getMonth() + 1).padStart(2, '0');
const day = String(today.getDate()).padStart(2, '0');
const dateStr = `${year}-${month}-${day}`;
flightData.etd = new Date(`${dateStr}T${value}`).toISOString();
} }
return; return;
} }