Files
ppr-ng/web/bulk-log.html
T
2026-06-15 15:45:58 -04:00

858 lines
34 KiB
HTML

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Bulk Flight Log - PPR System</title>
<link rel="stylesheet" href="admin.css">
<style>
.bulk-toolbar {
display: flex;
align-items: flex-end;
gap: 1rem;
flex-wrap: wrap;
background: white;
border-radius: 8px;
box-shadow: 0 2px 10px rgba(0,0,0,0.1);
padding: 1rem;
margin-bottom: 1rem;
}
.bulk-field {
display: flex;
flex-direction: column;
gap: 0.3rem;
}
.bulk-field label {
font-weight: 600;
color: #495057;
font-size: 0.85rem;
}
.bulk-field input,
.bulk-field select,
.bulk-field textarea {
border: 1px solid #d7dde3;
border-radius: 5px;
font-size: 0.95rem;
padding: 0.55rem 0.65rem;
min-width: 110px;
}
.bulk-entry {
background: white;
border-radius: 8px;
box-shadow: 0 2px 10px rgba(0,0,0,0.1);
padding: 1rem;
margin-bottom: 1rem;
overflow-x: auto;
}
.strip-type-picker {
display: grid;
grid-template-columns: repeat(4, minmax(120px, 1fr));
gap: 0.5rem;
margin-bottom: 0.75rem;
}
.strip-type-button {
border: 2px solid transparent;
border-radius: 6px;
cursor: pointer;
font-weight: 700;
padding: 0.65rem;
text-align: left;
}
.strip-type-button.active {
border-color: #222;
box-shadow: inset 0 0 0 1px rgba(255,255,255,0.55);
}
.strip-yellow { background: #ffe98a; color: #403400; }
.strip-blue { background: #9bd0ff; color: #0f3454; }
.strip-pink { background: #ffb3d1; color: #552039; }
.strip-green { background: #a7e7ac; color: #1d4923; }
.virtual-strip {
border-radius: 6px;
border: 1px solid rgba(0,0,0,0.18);
padding: 1rem;
box-shadow: inset 0 -3px 0 rgba(0,0,0,0.08);
}
.bulk-grid {
display: grid;
grid-template-columns: 140px 120px 120px 120px 120px 120px 120px 120px 1fr;
gap: 0.75rem;
align-items: end;
}
.bulk-grid .notes-field {
grid-column: span 2;
}
.strip-kind-local {
display: inline-block;
padding: 0;
overflow: hidden;
width: auto;
}
.strip-kind-local .bulk-grid {
grid-template-columns: 180px 110px 130px 72px 90px 240px;
grid-template-rows: 60px 60px;
gap: 0;
align-items: stretch;
}
.strip-kind-local .bulk-field {
border-right: 1px solid rgba(0,0,0,0.82);
border-bottom: 1px solid rgba(0,0,0,0.82);
gap: 0.15rem;
justify-content: center;
padding: 0.45rem;
position: relative;
}
.strip-kind-local .bulk-field label {
color: #8f98a3;
font-size: 0.95rem;
font-weight: 500;
letter-spacing: 0;
text-transform: uppercase;
}
.strip-kind-local .bulk-field input,
.strip-kind-local .bulk-field select,
.strip-kind-local .bulk-field textarea {
background: rgba(255,255,255,0.28);
border: 0;
border-radius: 0;
color: #222;
font-size: 1rem;
font-weight: 650;
min-width: 0;
padding: 0.2rem;
text-transform: uppercase;
width: 100%;
}
.strip-kind-local .local-slash-cell {
grid-column: 1;
grid-row: 1 / span 2;
}
.strip-kind-local .local-slash-cell::after {
content: "";
position: absolute;
width: 78px;
height: 2px;
background: #9aa1a9;
right: 12px;
bottom: 32px;
transform: rotate(-36deg);
transform-origin: right center;
}
.strip-kind-local .local-nature-cell {
grid-column: 2;
grid-row: 1;
border-right: 0;
}
.strip-kind-local .type-cell {
grid-column: 3;
grid-row: 1;
}
.strip-kind-local .strip-registration {
grid-column: 2 / span 2;
grid-row: 2;
align-items: center;
justify-content: flex-start;
}
.strip-kind-local .strip-registration label {
align-self: center;
font-size: 1.25rem;
}
.strip-kind-local .strip-registration input {
background: rgba(255,255,255,0.55);
outline: 2px solid rgba(0,0,0,0.2);
}
.strip-kind-local .callsign-cell {
display: none !important;
}
.strip-kind-local .local-to-cell {
grid-column: 4;
grid-row: 1;
}
.strip-kind-local .local-ldg-cell {
grid-column: 4;
grid-row: 2;
}
.strip-kind-local .local-circuit-cell {
grid-column: 5;
grid-row: 1;
display: flex;
padding: 0.45rem;
}
.strip-kind-local .local-circuit-cell label {
padding: 0;
}
.strip-kind-local .local-circuit-cell input {
align-self: center;
text-align: center;
}
.strip-kind-local .pob-cell {
grid-column: 5;
grid-row: 2;
align-items: flex-end;
justify-content: flex-end;
}
.strip-kind-local .notes-field {
grid-column: 6;
grid-row: 1 / span 2;
align-items: stretch;
justify-content: flex-start;
}
.strip-kind-local .notes-field textarea {
flex: 1;
min-height: 0;
resize: none;
}
.strip-actions {
display: flex;
gap: 0.6rem;
justify-content: flex-start;
margin-top: 0.75rem;
}
.context-panel {
margin-top: 1rem;
border-left: 4px solid #3498db;
background: #eef7ff;
padding: 0.8rem 1rem;
color: #244763;
font-size: 0.95rem;
display: none;
}
.context-panel.warning {
border-left-color: #f39c12;
background: #fff5dc;
color: #6b4b09;
}
.match-pill {
display: inline-block;
padding: 0.25rem 0.45rem;
border-radius: 4px;
background: rgba(52, 73, 94, 0.12);
margin: 0.15rem 0.2rem 0 0;
font-size: 0.85rem;
}
.movement-table table {
min-width: 1050px;
}
@media (max-width: 1200px) {
.bulk-grid {
grid-template-columns: repeat(4, minmax(120px, 1fr));
}
.bulk-grid .notes-field {
grid-column: span 4;
}
}
@media (max-width: 700px) {
.strip-type-picker {
grid-template-columns: 1fr 1fr;
}
.bulk-grid {
grid-template-columns: 1fr;
}
.bulk-grid .notes-field {
grid-column: span 1;
}
}
</style>
</head>
<body>
<div class="top-bar">
<div class="menu-buttons">
<button class="btn btn-secondary" onclick="window.location.href='admin'">Back to Admin</button>
<button class="btn btn-secondary" onclick="window.location.href='movements'">Movements</button>
</div>
<div class="title">
<h1 id="tower-title">Bulk Flight Log</h1>
</div>
<div class="user-info">
Logged in as: <span id="current-user">Loading...</span> |
<a href="#" onclick="logout()" style="color: white;">Logout</a>
</div>
</div>
<div class="container">
<div class="bulk-toolbar">
<div class="bulk-field">
<label for="log-date">Log date</label>
<input type="date" id="log-date">
</div>
<button class="btn btn-primary" onclick="loadDayMovements()">Load Day</button>
<button class="btn btn-secondary" onclick="resetEntryForm()">Clear Entry</button>
</div>
<div class="bulk-entry">
<div class="strip-type-picker">
<button type="button" class="strip-type-button strip-yellow active" data-kind="ARRIVAL" onclick="setStripKind('ARRIVAL')">ARRIVAL<br><span>Yellow</span></button>
<button type="button" class="strip-type-button strip-blue" data-kind="DEPARTURE" onclick="setStripKind('DEPARTURE')">DEPARTURE<br><span>Blue</span></button>
<button type="button" class="strip-type-button strip-pink" data-kind="LOCAL" onclick="setStripKind('LOCAL')">LOCAL<br><span>Pink</span></button>
<button type="button" class="strip-type-button strip-green" data-kind="OVERFLIGHT" onclick="setStripKind('OVERFLIGHT')">OVERFLIGHT<br><span>Green</span></button>
</div>
<form id="bulk-log-form">
<div id="virtual-strip" class="virtual-strip strip-yellow">
<input type="hidden" id="flight-kind" value="ARRIVAL">
<div class="bulk-grid">
<div class="bulk-field strip-registration">
<label for="aircraft-registration">Registration</label>
<input type="text" id="aircraft-registration" autocomplete="off" required>
<div id="bulk-aircraft-lookup-results"></div>
</div>
<div class="bulk-field strip-field" data-show="ARRIVAL">
<label for="landing-time">LDG</label>
<input type="text" id="landing-time" inputmode="numeric" maxlength="4" placeholder="HHMM">
</div>
<div class="bulk-field strip-field" data-show="DEPARTURE">
<label for="takeoff-time">T/O</label>
<input type="text" id="takeoff-time" inputmode="numeric" maxlength="4" placeholder="HHMM">
</div>
<div class="bulk-field strip-field local-to-cell" data-show="LOCAL">
<label for="local-takeoff-time">T/O</label>
<input type="text" id="local-takeoff-time" inputmode="numeric" maxlength="4" placeholder="HHMM">
</div>
<div class="bulk-field strip-field local-ldg-cell" data-show="LOCAL">
<label for="local-landing-time">LDG</label>
<input type="text" id="local-landing-time" inputmode="numeric" maxlength="4" placeholder="HHMM">
</div>
<div class="bulk-field strip-field" data-show="OVERFLIGHT">
<label for="contact-time">Contact time</label>
<input type="text" id="contact-time" inputmode="numeric" maxlength="4" placeholder="HHMM">
</div>
<div class="bulk-field strip-field" data-show="OVERFLIGHT">
<label for="qsy-time">QSY time</label>
<input type="text" id="qsy-time" inputmode="numeric" maxlength="4" placeholder="HHMM">
</div>
<div class="bulk-field strip-field local-slash-cell" data-show="LOCAL"></div>
<div class="bulk-field type-cell">
<label for="aircraft-type">Type</label>
<input type="text" id="aircraft-type">
</div>
<div class="bulk-field callsign-cell">
<label for="callsign">C/SIGN</label>
<input type="text" id="callsign">
</div>
<div class="bulk-field strip-field" id="from-field" data-show="ARRIVAL OVERFLIGHT">
<label for="from-location">From</label>
<input type="text" id="from-location">
</div>
<div class="bulk-field strip-field" id="to-field" data-show="DEPARTURE OVERFLIGHT">
<label for="to-location">To</label>
<input type="text" id="to-location">
</div>
<div class="bulk-field pob-cell">
<label for="pob">POB</label>
<input type="number" id="pob" min="1">
</div>
<div class="bulk-field strip-field local-nature-cell" data-show="LOCAL">
<label for="local-nature">LOC / CCTS</label>
<select id="local-nature">
<option value="LOCAL">Local</option>
<option value="CIRCUITS">Circuits</option>
</select>
</div>
<div class="bulk-field strip-field local-circuit-cell" data-show="LOCAL">
<label for="circuits">CCTS</label>
<input type="number" id="circuits" min="0">
</div>
<div class="bulk-field strip-field runway-cell" data-show="ARRIVAL DEPARTURE">
<label for="runway">Runway</label>
<input type="text" id="runway">
</div>
<div class="bulk-field strip-field" data-show="ARRIVAL DEPARTURE OVERFLIGHT">
<label for="wind">Wind</label>
<input type="text" id="wind">
</div>
<div class="bulk-field strip-field" data-show="ARRIVAL DEPARTURE OVERFLIGHT">
<label for="pressure-setting">Pressure</label>
<input type="text" id="pressure-setting">
</div>
<div class="bulk-field notes-field">
<label for="notes">Notes</label>
<textarea id="notes" rows="2"></textarea>
</div>
</div>
</div>
<div class="strip-actions">
<button class="btn btn-success" type="submit">Save Movement</button>
</div>
<input type="hidden" id="matched-ppr-id">
<input type="hidden" id="matched-movement-id">
</form>
<div id="context-panel" class="context-panel"></div>
</div>
<div class="ppr-table movement-table">
<div class="table-header">
<span>Logged Movements - <span id="movement-count">0</span></span>
</div>
<div id="movements-loading" class="loading" style="display: none;">
<div class="spinner"></div>
Loading movements...
</div>
<div id="movements-content" style="display: none; overflow-x: auto;">
<table>
<thead>
<tr>
<th>Time</th>
<th>Movement</th>
<th>Registration</th>
<th>Type</th>
<th>Callsign</th>
<th>From</th>
<th>To</th>
<th>Runway</th>
<th>Wind</th>
<th>Pressure</th>
<th>Linked</th>
</tr>
</thead>
<tbody id="movements-table-body"></tbody>
</table>
</div>
<div id="movements-no-data" class="no-data" style="display: none;">
<h3>No movements logged for this day</h3>
</div>
</div>
</div>
<script src="lookups.js"></script>
<script>
const API_BASE = '/api/v1';
let accessToken = null;
let lookupTimer = null;
document.addEventListener('DOMContentLoaded', () => {
accessToken = localStorage.getItem('ppr_access_token');
const username = localStorage.getItem('ppr_username');
if (!accessToken) {
window.location.href = 'admin';
return;
}
document.getElementById('current-user').textContent = username || 'Operator';
document.getElementById('log-date').value = new Date().toISOString().split('T')[0];
updateKindFields();
loadDayMovements();
document.getElementById('log-date').addEventListener('change', () => {
lookupContext();
loadDayMovements();
});
document.getElementById('aircraft-registration').addEventListener('input', () => {
handleBulkAircraftLookupForPage(document.getElementById('aircraft-registration').value);
clearTimeout(lookupTimer);
lookupTimer = setTimeout(lookupContext, 250);
});
document.getElementById('aircraft-registration').addEventListener('blur', formatBulkAircraftRegistration);
document.getElementById('bulk-log-form').addEventListener('submit', saveMovement);
});
async function authFetch(url, options = {}) {
const response = await fetch(url, {
...options,
headers: {
...(options.headers || {}),
'Authorization': `Bearer ${accessToken}`
}
});
if (response.status === 401) logout();
return response;
}
async function authenticatedFetch(url, options = {}) {
return authFetch(url, options);
}
function handleBulkAircraftLookupForPage(value) {
if (typeof handleBulkAircraftLookup === 'function') {
handleBulkAircraftLookup(value);
return;
}
const lookup = window.lookupManager && window.lookupManager.lookups
? window.lookupManager.lookups['bulk-aircraft']
: null;
if (lookup) lookup.handle(value);
else fallbackAircraftTypeLookup(value);
}
async function fallbackAircraftTypeLookup(value) {
const cleaned = (value || '').replace(/[^a-zA-Z0-9]/g, '').toUpperCase();
if (cleaned.length < 4) return;
try {
const response = await authFetch(`${API_BASE}/aircraft/lookup/${cleaned}`);
if (!response.ok) return;
const results = await response.json();
if (results.length === 1) {
document.getElementById('aircraft-type').value = results[0].type_code || '';
}
} catch (error) {
console.error('Bulk aircraft lookup failed:', error);
}
}
function formatBulkAircraftRegistration() {
const field = document.getElementById('aircraft-registration');
if (!field || !field.value.trim()) return;
if (typeof formatAircraftRegistration === 'function') {
field.value = formatAircraftRegistration(field.value);
} else {
field.value = field.value.trim().toUpperCase();
}
}
function logout() {
localStorage.removeItem('ppr_access_token');
localStorage.removeItem('ppr_username');
localStorage.removeItem('ppr_token_expiry');
window.location.href = 'admin';
}
function setStripKind(kind) {
document.getElementById('flight-kind').value = kind;
document.querySelectorAll('.strip-type-button').forEach(button => {
button.classList.toggle('active', button.dataset.kind === kind);
});
updateKindFields();
lookupContext();
if (kind === 'LOCAL') {
document.getElementById('aircraft-registration').focus();
}
}
function updateKindFields() {
const kind = document.getElementById('flight-kind').value;
const strip = document.getElementById('virtual-strip');
strip.className = `virtual-strip ${stripClassForKind(kind)} strip-kind-${kind.toLowerCase()}`;
document.querySelector('label[for="aircraft-registration"]').textContent = kind === 'LOCAL' ? 'C/SIGN' : 'Registration';
updateTabOrder(kind);
document.querySelectorAll('.strip-field').forEach(field => {
const visible = field.dataset.show.split(' ').includes(kind);
field.style.display = visible ? 'flex' : 'none';
field.querySelectorAll('input, select, textarea').forEach(input => {
input.required = visible && ['landing-time', 'takeoff-time', 'local-takeoff-time', 'local-landing-time', 'contact-time'].includes(input.id);
});
});
}
function updateTabOrder(kind) {
['aircraft-registration', 'local-takeoff-time', 'local-landing-time', 'circuits', 'pob'].forEach(id => {
const field = document.getElementById(id);
if (field) field.removeAttribute('tabindex');
});
if (kind !== 'LOCAL') return;
[
['aircraft-registration', 1],
['local-takeoff-time', 2],
['local-landing-time', 3],
['circuits', 4],
['pob', 5]
].forEach(([id, index]) => {
const field = document.getElementById(id);
if (field) field.tabIndex = index;
});
}
function stripClassForKind(kind) {
return {
ARRIVAL: 'strip-yellow',
DEPARTURE: 'strip-blue',
LOCAL: 'strip-pink',
OVERFLIGHT: 'strip-green'
}[kind] || 'strip-yellow';
}
function resetEntryForm() {
const kind = document.getElementById('flight-kind').value;
document.getElementById('bulk-log-form').reset();
document.getElementById('flight-kind').value = kind;
document.getElementById('matched-ppr-id').value = '';
document.getElementById('matched-movement-id').value = '';
hideContext();
updateKindFields();
document.getElementById('aircraft-registration').focus();
}
async function lookupContext() {
const reg = document.getElementById('aircraft-registration').value.trim().toUpperCase();
const targetDate = document.getElementById('log-date').value;
const kind = document.getElementById('flight-kind').value;
document.getElementById('matched-ppr-id').value = '';
document.getElementById('matched-movement-id').value = '';
if (reg.length < 2 || !targetDate) {
hideContext();
return;
}
const response = await authFetch(`${API_BASE}/movements/bulk-context?target_date=${targetDate}&aircraft_registration=${encodeURIComponent(reg)}&flight_kind=${kind}`);
if (!response.ok) return;
const context = await response.json();
applySuggestion(context.suggested || {});
renderContext(context);
}
function applySuggestion(suggestion) {
if (!suggestion.source) return;
if (suggestion.movement_id) document.getElementById('matched-movement-id').value = suggestion.movement_id;
if (suggestion.ppr_id) document.getElementById('matched-ppr-id').value = suggestion.ppr_id;
fillSuggestedTime(suggestion.movement_time);
fillIfEmpty('aircraft-type', suggestion.aircraft_type);
fillIfEmpty('callsign', suggestion.callsign);
fillIfEmpty('from-location', suggestion.from_location);
fillIfEmpty('to-location', suggestion.to_location);
fillIfEmpty('pob', suggestion.pob);
fillIfEmpty('runway', suggestion.runway);
fillIfEmpty('wind', suggestion.wind);
fillIfEmpty('pressure-setting', suggestion.pressure_setting);
fillIfEmpty('notes', suggestion.notes);
}
function fillIfEmpty(id, value) {
if (value === null || value === undefined || value === '') return;
const field = document.getElementById(id);
if (!field.value) field.value = value;
}
function fillSuggestedTime(value) {
if (!value) return;
const kind = document.getElementById('flight-kind').value;
const target = {
ARRIVAL: 'landing-time',
DEPARTURE: 'takeoff-time',
LOCAL: 'local-takeoff-time',
OVERFLIGHT: 'contact-time'
}[kind];
fillIfEmpty(target, compactTime(value));
}
function renderContext(context) {
const panel = document.getElementById('context-panel');
const pprs = context.pprs || [];
const movements = context.movements || [];
if (!pprs.length && !movements.length) {
hideContext();
return;
}
panel.className = `context-panel ${movements.length ? 'warning' : ''}`;
const parts = [];
if (movements.length) {
parts.push(`<strong>Existing movement found.</strong> Saving will update it instead of adding another.`);
parts.push(movements.map(m => `<span class="match-pill">${formatTime(m.timestamp)} ${m.movement_type} #${m.id}</span>`).join(''));
}
if (pprs.length) {
parts.push(`<strong>Matching PPR${pprs.length > 1 ? 's' : ''}:</strong>`);
parts.push(pprs.map(p => {
const encoded = encodeURIComponent(JSON.stringify(p));
return `<button type="button" class="match-pill" onclick='selectPPR("${encoded}")'>#${p.id} ${p.aircraft_registration} ${p.from_location || ''}${p.to_location ? ' to ' + p.to_location : ''}</button>`;
}).join(''));
}
panel.innerHTML = parts.join('<br>');
panel.style.display = 'block';
}
function hideContext() {
const panel = document.getElementById('context-panel');
panel.style.display = 'none';
panel.innerHTML = '';
}
function selectPPR(encoded) {
const ppr = JSON.parse(decodeURIComponent(encoded));
document.getElementById('matched-ppr-id').value = ppr.id;
document.getElementById('aircraft-registration').value = ppr.aircraft_registration || '';
document.getElementById('aircraft-type').value = ppr.aircraft_type || '';
document.getElementById('callsign').value = ppr.callsign || '';
document.getElementById('from-location').value = ppr.from_location || '';
document.getElementById('to-location').value = ppr.to_location || '';
const kind = document.getElementById('flight-kind').value;
document.getElementById('pob').value = kind === 'ARRIVAL' ? (ppr.pob_in || '') : (ppr.pob_out || ppr.pob_in || '');
if (kind === 'ARRIVAL' && ppr.eta) document.getElementById('landing-time').value = compactTime(ppr.eta.slice(11, 16));
if (kind === 'DEPARTURE' && ppr.etd) document.getElementById('takeoff-time').value = compactTime(ppr.etd.slice(11, 16));
document.getElementById('notes').value = ppr.notes || '';
}
async function saveMovement(event) {
event.preventDefault();
formatBulkAircraftRegistration();
const kind = document.getElementById('flight-kind').value;
const payload = {
flight_kind: kind,
movement_date: document.getElementById('log-date').value,
movement_time: primaryTimeForKind(kind),
takeoff_time: kind === 'DEPARTURE' ? normalizedTime('takeoff-time') : (kind === 'LOCAL' ? normalizedTime('local-takeoff-time') : null),
landing_time: kind === 'ARRIVAL' ? normalizedTime('landing-time') : (kind === 'LOCAL' ? normalizedTime('local-landing-time') : null),
contact_time: kind === 'OVERFLIGHT' ? normalizedTime('contact-time') : null,
qsy_time: kind === 'OVERFLIGHT' ? normalizedTime('qsy-time') : null,
aircraft_registration: document.getElementById('aircraft-registration').value.trim().toUpperCase(),
aircraft_type: nullableValue('aircraft-type'),
callsign: nullableValue('callsign'),
from_location: ['ARRIVAL', 'OVERFLIGHT'].includes(kind) ? nullableValue('from-location') : null,
to_location: ['DEPARTURE', 'OVERFLIGHT'].includes(kind) ? nullableValue('to-location') : null,
pob: nullableNumber('pob'),
local_nature: kind === 'LOCAL' ? nullableValue('local-nature') : null,
circuits: kind === 'LOCAL' ? nullableNumber('circuits') : null,
runway: nullableValue('runway'),
wind: nullableValue('wind'),
pressure_setting: nullableValue('pressure-setting'),
notes: nullableValue('notes'),
ppr_id: nullableNumber('matched-ppr-id'),
movement_id: nullableNumber('matched-movement-id')
};
const response = await authFetch(`${API_BASE}/movements/bulk-log`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(payload)
});
const result = await response.json().catch(() => ({}));
if (!response.ok) {
alert(result.detail || 'Unable to save movement');
return;
}
resetEntryForm();
await loadDayMovements();
}
function primaryTimeForKind(kind) {
return {
ARRIVAL: normalizedTime('landing-time'),
DEPARTURE: normalizedTime('takeoff-time'),
LOCAL: normalizedTime('local-takeoff-time'),
OVERFLIGHT: normalizedTime('contact-time')
}[kind];
}
function compactTime(value) {
return (value || '').replace(':', '').slice(0, 4);
}
function normalizedTime(id) {
const raw = nullableValue(id);
if (!raw) return null;
const digits = raw.replace(/\D/g, '');
if (digits.length === 3) return `0${digits[0]}:${digits.slice(1)}`;
if (digits.length === 4) return `${digits.slice(0, 2)}:${digits.slice(2)}`;
return raw;
}
function nullableValue(id) {
const value = document.getElementById(id).value.trim();
return value || null;
}
function nullableNumber(id) {
const value = document.getElementById(id).value;
return value ? Number(value) : null;
}
async function loadDayMovements() {
const targetDate = document.getElementById('log-date').value;
if (!targetDate) return;
document.getElementById('movements-loading').style.display = 'block';
document.getElementById('movements-content').style.display = 'none';
document.getElementById('movements-no-data').style.display = 'none';
const response = await authFetch(`${API_BASE}/movements/?date_from=${targetDate}&date_to=${targetDate}&limit=1000`);
document.getElementById('movements-loading').style.display = 'none';
if (!response.ok) {
alert('Unable to load movements');
return;
}
const movements = await response.json();
document.getElementById('movement-count').textContent = movements.length;
renderMovements(movements);
}
function renderMovements(movements) {
const tbody = document.getElementById('movements-table-body');
tbody.innerHTML = '';
if (!movements.length) {
document.getElementById('movements-no-data').style.display = 'block';
return;
}
movements
.sort((a, b) => new Date(a.timestamp) - new Date(b.timestamp))
.forEach(movement => {
const row = document.createElement('tr');
row.innerHTML = `
<td>${formatTime(movement.timestamp)}</td>
<td>${movement.movement_type || '-'}</td>
<td><strong>${movement.aircraft_registration || '-'}</strong></td>
<td>${movement.aircraft_type || '-'}</td>
<td>${movement.callsign || '-'}</td>
<td>${movement.from_location || '-'}</td>
<td>${movement.to_location || '-'}</td>
<td>${movement.runway || '-'}</td>
<td>${movement.wind || '-'}</td>
<td>${movement.pressure_setting || '-'}</td>
<td>${movement.entity_type || '-'} #${movement.entity_id || '-'}</td>
`;
tbody.appendChild(row);
});
document.getElementById('movements-content').style.display = 'block';
}
function formatTime(value) {
if (!value) return '-';
return new Date(value.endsWith('Z') ? value : value + 'Z').toISOString().slice(11, 16);
}
</script>
</body>
</html>