pis #1

Closed
fred.boniface wants to merge 51 commits from pis into dev
32 changed files with 2542 additions and 1097 deletions

View File

@ -1,2 +1,6 @@
.dockerignore .dockerignore
Dockerfile Dockerfile
package.json
package-lock.json
.eslintrc.js
node_modules

31
.eslintrc.js Normal file
View File

@ -0,0 +1,31 @@
module.exports = {
'env': {
'browser': true,
'es2021': true
},
'extends': 'eslint:recommended',
'overrides': [
],
'parserOptions': {
'ecmaVersion': 'latest'
},
'rules': {
'indent': [
'error',
2
],
'linebreak-style': [
'error',
'unix'
],
'quotes': [
'error',
'single'
],
'semi': [
'error',
'never'
],
'no-undef': 'off',
}
}

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
node_modules

View File

@ -2,6 +2,7 @@
<head> <head>
<meta charset="UTF-8"/> <meta charset="UTF-8"/>
<meta name="description" content="OwlBoard - Live train departures for traincrew."/> <meta name="description" content="OwlBoard - Live train departures for traincrew."/>
<meta name="robots" content="noindex"/>
<meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="application-name" content="OwlBoard"> <meta name="application-name" content="OwlBoard">
<meta name="author" content="Frederick Boniface"> <meta name="author" content="Frederick Boniface">

View File

@ -1,16 +1,17 @@
<!DOCTYPE html> <!DOCTYPE html>
<html lang="en"> <html lang="en">
<head> <head>
<meta charset="UTF-8"/> <meta charset="UTF-8">
<meta name="description" content="OwlBoard - Live train departures for traincrew."/> <meta name="description" content="OwlBoard - Live train departures for traincrew.">
<meta name="robots" content="noindex">
<meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="application-name" content="OwlBoard"> <meta name="application-name" content="OwlBoard">
<meta name="author" content="Frederick Boniface"> <meta name="author" content="Frederick Boniface">
<meta name="theme-color" content="#00b7b7"> <meta name="theme-color" content="#00b7b7">
<link rel="apple-touch-icon" href="/images/app-icons/any/apple-192.png"> <link rel="apple-touch-icon" href="/images/app-icons/any/apple-192.png">
<link rel="stylesheet" type="text/css" href="./styles/main.css"/> <link rel="stylesheet" type="text/css" href="./styles/main.css">
<link rel="icon" type="image/svg+xml" href="./images/icon.svg"/> <link rel="icon" type="image/svg+xml" href="./images/icon.svg">
<link rel="manifest" type="application/json" href="./manifest.json"/> <link rel="manifest" type="application/json" href="./manifest.json">
<script src="./js/lib.main.js" defer></script> <script src="./js/lib.main.js" defer></script>
<script src="./js/auth.js" defer></script> <script src="./js/auth.js" defer></script>
<title>OwlBoard</title> <title>OwlBoard</title>

View File

@ -1,18 +1,19 @@
<!DOCTYPE html> <!DOCTYPE html>
<html lang="en"> <html lang="en">
<head> <head>
<meta charset="UTF-8"/> <meta charset="UTF-8">
<meta name="description" content="OwlBoard - Live train departures for traincrew."/> <meta name="description" content="OwlBoard - Live train departures for traincrew.">
<meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="robots" content="noindex">
<meta name="application-name" content="OwlBoard"> <meta name="application-name" content="OwlBoard">
<meta name="author" content="Frederick Boniface"> <meta name="author" content="Frederick Boniface">
<meta name="theme-color" content="#00b7b7"> <meta name="theme-color" content="#00b7b7">
<title>OwlBoard - Loading</title> <title>OwlBoard - Loading</title>
<link rel="apple-touch-icon" href="/images/app-icons/any/apple-192.png"> <link rel="apple-touch-icon" href="/images/app-icons/any/apple-192.png">
<link rel="stylesheet" type="text/css" href="./styles/main.css"/> <link rel="stylesheet" type="text/css" href="./styles/main.css">
<link rel="stylesheet" type="text/css" href="./styles/board.css"/> <link rel="stylesheet" type="text/css" href="./styles/board.css">
<link rel="icon" type="image/svg+xml" href="./images/icon.svg"/> <link rel="icon" type="image/svg+xml" href="./images/icon.svg">
<link rel="manifest" type="application/json" href="./manifest.json"/> <link rel="manifest" type="application/json" href="./manifest.json">
<script src="./js/lib.main.js" defer></script> <script src="./js/lib.main.js" defer></script>
<script src="./js/lib.board.js" defer></script> <script src="./js/lib.board.js" defer></script>
<script src="./js/staff-board.js" defer></script> <script src="./js/staff-board.js" defer></script>
@ -27,7 +28,7 @@
<div id="content"> <div id="content">
<div id="header"> <div id="header">
<div id="station_name"> <div id="station_name">
<h1 id="stn_name" class="header-large"></h1> <h1 id="stn_name" class="header-large">Arrivals &amp; Departures</h1>
</div> </div>
<div id="header-right"> <div id="header-right">
<picture id="refresh" onclick="location.reload()"> <picture id="refresh" onclick="location.reload()">

View File

@ -1,18 +1,20 @@
<!DOCTYPE html> <!DOCTYPE html>
<html lang="en"> <html lang="en">
<head> <head>
<meta charset="UTF-8"/> <meta charset="UTF-8">
<meta name="description" content="OwlBoard - Live train departures for traincrew."/> <meta name="description" content="OwlBoard - Live train departures for traincrew.">
<meta name="robots" content="noindex">
<meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="robots" content="noindex">
<meta name="application-name" content="OwlBoard"> <meta name="application-name" content="OwlBoard">
<meta name="author" content="Frederick Boniface"> <meta name="author" content="Frederick Boniface">
<meta name="theme-color" content="#00b7b7"> <meta name="theme-color" content="#00b7b7">
<title>OwlBoard - Loading</title> <title>OwlBoard - Loading</title>
<link rel="apple-touch-icon" href="/images/app-icons/any/apple-192.png"> <link rel="apple-touch-icon" href="/images/app-icons/any/apple-192.png">
<link rel="stylesheet" type="text/css" href="./styles/main.css"/> <link rel="stylesheet" type="text/css" href="./styles/main.css">
<link rel="stylesheet" type="text/css" href="./styles/board.css"/> <link rel="stylesheet" type="text/css" href="./styles/board.css">
<link rel="icon" type="image/svg+xml" href="./images/icon.svg"/> <link rel="icon" type="image/svg+xml" href="./images/icon.svg">
<link rel="manifest" type="application/json" href="./manifest.json"/> <link rel="manifest" type="application/json" href="./manifest.json">
<script src="./js/lib.main.js" defer></script> <script src="./js/lib.main.js" defer></script>
<script src="./js/lib.board.js" defer></script> <script src="./js/lib.board.js" defer></script>
<script src="./js/simple-board.js" defer></script> <script src="./js/simple-board.js" defer></script>
@ -27,7 +29,7 @@
<div id="content"> <div id="content">
<div id="header"> <div id="header">
<div id="station_name"> <div id="station_name">
<h1 id="stn_name" class="header-large"></h1> <h1 id="stn_name" class="header-large">Arrivals &amp; Departures</h1>
</div> </div>
<div id="header-right"> <div id="header-right">
<picture id="refresh" onclick="location.reload()"> <picture id="refresh" onclick="location.reload()">

View File

@ -39,8 +39,7 @@ http {
gzip_static on; gzip_static on;
brotli_static on; brotli_static on;
error_page 404 /404.html; error_page 404 /404.html;
expires 2d; add_header Cache-Control "public, no-transform, max-age=1209600";
add_header Cache-Control "public, no-transform";
} }
location /api/ { location /api/ {
@ -48,8 +47,7 @@ http {
proxy_cache_key $scheme://$host$uri$is_args$query_string; proxy_cache_key $scheme://$host$uri$is_args$query_string;
proxy_ignore_headers Cache-Control; proxy_ignore_headers Cache-Control;
proxy_cache_valid 200 2m; # Evaluate whether 2m or 1m is more appropriate proxy_cache_valid 200 2m; # Evaluate whether 2m or 1m is more appropriate
expires 2m; add_header Cache-Control "private, no-transform, max-age=120";
add_header Cache-Control "private, no-transform";
} }
location /api/v1/list/ { location /api/v1/list/ {
@ -57,8 +55,7 @@ http {
proxy_cache_key $scheme://$host$uri$is_args$query_string; proxy_cache_key $scheme://$host$uri$is_args$query_string;
proxy_ignore_headers Cache-Control; proxy_ignore_headers Cache-Control;
proxy_cache_valid 200 10080m; proxy_cache_valid 200 10080m;
expires 7d; add_header Cache-Control "public, no-transform, max-age=604800";
add_header Cache-Control "public, no-transform";
} }
} }
} }

View File

@ -2,6 +2,7 @@
<head> <head>
<meta charset="UTF-8"/> <meta charset="UTF-8"/>
<meta name="description" content="OwlBoard - Live train departures for traincrew."/> <meta name="description" content="OwlBoard - Live train departures for traincrew."/>
<meta name="robots" content="noindex"/>
<meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="application-name" content="OwlBoard"> <meta name="application-name" content="OwlBoard">
<meta name="author" content="Frederick Boniface"> <meta name="author" content="Frederick Boniface">

View File

@ -1,24 +1,23 @@
<!DOCTYPE html> <!DOCTYPE html>
<html lang="en"> <html lang="en">
<head> <head>
<meta charset="UTF-8"/> <meta charset="UTF-8">
<meta name="description" content="OwlBoard - Live train departures for traincrew."/> <meta name="description" content="OwlBoard - Find CRS, TIPLOC & STANOX Codes with ease.">
<meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="application-name" content="OwlBoard"> <meta name="application-name" content="OwlBoard">
<meta name="author" content="Frederick Boniface"> <meta name="author" content="Frederick Boniface">
<meta name="theme-color" content="#00b7b7"> <meta name="theme-color" content="#00b7b7">
<link rel="apple-touch-icon" href="/images/app-icons/any/apple-192.png"> <link rel="apple-touch-icon" href="/images/app-icons/any/apple-192.png">
<link rel="stylesheet" type="text/css" href="./styles/main.css"/> <link rel="stylesheet" type="text/css" href="./styles/main.css">
<link rel="stylesheet" type="text/css" href="./styles/find-code.css"/> <link rel="stylesheet" type="text/css" href="./styles/find-code.css">
<link rel="icon" type="image/svg+xml" href="./images/icon.svg"/> <link rel="icon" type="image/svg+xml" href="./images/icon.svg">
<link rel="manifest" type="application/json" href="./manifest.json"/> <link rel="manifest" type="application/json" href="./manifest.json">
<title>OwlBoard - Code Lookup</title> <title>OwlBoard - Code Lookup</title>
<script src="./js/lib.main.js" defer></script> <script src="./js/lib.main.js" defer></script>
<script src="./js/find-code.js" defer></script> <script src="./js/find-code.js" defer></script>
</head> </head>
<body> <body>
<div id="top_button" class="hide_micro"> <div id="top_button" class="hide_micro">
<a href="/"> <a href="/">
<picture aria-label="Home" class="sidebar_control"> <picture aria-label="Home" class="sidebar_control">
@ -27,7 +26,6 @@
</picture> </picture>
</a> </a>
</div> </div>
<picture> <picture>
<source srcset="/images/logo/wide_logo.svg" type="image/svg+xml"> <source srcset="/images/logo/wide_logo.svg" type="image/svg+xml">
<source media="(max-height: 739px)" srcset="/images/logo/logo-full-200.png" type="image/png"> <source media="(max-height: 739px)" srcset="/images/logo/logo-full-200.png" type="image/png">
@ -36,7 +34,7 @@
</picture> </picture>
<h2>Code Lookup</h2> <h2>Code Lookup</h2>
<p>Enter one known code in the relevant box below and hit submit. <p>Enter one known code in the relevant box below and hit submit.
Where they exist, the other code types will be filled in.</p> Where they exist, the other code types will be filled in.</p>
<p>You cannot yet lookup by location name as the values are not unique.</p> <p>You cannot yet lookup by location name as the values are not unique.</p>
<p>Location name search will be added in the future.</p> <p>Location name search will be added in the future.</p>
@ -47,7 +45,7 @@
</div> </div>
<label for="name">Location name:</label><br> <label for="name">Location name:</label><br>
<input type="text" class="small-lookup-box" id="name" name="name" readonly=""><br> <input type="text" class="small-lookup-box" id="name" name="name" readonly><br>
<label for="3alpha">CRS/3ALPHA:</label><br> <label for="3alpha">CRS/3ALPHA:</label><br>
<input type="text" class="small-lookup-box" id="3alpha" name="3alpha" maxlength="3"><br> <input type="text" class="small-lookup-box" id="3alpha" name="3alpha" maxlength="3"><br>
<label for="nlc">NLC:</label><br> <label for="nlc">NLC:</label><br>
@ -57,7 +55,7 @@
<label for="stanox">STANOX:</label><br> <label for="stanox">STANOX:</label><br>
<input type="number" class="small-lookup-box" id="stanox" name="stanox"><br> <input type="number" class="small-lookup-box" id="stanox" name="stanox"><br>
<label for="stanme" hidden>STANME:</label><br> <label for="stanme" hidden>STANME:</label><br>
<input type="test" class="small-lookup-box" id="stanme" name="stanme" readonly="" hidden><br> <input type="text" class="small-lookup-box" id="stanme" name="stanme" readonly hidden><br>
<input type="submit" value="Find" class="lookup-button" onclick="fetchEntry()"> <input type="submit" value="Find" class="lookup-button" onclick="fetchEntry()">
<input type="submit" value="Clear" class="lookup-button" onclick="clearForm()"> <input type="submit" value="Clear" class="lookup-button" onclick="clearForm()">
</body> </body>

View File

@ -2,7 +2,8 @@
<html lang="en"> <html lang="en">
<head> <head>
<meta charset="UTF-8"/> <meta charset="UTF-8"/>
<meta name="description" content="OwlBoard - Live train departures for traincrew."/> <meta name="description" content="OwlBoard - How to use OwlBoard."/>
<meta name="robots" content="noindex"/>
<meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="application-name" content="OwlBoard"> <meta name="application-name" content="OwlBoard">
<meta name="author" content="Frederick Boniface"> <meta name="author" content="Frederick Boniface">

View File

@ -2,7 +2,7 @@
<html lang="en"> <html lang="en">
<head> <head>
<meta charset="UTF-8"/> <meta charset="UTF-8"/>
<meta name="description" content="OwlBoard - Live train departures for traincrew."/> <meta name="description" content="OwlBoard - Live train departures, PIS codes & reference data for traincrew."/>
<meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="application-name" content="OwlBoard"> <meta name="application-name" content="OwlBoard">
<meta name="author" content="Frederick Boniface"> <meta name="author" content="Frederick Boniface">
@ -37,6 +37,7 @@
<div id="sidebar"> <div id="sidebar">
<a href="./">Home</a> <a href="./">Home</a>
<a href="./find-code.html">Code Search</a> <a href="./find-code.html">Code Search</a>
<a href="./pis.html">PIS Codes</a>
<a href="./settings.html">Settings</a> <a href="./settings.html">Settings</a>
<a href="./help.html">Help</a> <a href="./help.html">Help</a>
<a href="./issue.html">Report Issue</a> <a href="./issue.html">Report Issue</a>
@ -44,9 +45,9 @@
<!-- Main Content Begins --> <!-- Main Content Begins -->
<picture> <picture>
<source srcset="/images/logo/wide_logo.svg" type="image/svg+xml"> <source srcset="./images/logo/wide_logo.svg" type="image/svg+xml">
<source media="(max-height: 739px)" srcset="/images/logo/logo-full-200.png" type="image/png"> <source media="(max-height: 739px)" srcset="./images/logo/logo-full-200.png" type="image/png">
<source srcset="/images/logo/logo-full-250.png" type="image/png"> <source srcset="./images/logo/logo-full-250.png" type="image/png">
<img class="titleimg" src="./images/logo/logo-full-250.png" alt="OwlBoard Logo"> <img class="titleimg" src="./images/logo/logo-full-250.png" alt="OwlBoard Logo">
</picture> </picture>
<br> <br>
@ -60,7 +61,8 @@
<div id="quick_links"> <div id="quick_links">
</div> </div>
<div class="text-description"> <div class="text-description">
<p>Customise your quick links on the <a href="/settings.html">Settings</a> page.</p> <p>New feature in testing: <a href="./pis.html">PIS Code lookup</a></p>
<p>Customise your quick links on the <a href="./settings.html">Settings</a> page.</p>
</div> </div>
<!-- Footer --> <!-- Footer -->
<footer> <footer>

View File

@ -1,58 +1,59 @@
<html> <html lang="en">
<head> <head>
<meta charset="UTF-8"/> <meta charset="UTF-8">
<meta name="description" content="OwlBoard - Live train departures for traincrew."/> <meta name="description" content="OwlBoard - Report an issue with OwlBoard.">
<meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta name="robots" content="noindex">
<meta name="application-name" content="OwlBoard"> <meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="author" content="Frederick Boniface"> <meta name="application-name" content="OwlBoard">
<meta name="theme-color" content="#00b7b7"> <meta name="author" content="Frederick Boniface">
<link rel="apple-touch-icon" href="/images/app-icons/any/apple-192.png"> <meta name="theme-color" content="#00b7b7">
<link rel="stylesheet" type="text/css" href="./styles/main.css"/> <link rel="apple-touch-icon" href="/images/app-icons/any/apple-192.png">
<link rel="stylesheet" type="text/css" href="./styles/issue.css"/> <link rel="stylesheet" type="text/css" href="./styles/main.css">
<link rel="icon" type="image/svg+xml" href="./images/icon.svg"/> <link rel="stylesheet" type="text/css" href="./styles/issue.css">
<link rel="manifest" type="application/json" href="./manifest.json"/> <link rel="icon" type="image/svg+xml" href="./images/icon.svg">
<script src="./js/lib.main.js" defer></script> <link rel="manifest" type="application/json" href="./manifest.json">
<script src="./js/issue.js" defer></script> <script src="./js/lib.main.js" defer></script>
<title>OwlBoard - Report</title> <script src="./js/issue.js" defer></script>
</head> <title>OwlBoard - Report</title>
<body> </head>
<!-- Loading Box --> <body>
<div id="loading"> <!-- Loading Box -->
<div class="spinner"> <div id="loading">
</div> <div class="spinner">
<p id="loading_desc">Loading</p>
</div> </div>
<div id="top_button" class="hide_micro"> <p id="loading_desc">Loading</p>
<a href="/"> </div>
<picture aria-label="Home" class="sidebar_control"> <div id="top_button" class="hide_micro">
<source srcset="/images/nav/back.svg" type="image/svg+xml"> <a href="/">
<img src="back-40.png" alt="Home"> <picture aria-label="Home" class="sidebar_control">
</picture> <source srcset="/images/nav/back.svg" type="image/svg+xml">
</a> <img src="back-40.png" alt="Home">
</div> </picture>
<picture> </a>
<source srcset="/images/logo/wide_logo.svg" type="image/svg+xml"> </div>
<source media="(max-height: 739px)" srcset="/images/logo/logo-full-200.png" type="image/png"> <picture>
<source srcset="/images/logo/logo-full-250.png" type="image/png"> <source srcset="/images/logo/wide_logo.svg" type="image/svg+xml">
<img class="titleimg" src="/images/logo/logo-full-250.png" alt="OwlBoard Logo"> <source media="(max-height: 739px)" srcset="/images/logo/logo-full-200.png" type="image/png">
</picture> <source srcset="/images/logo/logo-full-250.png" type="image/png">
<h2>Report an Issue</h2> <img class="titleimg" src="/images/logo/logo-full-250.png" alt="OwlBoard Logo">
<p>To help diagnosing an issue, data about your browser and device will be </picture>
collected alongside the data that you enter below.</p> <h2>Report an Issue</h2>
<p>The data will be available publically in the <a href="https://git.fjla.uk/fred.boniface/owlboard/issues"> <p>To help diagnosing an issue, data about your browser and device will be
OwlBoard Issue Tracker</a>. A preview will be shown before the data is sent.</p> collected alongside the data that you enter below.</p>
<label for="subject">Subject:</label><br> <p>The data will be available publically in the <a href="https://git.fjla.uk/fred.boniface/owlboard/issues">
<input type="text" name="subject" id="subject" class="text-entry"/><br> OwlBoard Issue Tracker</a>. A preview will be shown before the data is sent.</p>
<label for="content">Message:</label><br> <label for="subject">Subject:</label><br>
<textarea name="message" id="message" class="text-entry-long"></textarea><br> <input type="text" name="subject" id="subject" class="text-entry"><br>
<input type="submit" name="submit" id="submit" label="Preview" class="lookup-button" onclick="submit()"> <label for="content">Message:</label><br>
<textarea name="message" id="message" class="text-entry-long"></textarea><br>
<input type="submit" name="submit" id="submit" label="Preview" class="lookup-button" onclick="submit()">
<div id="preflight"> <div id="preflight">
<h3>Check & Send</h3> <h3>Check &amp; Send</h3>
<h3>---</h3> <h3>---</h3>
<h4 id="pre_subject"></h4> <h4 id="pre_subject">Subject</h4>
<p id="pre_message"></p> <p id="pre_message"></p>
<button id="send" class="lookup-button" onclick="send()">Send</button> <button id="send" class="lookup-button" onclick="send()">Send</button>
<button id="cancel" class="lookup-button" onclick="cancel()">Cancel</button> <button id="cancel" class="lookup-button" onclick="cancel()">Cancel</button>
</div> </div>
</body> </body>
</html> </html>

View File

@ -5,75 +5,75 @@ Auth process: User Requests Key => Server emails key to user =>
Server responds with the users auth key => Server responds with the users auth key =>
auth.js adds this to localStorage auth.js adds this to localStorage
*/ */
const cmd = document.getElementById("cmd") // Assign element to const const cmd = document.getElementById('cmd') // Assign element to const
versionDisplay(); // Show web version in footer versionDisplay() // Show web version in footer
init(); // Run init function init() // Run init function
async function sendHome(){ async function sendHome(){
await delay(2000); await delay(2000)
location.replace('./') location.replace('./')
} }
async function cmdOut(message) { async function cmdOut(message) {
html = "<p>" + message + "</p>" html = '<p>' + message + '</p>'
cmd.insertAdjacentHTML("beforeend", html) cmd.insertAdjacentHTML('beforeend', html)
} }
async function registerKey(key) { // Posts key to server and listens for response. async function registerKey(key) { // Posts key to server and listens for response.
const url = `${window.location.origin}/api/v1/register/register`; const url = `${window.location.origin}/api/v1/register/register`
const res = await fetch(url, { // The response will contain the UUID which will be registered const res = await fetch(url, { // The response will contain the UUID which will be registered
method: "POST", method: 'POST',
headers: { headers: {
"Content-Type": "application/json" 'Content-Type': 'application/json'
}, },
redirect: "follow", redirect: 'follow',
body: JSON.stringify({uuid: key}) body: JSON.stringify({uuid: key})
}) })
const data = await res.json(); const data = await res.json()
return res.status === 201 return res.status === 201
? (localStorage.setItem("uuid", data.api_key), true) ? (localStorage.setItem('uuid', data.api_key), true)
: false; : false
} }
async function checkAuth(key) { async function checkAuth(key) {
const url = `${window.location.origin}/api/v1/auth/test`; const url = `${window.location.origin}/api/v1/auth/test`
const res = await fetch(url, { const res = await fetch(url, {
method: "GET", method: 'GET',
redirect: "follow", redirect: 'follow',
headers: { headers: {
"uuid": key 'uuid': key
} }
}) })
return res.status === 200 ? true : false return res.status === 200 ? true : false
} }
async function init(){ // Reads registration key from query, and calls registerKey(key) async function init(){ // Reads registration key from query, and calls registerKey(key)
cmdOut("Reading authorisation code"); cmdOut('Reading authorisation code')
const key = await getQuery("key"); const key = await getQuery('key')
if (key === "false") { if (key === 'false') {
cmdOut("No valid key found") cmdOut('No valid key found')
cmdOut("Try clicking the link again or request a new activation link") cmdOut('Try clicking the link again or request a new activation link')
hideLoading() hideLoading()
return return
} }
cmdOut("Requesting API Key from server"); cmdOut('Requesting API Key from server')
if (!await registerKey(key)) { if (!await registerKey(key)) {
cmdOut("Failed to register or invalid key") cmdOut('Failed to register or invalid key')
cmdOut("Try again later or request a new link") cmdOut('Try again later or request a new link')
hideLoading() hideLoading()
return return
} }
showLoading() showLoading()
if (! await checkAuth(localStorage.getItem("uuid"))) { if (! await checkAuth(localStorage.getItem('uuid'))) {
cmdOut("Authentication Check failed") cmdOut('Authentication Check failed')
cmdOut("Please logout and request a new link") cmdOut('Please logout and request a new link')
hideLoading() hideLoading()
await delay(2000) await delay(2000)
location.replace("./") location.replace('./')
} }
hideLoading(); hideLoading()
cmdOut("Authentication succesful") cmdOut('Authentication succesful')
cmdOut("Redirecting to home") cmdOut('Redirecting to home')
await delay(3000) await delay(3000)
location.replace("./") location.replace('./')
} }

View File

@ -1,97 +1,98 @@
hideLoading(); hideLoading()
async function fetchEntry(){ // This can be condensed async function fetchEntry(){ // This can be condensed
showLoading(); showLoading()
var name = document.getElementById("name") var name = document.getElementById('name')
var crs = document.getElementById("3alpha") var crs = document.getElementById('3alpha')
var nlc = document.getElementById("nlc") var nlc = document.getElementById('nlc')
var tiploc = document.getElementById("tiploc") var tiploc = document.getElementById('tiploc')
var stanox = document.getElementById("stanox") var stanox = document.getElementById('stanox')
var values = { var values = {
name: name.value, name: name.value,
crs: crs.value, crs: crs.value,
nlc: nlc.value, nlc: nlc.value,
tiploc: tiploc.value, tiploc: tiploc.value,
stanox: stanox.value stanox: stanox.value
} }
parseData(values) parseData(values)
} }
async function parseData(values){ async function parseData(values){
vibe() vibe()
if (values.crs != ""){ let data
setLoadingDesc(`Searching\n${values.crs.toUpperCase()}`) if (values.crs != ''){
var data = await getData("crs", values.crs) setLoadingDesc(`Searching\n${values.crs.toUpperCase()}`)
} else if (values.nlc != ""){ data = await getData('crs', values.crs)
setLoadingDesc(`Searching\n${values.nlc.toUpperCase()}`) } else if (values.nlc != ''){
var data = await getData("nlc", values.nlc) setLoadingDesc(`Searching\n${values.nlc.toUpperCase()}`)
} else if (values.tiploc != ""){ data = await getData('nlc', values.nlc)
setLoadingDesc(`Searching\n${values.tiploc.toUpperCase()}`) } else if (values.tiploc != ''){
var data = await getData("tiploc", values.tiploc) setLoadingDesc(`Searching\n${values.tiploc.toUpperCase()}`)
} else if (values.stanox != ""){ data = await getData('tiploc', values.tiploc)
setLoadingDesc(`Searching\n${values.stanox.toUpperCase()}`) } else if (values.stanox != ''){
var data = await getData("stanox", values.stanox) setLoadingDesc(`Searching\n${values.stanox.toUpperCase()}`)
} else if (values.name != ""){ data = await getData('stanox', values.stanox)
setLoadingDesc(`Searching\n${values.name}`) } else if (values.name != ''){
var data = await getData("name", values.name) setLoadingDesc(`Searching\n${values.name}`)
} else { data = await getData('name', values.name)
log("find-code.parseData: No data entered", "WARN") } else {
await clearForm(); log('find-code.parseData: No data entered', 'WARN')
document.getElementById("name").value = "No data entered" await clearForm()
vibe("err"); document.getElementById('name').value = 'No data entered'
hideLoading(); vibe('err')
return; hideLoading()
} return
displayData(data); }
displayData(data)
} }
async function getData(type, value){ async function getData(type, value){
log(`find-code.getData: Looking for: ${type} '${value}'`, "INFO") log(`find-code.getData: Looking for: ${type} '${value}'`, 'INFO')
try { try {
var url = `${window.location.origin}/api/v1/find/${type}/${value}`; var url = `${window.location.origin}/api/v1/find/${type}/${value}`
var resp = await fetch(url); var resp = await fetch(url)
return await resp.json() return await resp.json()
} catch (err) { } catch (err) {
log(`find-code.getData: Error getting data: ${err}`, "WARN") log(`find-code.getData: Error getting data: ${err}`, 'WARN')
vibe("err") vibe('err')
return ""; return ''
} }
} }
async function displayData(data){ async function displayData(data){
hideLoading(); hideLoading()
if (data.status === "failed" || data == ""){ if (data.status === 'failed' || data == ''){
log(`find-code.displayData: Unable to find data`, "WARN") log('find-code.displayData: Unable to find data', 'WARN')
clearForm(); clearForm()
document.getElementById("name").value = "Not Found"; document.getElementById('name').value = 'Not Found'
} else { } else {
log(`find-code.displayData: Inserting data`, "INFO") log('find-code.displayData: Inserting data', 'INFO')
vibe("ok") vibe('ok')
try { try {
document.getElementById("name").value = data['0']['NLCDESC'] document.getElementById('name').value = data['0']['NLCDESC']
} catch (err) {} } catch (err) {}
try { try {
document.getElementById("3alpha").value = data['0']['3ALPHA'] document.getElementById('3alpha').value = data['0']['3ALPHA']
} catch (err) {} } catch (err) {}
try { try {
document.getElementById("nlc").value = data['0']['NLC'] document.getElementById('nlc').value = data['0']['NLC']
} catch (err) {} } catch (err) {}
try { try {
document.getElementById("tiploc").value = data['0']['TIPLOC'] document.getElementById('tiploc').value = data['0']['TIPLOC']
} catch (err) {} } catch (err) {}
try { try {
document.getElementById("stanox").value = data['0']['STANOX'] document.getElementById('stanox').value = data['0']['STANOX']
} catch (err) {} } catch (err) {}
} }
} }
async function clearForm(){ async function clearForm(){
document.getElementById("name").value = "" document.getElementById('name').value = ''
document.getElementById("3alpha").value = "" document.getElementById('3alpha').value = ''
document.getElementById("nlc").value = "" document.getElementById('nlc').value = ''
document.getElementById("tiploc").value = "" document.getElementById('tiploc').value = ''
document.getElementById("stanox").value = "" document.getElementById('stanox').value = ''
vibe("ok"); vibe('ok')
hideLoading(); hideLoading()
} }

View File

@ -1,27 +1,27 @@
// Init: // Init:
pageInit(); pageInit()
versionDisplay(); versionDisplay()
if ("serviceWorker" in navigator) { if ('serviceWorker' in navigator) {
navigator.serviceWorker.register("/sw.js"); navigator.serviceWorker.register('/sw.js')
} }
async function pageInit() { async function pageInit() {
await loadQuickLinks(); await loadQuickLinks()
hideLoading(); // From lib.main hideLoading() // From lib.main
} }
async function gotoBoard(station){ async function gotoBoard(station){
vibe("ok") vibe('ok')
window.location.assign(`${window.location.origin}/board.html?stn=${station}`); window.location.assign(`${window.location.origin}/board.html?stn=${station}`)
} }
async function loadQuickLinks(){ async function loadQuickLinks(){
var data = await getQuickLinks(); // From lib.main var data = await getQuickLinks() // From lib.main
var buttons = ""; var buttons = ''
for(var i = 0; i < data.length; i++) { for(var i = 0; i < data.length; i++) {
buttons += ` buttons += `
<button class="actionbutton" onclick="gotoBoard('${data[i]}')">${data[i].toUpperCase()}</button>` <button class="actionbutton" onclick="gotoBoard('${data[i]}')">${data[i].toUpperCase()}</button>`
} }
document.getElementById("quick_links").insertAdjacentHTML("beforeend", buttons) document.getElementById('quick_links').insertAdjacentHTML('beforeend', buttons)
} }

View File

@ -1,88 +1,88 @@
init(); init()
async function init() { async function init() {
hideLoading() hideLoading()
} }
async function submit() { async function submit() {
setLoadingDesc("Collecting\nData") setLoadingDesc('Collecting\nData')
showLoading() showLoading()
var browserData = await getBrowserData(); var browserData = await getBrowserData()
setLoadingDesc("Reading\nForm") setLoadingDesc('Reading\nForm')
var formData = await getFormData(); var formData = await getFormData()
preflight({browserData: browserData, formData: formData}) preflight({browserData: browserData, formData: formData})
} }
async function getFormData() { async function getFormData() {
let data = {} let data = {}
data.subject = document.getElementById("subject").value data.subject = document.getElementById('subject').value
data.message = document.getElementById("message").value data.message = document.getElementById('message').value
return data return data
} }
async function getBrowserData() { async function getBrowserData() {
let data = {} let data = {}
data.userAgent = navigator.userAgent data.userAgent = navigator.userAgent
data.userAgentData = JSON.stringify(navigator.userAgentData) data.userAgentData = JSON.stringify(navigator.userAgentData)
data.localStorage = JSON.stringify(await storageAvailable('localStorage')) data.localStorage = JSON.stringify(await storageAvailable('localStorage'))
data.sessionStorage = JSON.stringify(await storageAvailable('sessionStorage')) data.sessionStorage = JSON.stringify(await storageAvailable('sessionStorage'))
data.viewport = `${window.innerWidth} x ${window.innerHeight}` data.viewport = `${window.innerWidth} x ${window.innerHeight}`
return data return data
} }
async function preflight(data) { async function preflight(data) {
document.getElementById("pre_subject").textContent = data.formData.subject document.getElementById('pre_subject').textContent = data.formData.subject
pre_msg = `UserAgent: ${data.browserData.userAgent} pre_msg = `UserAgent: ${data.browserData.userAgent}
\nUserAgentData: ${data.browserData.userAgentData} \nUserAgentData: ${data.browserData.userAgentData}
\nlocalStorage Avail: ${data.browserData.localStorage} \nlocalStorage Avail: ${data.browserData.localStorage}
\nsessionStorage Avail: ${data.browserData.sessionStorage} \nsessionStorage Avail: ${data.browserData.sessionStorage}
\nViewport size: ${data.browserData.viewport} \nViewport size: ${data.browserData.viewport}
\nUser message:\n\n${data.formData.message}` \nUser message:\n\n${data.formData.message}`
document.getElementById("pre_message").innerText = pre_msg document.getElementById('pre_message').innerText = pre_msg
hideLoading() hideLoading()
document.getElementById("preflight").style = "display: block" document.getElementById('preflight').style = 'display: block'
sessionStorage.setItem("preflight_subject", data.formData.subject) sessionStorage.setItem('preflight_subject', data.formData.subject)
sessionStorage.setItem("preflight_msg", pre_msg) sessionStorage.setItem('preflight_msg', pre_msg)
} }
async function cancel() { async function cancel() {
document.getElementById("preflight").style = "display: none" document.getElementById('preflight').style = 'display: none'
} }
async function send() { async function send() {
setLoadingDesc("Sending\nData") setLoadingDesc('Sending\nData')
document.getElementById("preflight").style = "display: none" document.getElementById('preflight').style = 'display: none'
showLoading() showLoading()
var subject = sessionStorage.getItem("preflight_subject"); var subject = sessionStorage.getItem('preflight_subject')
var msg = sessionStorage.getItem("preflight_msg") var msg = sessionStorage.getItem('preflight_msg')
if (typeof subject != "string") { if (typeof subject != 'string') {
subject = document.getElementById("preflight_subject").innerText subject = document.getElementById('preflight_subject').innerText
} }
if (typeof msg != "string") { if (typeof msg != 'string') {
msg = document.getElementById("preflight_msg") msg = document.getElementById('preflight_msg')
} }
var payload = JSON.stringify({subject: subject, msg: msg}) var payload = JSON.stringify({subject: subject, msg: msg})
console.log(payload); console.log(payload)
let opt = { let opt = {
method: 'POST', method: 'POST',
headers: { headers: {
'Content-Type': 'application/json', 'Content-Type': 'application/json',
'Accept': 'application/json' 'Accept': 'application/json'
}, },
redirect: 'follow', redirect: 'follow',
body: payload body: payload
} }
var res = await fetch(`${window.location.origin}/api/v1/issue`, opt) var res = await fetch(`${window.location.origin}/api/v1/issue`, opt)
if (res.status == 200) { if (res.status == 200) {
setLoadingDesc("Success") setLoadingDesc('Success')
vibe("ok") vibe('ok')
await delay(2500) await delay(2500)
window.location.replace("/") window.location.replace('/')
} else { } else {
setLoadingDesc("Error") setLoadingDesc('Error')
vibe("err") vibe('err')
await delay(2500) await delay(2500)
hideLoading() hideLoading()
document.getElementById("preflight").style = "display: none;" document.getElementById('preflight').style = 'display: none;'
} }
} }

View File

@ -1,196 +1,196 @@
/* Fetch Functions */ /* Fetch Functions */
async function publicLdb(stn) { async function publicLdb(stn) {
var url = `${window.location.origin}/api/v1/ldb/${stn}`; var url = `${window.location.origin}/api/v1/ldb/${stn}`
console.time("Time: Fetch LDB Data") console.time('Time: Fetch LDB Data')
var resp = await fetch(url); var resp = await fetch(url)
console.timeEnd("Time: Fetch LDB Data") console.timeEnd('Time: Fetch LDB Data')
return await resp.json(); return await resp.json()
} }
/* Set page heading */ /* Set page heading */
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("stn_name").textContent = title document.getElementById('stn_name').textContent = title
document.getElementById("fetch_time").textContent = time.toLocaleTimeString() document.getElementById('fetch_time').textContent = time.toLocaleTimeString()
sessionStorage.setItem("board_location", title); sessionStorage.setItem('board_location', title)
} }
/* Display No Trains Message */ /* Display No Trains Message */
async function displayNoTrains() { async function displayNoTrains() {
log("No Trains", "WARN") log('No Trains', 'WARN')
document.getElementById('no_services').style = "display: block;"; document.getElementById('no_services').style = 'display: block;'
hideLoading(); hideLoading()
} }
/* Parse the value of `platform` to account for unknown platforms */ /* Parse the value of `platform` to account for unknown platforms */
async function parsePlatform(svc){ async function parsePlatform(svc){
if (svc.platform != undefined) { if (svc.platform != undefined) {
var platform = svc.platform; var platform = svc.platform
} else { } else {
var platform = "-"; var platform = '-'
} }
if (svc.platformChanged) { // Not present in public API, ready for staff version. if (svc.platformChanged) { // Not present in public API, ready for staff version.
var changed = "changed"; var changed = 'changed'
} else { } else {
var changed = ""; var changed = ''
} }
return {num: platform, change: changed} return {num: platform, change: changed}
} }
/* Change value of time strings to fit well on small screens */ /* Change value of time strings to fit well on small screens */
async function parseTime(string){ async function parseTime(string){
switch (string) { switch (string) {
case "Delayed": case 'Delayed':
var output = "LATE"; var output = 'LATE'
var change = "changed"; var change = 'changed'
break; break
case "Cancelled": case 'Cancelled':
var output = "CANC"; var output = 'CANC'
var change = "cancelled"; var change = 'cancelled'
break; break
case "On time": case 'On time':
var output = "RT"; var output = 'RT'
var change = ""; var change = ''
break; break
case "": case '':
var output = "-"; var output = '-'
var change = ""; var change = ''
break; break
case undefined: case undefined:
var output = "-"; var output = '-'
var change = ""; var change = ''
break; break
case "No report": case 'No report':
var output = "-"; var output = '-'
var change = ""; var change = ''
break; break
case "undefined": case 'undefined':
var output = false; var output = false
var change = ""; var change = ''
break; break
default: default:
var output = string; var output = string
var change = "changed"; var change = 'changed'
} }
return {data: output, changed: change}; return {data: output, changed: change}
} }
/* Convert multiple Origin/Destinations to single string */ /* Convert multiple Origin/Destinations to single string */
async function parseName(location) { async function parseName(location) {
if (Array.isArray(location)) { if (Array.isArray(location)) {
var name = `${location[0]['locationName']} & ${location[1]['locationName']}` var name = `${location[0]['locationName']} & ${location[1]['locationName']}`
return name; return name
} }
else { else {
return location.locationName; return location.locationName
} }
} }
// Display Alert Messages // Display Alert Messages
async function displayAlerts(array) { async function displayAlerts(array) {
var counter = 0 var counter = 0
var messages = "" var messages = ''
for(var i = 0; i < array.length; i++) { for(var i = 0; i < array.length; i++) {
// Increment counter // Increment counter
counter += 1; counter += 1
// Reset Vars // Reset Vars
messages += `<p>${array[i]}</p>`; messages += `<p>${array[i]}</p>`
}
if (counter > 0) {
document.getElementById('alerts_msg').insertAdjacentHTML('beforeend', messages)
document.getElementById('alerts').style = 'display:block'
document.getElementById('alerts_bar').style = 'display:block'
if (counter == 1) {
document.getElementById('alert_bar_note').textContent = `There is ${counter} active alert`
} else if (counter > 1) {
document.getElementById('alert_bar_note').textContent = `There are ${counter} active alerts`
} }
if (counter > 0) { return true
document.getElementById("alerts_msg").insertAdjacentHTML("beforeend", messages) }
document.getElementById("alerts").style = "display:block" return false
document.getElementById("alerts_bar").style = "display:block"
if (counter == 1) {
document.getElementById("alert_bar_note").textContent = `There is ${counter} active alert`
} else if (counter > 1) {
document.getElementById("alert_bar_note").textContent = `There are ${counter} active alerts`
}
return true;
}
return false;
} }
/* Show/Hide alerts box */ /* Show/Hide alerts box */
async function inflateAlerts() { async function inflateAlerts() {
document.getElementById("alerts_msg").style = "display:block;"; document.getElementById('alerts_msg').style = 'display:block;'
document.getElementById("alert_expand_arrow").style = "transform: rotate(180deg);"; document.getElementById('alert_expand_arrow').style = 'transform: rotate(180deg);'
document.getElementById("alerts_bar").setAttribute("onclick", "deflateAlerts()") document.getElementById('alerts_bar').setAttribute('onclick', 'deflateAlerts()')
} }
async function deflateAlerts() { async function deflateAlerts() {
document.getElementById("alerts_msg").style = "display.none;"; document.getElementById('alerts_msg').style = 'display.none;'
document.getElementById("alert_expand_arrow").style = "transform: rotate(0deg);"; document.getElementById('alert_expand_arrow').style = 'transform: rotate(0deg);'
document.getElementById("alerts_bar").setAttribute("onclick", "inflateAlerts()") document.getElementById('alerts_bar').setAttribute('onclick', 'inflateAlerts()')
} }
/*//// SERVICE DETAIL LISTS ////*/ /*//// SERVICE DETAIL LISTS ////*/
// Build calling list: -- This outputs calling point data to sessionStorage in the format: key{pre: [{PREVIOUS_Stops}], post: [{POST_STOPS}]} // Build calling list: -- This outputs calling point data to sessionStorage in the format: key{pre: [{PREVIOUS_Stops}], post: [{POST_STOPS}]}
async function buildCallLists(svc) { async function buildCallLists(svc) {
var sSvcId = svc.serviceID; var sSvcId = svc.serviceID
var oSvcData = { var oSvcData = {
plat: svc.platform, plat: svc.platform,
sta: svc.sta, sta: svc.sta,
eta: svc.eta, eta: svc.eta,
std: svc.std, std: svc.std,
etd: svc.etd etd: svc.etd
}; }
try { try {
if (typeof svc.previousCallingPoints.callingPointList.callingPoint != 'undefined') { if (typeof svc.previousCallingPoints.callingPointList.callingPoint != 'undefined') {
let array = await makeArray(svc.previousCallingPoints.callingPointList.callingPoint); let array = await makeArray(svc.previousCallingPoints.callingPointList.callingPoint)
oSvcData.pre = array; oSvcData.pre = array
} }
} catch (err) { /* Do nothing if ERR */ } } catch (err) { /* Do nothing if ERR */ }
try { try {
if (typeof svc.subsequentCallingPoints.callingPointList.callingPoint != 'undefined') { if (typeof svc.subsequentCallingPoints.callingPointList.callingPoint != 'undefined') {
let array = await makeArray(svc.subsequentCallingPoints.callingPointList.callingPoint); let array = await makeArray(svc.subsequentCallingPoints.callingPointList.callingPoint)
oSvcData.post = array; oSvcData.post = array
} }
} catch (err) { /* Do nothing if ERR */ } } catch (err) { /* Do nothing if ERR */ }
sessionStorage.setItem(sSvcId, JSON.stringify(oSvcData)) sessionStorage.setItem(sSvcId, JSON.stringify(oSvcData))
} }
/* Display calling list: - Read data from sessionStorage and write to DOM. */ /* Display calling list: - Read data from sessionStorage and write to DOM. */
async function showCalls(id) { async function showCalls(id) {
log(`Showing details for service ${id}`, "INFO") log(`Showing details for service ${id}`, 'INFO')
var svcDetail = await JSON.parse(sessionStorage.getItem(id)); var svcDetail = await JSON.parse(sessionStorage.getItem(id))
var pre = ""; var pre = ''
var post = ""; var post = ''
if (typeof svcDetail.pre != 'undefined') { if (typeof svcDetail.pre != 'undefined') {
for(var preCall = 0; preCall < svcDetail.pre.length; preCall++) { for(var preCall = 0; preCall < svcDetail.pre.length; preCall++) {
pre += await singleCall(svcDetail.pre[preCall]); pre += await singleCall(svcDetail.pre[preCall])
}
} }
if (typeof svcDetail.post != 'undefined') { }
for(var postCall = 0; postCall < svcDetail.post.length; postCall++) { if (typeof svcDetail.post != 'undefined') {
post += await singleCall(svcDetail.post[postCall]); for(var postCall = 0; postCall < svcDetail.post.length; postCall++) {
} post += await singleCall(svcDetail.post[postCall])
} }
/* Run retreived data through parsers */ }
var thisStd = await parseTime(svcDetail.std); /* Run retreived data through parsers */
var thisEtd = await parseTime(svcDetail.etd); var thisStd = await parseTime(svcDetail.std)
var thisSta = await parseTime(svcDetail.sta); var thisEtd = await parseTime(svcDetail.etd)
var thisEta = await parseTime(svcDetail.eta); var thisSta = await parseTime(svcDetail.sta)
/* Prepare data for this station */ var thisEta = await parseTime(svcDetail.eta)
if (thisStd.data != "-") { /* Prepare data for this station */
var sTime = `${thisStd.data}` if (thisStd.data != '-') {
var eTime = `${thisEtd.data}` var sTime = `${thisStd.data}`
var change = thisEtd.changed var eTime = `${thisEtd.data}`
} else { var change = thisEtd.changed
var sTime = `${thisSta.data}` } else {
var eTime = `${thisEta.data}` var sTime = `${thisSta.data}`
var change = thisEta.changed var eTime = `${thisEta.data}`
}; var change = thisEta.changed
};
let here = `<tr> let here = `<tr>
<td class="detail-name detail-name-here detail-table-content">${sessionStorage.getItem("board_location")}</td> <td class="detail-name detail-name-here detail-table-content">${sessionStorage.getItem('board_location')}</td>
<td class="detail-table-content">${sTime}</td> <td class="detail-table-content">${sTime}</td>
<td class="detail-table-content ${change}">${eTime}</td> <td class="detail-table-content ${change}">${eTime}</td>
</tr> ` </tr> `
/* Prepare then insert DOM Data */ /* Prepare then insert DOM Data */
let dom = ` <div id="${id}" class="call-data"> let dom = ` <div id="${id}" class="call-data">
<p class="close-data" onclick="hideCalls('${id}')">X</p> <p class="close-data" onclick="hideCalls('${id}')">X</p>
<table class="call-table"> <table class="call-table">
<tr> <tr>
@ -204,26 +204,26 @@ async function showCalls(id) {
</table> </table>
</div>` </div>`
document.body.insertAdjacentHTML("beforeend", dom); document.body.insertAdjacentHTML('beforeend', dom)
document.getElementById(id).style = "display: block;"; document.getElementById(id).style = 'display: block;'
return; return
} }
async function hideCalls(id) { async function hideCalls(id) {
let element = document.getElementById(id) let element = document.getElementById(id)
element.style = "display: none;"; element.style = 'display: none;'
element.remove(); element.remove()
return; return
} }
/* Builds the train data information in to a table row */ /* Builds the train data information in to a table row */
async function singleCall(data) { async function singleCall(data) {
if (typeof data.et != "undefined") { if (typeof data.et != 'undefined') {
var time = await parseTime(data.et) var time = await parseTime(data.et)
} else if (typeof data.at != "undefined") { } else if (typeof data.at != 'undefined') {
var time = await parseTime(data.at) var time = await parseTime(data.at)
} }
return `<tr> return `<tr>
<td class="detail-name detail-table-content">${data.locationName}</td> <td class="detail-name detail-table-content">${data.locationName}</td>
<td class="detail-table-content">${data.st}</td> <td class="detail-table-content">${data.st}</td>
<td class="detail-table-content ${time.changed}">${time.data}</td> <td class="detail-table-content ${time.changed}">${time.data}</td>
@ -232,19 +232,19 @@ async function singleCall(data) {
/* Error Handler */ /* Error Handler */
async function errorHandler() { async function errorHandler() {
if (sessionStorage.getItem("failcount")) { if (sessionStorage.getItem('failcount')) {
var errCount = parseInt(sessionStorage.getItem("failcount")) var errCount = parseInt(sessionStorage.getItem('failcount'))
} else { } else {
var errCount = 0; var errCount = 0
} }
errCount += 1; errCount += 1
sessionStorage.setItem("failcount", errCount.toString()) sessionStorage.setItem('failcount', errCount.toString())
if (errCount < 10){ if (errCount < 10){
await delay(3000); await delay(3000)
vibe("err") vibe('err')
location.reload() location.reload()
} else { } else {
sessionStorage.removeItem("failcount"); sessionStorage.removeItem('failcount')
window.location.assign("conn-err.html") window.location.assign('conn-err.html')
} }
} }

View File

@ -1,150 +1,196 @@
/* All Page Init */ /* All Page Init */
const version = "2.0.0-dev"; const version = '2.0.0'
/* Feature Detectors */ /* Feature Detectors */
/* Valid values for ${type}: localstorage, sessionstorage */ /* Valid values for ${type}: localstorage, sessionstorage */
async function storageAvailable(type) { // Currently not used async function storageAvailable(type) { // Currently not used
try { try {
let storage = window[type]; let storage = window[type]
let x = '__storage_test__'; let x = '__storage_test__'
storage.setItem(x, "test"); storage.setItem(x, 'test')
storage.getItem(x); storage.getItem(x)
storage.removeItem(x); storage.removeItem(x)
log(`lib.main.storageAvailable: ${type} is available`, "INFO") log(`lib.main.storageAvailable: ${type} is available`, 'INFO')
return true; return true
} catch (err) { } catch (err) {
log(`lib.main.storageAvailable: ${type} is not available`, "ERR") log(`lib.main.storageAvailable: ${type} is not available`, 'ERR')
return false; return false
} }
} }
async function versionDisplay() { // Outputs version string on to any page with a tag with id="ver_str" async function versionDisplay() { // Outputs version string on to any page with a tag with id="ver_str"
localStorage.setItem("version", version) localStorage.setItem('version', version)
document.getElementById('ver_str').textContent = version document.getElementById('ver_str').textContent = version
return; return
} }
/* Array Converter /* Array Converter
Converts a string to a single item array */ Converts a string to a single item array */
async function makeArray(data) { async function makeArray(data) {
if (!Array.isArray(data)) { if (!Array.isArray(data)) {
var array = []; var array = []
array.push(data); array.push(data)
return array; return array
} }
return data; return data
} }
/* Timeouts */ /* Timeouts */
/* Usage: '' */ /* Usage: '' */
const delay = ms => new Promise(res => setTimeout(res, ms)); const delay = ms => new Promise(res => setTimeout(res, ms))
/* Log Helper */ /* Log Helper */
/* Maintains backwards compatibility for previous /* Maintains backwards compatibility for previous
implementation of log helper */ implementation of log helper */
async function log(msg, type) { async function log(msg, type) {
const mode = "dev" const mode = 'tst'
if (mode === "prod" && type != "ERR") { if (mode === 'prod' && type != 'ERR') {
return; return
} }
var time = new Date().toISOString(); var time = new Date().toISOString()
switch (type) { switch (type) {
case "ERR": case 'ERR':
console.error(`${time} - ${msg}`); console.error(`${time} - ${msg}`)
break; break
case "WARN": case 'WARN':
console.warn(`${time} - ${msg}`); console.warn(`${time} - ${msg}`)
break; break
case "INFO": case 'INFO':
console.info(`${time} - ${msg}`); console.info(`${time} - ${msg}`)
break; break
default: default:
console.log(`${time} - ${msg}`); console.log(`${time} - ${msg}`)
break; break
}; }
}; }
/* Show/Hide - Menu Control */ /* Show/Hide - Menu Control */
async function sidebarOpen() { async function sidebarOpen() {
document.getElementById("sidebar").style.width = "50%"; document.getElementById('sidebar').style.width = '50%'
document.getElementById("sidebar_open_short").style.display = "none"; document.getElementById('sidebar_open_short').style.display = 'none'
document.getElementById("sidebar_close_short").style.display = "block"; document.getElementById('sidebar_close_short').style.display = 'block'
} }
async function sidebarClose() { async function sidebarClose() {
document.getElementById("sidebar").style.width = "0%" document.getElementById('sidebar').style.width = '0%'
document.getElementById("sidebar_open_short").style.display = "block"; document.getElementById('sidebar_open_short').style.display = 'block'
document.getElementById("sidebar_close_short").style.display = "none"; document.getElementById('sidebar_close_short').style.display = 'none'
} }
/* Loading Box Control */ /* Loading Box Control */
async function hideLoading() { async function hideLoading() {
document.getElementById("loading").style = "display: none;"; document.getElementById('loading').style = 'display: none;'
} }
/* DEPRECIATED: Alias for hideLoading() - Marked for removal*/ /* DEPRECIATED: Alias for hideLoading() - Marked for removal*/
async function clearLoading() { async function clearLoading() {
log("Depreciated function called - clearLoading() - Alias to hideLoading()", "WARN") log('Depreciated function called - clearLoading() - Alias to hideLoading()', 'WARN')
hideLoading(); hideLoading()
} }
async function showLoading() { async function showLoading() {
document.getElementById("loading").style = "display: block;"; document.getElementById('loading').style = 'display: block;'
} }
async function setLoadingDesc(desc) { async function setLoadingDesc(desc) {
document.getElementById("loading_desc").textContent = `${desc}`; document.getElementById('loading_desc').textContent = `${desc}`
} }
/* Fetch User Settings */ /* Fetch User Settings */
async function getQuickLinks() { async function getQuickLinks() {
var defaults = var defaults =
["bri","lwh","srd","mtp","rda","cfn", ['bri','lwh','srd','mtp','rda','cfn',
"sml","shh","pri","avn","sar","svb"]; 'sml','shh','pri','avn','sar','svb']
try { try {
if (localStorage.getItem("qlOpt")) { if (localStorage.getItem('qlOpt')) {
var data = JSON.parse(localStorage.getItem("qlOpt")); var data = JSON.parse(localStorage.getItem('qlOpt'))
} else { } else {
data = defaults; data = defaults
}
} catch (err) {
data = defaults;
} }
return data.sort(); } catch (err) {
data = defaults
}
return data.sort()
} }
/* Fetch a known query parameter from the pages URL */ /* Fetch a known query parameter from the pages URL */
async function getQuery(param) { async function getQuery(param) {
var params = new URLSearchParams(window.location.search) var params = new URLSearchParams(window.location.search)
var query = params.get(param) var query = params.get(param)
if (query) { if (query) {
return query return query
} else { } else {
return 'false' return 'false'
} }
} }
async function vibe(type) { // Offers three standard vibration patterns for consistency async function getApi(path,auth = false) {
let canVibrate = "vibrate" in navigator || "mozVibrate" in navigator let apiVer = 'v1'
if (canVibrate && !("vibrate" in navigator)){ let url = `${window.location.origin}/api/${apiVer}/${path}`
navigator.vibrate = navigator.mozVibrate log(`getApi: Fetching from endpoint: ${url}, Auth=${auth}`)
if (auth) {
let key = localStorage.getItem('uuid')
var options = {
method: 'GET',
redirect: 'follow',
headers: {
'uuid': key
}
} }
switch (type) { } else {
case "err": var options = {
navigator.vibrate([300]) method: 'GET',
break; redirect: 'follow'
case "ok":
navigator.vibrate([50,50,50])
break;
default:
navigator.vibrate(30)
} }
}
try {
var resp = await fetch(url, options)
var json = await resp.json()
log(`resp.status: ${resp.status}`)
log(`resp.json: ${json}`)
if (resp.status != 200) {
log(`lib.main: getApi: Response status: ${resp.status}`)
return resp.status
}
if (!resp.ok) {
log('lib.main: getApi: Fetch error')
return false
}
return json
} catch(err) {
log(`lib.main: getApi: Caught fetch error. Status: ${resp.status}`)
return resp.status
}
}
async function showHideAuthNotice() {
let uuid = localStorage.getItem('uuid')
if (uuid) {
document.getElementById('auth-required').style = 'display:none'
}
}
async function vibe(type) {
let canVibrate = 'vibrate' in navigator || 'mozVibrate' in navigator
if (canVibrate && !('vibrate' in navigator)){
navigator.vibrate = navigator.mozVibrate
}
switch (type) {
case 'err':
navigator.vibrate([300])
break
case 'ok':
navigator.vibrate([50,50,50])
break
default:
navigator.vibrate(30)
}
} }
async function convertUnixLocal(unix) { // Convert unix time string to local async function convertUnixLocal(unix) { // Convert unix time string to local
var jsTime = unix*1000 var jsTime = unix*1000
var dt = new Date(jsTime) var dt = new Date(jsTime)
return dt.toLocaleString() return dt.toLocaleString()
} }

75
js/pis.js Normal file
View File

@ -0,0 +1,75 @@
hideLoading()
versionDisplay()
showHideAuthNotice()
async function findByOrigDest() {
showLoading()
const formData = await fetchOrigDest()
log(`findByOrigDest: Searching for PIS Code for ${JSON.stringify(formData)}`)
const endpoint = `pis/origdest/${formData.origin}/${formData.destination}`
console.time('findByOrigDest-GET')
const json = await getApi(endpoint, auth = true)
console.timeEnd('findByOrigDest-GET')
if (json == false) {
await displayNoData()
} else if (json == 401) {
await displayUnauthorised()
} else {
await insertData(json)
}
document.getElementById('crs-box').style = 'display:none'
document.getElementById('result-box').style = 'display:block'
hideLoading()
}
async function fetchOrigDest() {
var orig = document.getElementById('origin').value
var dest = document.getElementById('destination').value
return {origin: orig, destination: dest}
}
async function insertData(json) {
// Receives the JSON Respose ([{},{}]) containing one or more possible
// PIS codes. Display the code and the stops with a method of scrolling between them.
// Maybe as a table or a carousel?
console.time('insertData')
const div = document.getElementById('result-box')
let tableData = `<table id="result-table">
<tr>
<th>Code</th>
<th>Stations</th>
</tr>`
let results = 0
for(var i = 0; i < json.length; i++) { // Hopefully can style output with CSS
tableData += `<tr><td class="pis-code">${json[i]['code']}</td>
<td class="station">${json[i]['stops'].join(', ')}</td></tr>`
results++
}
tableData += '</table>'
div.insertAdjacentHTML('beforeend', tableData)
document.getElementById('result-count').textContent = results.toString()
console.timeEnd('insertData')
}
async function displayNoData() {
const msg = '<p id="result-table">No results found</p>'
document.getElementById('result-box').insertAdjacentHTML('beforeend', msg)
}
async function displayUnauthorised() {
const msg = '<p id="result-table">Unauthorised - please ensure you are logged into the <a href="./settings.html">rail staff version</a></p>'
document.getElementById('result-box').insertAdjacentHTML('beforeend', msg)
}
async function reset() {
try {
document.getElementById('origin').value = ''
document.getElementById('destination').value = ''
document.getElementById('result-box').style = 'display:none'
document.getElementById('result-table').remove()
document.getElementById('crs-box').style = 'display:block'
document.getElementById('result-count').textContent = 0
} catch(e) {
log('Nothing to reset')
}
}

View File

@ -2,114 +2,114 @@
// Init: // Init:
// //
// Setup quick links // Setup quick links
const ql = ["ql0","ql1","ql2","ql3","ql4","ql5","ql6","ql7","ql8","ql9","ql10","ql11"] const ql = ['ql0','ql1','ql2','ql3','ql4','ql5','ql6','ql7','ql8','ql9','ql10','ql11']
storageAvailable("localStorage"); storageAvailable('localStorage')
getQl(); getQl()
// Check if already registered // Check if already registered
ifAlreadyRegistered(); ifAlreadyRegistered()
// Hide loading // Hide loading
hideLoading(); hideLoading()
async function ifAlreadyRegistered() { // If already registered, show this on the page async function ifAlreadyRegistered() { // If already registered, show this on the page
if (! await isRegistered()) { if (! await isRegistered()) {
return null return null
} else { } else {
document.getElementsByName("eml")[0].placeholder = "Registered"; document.getElementsByName('eml')[0].placeholder = 'Registered'
document.getElementById("reg_text").textContent = "You are already registered"; document.getElementById('reg_text').textContent = 'You are already registered'
document.getElementById("reg_button").textContent = "Log Out"; document.getElementById('reg_button').textContent = 'Log Out'
} }
} }
async function getQl(){ // Fetch Quick Links from localstorage async function getQl(){ // Fetch Quick Links from localstorage
var qlOpt = await getQuickLinks() var qlOpt = await getQuickLinks()
if (qlOpt){ if (qlOpt){
var i = 0 var i = 0
while (i < 12) { while (i < 12) {
if (qlOpt[i] != 'undefined') { if (qlOpt[i] != 'undefined') {
document.getElementById(`ql${i}`).value = qlOpt[i] document.getElementById(`ql${i}`).value = qlOpt[i]
i +=1 i +=1
} }
}
} }
}
} }
async function setQl(){ // Fetch Quick Links from text input and save to localstorage async function setQl(){ // Fetch Quick Links from text input and save to localstorage
await showLoading();// called as an onclick function await showLoading()// called as an onclick function
var qlSet = [] var qlSet = []
for (i in ql) { for (i in ql) {
var opt = document.getElementById(`ql${i}`).value var opt = document.getElementById(`ql${i}`).value
if (opt != ""){ if (opt != ''){
qlSet.push(opt) qlSet.push(opt)
}
qlSet.sort()
} }
localStorage.setItem("qlOpt", JSON.stringify(qlSet)) qlSet.sort()
log(`settings.setQl: User settings saved`, "INFO") }
await hideLoading(); localStorage.setItem('qlOpt', JSON.stringify(qlSet))
await showDone(); log('settings.setQl: User settings saved', 'INFO')
vibe("ok") await hideLoading()
await delay(800); await showDone()
hideDone(); vibe('ok')
await delay(800)
hideDone()
} }
async function clearQl(){ // Clear Quick Links from localstorage async function clearQl(){ // Clear Quick Links from localstorage
showLoading(); showLoading()
localStorage.removeItem("qlOpt") localStorage.removeItem('qlOpt')
log(`settings.setQl: User settings reset to default`, "INFO") log('settings.setQl: User settings reset to default', 'INFO')
getQl() getQl()
await hideLoading(); await hideLoading()
await showDone(); await showDone()
vibe("ok"); vibe('ok')
await delay(800); await delay(800)
hideDone(); hideDone()
} }
async function isRegistered() { // Check if a device is registered, returns BOOL async function isRegistered() { // Check if a device is registered, returns BOOL
if (localStorage.getItem("uuid")) { if (localStorage.getItem('uuid')) {
return true return true
// Also need an API Call here to check if auth is working. // Also need an API Call here to check if auth is working.
// A Suitable function exists in auth.js - move it to lib.main.js // A Suitable function exists in auth.js - move it to lib.main.js
} }
localStorage.removeItem("uuid"); localStorage.removeItem('uuid')
return false return false
} }
async function register() { // Registers a device by sending POST request to API Server async function register() { // Registers a device by sending POST request to API Server
if (! await isRegistered()) { if (! await isRegistered()) {
showLoading() showLoading()
let url = `${window.location.origin}/api/v1/register/request`; let url = `${window.location.origin}/api/v1/register/request`
let email = document.getElementById("eml").value let email = document.getElementById('eml').value
let res = await fetch(url, { let res = await fetch(url, {
method: "POST", method: 'POST',
headers: { headers: {
"Content-Type": "application/json" 'Content-Type': 'application/json'
}, },
redirect: "follow", redirect: 'follow',
body: JSON.stringify({email: email}) body: JSON.stringify({email: email})
}) })
if (res.status == 201) { if (res.status == 201) {
showDone(); showDone()
hideLoading(); hideLoading()
return; return
} else if (res.status == 403) { } else if (res.status == 403) {
log(`settings.register: Error: Fetch returned: ${res.body['errorCode']}`, "err") log(`settings.register: Error: Fetch returned: ${res.body['errorCode']}`, 'err')
document.getElementsByName("eml")[0].placeholder = "Not Authorised"; document.getElementsByName('eml')[0].placeholder = 'Not Authorised'
}
} else {
logout()
} }
} else {
logout()
}
} }
async function logout() { // Simply removed the UUID from localstorage async function logout() { // Simply removed the UUID from localstorage
localStorage.removeItem("uuid"); localStorage.removeItem('uuid')
location.reload(); location.reload()
return return
} }
async function showDone() { // Diaplays the 'Done' dialogue. async function showDone() { // Diaplays the 'Done' dialogue.
document.getElementById("done").style = "opacity: 1; display: block"; document.getElementById('done').style = 'opacity: 1; display: block'
} }
async function hideDone() { // Hides the 'Done' dialogue. async function hideDone() { // Hides the 'Done' dialogue.
document.getElementById("done").style = "opacity: 0; display: none"; document.getElementById('done').style = 'opacity: 0; display: none'
} }

View File

@ -4,128 +4,128 @@ init()
/* Init function */ /* Init function */
async function init() { // Gets query string and then fetch API response and pass to parsing function async function init() { // Gets query string and then fetch API response and pass to parsing function
console.time("Time: Init to Complete") console.time('Time: Init to Complete')
setLoadingDesc(`Loading\nservices`) setLoadingDesc('Loading\nservices')
var stn = await getQuery("stn"); var stn = await getQuery('stn')
setLoadingDesc(`Loading\n${stn.toUpperCase()}`) setLoadingDesc(`Loading\n${stn.toUpperCase()}`)
log(`init: Looking up: ${stn}`); log(`init: Looking up: ${stn}`)
var sv = await getQuery("sv"); var sv = await getQuery('sv')
log(`init: Staff Version: ${sv}`); log(`init: Staff Version: ${sv}`)
if (sv === 'true') { if (sv === 'true') {
log("init: Staff Version not supported yet.") log('init: Staff Version not supported yet.')
log("init: Unable to proceed.") log('init: Unable to proceed.')
} else { } else {
try { try {
var data = await publicLdb(stn) var data = await publicLdb(stn)
setLoadingDesc(`${stn.toUpperCase()}\nParsing Data`) setLoadingDesc(`${stn.toUpperCase()}\nParsing Data`)
log("simple-board.init: Fetched LDB Data", "INFO") log('simple-board.init: Fetched LDB Data', 'INFO')
} catch (err) { } catch (err) {
var data = "err" var data = 'err'
setLoadingDesc(`Waiting\nConnection`) setLoadingDesc('Waiting\nConnection')
log(`simple-board.init: Error fetching data: ${err}`, "ERR") log(`simple-board.init: Error fetching data: ${err}`, 'ERR')
}
parseLdb(data)
} }
parseLdb(data)
}
} }
/* Check for any errors in data returned from the Fetch call /* Check for any errors in data returned from the Fetch call
If no errors, if there are none, call buildPage(). */ If no errors, if there are none, call buildPage(). */
async function parseLdb(data) { async function parseLdb(data) {
if (data.ERROR == "NOT_FOUND") { // Station not found if (data.ERROR == 'NOT_FOUND') { // Station not found
hideLoading(); hideLoading()
document.getElementById("error_notice").style = "display: block;"; document.getElementById('error_notice').style = 'display: block;'
document.getElementById("err_not_found").style = "display: block;"; document.getElementById('err_not_found').style = 'display: block;'
setHeaders("Not Found",new Date()) setHeaders('Not Found',new Date())
} else if (data == false) { // No data for station } else if (data == false) { // No data for station
hideLoading(); hideLoading()
document.getElementById("error_notice").style = "display: block;"; document.getElementById('error_notice').style = 'display: block;'
document.getElementById("err_no_data").style = "display:block;"; document.getElementById('err_no_data').style = 'display:block;'
setHeaders("No Data",new Date()) setHeaders('No Data',new Date())
} else if (data == "err") { // Connection Error } else if (data == 'err') { // Connection Error
await delay(2000); await delay(2000)
hideLoading(); hideLoading()
document.getElementById("error_notice").style = "display: block;"; document.getElementById('error_notice').style = 'display: block;'
document.getElementById("err_conn").style = "display: block;"; document.getElementById('err_conn').style = 'display: block;'
setHeaders("Connection Error",new Date()) setHeaders('Connection Error',new Date())
showLoading(); showLoading()
await delay(5000); await delay(5000)
log(`parseLdb: Passing to error handler`, "ERR") log('parseLdb: Passing to error handler', 'ERR')
errorHandler(); errorHandler()
} else { } else {
buildPage(data); buildPage(data)
} }
} }
// Build and Display Functions // Build and Display Functions
async function buildPage(data) { async function buildPage(data) {
setLoadingDesc('Loading\nData') setLoadingDesc('Loading\nData')
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)
log(`buildPage: 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 // Check for notices and if true pass to function
if (data.GetStationBoardResult.nrccMessages) { if (data.GetStationBoardResult.nrccMessages) {
setLoadingDesc('Loading\nAlerts') setLoadingDesc('Loading\nAlerts')
await displayAlerts(await makeArray(data.GetStationBoardResult.nrccMessages.message)); await displayAlerts(await makeArray(data.GetStationBoardResult.nrccMessages.message))
} }
if (data.GetStationBoardResult.trainServices) { if (data.GetStationBoardResult.trainServices) {
setLoadingDesc('Loading\nTrains') setLoadingDesc('Loading\nTrains')
displayTrains(await makeArray(data.GetStationBoardResult.trainServices.service)) displayTrains(await makeArray(data.GetStationBoardResult.trainServices.service))
} else { } else {
displayNoTrains() displayNoTrains()
} }
if (data.GetStationBoardResult.ferryServices) { if (data.GetStationBoardResult.ferryServices) {
setLoadingDesc('Loading\nFerries') setLoadingDesc('Loading\nFerries')
displayFerry(await makeArray(data.GetStationBoardResult.ferryServices.service)) displayFerry(await makeArray(data.GetStationBoardResult.ferryServices.service))
} }
if (data.GetStationBoardResult.busServices) { if (data.GetStationBoardResult.busServices) {
setLoadingDesc('Loading\nBusses') setLoadingDesc('Loading\nBusses')
displayBus(await makeArray(data.GetStationBoardResult.busServices.service)) displayBus(await makeArray(data.GetStationBoardResult.busServices.service))
} }
hideLoading(); hideLoading()
console.timeEnd("Time: Init to Complete") console.timeEnd('Time: Init to Complete')
} }
async function displayTrains(data) { // Iterated through train services and passes API sections to other functions async function displayTrains(data) { // Iterated through train services and passes API sections to other functions
log(`simple-board.displayTrains: Inserting data in DOM`) log('simple-board.displayTrains: Inserting data in DOM')
for(var i = 0; i < data.length; i++) { for(var i = 0; i < data.length; i++) {
// Reset Vars // Reset Vars
var svc = data[i]; var svc = data[i]
displayService(svc); displayService(svc)
buildCallLists(svc); buildCallLists(svc)
} }
document.getElementById("output").style = "display:block;"; document.getElementById('output').style = 'display:block;'
log(`simple-board.displayTrains: Insertion complete`) log('simple-board.displayTrains: Insertion complete')
} }
async function displayFerry(ferrySvc) { // Iterates through each ferry service and passes to another function async function displayFerry(ferrySvc) { // Iterates through each ferry service and passes to another function
for(var i = 0; i < ferrySvc.length; i++) { for(var i = 0; i < ferrySvc.length; i++) {
displayFerryService(ferrySvc[i]) displayFerryService(ferrySvc[i])
} }
} }
async function displayBus(busSvc) { // Iterates through each bus service and passes to other functions. async function displayBus(busSvc) { // Iterates through each bus service and passes to other functions.
for(var i = 0; i < busSvc.length; i++) { for(var i = 0; i < busSvc.length; i++) {
displayBusService(busSvc[i]) displayBusService(busSvc[i])
buildCallLists(busSvc[i]) buildCallLists(busSvc[i])
} }
} }
async function displayService(svc) { // Creates a table row from each train service. async function displayService(svc) { // Creates a table row from each train service.
var table = document.getElementById("output"); var table = document.getElementById('output')
// Determine Time Message // Determine Time Message
var sta = await parseTime(svc.sta); var sta = await parseTime(svc.sta)
var eta = await parseTime(svc.eta); var eta = await parseTime(svc.eta)
var std = await parseTime(svc.std); var std = await parseTime(svc.std)
var etd = await parseTime(svc.etd); var etd = await parseTime(svc.etd)
// Determine Platform Message // Determine Platform Message
//if (svc.platform != undefined){var plt = svc.platform} else {var plt = "-"}; //if (svc.platform != undefined){var plt = svc.platform} else {var plt = "-"};
var plt = await parsePlatform(svc); var plt = await parsePlatform(svc)
// Define Table Row // Define Table Row
var row = ` var row = `
<table> <table>
<tr> <tr>
<td class="name name-item" onclick="showCalls('${svc.serviceID}')">${await parseName(svc.origin.location)}</td> <td class="name name-item" onclick="showCalls('${svc.serviceID}')">${await parseName(svc.origin.location)}</td>
@ -137,41 +137,41 @@ async function displayService(svc) { // Creates a table row from each train serv
<td class="time ${etd.changed}">${etd.data}</td> <td class="time ${etd.changed}">${etd.data}</td>
</tr> </tr>
</table>` </table>`
// Put Table Row // Put Table Row
table.insertAdjacentHTML("beforeend", row) table.insertAdjacentHTML('beforeend', row)
// Display Operator where provided (it always will be, I think) // Display Operator where provided (it always will be, I think)
if (svc.operator) { if (svc.operator) {
var opRow = `<p class="msg op">A ${svc.operator} service` var opRow = `<p class="msg op">A ${svc.operator} service`
if (svc.length) { // Displays number of carriages where provided if (svc.length) { // Displays number of carriages where provided
opRow += ` with ${svc.length} carriages</p>`; opRow += ` with ${svc.length} carriages</p>`
} else { } else {
opRow += `</p>` opRow += '</p>'
}
table.insertAdjacentHTML("beforeend", opRow);
}
// Parse cancelReason and then delayReason
if (svc.cancelReason) {
var cancelRow = `<p class="msg">${svc.cancelReason}</p>`
table.insertAdjacentHTML("beforeend", cancelRow);
}
if (svc.delayReason) {
var delayRow = `<p class="msg">${svc.delayReason}</p>`
table.insertAdjacentHTML("beforeend", delayRow);
} }
table.insertAdjacentHTML('beforeend', opRow)
}
// Parse cancelReason and then delayReason
if (svc.cancelReason) {
var cancelRow = `<p class="msg">${svc.cancelReason}</p>`
table.insertAdjacentHTML('beforeend', cancelRow)
}
if (svc.delayReason) {
var delayRow = `<p class="msg">${svc.delayReason}</p>`
table.insertAdjacentHTML('beforeend', delayRow)
}
} }
async function displayFerryService(svc) { // Creates a table for for each ferry service async function displayFerryService(svc) { // Creates a table for for each ferry service
var table = document.getElementById("ferry"); var table = document.getElementById('ferry')
log(JSON.stringify(svc)) log(JSON.stringify(svc))
// Determine Time Message // Determine Time Message
var sta = await parseTime(svc.sta); var sta = await parseTime(svc.sta)
var eta = await parseTime(svc.eta); var eta = await parseTime(svc.eta)
var std = await parseTime(svc.std); var std = await parseTime(svc.std)
var etd = await parseTime(svc.etd); var etd = await parseTime(svc.etd)
// Determine Platform Message // Determine Platform Message
var plt = ""; var plt = ''
// Define Table Row // Define Table Row
var row = ` var row = `
<table> <table>
<tr> <tr>
<td class="name name-item">${await parseName(svc.origin.location)}</td> <td class="name name-item">${await parseName(svc.origin.location)}</td>
@ -183,32 +183,32 @@ async function displayFerryService(svc) { // Creates a table for for each ferry
<td class="time ${etd.changed}">${etd.data}</td> <td class="time ${etd.changed}">${etd.data}</td>
</tr> </tr>
</table>` </table>`
// Put Table Row // Put Table Row
table.insertAdjacentHTML("beforeend", row) table.insertAdjacentHTML('beforeend', row)
// Parse cancelReason & delayReason // Parse cancelReason & delayReason
if (svc.cancelReason) { if (svc.cancelReason) {
var cancelRow = `<p class="msg">${svc.cancelReason}</p>` var cancelRow = `<p class="msg">${svc.cancelReason}</p>`
table.insertAdjacentHTML("beforeend", cancelRow); table.insertAdjacentHTML('beforeend', cancelRow)
} }
if (svc.delayReason) { if (svc.delayReason) {
var delayRow = `<p class="msg">${svc.delayReason}</p>` var delayRow = `<p class="msg">${svc.delayReason}</p>`
table.insertAdjacentHTML("beforeend", delayRow); table.insertAdjacentHTML('beforeend', delayRow)
} }
document.getElementById("ferry").style = "display:block" document.getElementById('ferry').style = 'display:block'
} }
async function displayBusService(svc) { // Creates a table row for each bus service. async function displayBusService(svc) { // Creates a table row for each bus service.
var table = document.getElementById("bus"); var table = document.getElementById('bus')
log(JSON.stringify(svc)) log(JSON.stringify(svc))
// Determine Time Message // Determine Time Message
var sta = await parseTime(svc.sta); var sta = await parseTime(svc.sta)
var eta = await parseTime(svc.eta); var eta = await parseTime(svc.eta)
var std = await parseTime(svc.std); var std = await parseTime(svc.std)
var etd = await parseTime(svc.etd); var etd = await parseTime(svc.etd)
// Determine Platform Message // Determine Platform Message
var plt = ""; var plt = ''
// Define Table Row // Define Table Row
var row = ` var row = `
<table> <table>
<tr> <tr>
<td class="name name-item" onclick="showCalls('${svc.serviceID}')">${svc.origin.location.locationName}</td> <td class="name name-item" onclick="showCalls('${svc.serviceID}')">${svc.origin.location.locationName}</td>
@ -220,21 +220,21 @@ async function displayBusService(svc) { // Creates a table row for each bus serv
<td class="time ${etd.changed}">${etd.data}</td> <td class="time ${etd.changed}">${etd.data}</td>
</tr> </tr>
</table>` </table>`
// Put Table Row // Put Table Row
table.insertAdjacentHTML("beforeend", row) table.insertAdjacentHTML('beforeend', row)
// Display operator // Display operator
if (svc.operator) { if (svc.operator) {
var opRow = `<p class="msg op">A ${svc.operator} service</p>` var opRow = `<p class="msg op">A ${svc.operator} service</p>`
table.insertAdjacentHTML("beforeend", opRow); table.insertAdjacentHTML('beforeend', opRow)
} }
// Parse cancelReason & delayReason // Parse cancelReason & delayReason
if (svc.cancelReason) { if (svc.cancelReason) {
var cancelRow = `<p class="msg">${svc.cancelReason}</p>` var cancelRow = `<p class="msg">${svc.cancelReason}</p>`
table.insertAdjacentHTML("beforeend", cancelRow); table.insertAdjacentHTML('beforeend', cancelRow)
} }
if (svc.delayReason) { if (svc.delayReason) {
var delayRow = `<p class="msg">${svc.delayReason}</p>` var delayRow = `<p class="msg">${svc.delayReason}</p>`
table.insertAdjacentHTML("beforeend", delayRow); table.insertAdjacentHTML('beforeend', delayRow)
} }
document.getElementById("bus").style = "display:block" document.getElementById('bus').style = 'display:block'
} }

View File

@ -4,128 +4,129 @@ init()
/* Init function */ /* Init function */
async function init() { // Gets query string and then fetch API response and pass to parsing function async function init() { // Gets query string and then fetch API response and pass to parsing function
console.time("Time: Init to Complete") console.time('Time: Init to Complete')
setLoadingDesc(`Loading\nservices`) setLoadingDesc('Loading\nservices')
var stn = await getQuery("stn"); var stn = await getQuery('stn')
setLoadingDesc(`Loading\n${stn.toUpperCase()}`) setLoadingDesc(`Loading\n${stn.toUpperCase()}`)
log(`init: Looking up: ${stn}`); log(`init: Looking up: ${stn}`)
var sv = await getQuery("sv"); var sv = await getQuery('sv')
log(`init: Staff Version: ${sv}`); log(`init: Staff Version: ${sv}`)
if (sv === 'true') { if (sv === 'true') {
log("init: Staff Version not supported yet.") log('init: Staff Version not supported yet.')
log("init: Unable to proceed.") log('init: Unable to proceed.')
} else { } else {
try { let data
var data = await publicLdb(stn) try {
setLoadingDesc(`${stn.toUpperCase()}\nParsing Data`) data = await publicLdb(stn)
log("simple-board.init: Fetched LDB Data", "INFO") setLoadingDesc(`${stn.toUpperCase()}\nParsing Data`)
} catch (err) { log('simple-board.init: Fetched LDB Data', 'INFO')
var data = "err" } catch (err) {
setLoadingDesc(`Waiting\nConnection`) data = 'err'
log(`simple-board.init: Error fetching data: ${err}`, "ERR") setLoadingDesc('Waiting\nConnection')
} log(`simple-board.init: Error fetching data: ${err}`, 'ERR')
parseLdb(data)
} }
parseLdb(data)
}
} }
/* Check for any errors in data returned from the Fetch call /* Check for any errors in data returned from the Fetch call
If no errors, if there are none, call buildPage(). */ If no errors, if there are none, call buildPage(). */
async function parseLdb(data) { async function parseLdb(data) {
if (data.ERROR == "NOT_FOUND") { // Station not found if (data.ERROR == 'NOT_FOUND') { // Station not found
hideLoading(); hideLoading()
document.getElementById("error_notice").style = "display: block;"; document.getElementById('error_notice').style = 'display: block;'
document.getElementById("err_not_found").style = "display: block;"; document.getElementById('err_not_found').style = 'display: block;'
setHeaders("Not Found",new Date()) setHeaders('Not Found',new Date())
} else if (data == false) { // No data for station } else if (data == false) { // No data for station
hideLoading(); hideLoading()
document.getElementById("error_notice").style = "display: block;"; document.getElementById('error_notice').style = 'display: block;'
document.getElementById("err_no_data").style = "display:block;"; document.getElementById('err_no_data').style = 'display:block;'
setHeaders("No Data",new Date()) setHeaders('No Data',new Date())
} else if (data == "err") { // Connection Error } else if (data == 'err') { // Connection Error
await delay(2000); await delay(2000)
hideLoading(); hideLoading()
document.getElementById("error_notice").style = "display: block;"; document.getElementById('error_notice').style = 'display: block;'
document.getElementById("err_conn").style = "display: block;"; document.getElementById('err_conn').style = 'display: block;'
setHeaders("Connection Error",new Date()) setHeaders('Connection Error',new Date())
showLoading(); showLoading()
await delay(5000); await delay(5000)
log(`parseLdb: Passing to error handler`, "ERR") log('parseLdb: Passing to error handler', 'ERR')
errorHandler(); errorHandler()
} else { } else {
buildPage(data); buildPage(data)
} }
} }
// Build and Display Functions // Build and Display Functions
async function buildPage(data) { async function buildPage(data) {
setLoadingDesc('Loading\nData') setLoadingDesc('Loading\nData')
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)
log(`buildPage: 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 // Check for notices and if true pass to function
if (data.GetStationBoardResult.nrccMessages) { if (data.GetStationBoardResult.nrccMessages) {
setLoadingDesc('Loading\nAlerts') setLoadingDesc('Loading\nAlerts')
await displayAlerts(await makeArray(data.GetStationBoardResult.nrccMessages.message)); await displayAlerts(await makeArray(data.GetStationBoardResult.nrccMessages.message))
} }
if (data.GetStationBoardResult.trainServices) { if (data.GetStationBoardResult.trainServices) {
setLoadingDesc('Loading\nTrains') setLoadingDesc('Loading\nTrains')
displayTrains(await makeArray(data.GetStationBoardResult.trainServices.service)) displayTrains(await makeArray(data.GetStationBoardResult.trainServices.service))
} else { } else {
displayNoTrains() displayNoTrains()
} }
if (data.GetStationBoardResult.ferryServices) { if (data.GetStationBoardResult.ferryServices) {
setLoadingDesc('Loading\nFerries') setLoadingDesc('Loading\nFerries')
displayFerry(await makeArray(data.GetStationBoardResult.ferryServices.service)) displayFerry(await makeArray(data.GetStationBoardResult.ferryServices.service))
} }
if (data.GetStationBoardResult.busServices) { if (data.GetStationBoardResult.busServices) {
setLoadingDesc('Loading\nBusses') setLoadingDesc('Loading\nBusses')
displayBus(await makeArray(data.GetStationBoardResult.busServices.service)) displayBus(await makeArray(data.GetStationBoardResult.busServices.service))
} }
hideLoading(); hideLoading()
console.timeEnd("Time: Init to Complete") console.timeEnd('Time: Init to Complete')
} }
async function displayTrains(data) { // Iterated through train services and passes API sections to other functions async function displayTrains(data) { // Iterated through train services and passes API sections to other functions
log(`simple-board.displayTrains: Inserting data in DOM`) log('simple-board.displayTrains: Inserting data in DOM')
for(var i = 0; i < data.length; i++) { for(var i = 0; i < data.length; i++) {
// Reset Vars // Reset Vars
var svc = data[i]; var svc = data[i]
displayService(svc); displayService(svc)
buildCallLists(svc); buildCallLists(svc)
} }
document.getElementById("output").style = "display:block;"; document.getElementById('output').style = 'display:block;'
log(`simple-board.displayTrains: Insertion complete`) log('simple-board.displayTrains: Insertion complete')
} }
async function displayFerry(ferrySvc) { // Iterates through each ferry service and passes to another function async function displayFerry(ferrySvc) { // Iterates through each ferry service and passes to another function
for(var i = 0; i < ferrySvc.length; i++) { for(var i = 0; i < ferrySvc.length; i++) {
displayFerryService(ferrySvc[i]) displayFerryService(ferrySvc[i])
} }
} }
async function displayBus(busSvc) { // Iterates through each bus service and passes to other functions. async function displayBus(busSvc) { // Iterates through each bus service and passes to other functions.
for(var i = 0; i < busSvc.length; i++) { for(var i = 0; i < busSvc.length; i++) {
displayBusService(busSvc[i]) displayBusService(busSvc[i])
buildCallLists(busSvc[i]) buildCallLists(busSvc[i])
} }
} }
async function displayService(svc) { // Creates a table row from each train service. async function displayService(svc) { // Creates a table row from each train service.
var table = document.getElementById("output"); var table = document.getElementById('output')
// Determine Time Message // Determine Time Message
var sta = await parseTime(svc.sta); var sta = await parseTime(svc.sta)
var eta = await parseTime(svc.eta); var eta = await parseTime(svc.eta)
var std = await parseTime(svc.std); var std = await parseTime(svc.std)
var etd = await parseTime(svc.etd); var etd = await parseTime(svc.etd)
// Determine Platform Message // Determine Platform Message
//if (svc.platform != undefined){var plt = svc.platform} else {var plt = "-"}; //if (svc.platform != undefined){var plt = svc.platform} else {var plt = "-"};
var plt = await parsePlatform(svc); var plt = await parsePlatform(svc)
// Define Table Row // Define Table Row
var row = ` var row = `
<table> <table>
<tr> <tr>
<td class="name name-item" onclick="showCalls('${svc.serviceID}')">${await parseName(svc.origin.location)}</td> <td class="name name-item" onclick="showCalls('${svc.serviceID}')">${await parseName(svc.origin.location)}</td>
@ -137,41 +138,41 @@ async function displayService(svc) { // Creates a table row from each train serv
<td class="time ${etd.changed}">${etd.data}</td> <td class="time ${etd.changed}">${etd.data}</td>
</tr> </tr>
</table>` </table>`
// Put Table Row // Put Table Row
table.insertAdjacentHTML("beforeend", row) table.insertAdjacentHTML('beforeend', row)
// Display Operator where provided (it always will be, I think) // Display Operator where provided (it always will be, I think)
if (svc.operator) { if (svc.operator) {
var opRow = `<p class="msg op">A ${svc.operator} service` var opRow = `<p class="msg op">A ${svc.operator} service`
if (svc.length) { // Displays number of carriages where provided if (svc.length) { // Displays number of carriages where provided
opRow += ` with ${svc.length} carriages</p>`; opRow += ` with ${svc.length} carriages</p>`
} else { } else {
opRow += `</p>` opRow += '</p>'
}
table.insertAdjacentHTML("beforeend", opRow);
}
// Parse cancelReason and then delayReason
if (svc.cancelReason) {
var cancelRow = `<p class="msg">${svc.cancelReason}</p>`
table.insertAdjacentHTML("beforeend", cancelRow);
}
if (svc.delayReason) {
var delayRow = `<p class="msg">${svc.delayReason}</p>`
table.insertAdjacentHTML("beforeend", delayRow);
} }
table.insertAdjacentHTML('beforeend', opRow)
}
// Parse cancelReason and then delayReason
if (svc.cancelReason) {
var cancelRow = `<p class="msg">${svc.cancelReason}</p>`
table.insertAdjacentHTML('beforeend', cancelRow)
}
if (svc.delayReason) {
var delayRow = `<p class="msg">${svc.delayReason}</p>`
table.insertAdjacentHTML('beforeend', delayRow)
}
} }
async function displayFerryService(svc) { // Creates a table for for each ferry service async function displayFerryService(svc) { // Creates a table for for each ferry service
var table = document.getElementById("ferry"); var table = document.getElementById('ferry')
log(JSON.stringify(svc)) log(JSON.stringify(svc))
// Determine Time Message // Determine Time Message
var sta = await parseTime(svc.sta); var sta = await parseTime(svc.sta)
var eta = await parseTime(svc.eta); var eta = await parseTime(svc.eta)
var std = await parseTime(svc.std); var std = await parseTime(svc.std)
var etd = await parseTime(svc.etd); var etd = await parseTime(svc.etd)
// Determine Platform Message // Determine Platform Message
var plt = ""; var plt = ''
// Define Table Row // Define Table Row
var row = ` var row = `
<table> <table>
<tr> <tr>
<td class="name name-item">${await parseName(svc.origin.location)}</td> <td class="name name-item">${await parseName(svc.origin.location)}</td>
@ -183,32 +184,32 @@ async function displayFerryService(svc) { // Creates a table for for each ferry
<td class="time ${etd.changed}">${etd.data}</td> <td class="time ${etd.changed}">${etd.data}</td>
</tr> </tr>
</table>` </table>`
// Put Table Row // Put Table Row
table.insertAdjacentHTML("beforeend", row) table.insertAdjacentHTML('beforeend', row)
// Parse cancelReason & delayReason // Parse cancelReason & delayReason
if (svc.cancelReason) { if (svc.cancelReason) {
var cancelRow = `<p class="msg">${svc.cancelReason}</p>` var cancelRow = `<p class="msg">${svc.cancelReason}</p>`
table.insertAdjacentHTML("beforeend", cancelRow); table.insertAdjacentHTML('beforeend', cancelRow)
} }
if (svc.delayReason) { if (svc.delayReason) {
var delayRow = `<p class="msg">${svc.delayReason}</p>` var delayRow = `<p class="msg">${svc.delayReason}</p>`
table.insertAdjacentHTML("beforeend", delayRow); table.insertAdjacentHTML('beforeend', delayRow)
} }
document.getElementById("ferry").style = "display:block" document.getElementById('ferry').style = 'display:block'
} }
async function displayBusService(svc) { // Creates a table row for each bus service. async function displayBusService(svc) { // Creates a table row for each bus service.
var table = document.getElementById("bus"); var table = document.getElementById('bus')
log(JSON.stringify(svc)) log(JSON.stringify(svc))
// Determine Time Message // Determine Time Message
var sta = await parseTime(svc.sta); var sta = await parseTime(svc.sta)
var eta = await parseTime(svc.eta); var eta = await parseTime(svc.eta)
var std = await parseTime(svc.std); var std = await parseTime(svc.std)
var etd = await parseTime(svc.etd); var etd = await parseTime(svc.etd)
// Determine Platform Message // Determine Platform Message
var plt = ""; var plt = ''
// Define Table Row // Define Table Row
var row = ` var row = `
<table> <table>
<tr> <tr>
<td class="name name-item" onclick="showCalls('${svc.serviceID}')">${svc.origin.location.locationName}</td> <td class="name name-item" onclick="showCalls('${svc.serviceID}')">${svc.origin.location.locationName}</td>
@ -220,21 +221,21 @@ async function displayBusService(svc) { // Creates a table row for each bus serv
<td class="time ${etd.changed}">${etd.data}</td> <td class="time ${etd.changed}">${etd.data}</td>
</tr> </tr>
</table>` </table>`
// Put Table Row // Put Table Row
table.insertAdjacentHTML("beforeend", row) table.insertAdjacentHTML('beforeend', row)
// Display operator // Display operator
if (svc.operator) { if (svc.operator) {
var opRow = `<p class="msg op">A ${svc.operator} service</p>` var opRow = `<p class="msg op">A ${svc.operator} service</p>`
table.insertAdjacentHTML("beforeend", opRow); table.insertAdjacentHTML('beforeend', opRow)
} }
// Parse cancelReason & delayReason // Parse cancelReason & delayReason
if (svc.cancelReason) { if (svc.cancelReason) {
var cancelRow = `<p class="msg">${svc.cancelReason}</p>` var cancelRow = `<p class="msg">${svc.cancelReason}</p>`
table.insertAdjacentHTML("beforeend", cancelRow); table.insertAdjacentHTML('beforeend', cancelRow)
} }
if (svc.delayReason) { if (svc.delayReason) {
var delayRow = `<p class="msg">${svc.delayReason}</p>` var delayRow = `<p class="msg">${svc.delayReason}</p>`
table.insertAdjacentHTML("beforeend", delayRow); table.insertAdjacentHTML('beforeend', delayRow)
} }
document.getElementById("bus").style = "display:block" document.getElementById('bus').style = 'display:block'
} }

View File

@ -1,29 +1,30 @@
init(); init()
async function init() { // The page init function async function init() { // The page init function
display(await get()) versionDisplay()
display(await get())
} }
async function get() { // Fetch data from API async function get() { // Fetch data from API
var url = `${window.location.origin}/api/v1/stats`; var url = `${window.location.origin}/api/v1/stats`
var resp = await fetch(url); var resp = await fetch(url)
return await resp.json(); return await resp.json()
} }
async function display(data) { // Parses and displays data from API async function display(data) { // Parses and displays data from API
document.getElementById('server_host').textContent = data.host; document.getElementById('server_host').textContent = data.host
document.getElementById('server_mode').textContent = data.mode || "Unknown"; document.getElementById('server_mode').textContent = data.mode || 'Unknown'
document.getElementById('ver-bkend').textContent = data.verBkend || "Unknown"; document.getElementById('ver-bkend').textContent = data.verBkend || 'Unknown'
let dat = data.dat[0] let dat = data.dat[0]
let ver = data.ver[0] let ver = data.ver[0]
document.getElementById('time').textContent = await convertUnixLocal(dat.since); document.getElementById('time').textContent = await convertUnixLocal(dat.since)
document.getElementById('ldbws').textContent = dat.ldbws || "0"; document.getElementById('ldbws').textContent = dat.ldbws || '0'
document.getElementById('ldbsvws').textContent = dat.ldbsvws || "0"; document.getElementById('ldbsvws').textContent = dat.ldbsvws || '0'
document.getElementById('apicorpus').textContent = dat.corpus_api || "0"; document.getElementById('apicorpus').textContent = dat.corpus_api || '0'
document.getElementById('corpus').textContent = dat.corpus || "0"; document.getElementById('corpus').textContent = dat.corpus || '0'
document.getElementById('stations').textContent = dat.stations || "0"; document.getElementById('stations').textContent = dat.stations || '0'
document.getElementById('users').textContent = dat.user || "0"; document.getElementById('users').textContent = dat.user || '0'
document.getElementById('meta').textContent = dat.meta || "0"; document.getElementById('meta').textContent = dat.meta || '0'
document.getElementById('ver-dbman').textContent = ver.dbmanager || "Unknown"; document.getElementById('pis').textContent = dat.pis
document.getElementById('ver-web').textContent = localStorage.getItem('ver-web') || "Unknown"; document.getElementById('ver-dbman').textContent = ver.dbmanager || 'Unknown'
} }

1125
package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

14
package.json Normal file
View File

@ -0,0 +1,14 @@
{
"name": "web",
"version": "0.0.1",
"description": "web",
"main": "index.html",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"devDependencies": {
"eslint": "^8.39.0"
}
}

76
pis.html Normal file
View File

@ -0,0 +1,76 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="description" content="OwlBoard - Beta: Quick access to route codes for PIS Systems.">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="application-name" content="OwlBoard">
<meta name="author" content="Frederick Boniface">
<meta name="theme-color" content="#00b7b7">
<link rel="apple-touch-icon" href="/images/app-icons/any/apple-192.png">
<link rel="stylesheet" type="text/css" href="./styles/main.css">
<link rel="stylesheet" type="text/css" href="./styles/pis.css">
<link rel="icon" type="image/svg+xml" href="./images/icon.svg">
<link rel="manifest" type="application/json" href="./manifest.json">
<title>OwlBoard - PIS</title>
<script src="./js/lib.main.js" defer></script>
<script src="./js/pis.js" defer></script>
</head>
<body>
<div id="top_button" class="hide_micro">
<a href="/">
<picture aria-label="Home" class="sidebar_control">
<source srcset="/images/nav/back.svg" type="image/svg+xml">
<img src="back-40.png" alt="Home">
</picture>
</a>
</div>
<picture>
<source srcset="/images/logo/wide_logo.svg" type="image/svg+xml">
<source media="(max-height: 739px)" srcset="/images/logo/logo-full-200.png" type="image/png">
<source srcset="/images/logo/logo-full-250.png" type="image/png">
<img class="titleimg" src="/images/logo/logo-full-250.png" alt="OwlBoard Logo">
</picture>
<h2>PIS Codes</h2>
<div id="loading">
<div class="spinner">
</div>
<p id="loading_desc">Searching</p>
</div>
<div id="crs-box">
<p>Enter a services start and end station CRS codes to see code options and stopping patterns.</p>
<p>Currently supported (Beta): GWR: Up/Dn SVB-EXD, Dn CDF-PNZ, Up/Dn GMV/CDF-PMH, HEx<br>Duplicate stopping patterns have been removed.</p>
<p id="auth-required">You need to be logged into a free <a href="./settings.html">rail staff version</a> account for this feature.</p>
<form action="javascript:findByOrigDest();">
<div id="crs-inputs">
<div class="crs-input">
<label for="origin">From:</label><br>
<input type="text" class="small-lookup-box pis-input" id="origin" name="origin" maxlength="3">
</div>
<div class="crs-input">
<label for="destination">To:</label><br>
<input type="text" class="small-lookup-box pis-input" id="destination" name="destination" maxlength="3"><br><br>
</div>
</div>
<button type="submit" value="Find" class="lookup-button">Submit</button>
</form>
</div>
<div id="result-box">
<h3>Results: <span id="result-count">0</span></h3>
<!-- display: none; by default, some kind of box which shows each code
and destination individually with a previous and next arrow. -->
</div>
<button type="reset" id="reset" class="lookup-button" onclick="reset()">Reset</button>
<!-- Footer -->
<footer>
<p>Created by <a href="https://fredboniface.co.uk" target="_blank" rel="noreferrer noopener">Fred Boniface</a> - <span id="ver_str">d</span></p>
</footer>
</body>
</html>

View File

@ -1,17 +1,18 @@
<!DOCTYPE html> <!DOCTYPE html>
<html lang="en"> <html lang="en">
<head> <head>
<meta charset="UTF-8"/> <meta charset="UTF-8">
<meta name="description" content="OwlBoard - Live train departures for traincrew."/> <meta name="description" content="OwlBoard - Personalise your OwlBoard.">
<meta name="robots" content="noindex">
<meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="application-name" content="OwlBoard"> <meta name="application-name" content="OwlBoard">
<meta name="author" content="Frederick Boniface"> <meta name="author" content="Frederick Boniface">
<meta name="theme-color" content="#00b7b7"> <meta name="theme-color" content="#00b7b7">
<link rel="apple-touch-icon" href="/images/app-icons/any/apple-192.png"> <link rel="apple-touch-icon" href="/images/app-icons/any/apple-192.png">
<link rel="stylesheet" type="text/css" href="./styles/main.css"/> <link rel="stylesheet" type="text/css" href="./styles/main.css">
<link rel="stylesheet" type="text/css" href="./styles/settings.css"/> <link rel="stylesheet" type="text/css" href="./styles/settings.css">
<link rel="icon" type="image/svg+xml" href="./images/icon.svg"/> <link rel="icon" type="image/svg+xml" href="./images/icon.svg">
<link rel="manifest" type="application/json" href="./manifest.json"/> <link rel="manifest" type="application/json" href="./manifest.json">
<title>OwlBoard - Settings</title> <title>OwlBoard - Settings</title>
<script src="./js/lib.main.js" defer></script> <script src="./js/lib.main.js" defer></script>
<script src="./js/settings.js" defer></script> <script src="./js/settings.js" defer></script>
@ -65,16 +66,16 @@
<input type="text" maxlength="3" id="ql9" name="ql9" autocomplete="off" class="small-lookup-box"><br> <input type="text" maxlength="3" id="ql9" name="ql9" autocomplete="off" class="small-lookup-box"><br>
<input type="text" maxlength="3" id="ql10" name="ql10" autocomplete="off" class="small-lookup-box"> <input type="text" maxlength="3" id="ql10" name="ql10" autocomplete="off" class="small-lookup-box">
<input type="text" maxlength="3" id="ql11" name="ql11" autocomplete="off" class="small-lookup-box"><br> <input type="text" maxlength="3" id="ql11" name="ql11" autocomplete="off" class="small-lookup-box"><br>
<button onclick="setQl()" class="lookup-button">Apply</button> <button type="submit" onclick="setQl()" class="lookup-button">Apply</button>
<button onclick="clearQl()" class="lookup-button">Defaults</button> <button type="reset" onclick="clearQl()" class="lookup-button">Defaults</button>
<br><br><br> <br><br><br>
<label>Register for Rail Staff Version:</label> <label>Register for Rail Staff Version:</label>
<p id="reg_text">Enter your work email address:</p> <p id="reg_text">Enter your work email address:</p>
<input type="text" maxlength="128" id="eml" name="eml" autocomplete="email" class="lookup-box" placeholder="Not yet available"><br> <input type="text" maxlength="128" id="eml" name="eml" autocomplete="email" class="lookup-box" placeholder="email"><br>
<p>One registration confirmation email will be sent which will include more details about your account</p> <p>One registration confirmation email will be sent which will include more details about your account</p>
<p>Your address will not be stored</p> <p>Your address will not be stored</p>
<p>If your domain is not authorised and you are a using a railway company email address, <p>If your domain is not authorised and you are a using a railway company email address,
<a href="./issue.html">submit an issue</a> and it can be added.</p> <a href="./issue.html">submit an issue</a> and it can be added.</p>
<button onclick="register()" class="lookup-button" id="reg_button">Register</button> <button type="submit" onclick="register()" class="lookup-button" id="reg_button">Register</button>
</body> </body>
</html> </html>

View File

@ -2,6 +2,7 @@
<html lang="en"> <html lang="en">
<head> <head>
<meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="robots" content="none">
<title>OwlBoard - Statistics</title> <title>OwlBoard - Statistics</title>
<script src="./js/lib.main.js" defer></script> <script src="./js/lib.main.js" defer></script>
<script src="./js/stat.js" defer></script> <script src="./js/stat.js" defer></script>
@ -44,6 +45,10 @@
<td>DB-meta</td> <td>DB-meta</td>
<td id="meta"></td> <td id="meta"></td>
</tr> </tr>
<tr>
<td>DB-pis</td>
<td id="pis"></td>
</tr>
</table> </table>
<br><br> <br><br>
<table style="margin:auto;text-align:center;"> <table style="margin:auto;text-align:center;">
@ -73,7 +78,7 @@
web-frontend web-frontend
</a> </a>
</td> </td>
<td id="ver-web"></td> <td id="ver_str">Unknown</td>
</tr> </tr>
</table> </table>
<p>The statistics represent hits & queries from all instances in the stack.</p> <p>The statistics represent hits & queries from all instances in the stack.</p>

View File

@ -301,6 +301,10 @@ label {
transition: 0.5s; transition: 0.5s;
} }
#auth-required {
color: var(--main-warning-color);
}
/* Footer Styles */ /* Footer Styles */
footer { footer {
background-color: var(--accent-color); background-color: var(--accent-color);

45
styles/pis.css Normal file
View File

@ -0,0 +1,45 @@
#crs-inputs {
display: flex;
justify-content: center;
}
.pis-input {
width: 55%;
max-width: 200px;
margin: auto;
}
#result-box {
display: none;
}
#result-table {
margin: auto;
color: var(--second-text-color);
width: 85%;
max-width: 700px;
text-align: center;
}
td, th {
border-bottom: 1px solid;
}
#reset {
margin-top: 15px
}
#reset {
margin-top: 25px;
}
.pis-code {
font-weight:bold;
}
.station {
text-transform: uppercase;
overflow-wrap: anywhere;
font-family: firamono, monospace;
line-height: 1.2;
}

152
sw.js
View File

@ -1,86 +1,96 @@
/* Service Worker */ /* Service Worker */
const appVersion = "2.0.0-dev" const swVersion = '2.0.0-20230506'
const cacheName = `owlboard-${appVersion}`; const cacheName = `owlboard-${swVersion}`
const cacheIDs = [cacheName]; const cacheIDs = [cacheName]
const cacheFiles = [ let staticCache = [
"/404.html", '/styles/fonts/firamono/firamono-500.woff2',
"/auth.html", '/styles/fonts/firamono/firamono-regular.woff2',
"/board.html", '/styles/fonts/urwgothic/urwgothic.woff2',
"/conn-err.html", '/styles/fonts/urwgothic/urwgothicDemi.woff2',
"/help.html", '/images/icon.svg',
"/", '/images/logo/wide_logo.svg',
"/issue.html", '/images/logo/mono-logo.svg',
"/find-code.html", '/images/app-icons/any/plain-logo.svg',
"/settings.html", '/images/app-icons/any/plain-logo-512.png',
"/manifest.json", '/images/nav/alert_icon.svg',
"/styles/fonts/firamono/firamono-500.woff2", '/images/nav/save.svg',
"/styles/fonts/firamono/firamono-regular.woff2", '/images/nav/home_icon.svg',
"/styles/fonts/urwgothic/urwgothic.woff2", '/images/nav/back.svg',
"/styles/fonts/urwgothic/urwgothicDemi.woff2", '/images/nav/hamburger.svg',
"/styles/board.css", '/images/nav/close.svg',
"/styles/find-code.css", '/images/nav/refresh.svg',
"/styles/help.css", '/images/nre/nre-powered_400w.webp',
"/styles/issue.css", '/images/nre/nre-powered_400w.jxl'
"/styles/main.css", ]
"/styles/settings.css", const dynamicCache = [
"/js/find-code.js", '/404.html',
"/js/index.js", '/auth.html',
"/js/issue.js", '/board.html',
"/js/lib.board.js", '/conn-err.html',
"/js/lib.main.js", '/help.html',
"/js/auth.js", '/',
"/js/settings.js", '/issue.html',
"/js/simple-board.js", '/find-code.html',
"/images/icon.svg", '/settings.html',
"/images/logo/wide_logo.svg", '/pis.html',
"/images/logo/mono-logo.svg", '/manifest.json',
"/images/app-icons/any/plain-logo.svg", '/styles/board.css',
"/images/app-icons/any/plain-logo-512.png", '/styles/find-code.css',
"/images/nav/alert_icon.svg", '/styles/help.css',
"/images/nav/save.svg", '/styles/issue.css',
"/images/nav/home_icon.svg", '/styles/main.css',
"/images/nav/back.svg", '/styles/settings.css',
"/images/nav/hamburger.svg", '/styles/pis.css',
"/images/nav/close.svg", '/js/find-code.js',
"/images/nav/refresh.svg", '/js/index.js',
"/images/nre/nre-powered_400w.webp", '/js/issue.js',
"/images/nre/nre-powered_400w.jxl" '/js/lib.board.js',
]; '/js/lib.main.js',
'/js/auth.js',
'/js/settings.js',
'/js/simple-board.js',
'/js/pis.js'
]
self.addEventListener("install", (e) => { for(let i = 0; i < dynamicCache.length; i++) {
console.log("[Service Worker] Install"); let item = dynamicCache[i] + `?${swVersion}`
e.waitUntil( staticCache.push(item)
(async () => { }
const cache = await caches.open(cacheName);
console.log("[Service Worker] Caching app data");
await cache.addAll(cacheFiles);
})()
);
});
self.addEventListener("fetch", (e) => { self.addEventListener('install', (e) => {
console.log('[Service Worker] Install')
e.waitUntil(
(async () => {
const cache = await caches.open(cacheName)
console.log('[Service Worker] Caching app data')
await cache.addAll(staticCache)
})()
)
})
self.addEventListener('fetch', (e) => {
e.respondWith( e.respondWith(
(async () => { (async () => {
const r = await caches.match(e.request,{ignoreSearch: true}); const r = await caches.match(e.request,{ignoreSearch: true})
if (r) { if (r) {
return r; return r
} }
const response = await fetch(e.request); const response = await fetch(e.request)
console.log(`[Service Worker] Not cached - fetching from server: ${e.request.url}`); console.log(`[Service Worker] Not cached - fetching from server: ${e.request.url}`)
return response; return response
})() })()
); )
}); })
self.addEventListener('activate', function (event) { self.addEventListener('activate', function (event) {
event.waitUntil(caches.keys().then(function (keys) { event.waitUntil(caches.keys().then(function (keys) {
return Promise.all(keys.filter(function (key) { return Promise.all(keys.filter(function (key) {
return !cacheIDs.includes(key); return !cacheIDs.includes(key)
}).map(function (key) { }).map(function (key) {
return caches.delete(key); return caches.delete(key)
})); }))
}).then(function () { }).then(function () {
return self.clients.claim(); return self.clients.claim()
})); }))
}); })