pis #2
@ -12,7 +12,7 @@ module.exports = {
|
||||
'rules': {
|
||||
'indent': [
|
||||
'error',
|
||||
4
|
||||
2
|
||||
],
|
||||
'linebreak-style': [
|
||||
'error',
|
||||
@ -25,6 +25,7 @@ module.exports = {
|
||||
'semi': [
|
||||
'error',
|
||||
'never'
|
||||
]
|
||||
],
|
||||
'no-undef': 'off',
|
||||
}
|
||||
}
|
||||
|
@ -1,24 +1,23 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8"/>
|
||||
<meta name="description" content="OwlBoard - Find CRS, TIPLOC & STANOX Codes with ease."/>
|
||||
<meta charset="UTF-8">
|
||||
<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="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/find-code.css"/>
|
||||
<link rel="icon" type="image/svg+xml" href="./images/icon.svg"/>
|
||||
<link rel="manifest" type="application/json" href="./manifest.json"/>
|
||||
<link rel="stylesheet" type="text/css" href="./styles/main.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="manifest" type="application/json" href="./manifest.json">
|
||||
<title>OwlBoard - Code Lookup</title>
|
||||
<script src="./js/lib.main.js" defer></script>
|
||||
<script src="./js/find-code.js" defer></script>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
|
||||
<div id="top_button" class="hide_micro">
|
||||
<a href="/">
|
||||
<picture aria-label="Home" class="sidebar_control">
|
||||
@ -27,7 +26,6 @@
|
||||
</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">
|
||||
@ -47,7 +45,7 @@
|
||||
</div>
|
||||
|
||||
<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>
|
||||
<input type="text" class="small-lookup-box" id="3alpha" name="3alpha" maxlength="3"><br>
|
||||
<label for="nlc">NLC:</label><br>
|
||||
@ -57,7 +55,7 @@
|
||||
<label for="stanox">STANOX:</label><br>
|
||||
<input type="number" class="small-lookup-box" id="stanox" name="stanox"><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="Clear" class="lookup-button" onclick="clearForm()">
|
||||
</body>
|
||||
|
62
js/auth.js
62
js/auth.js
@ -6,74 +6,74 @@ Auth process: User Requests Key => Server emails key to user =>
|
||||
auth.js adds this to localStorage
|
||||
*/
|
||||
const cmd = document.getElementById('cmd') // Assign element to const
|
||||
versionDisplay(); // Show web version in footer
|
||||
init(); // Run init function
|
||||
versionDisplay() // Show web version in footer
|
||||
init() // Run init function
|
||||
|
||||
async function sendHome(){
|
||||
await delay(2000);
|
||||
await delay(2000)
|
||||
location.replace('./')
|
||||
}
|
||||
|
||||
async function cmdOut(message) {
|
||||
html = "<p>" + message + "</p>"
|
||||
html = '<p>' + message + '</p>'
|
||||
cmd.insertAdjacentHTML('beforeend', html)
|
||||
}
|
||||
|
||||
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
|
||||
method: "POST",
|
||||
method: 'POST',
|
||||
headers: {
|
||||
"Content-Type": "application/json"
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
redirect: "follow",
|
||||
redirect: 'follow',
|
||||
body: JSON.stringify({uuid: key})
|
||||
})
|
||||
const data = await res.json();
|
||||
const data = await res.json()
|
||||
return res.status === 201
|
||||
? (localStorage.setItem("uuid", data.api_key), true)
|
||||
: false;
|
||||
? (localStorage.setItem('uuid', data.api_key), true)
|
||||
: false
|
||||
}
|
||||
|
||||
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, {
|
||||
method: "GET",
|
||||
redirect: "follow",
|
||||
method: 'GET',
|
||||
redirect: 'follow',
|
||||
headers: {
|
||||
"uuid": key
|
||||
'uuid': key
|
||||
}
|
||||
})
|
||||
return res.status === 200 ? true : false
|
||||
}
|
||||
|
||||
async function init(){ // Reads registration key from query, and calls registerKey(key)
|
||||
cmdOut("Reading authorisation code");
|
||||
const key = await getQuery("key");
|
||||
if (key === "false") {
|
||||
cmdOut("No valid key found")
|
||||
cmdOut("Try clicking the link again or request a new activation link")
|
||||
cmdOut('Reading authorisation code')
|
||||
const key = await getQuery('key')
|
||||
if (key === 'false') {
|
||||
cmdOut('No valid key found')
|
||||
cmdOut('Try clicking the link again or request a new activation link')
|
||||
hideLoading()
|
||||
return
|
||||
}
|
||||
cmdOut("Requesting API Key from server");
|
||||
cmdOut('Requesting API Key from server')
|
||||
if (!await registerKey(key)) {
|
||||
cmdOut("Failed to register or invalid key")
|
||||
cmdOut("Try again later or request a new link")
|
||||
cmdOut('Failed to register or invalid key')
|
||||
cmdOut('Try again later or request a new link')
|
||||
hideLoading()
|
||||
return
|
||||
}
|
||||
showLoading()
|
||||
if (! await checkAuth(localStorage.getItem("uuid"))) {
|
||||
cmdOut("Authentication Check failed")
|
||||
cmdOut("Please logout and request a new link")
|
||||
if (! await checkAuth(localStorage.getItem('uuid'))) {
|
||||
cmdOut('Authentication Check failed')
|
||||
cmdOut('Please logout and request a new link')
|
||||
hideLoading()
|
||||
await delay(2000)
|
||||
location.replace("./")
|
||||
location.replace('./')
|
||||
}
|
||||
hideLoading();
|
||||
cmdOut("Authentication succesful")
|
||||
cmdOut("Redirecting to home")
|
||||
hideLoading()
|
||||
cmdOut('Authentication succesful')
|
||||
cmdOut('Redirecting to home')
|
||||
await delay(3000)
|
||||
location.replace("./")
|
||||
location.replace('./')
|
||||
}
|
@ -1,12 +1,12 @@
|
||||
hideLoading();
|
||||
hideLoading()
|
||||
|
||||
async function fetchEntry(){ // This can be condensed
|
||||
showLoading();
|
||||
var name = document.getElementById("name")
|
||||
var crs = document.getElementById("3alpha")
|
||||
var nlc = document.getElementById("nlc")
|
||||
var tiploc = document.getElementById("tiploc")
|
||||
var stanox = document.getElementById("stanox")
|
||||
showLoading()
|
||||
var name = document.getElementById('name')
|
||||
var crs = document.getElementById('3alpha')
|
||||
var nlc = document.getElementById('nlc')
|
||||
var tiploc = document.getElementById('tiploc')
|
||||
var stanox = document.getElementById('stanox')
|
||||
|
||||
var values = {
|
||||
name: name.value,
|
||||
@ -20,78 +20,79 @@ async function fetchEntry(){ // This can be condensed
|
||||
|
||||
async function parseData(values){
|
||||
vibe()
|
||||
if (values.crs != ""){
|
||||
let data
|
||||
if (values.crs != ''){
|
||||
setLoadingDesc(`Searching\n${values.crs.toUpperCase()}`)
|
||||
var data = await getData("crs", values.crs)
|
||||
} else if (values.nlc != ""){
|
||||
data = await getData('crs', values.crs)
|
||||
} else if (values.nlc != ''){
|
||||
setLoadingDesc(`Searching\n${values.nlc.toUpperCase()}`)
|
||||
var data = await getData("nlc", values.nlc)
|
||||
} else if (values.tiploc != ""){
|
||||
data = await getData('nlc', values.nlc)
|
||||
} else if (values.tiploc != ''){
|
||||
setLoadingDesc(`Searching\n${values.tiploc.toUpperCase()}`)
|
||||
var data = await getData("tiploc", values.tiploc)
|
||||
} else if (values.stanox != ""){
|
||||
data = await getData('tiploc', values.tiploc)
|
||||
} else if (values.stanox != ''){
|
||||
setLoadingDesc(`Searching\n${values.stanox.toUpperCase()}`)
|
||||
var data = await getData("stanox", values.stanox)
|
||||
} else if (values.name != ""){
|
||||
data = await getData('stanox', values.stanox)
|
||||
} else if (values.name != ''){
|
||||
setLoadingDesc(`Searching\n${values.name}`)
|
||||
var data = await getData("name", values.name)
|
||||
data = await getData('name', values.name)
|
||||
} else {
|
||||
log("find-code.parseData: No data entered", "WARN")
|
||||
await clearForm();
|
||||
document.getElementById("name").value = "No data entered"
|
||||
vibe("err");
|
||||
hideLoading();
|
||||
return;
|
||||
log('find-code.parseData: No data entered', 'WARN')
|
||||
await clearForm()
|
||||
document.getElementById('name').value = 'No data entered'
|
||||
vibe('err')
|
||||
hideLoading()
|
||||
return
|
||||
}
|
||||
displayData(data);
|
||||
displayData(data)
|
||||
}
|
||||
|
||||
async function getData(type, value){
|
||||
log(`find-code.getData: Looking for: ${type} '${value}'`, "INFO")
|
||||
log(`find-code.getData: Looking for: ${type} '${value}'`, 'INFO')
|
||||
try {
|
||||
var url = `${window.location.origin}/api/v1/find/${type}/${value}`;
|
||||
var resp = await fetch(url);
|
||||
var url = `${window.location.origin}/api/v1/find/${type}/${value}`
|
||||
var resp = await fetch(url)
|
||||
return await resp.json()
|
||||
} catch (err) {
|
||||
log(`find-code.getData: Error getting data: ${err}`, "WARN")
|
||||
vibe("err")
|
||||
return "";
|
||||
log(`find-code.getData: Error getting data: ${err}`, 'WARN')
|
||||
vibe('err')
|
||||
return ''
|
||||
}
|
||||
}
|
||||
|
||||
async function displayData(data){
|
||||
hideLoading();
|
||||
if (data.status === "failed" || data == ""){
|
||||
log(`find-code.displayData: Unable to find data`, "WARN")
|
||||
clearForm();
|
||||
document.getElementById("name").value = "Not Found";
|
||||
hideLoading()
|
||||
if (data.status === 'failed' || data == ''){
|
||||
log('find-code.displayData: Unable to find data', 'WARN')
|
||||
clearForm()
|
||||
document.getElementById('name').value = 'Not Found'
|
||||
} else {
|
||||
log(`find-code.displayData: Inserting data`, "INFO")
|
||||
vibe("ok")
|
||||
log('find-code.displayData: Inserting data', 'INFO')
|
||||
vibe('ok')
|
||||
try {
|
||||
document.getElementById("name").value = data['0']['NLCDESC']
|
||||
document.getElementById('name').value = data['0']['NLCDESC']
|
||||
} catch (err) {}
|
||||
try {
|
||||
document.getElementById("3alpha").value = data['0']['3ALPHA']
|
||||
document.getElementById('3alpha').value = data['0']['3ALPHA']
|
||||
} catch (err) {}
|
||||
try {
|
||||
document.getElementById("nlc").value = data['0']['NLC']
|
||||
document.getElementById('nlc').value = data['0']['NLC']
|
||||
} catch (err) {}
|
||||
try {
|
||||
document.getElementById("tiploc").value = data['0']['TIPLOC']
|
||||
document.getElementById('tiploc').value = data['0']['TIPLOC']
|
||||
} catch (err) {}
|
||||
try {
|
||||
document.getElementById("stanox").value = data['0']['STANOX']
|
||||
document.getElementById('stanox').value = data['0']['STANOX']
|
||||
} catch (err) {}
|
||||
}
|
||||
}
|
||||
|
||||
async function clearForm(){
|
||||
document.getElementById("name").value = ""
|
||||
document.getElementById("3alpha").value = ""
|
||||
document.getElementById("nlc").value = ""
|
||||
document.getElementById("tiploc").value = ""
|
||||
document.getElementById("stanox").value = ""
|
||||
vibe("ok");
|
||||
hideLoading();
|
||||
document.getElementById('name').value = ''
|
||||
document.getElementById('3alpha').value = ''
|
||||
document.getElementById('nlc').value = ''
|
||||
document.getElementById('tiploc').value = ''
|
||||
document.getElementById('stanox').value = ''
|
||||
vibe('ok')
|
||||
hideLoading()
|
||||
}
|
22
js/index.js
22
js/index.js
@ -1,27 +1,27 @@
|
||||
// Init:
|
||||
pageInit();
|
||||
versionDisplay();
|
||||
pageInit()
|
||||
versionDisplay()
|
||||
|
||||
if ("serviceWorker" in navigator) {
|
||||
navigator.serviceWorker.register("/sw.js");
|
||||
if ('serviceWorker' in navigator) {
|
||||
navigator.serviceWorker.register('/sw.js')
|
||||
}
|
||||
|
||||
async function pageInit() {
|
||||
await loadQuickLinks();
|
||||
hideLoading(); // From lib.main
|
||||
await loadQuickLinks()
|
||||
hideLoading() // From lib.main
|
||||
}
|
||||
|
||||
async function gotoBoard(station){
|
||||
vibe("ok")
|
||||
window.location.assign(`${window.location.origin}/board.html?stn=${station}`);
|
||||
vibe('ok')
|
||||
window.location.assign(`${window.location.origin}/board.html?stn=${station}`)
|
||||
}
|
||||
|
||||
async function loadQuickLinks(){
|
||||
var data = await getQuickLinks(); // From lib.main
|
||||
var buttons = "";
|
||||
var data = await getQuickLinks() // From lib.main
|
||||
var buttons = ''
|
||||
for(var i = 0; i < data.length; i++) {
|
||||
buttons += `
|
||||
<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)
|
||||
}
|
56
js/issue.js
56
js/issue.js
@ -1,22 +1,22 @@
|
||||
init();
|
||||
init()
|
||||
|
||||
async function init() {
|
||||
hideLoading()
|
||||
}
|
||||
|
||||
async function submit() {
|
||||
setLoadingDesc("Collecting\nData")
|
||||
setLoadingDesc('Collecting\nData')
|
||||
showLoading()
|
||||
var browserData = await getBrowserData();
|
||||
setLoadingDesc("Reading\nForm")
|
||||
var formData = await getFormData();
|
||||
var browserData = await getBrowserData()
|
||||
setLoadingDesc('Reading\nForm')
|
||||
var formData = await getFormData()
|
||||
preflight({browserData: browserData, formData: formData})
|
||||
}
|
||||
|
||||
async function getFormData() {
|
||||
let data = {}
|
||||
data.subject = document.getElementById("subject").value
|
||||
data.message = document.getElementById("message").value
|
||||
data.subject = document.getElementById('subject').value
|
||||
data.message = document.getElementById('message').value
|
||||
return data
|
||||
}
|
||||
|
||||
@ -31,38 +31,38 @@ async function getBrowserData() {
|
||||
}
|
||||
|
||||
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}
|
||||
\nUserAgentData: ${data.browserData.userAgentData}
|
||||
\nlocalStorage Avail: ${data.browserData.localStorage}
|
||||
\nsessionStorage Avail: ${data.browserData.sessionStorage}
|
||||
\nViewport size: ${data.browserData.viewport}
|
||||
\nUser message:\n\n${data.formData.message}`
|
||||
document.getElementById("pre_message").innerText = pre_msg
|
||||
document.getElementById('pre_message').innerText = pre_msg
|
||||
hideLoading()
|
||||
document.getElementById("preflight").style = "display: block"
|
||||
sessionStorage.setItem("preflight_subject", data.formData.subject)
|
||||
sessionStorage.setItem("preflight_msg", pre_msg)
|
||||
document.getElementById('preflight').style = 'display: block'
|
||||
sessionStorage.setItem('preflight_subject', data.formData.subject)
|
||||
sessionStorage.setItem('preflight_msg', pre_msg)
|
||||
}
|
||||
|
||||
async function cancel() {
|
||||
document.getElementById("preflight").style = "display: none"
|
||||
document.getElementById('preflight').style = 'display: none'
|
||||
}
|
||||
|
||||
async function send() {
|
||||
setLoadingDesc("Sending\nData")
|
||||
document.getElementById("preflight").style = "display: none"
|
||||
setLoadingDesc('Sending\nData')
|
||||
document.getElementById('preflight').style = 'display: none'
|
||||
showLoading()
|
||||
var subject = sessionStorage.getItem("preflight_subject");
|
||||
var msg = sessionStorage.getItem("preflight_msg")
|
||||
if (typeof subject != "string") {
|
||||
subject = document.getElementById("preflight_subject").innerText
|
||||
var subject = sessionStorage.getItem('preflight_subject')
|
||||
var msg = sessionStorage.getItem('preflight_msg')
|
||||
if (typeof subject != 'string') {
|
||||
subject = document.getElementById('preflight_subject').innerText
|
||||
}
|
||||
if (typeof msg != "string") {
|
||||
msg = document.getElementById("preflight_msg")
|
||||
if (typeof msg != 'string') {
|
||||
msg = document.getElementById('preflight_msg')
|
||||
}
|
||||
var payload = JSON.stringify({subject: subject, msg: msg})
|
||||
console.log(payload);
|
||||
console.log(payload)
|
||||
let opt = {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
@ -74,15 +74,15 @@ async function send() {
|
||||
}
|
||||
var res = await fetch(`${window.location.origin}/api/v1/issue`, opt)
|
||||
if (res.status == 200) {
|
||||
setLoadingDesc("Success")
|
||||
vibe("ok")
|
||||
setLoadingDesc('Success')
|
||||
vibe('ok')
|
||||
await delay(2500)
|
||||
window.location.replace("/")
|
||||
window.location.replace('/')
|
||||
} else {
|
||||
setLoadingDesc("Error")
|
||||
vibe("err")
|
||||
setLoadingDesc('Error')
|
||||
vibe('err')
|
||||
await delay(2500)
|
||||
hideLoading()
|
||||
document.getElementById("preflight").style = "display: none;"
|
||||
document.getElementById('preflight').style = 'display: none;'
|
||||
}
|
||||
}
|
198
js/lib.board.js
198
js/lib.board.js
@ -1,39 +1,39 @@
|
||||
/* Fetch Functions */
|
||||
async function publicLdb(stn) {
|
||||
var url = `${window.location.origin}/api/v1/ldb/${stn}`;
|
||||
console.time("Time: Fetch LDB Data")
|
||||
var resp = await fetch(url);
|
||||
console.timeEnd("Time: Fetch LDB Data")
|
||||
return await resp.json();
|
||||
var url = `${window.location.origin}/api/v1/ldb/${stn}`
|
||||
console.time('Time: Fetch LDB Data')
|
||||
var resp = await fetch(url)
|
||||
console.timeEnd('Time: Fetch LDB Data')
|
||||
return await resp.json()
|
||||
}
|
||||
|
||||
/* Set page heading */
|
||||
async function setHeaders(title,time) {
|
||||
var prefix = `OwlBoard - `
|
||||
var prefix = 'OwlBoard - '
|
||||
document.title = `${prefix}${title}`
|
||||
document.getElementById("stn_name").textContent = title
|
||||
document.getElementById("fetch_time").textContent = time.toLocaleTimeString()
|
||||
sessionStorage.setItem("board_location", title);
|
||||
document.getElementById('stn_name').textContent = title
|
||||
document.getElementById('fetch_time').textContent = time.toLocaleTimeString()
|
||||
sessionStorage.setItem('board_location', title)
|
||||
}
|
||||
|
||||
/* Display No Trains Message */
|
||||
async function displayNoTrains() {
|
||||
log("No Trains", "WARN")
|
||||
document.getElementById('no_services').style = "display: block;";
|
||||
hideLoading();
|
||||
log('No Trains', 'WARN')
|
||||
document.getElementById('no_services').style = 'display: block;'
|
||||
hideLoading()
|
||||
}
|
||||
|
||||
/* Parse the value of `platform` to account for unknown platforms */
|
||||
async function parsePlatform(svc){
|
||||
if (svc.platform != undefined) {
|
||||
var platform = svc.platform;
|
||||
var platform = svc.platform
|
||||
} else {
|
||||
var platform = "-";
|
||||
var platform = '-'
|
||||
}
|
||||
if (svc.platformChanged) { // Not present in public API, ready for staff version.
|
||||
var changed = "changed";
|
||||
var changed = 'changed'
|
||||
} else {
|
||||
var changed = "";
|
||||
var changed = ''
|
||||
}
|
||||
return {num: platform, change: changed}
|
||||
}
|
||||
@ -42,111 +42,111 @@ async function parsePlatform(svc){
|
||||
/* Change value of time strings to fit well on small screens */
|
||||
async function parseTime(string){
|
||||
switch (string) {
|
||||
case "Delayed":
|
||||
var output = "LATE";
|
||||
var change = "changed";
|
||||
break;
|
||||
case "Cancelled":
|
||||
var output = "CANC";
|
||||
var change = "cancelled";
|
||||
break;
|
||||
case "On time":
|
||||
var output = "RT";
|
||||
var change = "";
|
||||
break;
|
||||
case "":
|
||||
var output = "-";
|
||||
var change = "";
|
||||
break;
|
||||
case 'Delayed':
|
||||
var output = 'LATE'
|
||||
var change = 'changed'
|
||||
break
|
||||
case 'Cancelled':
|
||||
var output = 'CANC'
|
||||
var change = 'cancelled'
|
||||
break
|
||||
case 'On time':
|
||||
var output = 'RT'
|
||||
var change = ''
|
||||
break
|
||||
case '':
|
||||
var output = '-'
|
||||
var change = ''
|
||||
break
|
||||
case undefined:
|
||||
var output = "-";
|
||||
var change = "";
|
||||
break;
|
||||
case "No report":
|
||||
var output = "-";
|
||||
var change = "";
|
||||
break;
|
||||
case "undefined":
|
||||
var output = false;
|
||||
var change = "";
|
||||
break;
|
||||
var output = '-'
|
||||
var change = ''
|
||||
break
|
||||
case 'No report':
|
||||
var output = '-'
|
||||
var change = ''
|
||||
break
|
||||
case 'undefined':
|
||||
var output = false
|
||||
var change = ''
|
||||
break
|
||||
default:
|
||||
var output = string;
|
||||
var change = "changed";
|
||||
var output = string
|
||||
var change = 'changed'
|
||||
}
|
||||
return {data: output, changed: change};
|
||||
return {data: output, changed: change}
|
||||
}
|
||||
|
||||
/* Convert multiple Origin/Destinations to single string */
|
||||
async function parseName(location) {
|
||||
if (Array.isArray(location)) {
|
||||
var name = `${location[0]['locationName']} & ${location[1]['locationName']}`
|
||||
return name;
|
||||
return name
|
||||
}
|
||||
else {
|
||||
return location.locationName;
|
||||
return location.locationName
|
||||
}
|
||||
}
|
||||
|
||||
// Display Alert Messages
|
||||
async function displayAlerts(array) {
|
||||
var counter = 0
|
||||
var messages = ""
|
||||
var messages = ''
|
||||
for(var i = 0; i < array.length; i++) {
|
||||
// Increment counter
|
||||
counter += 1;
|
||||
counter += 1
|
||||
// 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"
|
||||
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`
|
||||
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`
|
||||
document.getElementById('alert_bar_note').textContent = `There are ${counter} active alerts`
|
||||
}
|
||||
return true;
|
||||
return true
|
||||
}
|
||||
return false;
|
||||
return false
|
||||
}
|
||||
|
||||
|
||||
/* Show/Hide alerts box */
|
||||
async function inflateAlerts() {
|
||||
document.getElementById("alerts_msg").style = "display:block;";
|
||||
document.getElementById("alert_expand_arrow").style = "transform: rotate(180deg);";
|
||||
document.getElementById("alerts_bar").setAttribute("onclick", "deflateAlerts()")
|
||||
document.getElementById('alerts_msg').style = 'display:block;'
|
||||
document.getElementById('alert_expand_arrow').style = 'transform: rotate(180deg);'
|
||||
document.getElementById('alerts_bar').setAttribute('onclick', 'deflateAlerts()')
|
||||
}
|
||||
|
||||
async function deflateAlerts() {
|
||||
document.getElementById("alerts_msg").style = "display.none;";
|
||||
document.getElementById("alert_expand_arrow").style = "transform: rotate(0deg);";
|
||||
document.getElementById("alerts_bar").setAttribute("onclick", "inflateAlerts()")
|
||||
document.getElementById('alerts_msg').style = 'display.none;'
|
||||
document.getElementById('alert_expand_arrow').style = 'transform: rotate(0deg);'
|
||||
document.getElementById('alerts_bar').setAttribute('onclick', 'inflateAlerts()')
|
||||
}
|
||||
|
||||
/*//// SERVICE DETAIL LISTS ////*/
|
||||
// Build calling list: -- This outputs calling point data to sessionStorage in the format: key{pre: [{PREVIOUS_Stops}], post: [{POST_STOPS}]}
|
||||
async function buildCallLists(svc) {
|
||||
var sSvcId = svc.serviceID;
|
||||
var sSvcId = svc.serviceID
|
||||
var oSvcData = {
|
||||
plat: svc.platform,
|
||||
sta: svc.sta,
|
||||
eta: svc.eta,
|
||||
std: svc.std,
|
||||
etd: svc.etd
|
||||
};
|
||||
}
|
||||
try {
|
||||
if (typeof svc.previousCallingPoints.callingPointList.callingPoint != 'undefined') {
|
||||
let array = await makeArray(svc.previousCallingPoints.callingPointList.callingPoint);
|
||||
oSvcData.pre = array;
|
||||
let array = await makeArray(svc.previousCallingPoints.callingPointList.callingPoint)
|
||||
oSvcData.pre = array
|
||||
}
|
||||
} catch (err) { /* Do nothing if ERR */ }
|
||||
try {
|
||||
if (typeof svc.subsequentCallingPoints.callingPointList.callingPoint != 'undefined') {
|
||||
let array = await makeArray(svc.subsequentCallingPoints.callingPointList.callingPoint);
|
||||
oSvcData.post = array;
|
||||
let array = await makeArray(svc.subsequentCallingPoints.callingPointList.callingPoint)
|
||||
oSvcData.post = array
|
||||
}
|
||||
} catch (err) { /* Do nothing if ERR */ }
|
||||
sessionStorage.setItem(sSvcId, JSON.stringify(oSvcData))
|
||||
@ -154,27 +154,27 @@ async function buildCallLists(svc) {
|
||||
|
||||
/* Display calling list: - Read data from sessionStorage and write to DOM. */
|
||||
async function showCalls(id) {
|
||||
log(`Showing details for service ${id}`, "INFO")
|
||||
var svcDetail = await JSON.parse(sessionStorage.getItem(id));
|
||||
var pre = "";
|
||||
var post = "";
|
||||
log(`Showing details for service ${id}`, 'INFO')
|
||||
var svcDetail = await JSON.parse(sessionStorage.getItem(id))
|
||||
var pre = ''
|
||||
var post = ''
|
||||
if (typeof svcDetail.pre != 'undefined') {
|
||||
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++) {
|
||||
post += await singleCall(svcDetail.post[postCall]);
|
||||
post += await singleCall(svcDetail.post[postCall])
|
||||
}
|
||||
}
|
||||
/* Run retreived data through parsers */
|
||||
var thisStd = await parseTime(svcDetail.std);
|
||||
var thisEtd = await parseTime(svcDetail.etd);
|
||||
var thisSta = await parseTime(svcDetail.sta);
|
||||
var thisEta = await parseTime(svcDetail.eta);
|
||||
var thisStd = await parseTime(svcDetail.std)
|
||||
var thisEtd = await parseTime(svcDetail.etd)
|
||||
var thisSta = await parseTime(svcDetail.sta)
|
||||
var thisEta = await parseTime(svcDetail.eta)
|
||||
/* Prepare data for this station */
|
||||
if (thisStd.data != "-") {
|
||||
if (thisStd.data != '-') {
|
||||
var sTime = `${thisStd.data}`
|
||||
var eTime = `${thisEtd.data}`
|
||||
var change = thisEtd.changed
|
||||
@ -185,7 +185,7 @@ async function showCalls(id) {
|
||||
};
|
||||
|
||||
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 ${change}">${eTime}</td>
|
||||
</tr> `
|
||||
@ -204,23 +204,23 @@ async function showCalls(id) {
|
||||
</table>
|
||||
</div>`
|
||||
|
||||
document.body.insertAdjacentHTML("beforeend", dom);
|
||||
document.getElementById(id).style = "display: block;";
|
||||
return;
|
||||
document.body.insertAdjacentHTML('beforeend', dom)
|
||||
document.getElementById(id).style = 'display: block;'
|
||||
return
|
||||
}
|
||||
|
||||
async function hideCalls(id) {
|
||||
let element = document.getElementById(id)
|
||||
element.style = "display: none;";
|
||||
element.remove();
|
||||
return;
|
||||
element.style = 'display: none;'
|
||||
element.remove()
|
||||
return
|
||||
}
|
||||
|
||||
/* Builds the train data information in to a table row */
|
||||
async function singleCall(data) {
|
||||
if (typeof data.et != "undefined") {
|
||||
if (typeof data.et != 'undefined') {
|
||||
var time = await parseTime(data.et)
|
||||
} else if (typeof data.at != "undefined") {
|
||||
} else if (typeof data.at != 'undefined') {
|
||||
var time = await parseTime(data.at)
|
||||
}
|
||||
return `<tr>
|
||||
@ -232,19 +232,19 @@ async function singleCall(data) {
|
||||
|
||||
/* Error Handler */
|
||||
async function errorHandler() {
|
||||
if (sessionStorage.getItem("failcount")) {
|
||||
var errCount = parseInt(sessionStorage.getItem("failcount"))
|
||||
if (sessionStorage.getItem('failcount')) {
|
||||
var errCount = parseInt(sessionStorage.getItem('failcount'))
|
||||
} else {
|
||||
var errCount = 0;
|
||||
var errCount = 0
|
||||
}
|
||||
errCount += 1;
|
||||
sessionStorage.setItem("failcount", errCount.toString())
|
||||
errCount += 1
|
||||
sessionStorage.setItem('failcount', errCount.toString())
|
||||
if (errCount < 10){
|
||||
await delay(3000);
|
||||
vibe("err")
|
||||
await delay(3000)
|
||||
vibe('err')
|
||||
location.reload()
|
||||
} else {
|
||||
sessionStorage.removeItem("failcount");
|
||||
window.location.assign("conn-err.html")
|
||||
sessionStorage.removeItem('failcount')
|
||||
window.location.assign('conn-err.html')
|
||||
}
|
||||
}
|
132
js/lib.main.js
132
js/lib.main.js
@ -1,118 +1,118 @@
|
||||
/* All Page Init */
|
||||
const version = "2.0.0-dev";
|
||||
const version = '2.0.0-dev'
|
||||
|
||||
/* Feature Detectors */
|
||||
|
||||
/* Valid values for ${type}: localstorage, sessionstorage */
|
||||
async function storageAvailable(type) { // Currently not used
|
||||
try {
|
||||
let storage = window[type];
|
||||
let x = '__storage_test__';
|
||||
storage.setItem(x, "test");
|
||||
storage.getItem(x);
|
||||
storage.removeItem(x);
|
||||
log(`lib.main.storageAvailable: ${type} is available`, "INFO")
|
||||
return true;
|
||||
let storage = window[type]
|
||||
let x = '__storage_test__'
|
||||
storage.setItem(x, 'test')
|
||||
storage.getItem(x)
|
||||
storage.removeItem(x)
|
||||
log(`lib.main.storageAvailable: ${type} is available`, 'INFO')
|
||||
return true
|
||||
} catch (err) {
|
||||
log(`lib.main.storageAvailable: ${type} is not available`, "ERR")
|
||||
return false;
|
||||
log(`lib.main.storageAvailable: ${type} is not available`, 'ERR')
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
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
|
||||
return;
|
||||
return
|
||||
}
|
||||
|
||||
/* Array Converter
|
||||
Converts a string to a single item array */
|
||||
async function makeArray(data) {
|
||||
if (!Array.isArray(data)) {
|
||||
var array = [];
|
||||
array.push(data);
|
||||
return array;
|
||||
var array = []
|
||||
array.push(data)
|
||||
return array
|
||||
}
|
||||
return data;
|
||||
return data
|
||||
}
|
||||
|
||||
/* Timeouts */
|
||||
/* Usage: '' */
|
||||
const delay = ms => new Promise(res => setTimeout(res, ms));
|
||||
const delay = ms => new Promise(res => setTimeout(res, ms))
|
||||
|
||||
|
||||
/* Log Helper */
|
||||
/* Maintains backwards compatibility for previous
|
||||
implementation of log helper */
|
||||
async function log(msg, type) {
|
||||
const mode = "tst"
|
||||
if (mode === "prod" && type != "ERR") {
|
||||
return;
|
||||
const mode = 'tst'
|
||||
if (mode === 'prod' && type != 'ERR') {
|
||||
return
|
||||
}
|
||||
var time = new Date().toISOString();
|
||||
var time = new Date().toISOString()
|
||||
switch (type) {
|
||||
case "ERR":
|
||||
console.error(`${time} - ${msg}`);
|
||||
break;
|
||||
case "WARN":
|
||||
console.warn(`${time} - ${msg}`);
|
||||
break;
|
||||
case "INFO":
|
||||
console.info(`${time} - ${msg}`);
|
||||
break;
|
||||
case 'ERR':
|
||||
console.error(`${time} - ${msg}`)
|
||||
break
|
||||
case 'WARN':
|
||||
console.warn(`${time} - ${msg}`)
|
||||
break
|
||||
case 'INFO':
|
||||
console.info(`${time} - ${msg}`)
|
||||
break
|
||||
default:
|
||||
console.log(`${time} - ${msg}`);
|
||||
break;
|
||||
};
|
||||
};
|
||||
console.log(`${time} - ${msg}`)
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
/* Show/Hide - Menu Control */
|
||||
async function sidebarOpen() {
|
||||
document.getElementById("sidebar").style.width = "50%";
|
||||
document.getElementById("sidebar_open_short").style.display = "none";
|
||||
document.getElementById("sidebar_close_short").style.display = "block";
|
||||
document.getElementById('sidebar').style.width = '50%'
|
||||
document.getElementById('sidebar_open_short').style.display = 'none'
|
||||
document.getElementById('sidebar_close_short').style.display = 'block'
|
||||
}
|
||||
|
||||
async function sidebarClose() {
|
||||
document.getElementById("sidebar").style.width = "0%"
|
||||
document.getElementById("sidebar_open_short").style.display = "block";
|
||||
document.getElementById("sidebar_close_short").style.display = "none";
|
||||
document.getElementById('sidebar').style.width = '0%'
|
||||
document.getElementById('sidebar_open_short').style.display = 'block'
|
||||
document.getElementById('sidebar_close_short').style.display = 'none'
|
||||
}
|
||||
|
||||
/* Loading Box Control */
|
||||
async function hideLoading() {
|
||||
document.getElementById("loading").style = "display: none;";
|
||||
document.getElementById('loading').style = 'display: none;'
|
||||
}
|
||||
|
||||
/* DEPRECIATED: Alias for hideLoading() - Marked for removal*/
|
||||
async function clearLoading() {
|
||||
log("Depreciated function called - clearLoading() - Alias to hideLoading()", "WARN")
|
||||
hideLoading();
|
||||
log('Depreciated function called - clearLoading() - Alias to hideLoading()', 'WARN')
|
||||
hideLoading()
|
||||
}
|
||||
|
||||
async function showLoading() {
|
||||
document.getElementById("loading").style = "display: block;";
|
||||
document.getElementById('loading').style = 'display: block;'
|
||||
}
|
||||
|
||||
async function setLoadingDesc(desc) {
|
||||
document.getElementById("loading_desc").textContent = `${desc}`;
|
||||
document.getElementById('loading_desc').textContent = `${desc}`
|
||||
}
|
||||
|
||||
/* Fetch User Settings */
|
||||
async function getQuickLinks() {
|
||||
var defaults =
|
||||
["bri","lwh","srd","mtp","rda","cfn",
|
||||
"sml","shh","pri","avn","sar","svb"];
|
||||
['bri','lwh','srd','mtp','rda','cfn',
|
||||
'sml','shh','pri','avn','sar','svb']
|
||||
try {
|
||||
if (localStorage.getItem("qlOpt")) {
|
||||
var data = JSON.parse(localStorage.getItem("qlOpt"));
|
||||
if (localStorage.getItem('qlOpt')) {
|
||||
var data = JSON.parse(localStorage.getItem('qlOpt'))
|
||||
} else {
|
||||
data = defaults;
|
||||
data = defaults
|
||||
}
|
||||
} catch (err) {
|
||||
data = defaults;
|
||||
data = defaults
|
||||
}
|
||||
return data.sort();
|
||||
return data.sort()
|
||||
}
|
||||
|
||||
/* Fetch a known query parameter from the pages URL */
|
||||
@ -133,16 +133,16 @@ async function getApi(path,auth = false) {
|
||||
if (auth) {
|
||||
let key = localStorage.getItem('uuid')
|
||||
var options = {
|
||||
method: "GET",
|
||||
redirect: "follow",
|
||||
method: 'GET',
|
||||
redirect: 'follow',
|
||||
headers: {
|
||||
"uuid": key
|
||||
'uuid': key
|
||||
}
|
||||
}
|
||||
} else {
|
||||
var options = {
|
||||
method: "GET",
|
||||
redirect: "follow"
|
||||
method: 'GET',
|
||||
redirect: 'follow'
|
||||
}
|
||||
}
|
||||
try {
|
||||
@ -155,10 +155,10 @@ async function getApi(path,auth = false) {
|
||||
return resp.status
|
||||
}
|
||||
if (!resp.ok) {
|
||||
log(`lib.main: getApi: Fetch error`)
|
||||
log('lib.main: getApi: Fetch error')
|
||||
return false
|
||||
}
|
||||
return json;
|
||||
return json
|
||||
} catch(err) {
|
||||
log(`lib.main: getApi: Caught fetch error. Status: ${resp.status}`)
|
||||
return resp.status
|
||||
@ -166,24 +166,24 @@ async function getApi(path,auth = false) {
|
||||
}
|
||||
|
||||
async function showHideAuthNotice() {
|
||||
let uuid = localStorage.getItem("uuid")
|
||||
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)){
|
||||
let canVibrate = 'vibrate' in navigator || 'mozVibrate' in navigator
|
||||
if (canVibrate && !('vibrate' in navigator)){
|
||||
navigator.vibrate = navigator.mozVibrate
|
||||
}
|
||||
switch (type) {
|
||||
case "err":
|
||||
case 'err':
|
||||
navigator.vibrate([300])
|
||||
break;
|
||||
case "ok":
|
||||
break
|
||||
case 'ok':
|
||||
navigator.vibrate([50,50,50])
|
||||
break;
|
||||
break
|
||||
default:
|
||||
navigator.vibrate(30)
|
||||
}
|
||||
|
18
js/pis.js
18
js/pis.js
@ -21,8 +21,8 @@ async function findByOrigDest() {
|
||||
}
|
||||
|
||||
async function fetchOrigDest() {
|
||||
var orig = document.getElementById("origin").value
|
||||
var dest = document.getElementById("destination").value
|
||||
var orig = document.getElementById('origin').value
|
||||
var dest = document.getElementById('destination').value
|
||||
return {origin: orig, destination: dest}
|
||||
}
|
||||
|
||||
@ -42,30 +42,30 @@ async function insertData(json) {
|
||||
<td class="station">${json[i]['stops'].join(', ')}</td></tr>`
|
||||
results++
|
||||
}
|
||||
tableData += "</table>"
|
||||
div.insertAdjacentHTML("beforeend", tableData)
|
||||
tableData += '</table>'
|
||||
div.insertAdjacentHTML('beforeend', tableData)
|
||||
document.getElementById('result-count').textContent = results.toString()
|
||||
}
|
||||
|
||||
async function displayNoData() {
|
||||
const msg = '<p id="result-table">No results found</p>'
|
||||
document.getElementById('result-box').insertAdjacentHTML("beforeend", msg)
|
||||
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)
|
||||
document.getElementById('result-box').insertAdjacentHTML('beforeend', msg)
|
||||
}
|
||||
|
||||
async function reset() {
|
||||
try {
|
||||
document.getElementById('origin').value = ""
|
||||
document.getElementById('destination').value = ""
|
||||
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`)
|
||||
log('Nothing to reset')
|
||||
}
|
||||
}
|
@ -2,21 +2,21 @@
|
||||
// Init:
|
||||
//
|
||||
// Setup quick links
|
||||
const ql = ["ql0","ql1","ql2","ql3","ql4","ql5","ql6","ql7","ql8","ql9","ql10","ql11"]
|
||||
storageAvailable("localStorage");
|
||||
getQl();
|
||||
const ql = ['ql0','ql1','ql2','ql3','ql4','ql5','ql6','ql7','ql8','ql9','ql10','ql11']
|
||||
storageAvailable('localStorage')
|
||||
getQl()
|
||||
// Check if already registered
|
||||
ifAlreadyRegistered();
|
||||
ifAlreadyRegistered()
|
||||
// Hide loading
|
||||
hideLoading();
|
||||
hideLoading()
|
||||
|
||||
async function ifAlreadyRegistered() { // If already registered, show this on the page
|
||||
if (! await isRegistered()) {
|
||||
return null
|
||||
} else {
|
||||
document.getElementsByName("eml")[0].placeholder = "Registered";
|
||||
document.getElementById("reg_text").textContent = "You are already registered";
|
||||
document.getElementById("reg_button").textContent = "Log Out";
|
||||
document.getElementsByName('eml')[0].placeholder = 'Registered'
|
||||
document.getElementById('reg_text').textContent = 'You are already registered'
|
||||
document.getElementById('reg_button').textContent = 'Log Out'
|
||||
}
|
||||
}
|
||||
|
||||
@ -34,66 +34,66 @@ async function getQl(){ // Fetch Quick Links from 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 = []
|
||||
for (i in ql) {
|
||||
var opt = document.getElementById(`ql${i}`).value
|
||||
if (opt != ""){
|
||||
if (opt != ''){
|
||||
qlSet.push(opt)
|
||||
}
|
||||
qlSet.sort()
|
||||
}
|
||||
localStorage.setItem("qlOpt", JSON.stringify(qlSet))
|
||||
log(`settings.setQl: User settings saved`, "INFO")
|
||||
await hideLoading();
|
||||
await showDone();
|
||||
vibe("ok")
|
||||
await delay(800);
|
||||
hideDone();
|
||||
localStorage.setItem('qlOpt', JSON.stringify(qlSet))
|
||||
log('settings.setQl: User settings saved', 'INFO')
|
||||
await hideLoading()
|
||||
await showDone()
|
||||
vibe('ok')
|
||||
await delay(800)
|
||||
hideDone()
|
||||
}
|
||||
|
||||
async function clearQl(){ // Clear Quick Links from localstorage
|
||||
showLoading();
|
||||
localStorage.removeItem("qlOpt")
|
||||
log(`settings.setQl: User settings reset to default`, "INFO")
|
||||
showLoading()
|
||||
localStorage.removeItem('qlOpt')
|
||||
log('settings.setQl: User settings reset to default', 'INFO')
|
||||
getQl()
|
||||
await hideLoading();
|
||||
await showDone();
|
||||
vibe("ok");
|
||||
await delay(800);
|
||||
hideDone();
|
||||
await hideLoading()
|
||||
await showDone()
|
||||
vibe('ok')
|
||||
await delay(800)
|
||||
hideDone()
|
||||
}
|
||||
|
||||
async function isRegistered() { // Check if a device is registered, returns BOOL
|
||||
if (localStorage.getItem("uuid")) {
|
||||
if (localStorage.getItem('uuid')) {
|
||||
return true
|
||||
// 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
|
||||
}
|
||||
localStorage.removeItem("uuid");
|
||||
localStorage.removeItem('uuid')
|
||||
return false
|
||||
}
|
||||
|
||||
async function register() { // Registers a device by sending POST request to API Server
|
||||
if (! await isRegistered()) {
|
||||
showLoading()
|
||||
let url = `${window.location.origin}/api/v1/register/request`;
|
||||
let email = document.getElementById("eml").value
|
||||
let url = `${window.location.origin}/api/v1/register/request`
|
||||
let email = document.getElementById('eml').value
|
||||
let res = await fetch(url, {
|
||||
method: "POST",
|
||||
method: 'POST',
|
||||
headers: {
|
||||
"Content-Type": "application/json"
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
redirect: "follow",
|
||||
redirect: 'follow',
|
||||
body: JSON.stringify({email: email})
|
||||
})
|
||||
if (res.status == 201) {
|
||||
showDone();
|
||||
hideLoading();
|
||||
return;
|
||||
showDone()
|
||||
hideLoading()
|
||||
return
|
||||
} else if (res.status == 403) {
|
||||
log(`settings.register: Error: Fetch returned: ${res.body['errorCode']}`, "err")
|
||||
document.getElementsByName("eml")[0].placeholder = "Not Authorised";
|
||||
log(`settings.register: Error: Fetch returned: ${res.body['errorCode']}`, 'err')
|
||||
document.getElementsByName('eml')[0].placeholder = 'Not Authorised'
|
||||
}
|
||||
} else {
|
||||
logout()
|
||||
@ -101,15 +101,15 @@ async function register() { // Registers a device by sending POST request to API
|
||||
}
|
||||
|
||||
async function logout() { // Simply removed the UUID from localstorage
|
||||
localStorage.removeItem("uuid");
|
||||
location.reload();
|
||||
localStorage.removeItem('uuid')
|
||||
location.reload()
|
||||
return
|
||||
}
|
||||
|
||||
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.
|
||||
document.getElementById("done").style = "opacity: 0; display: none";
|
||||
document.getElementById('done').style = 'opacity: 0; display: none'
|
||||
}
|
@ -4,25 +4,25 @@ init()
|
||||
|
||||
/* Init function */
|
||||
async function init() { // Gets query string and then fetch API response and pass to parsing function
|
||||
console.time("Time: Init to Complete")
|
||||
setLoadingDesc(`Loading\nservices`)
|
||||
var stn = await getQuery("stn");
|
||||
console.time('Time: Init to Complete')
|
||||
setLoadingDesc('Loading\nservices')
|
||||
var stn = await getQuery('stn')
|
||||
setLoadingDesc(`Loading\n${stn.toUpperCase()}`)
|
||||
log(`init: Looking up: ${stn}`);
|
||||
var sv = await getQuery("sv");
|
||||
log(`init: Staff Version: ${sv}`);
|
||||
log(`init: Looking up: ${stn}`)
|
||||
var sv = await getQuery('sv')
|
||||
log(`init: Staff Version: ${sv}`)
|
||||
if (sv === 'true') {
|
||||
log("init: Staff Version not supported yet.")
|
||||
log("init: Unable to proceed.")
|
||||
log('init: Staff Version not supported yet.')
|
||||
log('init: Unable to proceed.')
|
||||
} else {
|
||||
try {
|
||||
var data = await publicLdb(stn)
|
||||
setLoadingDesc(`${stn.toUpperCase()}\nParsing Data`)
|
||||
log("simple-board.init: Fetched LDB Data", "INFO")
|
||||
log('simple-board.init: Fetched LDB Data', 'INFO')
|
||||
} catch (err) {
|
||||
var data = "err"
|
||||
setLoadingDesc(`Waiting\nConnection`)
|
||||
log(`simple-board.init: Error fetching data: ${err}`, "ERR")
|
||||
var data = 'err'
|
||||
setLoadingDesc('Waiting\nConnection')
|
||||
log(`simple-board.init: Error fetching data: ${err}`, 'ERR')
|
||||
}
|
||||
parseLdb(data)
|
||||
}
|
||||
@ -31,43 +31,43 @@ async function init() { // Gets query string and then fetch API response and pas
|
||||
/* Check for any errors in data returned from the Fetch call
|
||||
If no errors, if there are none, call buildPage(). */
|
||||
async function parseLdb(data) {
|
||||
if (data.ERROR == "NOT_FOUND") { // Station not found
|
||||
hideLoading();
|
||||
document.getElementById("error_notice").style = "display: block;";
|
||||
document.getElementById("err_not_found").style = "display: block;";
|
||||
setHeaders("Not Found",new Date())
|
||||
if (data.ERROR == 'NOT_FOUND') { // Station not found
|
||||
hideLoading()
|
||||
document.getElementById('error_notice').style = 'display: block;'
|
||||
document.getElementById('err_not_found').style = 'display: block;'
|
||||
setHeaders('Not Found',new Date())
|
||||
} else if (data == false) { // No data for station
|
||||
hideLoading();
|
||||
document.getElementById("error_notice").style = "display: block;";
|
||||
document.getElementById("err_no_data").style = "display:block;";
|
||||
setHeaders("No Data",new Date())
|
||||
} else if (data == "err") { // Connection Error
|
||||
await delay(2000);
|
||||
hideLoading();
|
||||
document.getElementById("error_notice").style = "display: block;";
|
||||
document.getElementById("err_conn").style = "display: block;";
|
||||
setHeaders("Connection Error",new Date())
|
||||
showLoading();
|
||||
await delay(5000);
|
||||
log(`parseLdb: Passing to error handler`, "ERR")
|
||||
errorHandler();
|
||||
hideLoading()
|
||||
document.getElementById('error_notice').style = 'display: block;'
|
||||
document.getElementById('err_no_data').style = 'display:block;'
|
||||
setHeaders('No Data',new Date())
|
||||
} else if (data == 'err') { // Connection Error
|
||||
await delay(2000)
|
||||
hideLoading()
|
||||
document.getElementById('error_notice').style = 'display: block;'
|
||||
document.getElementById('err_conn').style = 'display: block;'
|
||||
setHeaders('Connection Error',new Date())
|
||||
showLoading()
|
||||
await delay(5000)
|
||||
log('parseLdb: Passing to error handler', 'ERR')
|
||||
errorHandler()
|
||||
} else {
|
||||
buildPage(data);
|
||||
buildPage(data)
|
||||
}
|
||||
}
|
||||
|
||||
// Build and Display Functions
|
||||
async function buildPage(data) {
|
||||
setLoadingDesc('Loading\nData')
|
||||
var stationName = data.GetStationBoardResult.locationName;
|
||||
log(`buildPage: Data ready for ${stationName}`);
|
||||
var generateTime = new Date(await data.GetStationBoardResult.generatedAt);
|
||||
var stationName = data.GetStationBoardResult.locationName
|
||||
log(`buildPage: Data ready for ${stationName}`)
|
||||
var generateTime = new Date(await data.GetStationBoardResult.generatedAt)
|
||||
log(`buildPage: Data prepared at ${generateTime.toLocaleString()}`)
|
||||
setHeaders(stationName, generateTime);
|
||||
setHeaders(stationName, generateTime)
|
||||
// Check for notices and if true pass to function
|
||||
if (data.GetStationBoardResult.nrccMessages) {
|
||||
setLoadingDesc('Loading\nAlerts')
|
||||
await displayAlerts(await makeArray(data.GetStationBoardResult.nrccMessages.message));
|
||||
await displayAlerts(await makeArray(data.GetStationBoardResult.nrccMessages.message))
|
||||
}
|
||||
if (data.GetStationBoardResult.trainServices) {
|
||||
setLoadingDesc('Loading\nTrains')
|
||||
@ -83,21 +83,21 @@ async function buildPage(data) {
|
||||
setLoadingDesc('Loading\nBusses')
|
||||
displayBus(await makeArray(data.GetStationBoardResult.busServices.service))
|
||||
}
|
||||
hideLoading();
|
||||
console.timeEnd("Time: Init to Complete")
|
||||
hideLoading()
|
||||
console.timeEnd('Time: Init to Complete')
|
||||
}
|
||||
|
||||
|
||||
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++) {
|
||||
// Reset Vars
|
||||
var svc = data[i];
|
||||
displayService(svc);
|
||||
buildCallLists(svc);
|
||||
var svc = data[i]
|
||||
displayService(svc)
|
||||
buildCallLists(svc)
|
||||
}
|
||||
document.getElementById("output").style = "display:block;";
|
||||
log(`simple-board.displayTrains: Insertion complete`)
|
||||
document.getElementById('output').style = 'display:block;'
|
||||
log('simple-board.displayTrains: Insertion complete')
|
||||
}
|
||||
|
||||
async function displayFerry(ferrySvc) { // Iterates through each ferry service and passes to another function
|
||||
@ -114,16 +114,16 @@ async function displayBus(busSvc) { // Iterates through each bus service and pas
|
||||
}
|
||||
|
||||
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
|
||||
var sta = await parseTime(svc.sta);
|
||||
var eta = await parseTime(svc.eta);
|
||||
var std = await parseTime(svc.std);
|
||||
var etd = await parseTime(svc.etd);
|
||||
var sta = await parseTime(svc.sta)
|
||||
var eta = await parseTime(svc.eta)
|
||||
var std = await parseTime(svc.std)
|
||||
var etd = await parseTime(svc.etd)
|
||||
// Determine Platform Message
|
||||
//if (svc.platform != undefined){var plt = svc.platform} else {var plt = "-"};
|
||||
var plt = await parsePlatform(svc);
|
||||
var plt = await parsePlatform(svc)
|
||||
// Define Table Row
|
||||
var row = `
|
||||
<table>
|
||||
@ -138,38 +138,38 @@ async function displayService(svc) { // Creates a table row from each train serv
|
||||
</tr>
|
||||
</table>`
|
||||
// Put Table Row
|
||||
table.insertAdjacentHTML("beforeend", row)
|
||||
table.insertAdjacentHTML('beforeend', row)
|
||||
// Display Operator where provided (it always will be, I think)
|
||||
if (svc.operator) {
|
||||
var opRow = `<p class="msg op">A ${svc.operator} service`
|
||||
if (svc.length) { // Displays number of carriages where provided
|
||||
opRow += ` with ${svc.length} carriages</p>`;
|
||||
opRow += ` with ${svc.length} carriages</p>`
|
||||
} else {
|
||||
opRow += `</p>`
|
||||
opRow += '</p>'
|
||||
}
|
||||
table.insertAdjacentHTML("beforeend", opRow);
|
||||
table.insertAdjacentHTML('beforeend', opRow)
|
||||
}
|
||||
// Parse cancelReason and then delayReason
|
||||
if (svc.cancelReason) {
|
||||
var cancelRow = `<p class="msg">${svc.cancelReason}</p>`
|
||||
table.insertAdjacentHTML("beforeend", cancelRow);
|
||||
table.insertAdjacentHTML('beforeend', cancelRow)
|
||||
}
|
||||
if (svc.delayReason) {
|
||||
var delayRow = `<p class="msg">${svc.delayReason}</p>`
|
||||
table.insertAdjacentHTML("beforeend", delayRow);
|
||||
table.insertAdjacentHTML('beforeend', delayRow)
|
||||
}
|
||||
}
|
||||
|
||||
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))
|
||||
// Determine Time Message
|
||||
var sta = await parseTime(svc.sta);
|
||||
var eta = await parseTime(svc.eta);
|
||||
var std = await parseTime(svc.std);
|
||||
var etd = await parseTime(svc.etd);
|
||||
var sta = await parseTime(svc.sta)
|
||||
var eta = await parseTime(svc.eta)
|
||||
var std = await parseTime(svc.std)
|
||||
var etd = await parseTime(svc.etd)
|
||||
// Determine Platform Message
|
||||
var plt = "";
|
||||
var plt = ''
|
||||
// Define Table Row
|
||||
var row = `
|
||||
<table>
|
||||
@ -184,29 +184,29 @@ async function displayFerryService(svc) { // Creates a table for for each ferry
|
||||
</tr>
|
||||
</table>`
|
||||
// Put Table Row
|
||||
table.insertAdjacentHTML("beforeend", row)
|
||||
table.insertAdjacentHTML('beforeend', row)
|
||||
// Parse cancelReason & delayReason
|
||||
if (svc.cancelReason) {
|
||||
var cancelRow = `<p class="msg">${svc.cancelReason}</p>`
|
||||
table.insertAdjacentHTML("beforeend", cancelRow);
|
||||
table.insertAdjacentHTML('beforeend', cancelRow)
|
||||
}
|
||||
if (svc.delayReason) {
|
||||
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.
|
||||
var table = document.getElementById("bus");
|
||||
var table = document.getElementById('bus')
|
||||
log(JSON.stringify(svc))
|
||||
// Determine Time Message
|
||||
var sta = await parseTime(svc.sta);
|
||||
var eta = await parseTime(svc.eta);
|
||||
var std = await parseTime(svc.std);
|
||||
var etd = await parseTime(svc.etd);
|
||||
var sta = await parseTime(svc.sta)
|
||||
var eta = await parseTime(svc.eta)
|
||||
var std = await parseTime(svc.std)
|
||||
var etd = await parseTime(svc.etd)
|
||||
// Determine Platform Message
|
||||
var plt = "";
|
||||
var plt = ''
|
||||
// Define Table Row
|
||||
var row = `
|
||||
<table>
|
||||
@ -221,20 +221,20 @@ async function displayBusService(svc) { // Creates a table row for each bus serv
|
||||
</tr>
|
||||
</table>`
|
||||
// Put Table Row
|
||||
table.insertAdjacentHTML("beforeend", row)
|
||||
table.insertAdjacentHTML('beforeend', row)
|
||||
// Display operator
|
||||
if (svc.operator) {
|
||||
var opRow = `<p class="msg op">A ${svc.operator} service</p>`
|
||||
table.insertAdjacentHTML("beforeend", opRow);
|
||||
table.insertAdjacentHTML('beforeend', opRow)
|
||||
}
|
||||
// Parse cancelReason & delayReason
|
||||
if (svc.cancelReason) {
|
||||
var cancelRow = `<p class="msg">${svc.cancelReason}</p>`
|
||||
table.insertAdjacentHTML("beforeend", cancelRow);
|
||||
table.insertAdjacentHTML('beforeend', cancelRow)
|
||||
}
|
||||
if (svc.delayReason) {
|
||||
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'
|
||||
}
|
@ -4,25 +4,26 @@ init()
|
||||
|
||||
/* Init function */
|
||||
async function init() { // Gets query string and then fetch API response and pass to parsing function
|
||||
console.time("Time: Init to Complete")
|
||||
setLoadingDesc(`Loading\nservices`)
|
||||
var stn = await getQuery("stn");
|
||||
console.time('Time: Init to Complete')
|
||||
setLoadingDesc('Loading\nservices')
|
||||
var stn = await getQuery('stn')
|
||||
setLoadingDesc(`Loading\n${stn.toUpperCase()}`)
|
||||
log(`init: Looking up: ${stn}`);
|
||||
var sv = await getQuery("sv");
|
||||
log(`init: Staff Version: ${sv}`);
|
||||
log(`init: Looking up: ${stn}`)
|
||||
var sv = await getQuery('sv')
|
||||
log(`init: Staff Version: ${sv}`)
|
||||
if (sv === 'true') {
|
||||
log("init: Staff Version not supported yet.")
|
||||
log("init: Unable to proceed.")
|
||||
log('init: Staff Version not supported yet.')
|
||||
log('init: Unable to proceed.')
|
||||
} else {
|
||||
let data
|
||||
try {
|
||||
var data = await publicLdb(stn)
|
||||
data = await publicLdb(stn)
|
||||
setLoadingDesc(`${stn.toUpperCase()}\nParsing Data`)
|
||||
log("simple-board.init: Fetched LDB Data", "INFO")
|
||||
log('simple-board.init: Fetched LDB Data', 'INFO')
|
||||
} catch (err) {
|
||||
var data = "err"
|
||||
setLoadingDesc(`Waiting\nConnection`)
|
||||
log(`simple-board.init: Error fetching data: ${err}`, "ERR")
|
||||
data = 'err'
|
||||
setLoadingDesc('Waiting\nConnection')
|
||||
log(`simple-board.init: Error fetching data: ${err}`, 'ERR')
|
||||
}
|
||||
parseLdb(data)
|
||||
}
|
||||
@ -31,43 +32,43 @@ async function init() { // Gets query string and then fetch API response and pas
|
||||
/* Check for any errors in data returned from the Fetch call
|
||||
If no errors, if there are none, call buildPage(). */
|
||||
async function parseLdb(data) {
|
||||
if (data.ERROR == "NOT_FOUND") { // Station not found
|
||||
hideLoading();
|
||||
document.getElementById("error_notice").style = "display: block;";
|
||||
document.getElementById("err_not_found").style = "display: block;";
|
||||
setHeaders("Not Found",new Date())
|
||||
if (data.ERROR == 'NOT_FOUND') { // Station not found
|
||||
hideLoading()
|
||||
document.getElementById('error_notice').style = 'display: block;'
|
||||
document.getElementById('err_not_found').style = 'display: block;'
|
||||
setHeaders('Not Found',new Date())
|
||||
} else if (data == false) { // No data for station
|
||||
hideLoading();
|
||||
document.getElementById("error_notice").style = "display: block;";
|
||||
document.getElementById("err_no_data").style = "display:block;";
|
||||
setHeaders("No Data",new Date())
|
||||
} else if (data == "err") { // Connection Error
|
||||
await delay(2000);
|
||||
hideLoading();
|
||||
document.getElementById("error_notice").style = "display: block;";
|
||||
document.getElementById("err_conn").style = "display: block;";
|
||||
setHeaders("Connection Error",new Date())
|
||||
showLoading();
|
||||
await delay(5000);
|
||||
log(`parseLdb: Passing to error handler`, "ERR")
|
||||
errorHandler();
|
||||
hideLoading()
|
||||
document.getElementById('error_notice').style = 'display: block;'
|
||||
document.getElementById('err_no_data').style = 'display:block;'
|
||||
setHeaders('No Data',new Date())
|
||||
} else if (data == 'err') { // Connection Error
|
||||
await delay(2000)
|
||||
hideLoading()
|
||||
document.getElementById('error_notice').style = 'display: block;'
|
||||
document.getElementById('err_conn').style = 'display: block;'
|
||||
setHeaders('Connection Error',new Date())
|
||||
showLoading()
|
||||
await delay(5000)
|
||||
log('parseLdb: Passing to error handler', 'ERR')
|
||||
errorHandler()
|
||||
} else {
|
||||
buildPage(data);
|
||||
buildPage(data)
|
||||
}
|
||||
}
|
||||
|
||||
// Build and Display Functions
|
||||
async function buildPage(data) {
|
||||
setLoadingDesc('Loading\nData')
|
||||
var stationName = data.GetStationBoardResult.locationName;
|
||||
log(`buildPage: Data ready for ${stationName}`);
|
||||
var generateTime = new Date(await data.GetStationBoardResult.generatedAt);
|
||||
var stationName = data.GetStationBoardResult.locationName
|
||||
log(`buildPage: Data ready for ${stationName}`)
|
||||
var generateTime = new Date(await data.GetStationBoardResult.generatedAt)
|
||||
log(`buildPage: Data prepared at ${generateTime.toLocaleString()}`)
|
||||
setHeaders(stationName, generateTime);
|
||||
setHeaders(stationName, generateTime)
|
||||
// Check for notices and if true pass to function
|
||||
if (data.GetStationBoardResult.nrccMessages) {
|
||||
setLoadingDesc('Loading\nAlerts')
|
||||
await displayAlerts(await makeArray(data.GetStationBoardResult.nrccMessages.message));
|
||||
await displayAlerts(await makeArray(data.GetStationBoardResult.nrccMessages.message))
|
||||
}
|
||||
if (data.GetStationBoardResult.trainServices) {
|
||||
setLoadingDesc('Loading\nTrains')
|
||||
@ -83,21 +84,21 @@ async function buildPage(data) {
|
||||
setLoadingDesc('Loading\nBusses')
|
||||
displayBus(await makeArray(data.GetStationBoardResult.busServices.service))
|
||||
}
|
||||
hideLoading();
|
||||
console.timeEnd("Time: Init to Complete")
|
||||
hideLoading()
|
||||
console.timeEnd('Time: Init to Complete')
|
||||
}
|
||||
|
||||
|
||||
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++) {
|
||||
// Reset Vars
|
||||
var svc = data[i];
|
||||
displayService(svc);
|
||||
buildCallLists(svc);
|
||||
var svc = data[i]
|
||||
displayService(svc)
|
||||
buildCallLists(svc)
|
||||
}
|
||||
document.getElementById("output").style = "display:block;";
|
||||
log(`simple-board.displayTrains: Insertion complete`)
|
||||
document.getElementById('output').style = 'display:block;'
|
||||
log('simple-board.displayTrains: Insertion complete')
|
||||
}
|
||||
|
||||
async function displayFerry(ferrySvc) { // Iterates through each ferry service and passes to another function
|
||||
@ -114,16 +115,16 @@ async function displayBus(busSvc) { // Iterates through each bus service and pas
|
||||
}
|
||||
|
||||
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
|
||||
var sta = await parseTime(svc.sta);
|
||||
var eta = await parseTime(svc.eta);
|
||||
var std = await parseTime(svc.std);
|
||||
var etd = await parseTime(svc.etd);
|
||||
var sta = await parseTime(svc.sta)
|
||||
var eta = await parseTime(svc.eta)
|
||||
var std = await parseTime(svc.std)
|
||||
var etd = await parseTime(svc.etd)
|
||||
// Determine Platform Message
|
||||
//if (svc.platform != undefined){var plt = svc.platform} else {var plt = "-"};
|
||||
var plt = await parsePlatform(svc);
|
||||
var plt = await parsePlatform(svc)
|
||||
// Define Table Row
|
||||
var row = `
|
||||
<table>
|
||||
@ -138,38 +139,38 @@ async function displayService(svc) { // Creates a table row from each train serv
|
||||
</tr>
|
||||
</table>`
|
||||
// Put Table Row
|
||||
table.insertAdjacentHTML("beforeend", row)
|
||||
table.insertAdjacentHTML('beforeend', row)
|
||||
// Display Operator where provided (it always will be, I think)
|
||||
if (svc.operator) {
|
||||
var opRow = `<p class="msg op">A ${svc.operator} service`
|
||||
if (svc.length) { // Displays number of carriages where provided
|
||||
opRow += ` with ${svc.length} carriages</p>`;
|
||||
opRow += ` with ${svc.length} carriages</p>`
|
||||
} else {
|
||||
opRow += `</p>`
|
||||
opRow += '</p>'
|
||||
}
|
||||
table.insertAdjacentHTML("beforeend", opRow);
|
||||
table.insertAdjacentHTML('beforeend', opRow)
|
||||
}
|
||||
// Parse cancelReason and then delayReason
|
||||
if (svc.cancelReason) {
|
||||
var cancelRow = `<p class="msg">${svc.cancelReason}</p>`
|
||||
table.insertAdjacentHTML("beforeend", cancelRow);
|
||||
table.insertAdjacentHTML('beforeend', cancelRow)
|
||||
}
|
||||
if (svc.delayReason) {
|
||||
var delayRow = `<p class="msg">${svc.delayReason}</p>`
|
||||
table.insertAdjacentHTML("beforeend", delayRow);
|
||||
table.insertAdjacentHTML('beforeend', delayRow)
|
||||
}
|
||||
}
|
||||
|
||||
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))
|
||||
// Determine Time Message
|
||||
var sta = await parseTime(svc.sta);
|
||||
var eta = await parseTime(svc.eta);
|
||||
var std = await parseTime(svc.std);
|
||||
var etd = await parseTime(svc.etd);
|
||||
var sta = await parseTime(svc.sta)
|
||||
var eta = await parseTime(svc.eta)
|
||||
var std = await parseTime(svc.std)
|
||||
var etd = await parseTime(svc.etd)
|
||||
// Determine Platform Message
|
||||
var plt = "";
|
||||
var plt = ''
|
||||
// Define Table Row
|
||||
var row = `
|
||||
<table>
|
||||
@ -184,29 +185,29 @@ async function displayFerryService(svc) { // Creates a table for for each ferry
|
||||
</tr>
|
||||
</table>`
|
||||
// Put Table Row
|
||||
table.insertAdjacentHTML("beforeend", row)
|
||||
table.insertAdjacentHTML('beforeend', row)
|
||||
// Parse cancelReason & delayReason
|
||||
if (svc.cancelReason) {
|
||||
var cancelRow = `<p class="msg">${svc.cancelReason}</p>`
|
||||
table.insertAdjacentHTML("beforeend", cancelRow);
|
||||
table.insertAdjacentHTML('beforeend', cancelRow)
|
||||
}
|
||||
if (svc.delayReason) {
|
||||
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.
|
||||
var table = document.getElementById("bus");
|
||||
var table = document.getElementById('bus')
|
||||
log(JSON.stringify(svc))
|
||||
// Determine Time Message
|
||||
var sta = await parseTime(svc.sta);
|
||||
var eta = await parseTime(svc.eta);
|
||||
var std = await parseTime(svc.std);
|
||||
var etd = await parseTime(svc.etd);
|
||||
var sta = await parseTime(svc.sta)
|
||||
var eta = await parseTime(svc.eta)
|
||||
var std = await parseTime(svc.std)
|
||||
var etd = await parseTime(svc.etd)
|
||||
// Determine Platform Message
|
||||
var plt = "";
|
||||
var plt = ''
|
||||
// Define Table Row
|
||||
var row = `
|
||||
<table>
|
||||
@ -221,20 +222,20 @@ async function displayBusService(svc) { // Creates a table row for each bus serv
|
||||
</tr>
|
||||
</table>`
|
||||
// Put Table Row
|
||||
table.insertAdjacentHTML("beforeend", row)
|
||||
table.insertAdjacentHTML('beforeend', row)
|
||||
// Display operator
|
||||
if (svc.operator) {
|
||||
var opRow = `<p class="msg op">A ${svc.operator} service</p>`
|
||||
table.insertAdjacentHTML("beforeend", opRow);
|
||||
table.insertAdjacentHTML('beforeend', opRow)
|
||||
}
|
||||
// Parse cancelReason & delayReason
|
||||
if (svc.cancelReason) {
|
||||
var cancelRow = `<p class="msg">${svc.cancelReason}</p>`
|
||||
table.insertAdjacentHTML("beforeend", cancelRow);
|
||||
table.insertAdjacentHTML('beforeend', cancelRow)
|
||||
}
|
||||
if (svc.delayReason) {
|
||||
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'
|
||||
}
|
32
js/stat.js
32
js/stat.js
@ -1,4 +1,4 @@
|
||||
init();
|
||||
init()
|
||||
|
||||
async function init() { // The page init function
|
||||
versionDisplay()
|
||||
@ -6,25 +6,25 @@ async function init() { // The page init function
|
||||
}
|
||||
|
||||
async function get() { // Fetch data from API
|
||||
var url = `${window.location.origin}/api/v1/stats`;
|
||||
var resp = await fetch(url);
|
||||
return await resp.json();
|
||||
var url = `${window.location.origin}/api/v1/stats`
|
||||
var resp = await fetch(url)
|
||||
return await resp.json()
|
||||
}
|
||||
|
||||
async function display(data) { // Parses and displays data from API
|
||||
document.getElementById('server_host').textContent = data.host;
|
||||
document.getElementById('server_mode').textContent = data.mode || "Unknown";
|
||||
document.getElementById('ver-bkend').textContent = data.verBkend || "Unknown";
|
||||
document.getElementById('server_host').textContent = data.host
|
||||
document.getElementById('server_mode').textContent = data.mode || 'Unknown'
|
||||
document.getElementById('ver-bkend').textContent = data.verBkend || 'Unknown'
|
||||
let dat = data.dat[0]
|
||||
let ver = data.ver[0]
|
||||
document.getElementById('time').textContent = await convertUnixLocal(dat.since);
|
||||
document.getElementById('ldbws').textContent = dat.ldbws || "0";
|
||||
document.getElementById('ldbsvws').textContent = dat.ldbsvws || "0";
|
||||
document.getElementById('apicorpus').textContent = dat.corpus_api || "0";
|
||||
document.getElementById('corpus').textContent = dat.corpus || "0";
|
||||
document.getElementById('stations').textContent = dat.stations || "0";
|
||||
document.getElementById('users').textContent = dat.user || "0";
|
||||
document.getElementById('meta').textContent = dat.meta || "0";
|
||||
document.getElementById('time').textContent = await convertUnixLocal(dat.since)
|
||||
document.getElementById('ldbws').textContent = dat.ldbws || '0'
|
||||
document.getElementById('ldbsvws').textContent = dat.ldbsvws || '0'
|
||||
document.getElementById('apicorpus').textContent = dat.corpus_api || '0'
|
||||
document.getElementById('corpus').textContent = dat.corpus || '0'
|
||||
document.getElementById('stations').textContent = dat.stations || '0'
|
||||
document.getElementById('users').textContent = dat.user || '0'
|
||||
document.getElementById('meta').textContent = dat.meta || '0'
|
||||
document.getElementById('pis').textContent = dat.pis
|
||||
document.getElementById('ver-dbman').textContent = ver.dbmanager || "Unknown";
|
||||
document.getElementById('ver-dbman').textContent = ver.dbmanager || 'Unknown'
|
||||
}
|
140
sw.js
140
sw.js
@ -1,89 +1,89 @@
|
||||
/* Service Worker */
|
||||
|
||||
const appVersion = "PIS-DEV-23043001"
|
||||
const cacheName = `owlboard-${appVersion}`;
|
||||
const cacheIDs = [cacheName];
|
||||
const appVersion = 'PIS-DEV-23043001'
|
||||
const cacheName = `owlboard-${appVersion}`
|
||||
const cacheIDs = [cacheName]
|
||||
const cacheFiles = [
|
||||
"/404.html",
|
||||
"/auth.html",
|
||||
"/board.html",
|
||||
"/conn-err.html",
|
||||
"/help.html",
|
||||
"/",
|
||||
"/issue.html",
|
||||
"/find-code.html",
|
||||
"/settings.html",
|
||||
"/pis.html",
|
||||
"/manifest.json",
|
||||
"/styles/fonts/firamono/firamono-500.woff2",
|
||||
"/styles/fonts/firamono/firamono-regular.woff2",
|
||||
"/styles/fonts/urwgothic/urwgothic.woff2",
|
||||
"/styles/fonts/urwgothic/urwgothicDemi.woff2",
|
||||
"/styles/board.css",
|
||||
"/styles/find-code.css",
|
||||
"/styles/help.css",
|
||||
"/styles/issue.css",
|
||||
"/styles/main.css",
|
||||
"/styles/settings.css",
|
||||
"/styles/pis.css",
|
||||
"/js/find-code.js",
|
||||
"/js/index.js",
|
||||
"/js/issue.js",
|
||||
"/js/lib.board.js",
|
||||
"/js/lib.main.js",
|
||||
"/js/auth.js",
|
||||
"/js/settings.js",
|
||||
"/js/simple-board.js",
|
||||
"/js/pis.js",
|
||||
"/images/icon.svg",
|
||||
"/images/logo/wide_logo.svg",
|
||||
"/images/logo/mono-logo.svg",
|
||||
"/images/app-icons/any/plain-logo.svg",
|
||||
"/images/app-icons/any/plain-logo-512.png",
|
||||
"/images/nav/alert_icon.svg",
|
||||
"/images/nav/save.svg",
|
||||
"/images/nav/home_icon.svg",
|
||||
"/images/nav/back.svg",
|
||||
"/images/nav/hamburger.svg",
|
||||
"/images/nav/close.svg",
|
||||
"/images/nav/refresh.svg",
|
||||
"/images/nre/nre-powered_400w.webp",
|
||||
"/images/nre/nre-powered_400w.jxl"
|
||||
];
|
||||
'/404.html',
|
||||
'/auth.html',
|
||||
'/board.html',
|
||||
'/conn-err.html',
|
||||
'/help.html',
|
||||
'/',
|
||||
'/issue.html',
|
||||
'/find-code.html',
|
||||
'/settings.html',
|
||||
'/pis.html',
|
||||
'/manifest.json',
|
||||
'/styles/fonts/firamono/firamono-500.woff2',
|
||||
'/styles/fonts/firamono/firamono-regular.woff2',
|
||||
'/styles/fonts/urwgothic/urwgothic.woff2',
|
||||
'/styles/fonts/urwgothic/urwgothicDemi.woff2',
|
||||
'/styles/board.css',
|
||||
'/styles/find-code.css',
|
||||
'/styles/help.css',
|
||||
'/styles/issue.css',
|
||||
'/styles/main.css',
|
||||
'/styles/settings.css',
|
||||
'/styles/pis.css',
|
||||
'/js/find-code.js',
|
||||
'/js/index.js',
|
||||
'/js/issue.js',
|
||||
'/js/lib.board.js',
|
||||
'/js/lib.main.js',
|
||||
'/js/auth.js',
|
||||
'/js/settings.js',
|
||||
'/js/simple-board.js',
|
||||
'/js/pis.js',
|
||||
'/images/icon.svg',
|
||||
'/images/logo/wide_logo.svg',
|
||||
'/images/logo/mono-logo.svg',
|
||||
'/images/app-icons/any/plain-logo.svg',
|
||||
'/images/app-icons/any/plain-logo-512.png',
|
||||
'/images/nav/alert_icon.svg',
|
||||
'/images/nav/save.svg',
|
||||
'/images/nav/home_icon.svg',
|
||||
'/images/nav/back.svg',
|
||||
'/images/nav/hamburger.svg',
|
||||
'/images/nav/close.svg',
|
||||
'/images/nav/refresh.svg',
|
||||
'/images/nre/nre-powered_400w.webp',
|
||||
'/images/nre/nre-powered_400w.jxl'
|
||||
]
|
||||
|
||||
self.addEventListener("install", (e) => {
|
||||
console.log("[Service Worker] Install");
|
||||
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(cacheFiles);
|
||||
const cache = await caches.open(cacheName)
|
||||
console.log('[Service Worker] Caching app data')
|
||||
await cache.addAll(cacheFiles)
|
||||
})()
|
||||
);
|
||||
});
|
||||
)
|
||||
})
|
||||
|
||||
self.addEventListener("fetch", (e) => {
|
||||
self.addEventListener('fetch', (e) => {
|
||||
e.respondWith(
|
||||
(async () => {
|
||||
const r = await caches.match(e.request,{ignoreSearch: true});
|
||||
const r = await caches.match(e.request,{ignoreSearch: true})
|
||||
if (r) {
|
||||
return r;
|
||||
return r
|
||||
}
|
||||
const response = await fetch(e.request);
|
||||
console.log(`[Service Worker] Not cached - fetching from server: ${e.request.url}`);
|
||||
return response;
|
||||
const response = await fetch(e.request)
|
||||
console.log(`[Service Worker] Not cached - fetching from server: ${e.request.url}`)
|
||||
return response
|
||||
})()
|
||||
);
|
||||
});
|
||||
)
|
||||
})
|
||||
|
||||
self.addEventListener('activate', function (event) {
|
||||
event.waitUntil(caches.keys().then(function (keys) {
|
||||
return Promise.all(keys.filter(function (key) {
|
||||
return !cacheIDs.includes(key);
|
||||
return !cacheIDs.includes(key)
|
||||
}).map(function (key) {
|
||||
return caches.delete(key);
|
||||
}));
|
||||
return caches.delete(key)
|
||||
}))
|
||||
}).then(function () {
|
||||
return self.clients.claim();
|
||||
}));
|
||||
});
|
||||
return self.clients.claim()
|
||||
}))
|
||||
})
|
Reference in New Issue
Block a user