Frontend: Add support for 'No Scheduled Services'

Signed-off-by: Fred Boniface <fred@fjla.uk>
This commit is contained in:
Fred Boniface 2023-01-14 11:45:41 +00:00
parent 9434d7e3a8
commit f3f514b80d
5 changed files with 29 additions and 9 deletions

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1 @@
{"GetStationBoardResult":{"generatedAt":"2023-01-14T11:23:12.6558466+00:00","locationName":"Pilning","crs":"PIL","nrccMessages":{"message":"\nPoor weather affecting services in Wales due to flooding on the railway More details can be found in <a href=\"https://t.co/uBU966PUmX\">Latest Travel News</a>."},"platformAvailable":"true"}}

View File

@ -23,7 +23,7 @@
<div id="nrcc_notices" class="hidden-while-loading"> <div id="nrcc_notices" class="hidden-while-loading">
<p> <p>
Services may be subject to alterations due to heavy rain flooding the railway between Bristol Parkway and Swindon. Example: Services may be subject to alterations due to heavy rain flooding the railway between Bristol Parkway and Swindon.
</p> </p>
</div> </div>
@ -33,13 +33,16 @@
<p>Loading</p> <p>Loading</p>
</div> </div>
<div id="error_notice" class="hidden-unless-error"> <div id="error_notice" class="main-notice hidden-while-loading">
<h1 class="error">Oops</h1> <h1 class="error">Oops</h1>
<p class="error">There was an error with your request</p> <p class="error">There was an error with your request</p>
<p id="err_not_found">The station you are searching for cannot be found</p> <p id="err_not_found">The station you are searching for cannot be found</p>
<p id="err_no_data">The station has no data. It may not be in operation yet/anymore.</p> <p id="err_no_data">The station has no data. It may not be in operation yet/anymore.</p>
<p id="err_conn">Connection Error, check your data connection. Retrying.</p> <p id="err_conn">Connection Error, check your data connection. Retrying.</p>
</div> </div>
<div id="no_services" class="main-notice hidden-whille-loading">
<p>There are no scheduled services from this station</p>
</div>
<div id="output"> <div id="output">

View File

@ -40,7 +40,7 @@ async function publicLdb(stn) {
return await resp.json(); return await resp.json();
} }
async function setHeaders(title,time){ async function setHeaders(title,time) {
var prefix = `OwlBoard - ` var prefix = `OwlBoard - `
document.title = `${prefix}${title}` document.title = `${prefix}${title}`
document.getElementById("station_name").innerHTML = title document.getElementById("station_name").innerHTML = title
@ -71,12 +71,13 @@ async function parseLdb(data) {
} }
} }
// Hide all loading classes // Hide loading spinner
async function clearLoading(){ async function clearLoading() {
document.getElementById("loading").style = "display: none;"; document.getElementById("loading").style = "display: none;";
} }
async function buildPage(data){ // Build and Display Functions
async function buildPage(data) {
var stationName = data.GetStationBoardResult.locationName; var stationName = data.GetStationBoardResult.locationName;
log(`buildPage: Data ready for ${stationName}`); log(`buildPage: Data ready for ${stationName}`);
var generateTime = new Date(await data.GetStationBoardResult.generatedAt); var generateTime = new Date(await data.GetStationBoardResult.generatedAt);
@ -86,9 +87,14 @@ async function buildPage(data){
if (data.GetStationBoardResult.nrccMessages) { if (data.GetStationBoardResult.nrccMessages) {
displayNotices(data.GetStationBoardResult.nrccMessages.message) displayNotices(data.GetStationBoardResult.nrccMessages.message)
} }
if (typeof data.GetStationBoardResult.trainServices == 'undefined') {
displayNoTrains()
} else {
// Function here to Parse train services and display.
}
} }
async function displayNotices(notices){ async function displayNotices(notices) {
// Input: data.GetStationBoardResult.nrccMessages.messages // Input: data.GetStationBoardResult.nrccMessages.messages
// Processing: For each message, create a <p> inside #notices. // Processing: For each message, create a <p> inside #notices.
// If there is more than one notice, scroll between them. // If there is more than one notice, scroll between them.
@ -96,6 +102,15 @@ async function displayNotices(notices){
//document.getElementById("notices").innerHTML = notices; //document.getElementById("notices").innerHTML = notices;
} }
async function displayNoTrains() {
document.getElementById('no_services').style = "display: block;";
clearLoading();
}
async function displayTrains() {
return
}
// Log Helper // Log Helper
function log(msg) { function log(msg) {
var time = new Date().toISOString(); var time = new Date().toISOString();

View File

@ -39,8 +39,8 @@
font-weight: bolder; font-weight: bolder;
} }
/* Error Notices: */ /* Main Notices: */
.hidden-unless-error { .main-notice {
display: none; display: none;
margin-top: 150px; margin-top: 150px;
} }