502 lines
20 KiB
HTML
502 lines
20 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta http-equiv="refresh" content="300">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>Swansea Airport - Arrivals & Departures</title>
|
|
<style>
|
|
/* Overall page styling */
|
|
body {
|
|
margin: 0;
|
|
font-family: Arial, sans-serif;
|
|
display: grid;
|
|
grid-template-rows: auto 1fr auto;
|
|
grid-template-columns: 1fr;
|
|
height: 100vh;
|
|
font-size: 30px; /* Increased font size */
|
|
}
|
|
|
|
/* Header styles */
|
|
header {
|
|
background-color: #333;
|
|
color: white;
|
|
padding: 20px;
|
|
text-align: center;
|
|
position: relative;
|
|
}
|
|
|
|
header img.left-image {
|
|
position: absolute;
|
|
top: 0;
|
|
left: 0;
|
|
height: auto;
|
|
}
|
|
|
|
header img.right-image {
|
|
position: absolute;
|
|
top: 0;
|
|
right: 0;
|
|
width: 9%;
|
|
height: auto;
|
|
}
|
|
|
|
/* Main section styles */
|
|
main {
|
|
display: grid;
|
|
grid-template-columns: 1fr 1fr; /* Two equal-width columns */
|
|
gap: 20px;
|
|
padding: 20px;
|
|
overflow-y: auto;
|
|
}
|
|
|
|
/* Table styles */
|
|
table {
|
|
width: 100%;
|
|
border-collapse: collapse;
|
|
margin: 0;
|
|
border: 1px solid #ccc;
|
|
}
|
|
|
|
th, td {
|
|
padding: 12px;
|
|
text-align: left;
|
|
border: 1px solid #ccc;
|
|
white-space: nowrap;
|
|
overflow: hidden;
|
|
text-overflow: ellipsis;
|
|
}
|
|
|
|
th {
|
|
background-color: #f4f4f4;
|
|
}
|
|
|
|
tr:nth-child(even) {
|
|
background-color: #d3d3d3;
|
|
}
|
|
|
|
/* Footer styles */
|
|
footer {
|
|
background-color: #333;
|
|
color: white;
|
|
text-align: center;
|
|
padding: 10px 0;
|
|
position: relative;
|
|
overflow: hidden;
|
|
}
|
|
|
|
/* Marquee container */
|
|
.marquee {
|
|
display: inline-block;
|
|
white-space: nowrap;
|
|
padding-right: 100%; /* This makes the text start out of view */
|
|
animation: scroll-left 20s linear infinite;
|
|
}
|
|
|
|
/* Keyframes for scrolling animation */
|
|
@keyframes scroll-left {
|
|
from {
|
|
transform: translateX(100%);
|
|
}
|
|
to {
|
|
transform: translateX(-100%);
|
|
}
|
|
}
|
|
|
|
/* Marquee text styling */
|
|
.marquee-text {
|
|
font-size: 18px;
|
|
font-weight: bold;
|
|
color: #f4f4f4;
|
|
padding-left: 50px;
|
|
text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.2);
|
|
}
|
|
|
|
/* Loading indicator */
|
|
.loading {
|
|
text-align: center;
|
|
padding: 20px;
|
|
color: #666;
|
|
}
|
|
|
|
/* Error message */
|
|
.error {
|
|
text-align: center;
|
|
padding: 20px;
|
|
color: #e74c3c;
|
|
}
|
|
|
|
/* Responsive adjustments */
|
|
@media (max-width: 768px) {
|
|
main {
|
|
grid-template-columns: 1fr; /* Stack columns on smaller screens */
|
|
}
|
|
}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<header>
|
|
<img src="assets/logo.png" alt="EGFH Logo" class="left-image">
|
|
<h1>Flight Information</h1>
|
|
<img src="assets/flightImg.png" alt="EGFH Logo" class="right-image">
|
|
</header>
|
|
|
|
<main>
|
|
<!-- Left column with arrivals table -->
|
|
<div>
|
|
<h2><center>Arrivals</center></h2>
|
|
<table>
|
|
<thead>
|
|
<tr>
|
|
<th style="width: 25%;">Aircraft</th>
|
|
<th style="width: 60%;">From</th>
|
|
<th style="width: 15%;">Due</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody id="arrivals-tbody">
|
|
<tr>
|
|
<td colspan="3" class="loading">Loading arrivals...</td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
|
|
<!-- Right column with departures table -->
|
|
<div>
|
|
<h2><center>Departures</center></h2>
|
|
<table>
|
|
<thead>
|
|
<tr>
|
|
<th style="width: 25%;">Aircraft</th>
|
|
<th style="width: 60%;">To</th>
|
|
<th style="width: 15%;">Due</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody id="departures-tbody">
|
|
<tr>
|
|
<td colspan="3" class="loading">Loading departures...</td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
</main>
|
|
|
|
<footer>
|
|
<!-- Footer content -->
|
|
<div class="iso-marquee-linkwrap">
|
|
<div class="iso-marquee--long iso-marquee">
|
|
<!-- Add marquee content here -->
|
|
</div>
|
|
</div>
|
|
</footer>
|
|
|
|
<script>
|
|
let wsConnection = null;
|
|
|
|
// ICAO code to airport name cache
|
|
const airportNameCache = {};
|
|
|
|
async function getAirportName(code) {
|
|
if (!code || code.length !== 4 || !/^[A-Z]{4}$/.test(code)) return code;
|
|
if (airportNameCache[code]) return airportNameCache[code];
|
|
try {
|
|
const resp = await fetch(`/api/v1/airport/public/lookup/${code}`);
|
|
if (resp.ok) {
|
|
const data = await resp.json();
|
|
if (data && data.length && data[0].name) {
|
|
airportNameCache[code] = data[0].name;
|
|
return data[0].name;
|
|
}
|
|
}
|
|
} catch (error) {
|
|
console.error('Error looking up airport:', error);
|
|
}
|
|
return code;
|
|
}
|
|
|
|
// WebSocket connection for real-time updates
|
|
function connectWebSocket() {
|
|
if (wsConnection && wsConnection.readyState === WebSocket.OPEN) {
|
|
return; // Already connected
|
|
}
|
|
|
|
const protocol = window.location.protocol === 'https:' ? 'wss:' : 'ws:';
|
|
const wsUrl = `${protocol}//${window.location.host}/ws/tower-updates`;
|
|
|
|
wsConnection = new WebSocket(wsUrl);
|
|
|
|
wsConnection.onopen = function(event) {
|
|
console.log('WebSocket connected for real-time updates');
|
|
};
|
|
|
|
wsConnection.onmessage = function(event) {
|
|
try {
|
|
const data = JSON.parse(event.data);
|
|
console.log('WebSocket message received:', data);
|
|
|
|
// Refresh display when any PPR-related, local flight, departure, or arrival event occurs
|
|
if (data.type && (data.type.includes('ppr_') || data.type === 'status_update' || data.type.includes('local_flight_') || data.type.includes('departure_') || data.type.includes('arrival_'))) {
|
|
console.log('Flight update detected, refreshing display...');
|
|
loadArrivals();
|
|
loadDepartures();
|
|
}
|
|
} catch (error) {
|
|
console.error('Error parsing WebSocket message:', error);
|
|
}
|
|
};
|
|
|
|
wsConnection.onclose = function(event) {
|
|
console.log('WebSocket disconnected');
|
|
// Attempt to reconnect after 5 seconds
|
|
setTimeout(() => {
|
|
console.log('Attempting to reconnect WebSocket...');
|
|
connectWebSocket();
|
|
}, 5000);
|
|
};
|
|
|
|
wsConnection.onerror = function(error) {
|
|
console.error('WebSocket error:', error);
|
|
};
|
|
}
|
|
|
|
// Convert UTC datetime to local time display
|
|
function convertToLocalTime(utcDateTimeString) {
|
|
if (!utcDateTimeString) return '';
|
|
|
|
try {
|
|
// Parse the ISO datetime string
|
|
const date = new Date(utcDateTimeString);
|
|
|
|
// Check if valid date
|
|
if (isNaN(date.getTime())) {
|
|
console.error('Invalid date:', utcDateTimeString);
|
|
return utcDateTimeString;
|
|
}
|
|
|
|
// Format as HH:MM in local time
|
|
const localHours = date.getHours().toString().padStart(2, '0');
|
|
const localMinutes = date.getMinutes().toString().padStart(2, '0');
|
|
|
|
return `${localHours}:${localMinutes}`;
|
|
} catch (error) {
|
|
console.error('Error converting time:', error, utcDateTimeString);
|
|
return utcDateTimeString;
|
|
}
|
|
}
|
|
|
|
// Fetch and display arrivals
|
|
async function loadArrivals() {
|
|
const tbody = document.getElementById('arrivals-tbody');
|
|
|
|
try {
|
|
const response = await fetch('/api/v1/public/arrivals');
|
|
|
|
if (!response.ok) {
|
|
throw new Error('Failed to fetch arrivals');
|
|
}
|
|
|
|
const arrivals = await response.json();
|
|
|
|
if (arrivals.length === 0) {
|
|
tbody.innerHTML = '<tr><td colspan="3">No arrivals found.</td></tr>';
|
|
return;
|
|
}
|
|
|
|
// Build rows asynchronously to lookup airport names
|
|
const rows = await Promise.all(arrivals.map(async (arrival) => {
|
|
const isLocal = arrival.isLocalFlight;
|
|
const isBookedIn = arrival.isBookedIn;
|
|
|
|
if (isLocal) {
|
|
// Local flight
|
|
const aircraftId = arrival.ac_call || arrival.ac_reg || '';
|
|
const aircraftDisplay = `${escapeHtml(aircraftId)} <span style="font-size: 0.8em; color: #666;">(${escapeHtml(arrival.ac_type || '')})</span>`;
|
|
const fromDisplay = `<i>${getFlightTypeDisplay(arrival.flight_type)}</i>`;
|
|
const time = convertToLocalTime(arrival.eta);
|
|
const timeDisplay = `<div style="display: flex; align-items: center; gap: 8px;"><span style="color: #27ae60; font-weight: bold;">${time}</span><span style="font-size: 0.7em; background: #27ae60; color: white; padding: 2px 4px; border-radius: 3px; white-space: nowrap;">IN AIR</span></div>`;
|
|
|
|
return `
|
|
<tr>
|
|
<td>${aircraftDisplay}</td>
|
|
<td>${fromDisplay}</td>
|
|
<td>${timeDisplay}</td>
|
|
</tr>
|
|
`;
|
|
} else if (isBookedIn) {
|
|
// Booked-in arrival
|
|
const aircraftId = arrival.callsign || arrival.registration || '';
|
|
const aircraftDisplay = `${escapeHtml(aircraftId)} <span style="font-size: 0.8em; color: #666;">(${escapeHtml(arrival.type || '')})</span>`;
|
|
const fromDisplay = await getAirportName(arrival.in_from || '');
|
|
|
|
let timeDisplay;
|
|
if (arrival.status === 'LANDED' && arrival.landed_dt) {
|
|
// Show landed time if LANDED
|
|
const time = convertToLocalTime(arrival.landed_dt);
|
|
timeDisplay = `<div style="display: flex; align-items: center; gap: 8px;"><span style="color: #27ae60; font-weight: bold;">${time}</span><span style="font-size: 0.7em; background: #27ae60; color: white; padding: 2px 4px; border-radius: 3px; white-space: nowrap;">LANDED</span></div>`;
|
|
} else {
|
|
// Show ETA if BOOKED_IN
|
|
const time = convertToLocalTime(arrival.eta);
|
|
timeDisplay = `<div style="display: flex; align-items: center; gap: 8px;"><span style="color: #3498db; font-weight: bold;">${time}</span><span style="font-size: 0.7em; background: #3498db; color: white; padding: 2px 4px; border-radius: 3px; white-space: nowrap;">IN AIR</span></div>`;
|
|
}
|
|
|
|
return `
|
|
<tr>
|
|
<td>${aircraftDisplay}</td>
|
|
<td>${escapeHtml(fromDisplay)}</td>
|
|
<td>${timeDisplay}</td>
|
|
</tr>
|
|
`;
|
|
} else {
|
|
// PPR
|
|
const aircraftId = arrival.ac_call || arrival.ac_reg || '';
|
|
const aircraftDisplay = `${escapeHtml(aircraftId)} <span style="font-size: 0.8em; color: #666;">(${escapeHtml(arrival.ac_type || '')})</span>`;
|
|
const fromDisplay = await getAirportName(arrival.in_from || '');
|
|
|
|
// Show landed time if available, otherwise ETA
|
|
let timeDisplay;
|
|
if ((arrival.status === 'LANDED' || arrival.status === 'DEPARTED') && arrival.landed_dt) {
|
|
const time = convertToLocalTime(arrival.landed_dt);
|
|
timeDisplay = `<div style="display: flex; align-items: center; gap: 8px;"><span style="color: #27ae60; font-weight: bold;">${time}</span><span style="font-size: 0.7em; background: #27ae60; color: white; padding: 2px 4px; border-radius: 3px; white-space: nowrap;">LANDED</span></div>`;
|
|
} else {
|
|
timeDisplay = convertToLocalTime(arrival.eta);
|
|
}
|
|
|
|
return `
|
|
<tr>
|
|
<td>${aircraftDisplay}</td>
|
|
<td>${escapeHtml(fromDisplay)}</td>
|
|
<td>${timeDisplay}</td>
|
|
</tr>
|
|
`;
|
|
}
|
|
}));
|
|
|
|
tbody.innerHTML = rows.join('');
|
|
|
|
} catch (error) {
|
|
console.error('Error loading arrivals:', error);
|
|
tbody.innerHTML = '<tr><td colspan="3" class="error">Error loading arrivals</td></tr>';
|
|
}
|
|
}
|
|
|
|
// Fetch and display departures
|
|
async function loadDepartures() {
|
|
const tbody = document.getElementById('departures-tbody');
|
|
|
|
try {
|
|
const response = await fetch('/api/v1/public/departures');
|
|
|
|
if (!response.ok) {
|
|
throw new Error('Failed to fetch departures');
|
|
}
|
|
|
|
const departures = await response.json();
|
|
|
|
if (departures.length === 0) {
|
|
tbody.innerHTML = '<tr><td colspan="3">No departures found.</td></tr>';
|
|
return;
|
|
}
|
|
|
|
// Build rows asynchronously to lookup airport names
|
|
const rows = await Promise.all(departures.map(async (departure) => {
|
|
const isLocal = departure.isLocalFlight;
|
|
const isDeparture = departure.isDeparture;
|
|
|
|
if (isLocal) {
|
|
// Local flight
|
|
const aircraftId = departure.ac_call || departure.ac_reg || '';
|
|
const aircraftDisplay = `${escapeHtml(aircraftId)} <span style="font-size: 0.8em; color: #666;">(${escapeHtml(departure.ac_type || '')})</span>`;
|
|
const toDisplay = `<i>${getFlightTypeDisplay(departure.flight_type)}</i>`;
|
|
const time = convertToLocalTime(departure.etd);
|
|
const timeDisplay = `<div>${escapeHtml(time)}</div>`;
|
|
|
|
return `
|
|
<tr>
|
|
<td>${aircraftDisplay}</td>
|
|
<td>${toDisplay}</td>
|
|
<td>${timeDisplay}</td>
|
|
</tr>
|
|
`;
|
|
} else if (isDeparture) {
|
|
// Departure to other airport
|
|
const aircraftId = departure.ac_call || departure.ac_reg || '';
|
|
const aircraftDisplay = `${escapeHtml(aircraftId)} <span style="font-size: 0.8em; color: #666;">(${escapeHtml(departure.ac_type || '')})</span>`;
|
|
const toDisplay = await getAirportName(departure.out_to || '');
|
|
const time = convertToLocalTime(departure.etd);
|
|
const timeDisplay = `<div>${escapeHtml(time)}</div>`;
|
|
|
|
return `
|
|
<tr>
|
|
<td>${aircraftDisplay}</td>
|
|
<td>${toDisplay}</td>
|
|
<td>${timeDisplay}</td>
|
|
</tr>
|
|
`;
|
|
} else {
|
|
// PPR
|
|
const aircraftId = departure.ac_call || departure.ac_reg || '';
|
|
const aircraftDisplay = `${escapeHtml(aircraftId)} <span style="font-size: 0.8em; color: #666;">(${escapeHtml(departure.ac_type || '')})</span>`;
|
|
const toDisplay = await getAirportName(departure.out_to || '');
|
|
|
|
// Show departed time if available, otherwise ETD
|
|
let timeDisplay;
|
|
if (departure.status === 'DEPARTED' && departure.departed_dt) {
|
|
const time = convertToLocalTime(departure.departed_dt);
|
|
timeDisplay = `<div style="display: flex; align-items: center; gap: 8px;"><span style="color: #3498db; font-weight: bold;">${time}</span><span style="font-size: 0.7em; background: #3498db; color: white; padding: 2px 4px; border-radius: 3px; white-space: nowrap;">DEPARTED</span></div>`;
|
|
} else {
|
|
timeDisplay = convertToLocalTime(departure.etd);
|
|
}
|
|
|
|
return `
|
|
<tr>
|
|
<td>${aircraftDisplay}</td>
|
|
<td>${escapeHtml(toDisplay)}</td>
|
|
<td>${timeDisplay}</td>
|
|
</tr>
|
|
`;
|
|
}
|
|
}));
|
|
|
|
tbody.innerHTML = rows.join('');
|
|
|
|
} catch (error) {
|
|
console.error('Error loading departures:', error);
|
|
tbody.innerHTML = '<tr><td colspan="3" class="error">Error loading departures</td></tr>';
|
|
}
|
|
}
|
|
|
|
// Escape HTML to prevent XSS
|
|
function escapeHtml(text) {
|
|
const div = document.createElement('div');
|
|
div.textContent = text;
|
|
return div.innerHTML;
|
|
}
|
|
|
|
// Map flight type enum to friendly name
|
|
function getFlightTypeDisplay(flightType) {
|
|
const typeMap = {
|
|
'CIRCUITS': 'Circuit Traffic',
|
|
'LOCAL': 'Local Area',
|
|
'DEPARTURE': 'Departure'
|
|
};
|
|
return typeMap[flightType] || flightType;
|
|
}
|
|
|
|
// Load data on page load
|
|
window.addEventListener('load', function() {
|
|
loadArrivals();
|
|
loadDepartures();
|
|
|
|
// Connect to WebSocket for real-time updates
|
|
connectWebSocket();
|
|
|
|
// Refresh data every 60 seconds as fallback
|
|
setInterval(() => {
|
|
loadArrivals();
|
|
loadDepartures();
|
|
}, 60000);
|
|
});
|
|
</script>
|
|
</body>
|
|
</html>
|