Clarify missing Eurostar price states
This commit is contained in:
parent
ed8a5626a4
commit
2b475aa726
4 changed files with 122 additions and 6 deletions
|
|
@ -148,6 +148,7 @@
|
|||
let ADVANCE_STREAM_URLS = {};
|
||||
let TIMETABLE_REFRESH_URL = null;
|
||||
let HAS_PROVISIONAL_TIMETABLE = false;
|
||||
let eurostarRefreshPending = false;
|
||||
let cachedAdvanceFares = null;
|
||||
let currentNrClasses = {{ nr_classes_json | safe }};
|
||||
let currentEsClasses = {{ es_classes_json | safe }};
|
||||
|
|
@ -260,11 +261,34 @@
|
|||
var row = TRIP_FARES[rowKey];
|
||||
if (rowKey !== key && row.eurostar_key !== key) continue;
|
||||
if (prices[key].es_standard) row.es_standard = prices[key].es_standard;
|
||||
if (prices[key].es_standard_status !== undefined) row.es_standard_status = prices[key].es_standard_status;
|
||||
if (prices[key].es_plus) row.es_plus = prices[key].es_plus;
|
||||
if (prices[key].es_plus_status !== undefined) row.es_plus_status = prices[key].es_plus_status;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function eurostarMissingText(row, esClass) {
|
||||
var status = esClass === 'standard' ? row.es_standard_status : row.es_plus_status;
|
||||
if (status === 'sold_out') return 'Eurostar sold out';
|
||||
if (status === 'price_not_returned') return 'No Eurostar price returned';
|
||||
return 'No Eurostar price returned';
|
||||
}
|
||||
|
||||
function eurostarMissingTitle(row, esClass) {
|
||||
var status = esClass === 'standard' ? row.es_standard_status : row.es_plus_status;
|
||||
if (status === 'sold_out') return 'Eurostar returned 0 seats at this price for the selected class.';
|
||||
if (status === 'price_not_returned') return 'Eurostar returned this service without a price for the selected class.';
|
||||
return 'Eurostar did not return a price for the selected class. Check eurostar.com.';
|
||||
}
|
||||
|
||||
function eurostarMissingFareHtml(row, esClass) {
|
||||
var status = esClass === 'standard' ? row.es_standard_status : row.es_plus_status;
|
||||
if (eurostarRefreshPending && !status) return '<span class="text-sm text-muted">checking</span>';
|
||||
if (status === 'sold_out') return '<span class="text-sm text-muted">sold out</span>';
|
||||
return '<span class="text-sm text-muted">–</span>';
|
||||
}
|
||||
|
||||
function sectionNeedsAdvance(sectionId) {
|
||||
var nrClass = currentNrClasses[sectionId] || 'walkon';
|
||||
for (var key in TRIP_FARES) {
|
||||
|
|
@ -401,11 +425,11 @@
|
|||
var esStdEl = tr.querySelector('.es-standard');
|
||||
var esPlusEl = tr.querySelector('.es-plus');
|
||||
if (esStdEl) {
|
||||
esStdEl.innerHTML = '<span class="text-xs text-muted">Std</span> ' + (row.es_standard ? fareHtml(row.es_standard) : '<span class="text-sm text-muted">–</span>');
|
||||
esStdEl.innerHTML = '<span class="text-xs text-muted">Std</span> ' + (row.es_standard ? fareHtml(row.es_standard) : eurostarMissingFareHtml(row, 'standard'));
|
||||
esStdEl.classList.toggle('fare-inactive', esClass !== 'standard');
|
||||
}
|
||||
if (esPlusEl) {
|
||||
esPlusEl.innerHTML = '<span class="text-xs text-muted">SP</span> ' + (row.es_plus ? fareHtml(row.es_plus) : '<span class="text-sm text-muted">–</span>');
|
||||
esPlusEl.innerHTML = '<span class="text-xs text-muted">SP</span> ' + (row.es_plus ? fareHtml(row.es_plus) : eurostarMissingFareHtml(row, 'plus'));
|
||||
esPlusEl.classList.toggle('fare-inactive', esClass !== 'plus');
|
||||
}
|
||||
|
||||
|
|
@ -426,8 +450,10 @@
|
|||
totalSpan.innerHTML = '';
|
||||
} else if (!nrFare) {
|
||||
totalSpan.innerHTML = '<span class="text-xs text-muted" title="National Rail fare data is not available for this service">NR fare not available</span>';
|
||||
} else if (eurostarRefreshPending) {
|
||||
totalSpan.innerHTML = '<span class="text-xs text-muted" title="Checking exact Eurostar data for this service">Checking Eurostar price</span>';
|
||||
} else {
|
||||
totalSpan.innerHTML = '<span class="text-xs text-muted" title="No Eurostar price found for this service — it may be sold out in the selected class. Check eurostar.com.">No Eurostar price</span>';
|
||||
totalSpan.innerHTML = '<span class="text-xs text-muted" title="' + eurostarMissingTitle(row, esClass) + ' Check eurostar.com.">' + eurostarMissingText(row, esClass) + '</span>';
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
@ -618,6 +644,8 @@
|
|||
|
||||
function startTimetableRefresh() {
|
||||
if (!HAS_PROVISIONAL_TIMETABLE || !TIMETABLE_REFRESH_URL || !window.EventSource) return;
|
||||
eurostarRefreshPending = true;
|
||||
updateDisplay();
|
||||
var source = new EventSource(TIMETABLE_REFRESH_URL);
|
||||
source.onmessage = function(event) {
|
||||
var msg = JSON.parse(event.data);
|
||||
|
|
@ -631,11 +659,15 @@
|
|||
mergeWalkonFares(msg.section, msg.fares);
|
||||
updateDisplay();
|
||||
} else if (msg.type === 'done' || msg.type === 'error') {
|
||||
eurostarRefreshPending = false;
|
||||
source.close();
|
||||
updateDisplay();
|
||||
}
|
||||
};
|
||||
source.onerror = function() {
|
||||
eurostarRefreshPending = false;
|
||||
source.close();
|
||||
updateDisplay();
|
||||
};
|
||||
}
|
||||
|
||||
|
|
@ -655,6 +687,7 @@
|
|||
function finaliseResults(msg) {
|
||||
TIMETABLE_REFRESH_URL = msg.timetable_refresh_url || null;
|
||||
HAS_PROVISIONAL_TIMETABLE = msg.provisional_timetable || false;
|
||||
eurostarRefreshPending = HAS_PROVISIONAL_TIMETABLE && !!TIMETABLE_REFRESH_URL && !!window.EventSource;
|
||||
var summaryEl = document.getElementById('results-summary');
|
||||
if (summaryEl && msg.summary_html) summaryEl.innerHTML = msg.summary_html;
|
||||
initialiseResultsPage();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue