Implement notices
This commit is contained in:
parent
de834106b8
commit
3439c2ea26
@ -1,7 +1,9 @@
|
|||||||
# What to do next:
|
# What to do next:
|
||||||
|
|
||||||
|
* Development - `npm i` needs running on Desktop
|
||||||
* Docker - nginx-proxy needs rebuilding and repushing.
|
* Docker - nginx-proxy needs rebuilding and repushing.
|
||||||
* Docker - owlboard needs rebuilding and repushing.
|
* Docker - owlboard needs rebuilding and repushing.
|
||||||
* Frontend - Fix index.html form.
|
* Frontend - Implement scrolling NRCC Notices as they take up lots of space.
|
||||||
* Frontend - Implement message when API returns error state.
|
* Frontend - If Ferry Services Present - Load at bottom of screen.
|
||||||
* Frontend - Add page builder.
|
* Frontend - Load train services to screen.
|
||||||
|
* Frontend - Decide what to do with Bus Services.
|
@ -20,12 +20,23 @@
|
|||||||
<p class="header-right">Data from:</p>
|
<p class="header-right">Data from:</p>
|
||||||
<p id="fetch_time" class="header-right">Loading...</p>
|
<p id="fetch_time" class="header-right">Loading...</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div id="nrcc_notices" class="hidden-while-loading">
|
||||||
|
<p id="notices"></p>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div id="loading">
|
<div id="loading">
|
||||||
<div class="spinner">
|
<div class="spinner">
|
||||||
</div>
|
</div>
|
||||||
<p>
|
<p>Loading</p>
|
||||||
Loading
|
</div>
|
||||||
</p>
|
|
||||||
|
<div id="error_notice" class="hidden-unless-error">
|
||||||
|
<h1 class="error">Oops</h1>
|
||||||
|
<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_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>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div id="output">
|
<div id="output">
|
||||||
|
@ -1,3 +1,6 @@
|
|||||||
|
// Enable delays
|
||||||
|
const delay = ms => new Promise(res => setTimeout(res, ms));
|
||||||
|
|
||||||
init()
|
init()
|
||||||
|
|
||||||
/* Supporting Functions */
|
/* Supporting Functions */
|
||||||
@ -13,12 +16,10 @@ async function init() {
|
|||||||
try {
|
try {
|
||||||
var data = await publicLdb(stn)
|
var data = await publicLdb(stn)
|
||||||
log("init: Fetched LDB Data")
|
log("init: Fetched LDB Data")
|
||||||
|
parseLdb(data)
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
var data = null
|
var data = null
|
||||||
log("init: Unable to fetch LDB data")
|
log("init: Unable to fetch LDB data")
|
||||||
} finally {
|
|
||||||
log(data)
|
|
||||||
parseLdb(data)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -47,11 +48,52 @@ async function setHeaders(title,time){
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function parseLdb(data) {
|
async function parseLdb(data) {
|
||||||
|
if (data.ERROR == "NOT_FOUND") { // Station not found
|
||||||
|
clearLoading();
|
||||||
|
document.getElementById("error_notice").style = "display: block;";
|
||||||
|
document.getElementById("err_not_found").style = "display: block;";
|
||||||
|
setHeaders("Not Found",new Date())
|
||||||
|
} else if (data == false) { // No data for station
|
||||||
|
clearLoading();
|
||||||
|
document.getElementById("error_notice").style = "display: block;";
|
||||||
|
document.getElementById("err_no_data").style = "display:block;";
|
||||||
|
setHeaders("No Data",new Date())
|
||||||
|
} else if (data == "err") { // Connection Error
|
||||||
|
clearLoading();
|
||||||
|
document.getElementById("error_notice").style = "display: block;";
|
||||||
|
document.getElementById("err_conn").style = "display: block;";
|
||||||
|
setHeaders("Connection Error",new Date())
|
||||||
|
await delay(5000);
|
||||||
|
log(`parseLdb: Waited five seconds, reloading`)
|
||||||
|
location.reload()
|
||||||
|
} else {
|
||||||
|
buildPage(data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Hide all loading classes
|
||||||
|
async function clearLoading(){
|
||||||
|
document.getElementById("loading").style = "display: none;";
|
||||||
|
}
|
||||||
|
|
||||||
|
async function buildPage(data){
|
||||||
var stationName = data.GetStationBoardResult.locationName;
|
var stationName = data.GetStationBoardResult.locationName;
|
||||||
log(`parseLdb: 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);
|
||||||
log(`parseLdb: Data prepared at ${generateTime.toLocaleString()}`)
|
log(`buildPage: Data prepared at ${generateTime.toLocaleString()}`)
|
||||||
setHeaders(stationName, generateTime);
|
setHeaders(stationName, generateTime);
|
||||||
|
// Check for notices and if true pass to function
|
||||||
|
if (data.GetStationBoardResult.nrccMessages) {
|
||||||
|
displayNotices(data.GetStationBoardResult.nrccMessages.message)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function displayNotices(notices){
|
||||||
|
// Input: data.GetStationBoardResult.nrccMessages.messages
|
||||||
|
// Processing: For each message, add a text scroll to the top of the page.
|
||||||
|
// Output: Only to DOM.
|
||||||
|
document.getElementById("notices").innerHTML = notices; // This is a mess if more than one notice is present.
|
||||||
|
document.getElementById("nrcc_notices").style = "display: block;";
|
||||||
}
|
}
|
||||||
|
|
||||||
// Log Helper
|
// Log Helper
|
||||||
|
@ -39,7 +39,25 @@
|
|||||||
font-weight: bolder;
|
font-weight: bolder;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Content: */
|
/* Error Notices: */
|
||||||
|
.hidden-unless-error {
|
||||||
|
display: none;
|
||||||
|
margin-top: 150px;
|
||||||
|
}
|
||||||
|
|
||||||
|
#err_not_found {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
#err_no_data {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
#err_conn {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Fixed Content: */
|
||||||
#header {
|
#header {
|
||||||
position: fixed;
|
position: fixed;
|
||||||
top: 0;
|
top: 0;
|
||||||
@ -77,4 +95,9 @@
|
|||||||
|
|
||||||
.hide-when-loading {
|
.hide-when-loading {
|
||||||
display: none;
|
display: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Injected Data */
|
||||||
|
#nrcc_notices {
|
||||||
|
margin-top: 60px;
|
||||||
}
|
}
|
@ -40,6 +40,8 @@ body {
|
|||||||
text-align: center;
|
text-align: center;
|
||||||
padding-bottom: 60px; /*Footer height*/
|
padding-bottom: 60px; /*Footer height*/
|
||||||
}
|
}
|
||||||
|
body a {color:var(--link-color)}
|
||||||
|
body a:visited {color:var(--link-visited-color)}
|
||||||
.titleimg {
|
.titleimg {
|
||||||
width: 45%;
|
width: 45%;
|
||||||
padding-top: 20px;
|
padding-top: 20px;
|
||||||
|
Reference in New Issue
Block a user