From 1c8839ca1794db966a3118923c5e7eae896e9651 Mon Sep 17 00:00:00 2001 From: Fred Boniface Date: Sat, 22 Apr 2023 21:46:34 +0100 Subject: [PATCH 01/51] Add PIS Page and some logic --- js/lib.main.js | 46 ++++++++++++++++++++++++++++++++-- js/pis.js | 37 +++++++++++++++++++++++++++ pis.html | 68 ++++++++++++++++++++++++++++++++++++++++++++++++++ styles/pis.css | 7 ++++++ 4 files changed, 156 insertions(+), 2 deletions(-) create mode 100644 js/pis.js create mode 100644 pis.html create mode 100644 styles/pis.css diff --git a/js/lib.main.js b/js/lib.main.js index 9cc9747..e69940f 100644 --- a/js/lib.main.js +++ b/js/lib.main.js @@ -45,7 +45,7 @@ const delay = ms => new Promise(res => setTimeout(res, ms)); /* Maintains backwards compatibility for previous implementation of log helper */ async function log(msg, type) { - const mode = "dev" + const mode = "tst" if (mode === "prod" && type != "ERR") { return; } @@ -126,7 +126,49 @@ async function getQuery(param) { } } -async function vibe(type) { // Offers three standard vibration patterns for consistency +async function getApi(path,auth = false) { + let apiVer = 'v1' + let url = `https://${window.location.origin}/api/${apiVer}/${path}` + log(`getApi: Fetching from endpoint: ${url}, Auth=${auth}`) + try { + var resp = await fetch(url) + if (resp != 200) { + return false + } + if (!resp.ok) { + return false + } + if (resp.json() === "[]") { + return 'empty' + } + return resp.json(); + } catch(err) { + return false + } +} + +async function getApi(path,auth = false) { + let apiVer = 'v1' + let url = `https://${window.location.origin}/api/${apiVer}/${path}` + log(`getApi: Fetching from endpoint: ${url}, Auth=${auth}`) + try { + var resp = await fetch(url) + if (resp != 200) { + return false + } + if (!resp.ok) { + return false + } + if (resp.json() === "[]") { + return 'empty' + } + return resp.json(); + } catch(err) { + return false + } +} + +async function vibe(type) { let canVibrate = "vibrate" in navigator || "mozVibrate" in navigator if (canVibrate && !("vibrate" in navigator)){ navigator.vibrate = navigator.mozVibrate diff --git a/js/pis.js b/js/pis.js new file mode 100644 index 0000000..259aabb --- /dev/null +++ b/js/pis.js @@ -0,0 +1,37 @@ +hideLoading() + +async function findByOrigDest() { + showLoading() + const formData = await fetchOrigDest() + log(`findByOrigDest: Searching for PIS Code for ${JSON.stringify(formData)}`) + const endpoint = `pis/${formData.origin}/${formData.destination}` + const json = await getApi(endpoint) + if (json == false) { + await noData() + } else { + await displayData(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 displayData(json) { + log(`displayData: ${JSON.stringify(json)}`) +} + +async function noData() { + msg = '

No results found

' + document.getElementById('result-box').insertAdjacentHTML("beforeend", msg) +} + +async function reset() { + document.getElementById('result-box').style = 'display:none' + document.getElementById('crs-box').style = 'display:block' +} \ No newline at end of file diff --git a/pis.html b/pis.html new file mode 100644 index 0000000..bddeee8 --- /dev/null +++ b/pis.html @@ -0,0 +1,68 @@ + + + + + + + + + + + + + + + OwlBoard - PIS + + + + + + +
+ + + + Home + + +
+ + + + + + OwlBoard Logo + +

PIS Codes

+ +
+
+
+

Searching

+
+ +
+

Enter a services start and end CRS stations to see code options and + stopping patterns.

+

Currently supported (Beta): GWR Bristol Metro region only.

+
+

+
+

+ +
+ +
+

Results

+ +
+ + + + + + \ No newline at end of file diff --git a/styles/pis.css b/styles/pis.css new file mode 100644 index 0000000..8c42fb8 --- /dev/null +++ b/styles/pis.css @@ -0,0 +1,7 @@ +#crs-boxes { + display: block; +} + +#result-box { + display: none; +} \ No newline at end of file -- 2.34.1 From f4d008704009e57e433305037618534410541d70 Mon Sep 17 00:00:00 2001 From: Fred Boniface Date: Sat, 22 Apr 2023 21:48:55 +0100 Subject: [PATCH 02/51] Add notes --- js/pis.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/js/pis.js b/js/pis.js index 259aabb..a6c8a06 100644 --- a/js/pis.js +++ b/js/pis.js @@ -23,6 +23,9 @@ async function fetchOrigDest() { } async function displayData(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? log(`displayData: ${JSON.stringify(json)}`) } -- 2.34.1 From 4ee0fea66f4c1756295eef03a6380b6f43d38fdc Mon Sep 17 00:00:00 2001 From: Fred Boniface Date: Sat, 22 Apr 2023 21:52:42 +0100 Subject: [PATCH 03/51] Change page wording --- js/pis.js | 2 ++ pis.html | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/js/pis.js b/js/pis.js index a6c8a06..4486d7c 100644 --- a/js/pis.js +++ b/js/pis.js @@ -35,6 +35,8 @@ async function noData() { } async function reset() { + document.getElementById('origin').value = "" + document.getElementById('destination').value = "" document.getElementById('result-box').style = 'display:none' document.getElementById('crs-box').style = 'display:block' } \ No newline at end of file diff --git a/pis.html b/pis.html index bddeee8..2819fea 100644 --- a/pis.html +++ b/pis.html @@ -43,7 +43,7 @@
-

Enter a services start and end CRS stations to see code options and +

Enter a services start and end station CRS codes to see code options and stopping patterns.

Currently supported (Beta): GWR Bristol Metro region only.


-- 2.34.1 From d56af14f4fb466afc88564c5b94c090420c2aacb Mon Sep 17 00:00:00 2001 From: Fred Boniface Date: Sat, 22 Apr 2023 21:57:33 +0100 Subject: [PATCH 04/51] Change meta description --- index.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.html b/index.html index 8d04509..4e7753f 100644 --- a/index.html +++ b/index.html @@ -2,7 +2,7 @@ - + -- 2.34.1 From 3447c7fa6df70ae482a99d8977fe77760f75566a Mon Sep 17 00:00:00 2001 From: Fred Boniface Date: Sat, 22 Apr 2023 21:58:28 +0100 Subject: [PATCH 05/51] Update meta Description --- pis.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pis.html b/pis.html index 2819fea..14367f6 100644 --- a/pis.html +++ b/pis.html @@ -2,7 +2,7 @@ - + -- 2.34.1 From fe4e271bc95d1375a2e7aca13928c5eb50ff4b27 Mon Sep 17 00:00:00 2001 From: Fred Boniface Date: Sat, 22 Apr 2023 22:01:23 +0100 Subject: [PATCH 06/51] Adjust meta tags, particularly robot tags --- 404.html | 1 + board.html | 1 + conn-err.html | 1 + find-code.html | 2 +- help.html | 3 ++- issue.html | 3 ++- settings.html | 3 ++- stat.html | 1 + 8 files changed, 11 insertions(+), 4 deletions(-) diff --git a/404.html b/404.html index 0ba9f97..dd6f42c 100644 --- a/404.html +++ b/404.html @@ -2,6 +2,7 @@ + diff --git a/board.html b/board.html index 29f3d76..bbac91e 100644 --- a/board.html +++ b/board.html @@ -3,6 +3,7 @@ + diff --git a/conn-err.html b/conn-err.html index ab9797d..65f3629 100644 --- a/conn-err.html +++ b/conn-err.html @@ -2,6 +2,7 @@ + diff --git a/find-code.html b/find-code.html index c1167f2..bee7412 100644 --- a/find-code.html +++ b/find-code.html @@ -2,7 +2,7 @@ - + diff --git a/help.html b/help.html index d52d5d2..479604f 100644 --- a/help.html +++ b/help.html @@ -2,7 +2,8 @@ - + + diff --git a/issue.html b/issue.html index c59c79c..e27e1da 100644 --- a/issue.html +++ b/issue.html @@ -1,7 +1,8 @@ - + + diff --git a/settings.html b/settings.html index b2d05c4..4e0487d 100644 --- a/settings.html +++ b/settings.html @@ -2,7 +2,8 @@ - + + diff --git a/stat.html b/stat.html index 378f1f0..1ec42fd 100644 --- a/stat.html +++ b/stat.html @@ -2,6 +2,7 @@ + OwlBoard - Statistics -- 2.34.1 From 0bf39fbffde181dfb990eaf3ab7fb82364730671 Mon Sep 17 00:00:00 2001 From: Fred Boniface Date: Sat, 22 Apr 2023 22:03:54 +0100 Subject: [PATCH 07/51] Change references to relative --- index.html | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/index.html b/index.html index 4e7753f..ffec2f3 100644 --- a/index.html +++ b/index.html @@ -2,7 +2,7 @@ - + @@ -37,6 +37,7 @@
-

Results

+

Results: 0

-- 2.34.1 From 896ff6a532a41b5314760478d33c8e300b85d9ed Mon Sep 17 00:00:00 2001 From: Fred Boniface Date: Sat, 22 Apr 2023 22:45:24 +0100 Subject: [PATCH 13/51] Add notes --- js/pis.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/js/pis.js b/js/pis.js index c539fdb..b9b372e 100644 --- a/js/pis.js +++ b/js/pis.js @@ -37,7 +37,8 @@ async function insertData(json) { const data = JSON.parse(json) let results = 0 for(var i = 0; i < data.length; i++) { // Break into separate function. Need to - // iterate over stops. + // iterate over stops and print them in the + // format: `AVN, PRI, SHH... etc.` tableData += `${data[i][code]} ${data[i][stops]}` results++ -- 2.34.1 From a63e8611628f773480d4bbc6f54487cdf222a417 Mon Sep 17 00:00:00 2001 From: Fred Boniface Date: Sat, 22 Apr 2023 22:46:46 +0100 Subject: [PATCH 14/51] Remove unneccessary vars --- js/pis.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/js/pis.js b/js/pis.js index b9b372e..26a48b6 100644 --- a/js/pis.js +++ b/js/pis.js @@ -33,7 +33,6 @@ async function insertData(json) { Stations ` div.insertAdjacentHTML("beforeend", tableHtml) - const table = document.getElementById('result-table') const data = JSON.parse(json) let results = 0 for(var i = 0; i < data.length; i++) { // Break into separate function. Need to @@ -44,7 +43,7 @@ async function insertData(json) { results++ } tableData += "" - table.insertAdjacentHTML("beforeend", tableData) + document.getElementById('result-table').insertAdjacentHTML("beforeend", tableData) document.getElementById('result-count').textContent = results } -- 2.34.1 From 1e6b013507f6a7585ccf908cb5c0155a37877914 Mon Sep 17 00:00:00 2001 From: Fred Boniface Date: Sat, 22 Apr 2023 22:47:20 +0100 Subject: [PATCH 15/51] add missing const --- js/pis.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/js/pis.js b/js/pis.js index 26a48b6..dbf13cb 100644 --- a/js/pis.js +++ b/js/pis.js @@ -48,7 +48,7 @@ async function insertData(json) { } async function noData() { - msg = '

No results found

' + const msg = '

No results found

' document.getElementById('result-box').insertAdjacentHTML("beforeend", msg) } -- 2.34.1 From 7a8ab8ad4c5b69f7529fc4aa4507d0f8cc96d6db Mon Sep 17 00:00:00 2001 From: Fred Boniface Date: Mon, 24 Apr 2023 10:51:26 +0100 Subject: [PATCH 16/51] Add db-pis to stats --- js/stat.js | 1 + stat.html | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/js/stat.js b/js/stat.js index 86ca7b2..8a02453 100644 --- a/js/stat.js +++ b/js/stat.js @@ -24,6 +24,7 @@ async function display(data) { // Parses and displays data from API 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-web').textContent = localStorage.getItem('ver-web') || "Unknown"; } \ No newline at end of file diff --git a/stat.html b/stat.html index 1ec42fd..245269f 100644 --- a/stat.html +++ b/stat.html @@ -45,6 +45,10 @@ DB-meta + + DB-pis + +

-- 2.34.1 From 096a74b4bb4f5f3ee8351a97c292165cb7bbd429 Mon Sep 17 00:00:00 2001 From: Fred Boniface Date: Mon, 24 Apr 2023 12:10:19 +0100 Subject: [PATCH 17/51] Fix getApi base url --- js/lib.main.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/js/lib.main.js b/js/lib.main.js index e69940f..2c30710 100644 --- a/js/lib.main.js +++ b/js/lib.main.js @@ -128,7 +128,7 @@ async function getQuery(param) { async function getApi(path,auth = false) { let apiVer = 'v1' - let url = `https://${window.location.origin}/api/${apiVer}/${path}` + let url = `${window.location.origin}/api/${apiVer}/${path}` log(`getApi: Fetching from endpoint: ${url}, Auth=${auth}`) try { var resp = await fetch(url) -- 2.34.1 From d54098562d185443eb2ea39558c9f3cfcbbec19b Mon Sep 17 00:00:00 2001 From: Fred Boniface Date: Mon, 24 Apr 2023 12:14:45 +0100 Subject: [PATCH 18/51] Fix findByOrigDest API Path --- js/pis.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/js/pis.js b/js/pis.js index dbf13cb..918394d 100644 --- a/js/pis.js +++ b/js/pis.js @@ -4,7 +4,7 @@ async function findByOrigDest() { showLoading() const formData = await fetchOrigDest() log(`findByOrigDest: Searching for PIS Code for ${JSON.stringify(formData)}`) - const endpoint = `pis/${formData.origin}/${formData.destination}` + const endpoint = `pis/origdest/${formData.origin}/${formData.destination}` const json = await getApi(endpoint) if (json == false) { await noData() -- 2.34.1 From cd3a4dad33266d63ae4287ece85e4aa269336e4b Mon Sep 17 00:00:00 2001 From: Fred Boniface Date: Mon, 24 Apr 2023 12:50:57 +0100 Subject: [PATCH 19/51] Adjust PIS Code --- js/lib.main.js | 9 ++++++--- js/pis.js | 11 +++++------ 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/js/lib.main.js b/js/lib.main.js index 2c30710..81403f2 100644 --- a/js/lib.main.js +++ b/js/lib.main.js @@ -132,16 +132,19 @@ async function getApi(path,auth = false) { log(`getApi: Fetching from endpoint: ${url}, Auth=${auth}`) try { var resp = await fetch(url) - if (resp != 200) { + var json = await resp.json() + log(`resp.status: ${resp.status}`) + log(`resp.json: ${json}`) + if (resp.status != 200) { return false } if (!resp.ok) { return false } - if (resp.json() === "[]") { + if (json === "[]") { return 'empty' } - return resp.json(); + return json; } catch(err) { return false } diff --git a/js/pis.js b/js/pis.js index 918394d..8fa7a6f 100644 --- a/js/pis.js +++ b/js/pis.js @@ -32,18 +32,16 @@ async function insertData(json) { ` - div.insertAdjacentHTML("beforeend", tableHtml) - const data = JSON.parse(json) let results = 0 - for(var i = 0; i < data.length; i++) { // Break into separate function. Need to + for(var i = 0; i < json.length; i++) { // Break into separate function. Need to // iterate over stops and print them in the // format: `AVN, PRI, SHH... etc.` - tableData += ` - ` + tableData += ` + ` results++ } tableData += "
Code Stations
${data[i][code]}${data[i][stops]}
${json[i]['code']}${json[i]['stops']}
" - document.getElementById('result-table').insertAdjacentHTML("beforeend", tableData) + div.insertAdjacentHTML("beforeend", tableData) document.getElementById('result-count').textContent = results } @@ -56,5 +54,6 @@ async function reset() { document.getElementById('origin').value = "" document.getElementById('destination').value = "" document.getElementById('result-box').style = 'display:none' + document.getElementById('result-box').innerHTML = '' document.getElementById('crs-box').style = 'display:block' } \ No newline at end of file -- 2.34.1 From b17894f7f16086c419ba8904de47ae6d5a15d370 Mon Sep 17 00:00:00 2001 From: Fred Boniface Date: Mon, 24 Apr 2023 13:11:13 +0100 Subject: [PATCH 20/51] Try fix type error --- js/pis.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/js/pis.js b/js/pis.js index 8fa7a6f..282ab05 100644 --- a/js/pis.js +++ b/js/pis.js @@ -42,7 +42,9 @@ async function insertData(json) { } tableData += "" div.insertAdjacentHTML("beforeend", tableData) - document.getElementById('result-count').textContent = results + if (results > 1) { + document.getElementById('result-count').textContent = results.toString() + } } async function noData() { -- 2.34.1 From 0596b23355a48d470b47b3016562c36bab058154 Mon Sep 17 00:00:00 2001 From: Fred Boniface Date: Mon, 24 Apr 2023 13:17:06 +0100 Subject: [PATCH 21/51] Add notes --- js/pis.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/js/pis.js b/js/pis.js index 282ab05..c546a5c 100644 --- a/js/pis.js +++ b/js/pis.js @@ -56,6 +56,6 @@ async function reset() { document.getElementById('origin').value = "" document.getElementById('destination').value = "" document.getElementById('result-box').style = 'display:none' - document.getElementById('result-box').innerHTML = '' + document.getElementById('result-box').innerHTML = '' // This removes the results-count. I need to remove the ONLY. document.getElementById('crs-box').style = 'display:block' } \ No newline at end of file -- 2.34.1 From a1a99698d39584f3926038a170fb4b5e3d04423d Mon Sep 17 00:00:00 2001 From: Fred Boniface Date: Tue, 25 Apr 2023 00:16:24 +0100 Subject: [PATCH 22/51] Fix logic around pis reset --- js/pis.js | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/js/pis.js b/js/pis.js index c546a5c..b4f5c1d 100644 --- a/js/pis.js +++ b/js/pis.js @@ -33,9 +33,7 @@ async function insertData(json) { ` let results = 0 - for(var i = 0; i < json.length; i++) { // Break into separate function. Need to - // iterate over stops and print them in the - // format: `AVN, PRI, SHH... etc.` + for(var i = 0; i < json.length; i++) { // Hopefully can style output with CSS tableData += `` results++ @@ -48,7 +46,7 @@ async function insertData(json) { } async function noData() { - const msg = '

No results found

' + const msg = '

No results found

' document.getElementById('result-box').insertAdjacentHTML("beforeend", msg) } @@ -56,6 +54,6 @@ async function reset() { document.getElementById('origin').value = "" document.getElementById('destination').value = "" document.getElementById('result-box').style = 'display:none' - document.getElementById('result-box').innerHTML = '' // This removes the results-count. I need to remove the
Stations
${json[i]['code']} ${json[i]['stops']}
ONLY. + document.getElementById('result-table').remove() document.getElementById('crs-box').style = 'display:block' } \ No newline at end of file -- 2.34.1 From 2bf95e8134c98c5f443ff53982ac5e93dbd66a5d Mon Sep 17 00:00:00 2001 From: Fred Boniface Date: Tue, 25 Apr 2023 00:32:45 +0100 Subject: [PATCH 23/51] Update pis styling --- js/pis.js | 8 ++++---- styles/pis.css | 20 ++++++++++++++++++++ sw.js | 5 ++++- 3 files changed, 28 insertions(+), 5 deletions(-) diff --git a/js/pis.js b/js/pis.js index b4f5c1d..0d59d54 100644 --- a/js/pis.js +++ b/js/pis.js @@ -29,13 +29,13 @@ async function insertData(json) { const div = document.getElementById('result-box') let tableData = `
- - + + ` let results = 0 for(var i = 0; i < json.length; i++) { // Hopefully can style output with CSS - tableData += ` - ` + tableData += ` + ` results++ } tableData += "
CodeStationsCodeStations
${json[i]['code']}${json[i]['stops']}
${json[i]['code']}${json[i]['stops']}
" diff --git a/styles/pis.css b/styles/pis.css index 8c42fb8..3039e47 100644 --- a/styles/pis.css +++ b/styles/pis.css @@ -4,4 +4,24 @@ #result-box { display: none; +} + +#result-table { + margin: auto; + width: 85%; + max-width: 700px; + text-align: center; +} + +#reset { + margin-top: 25px; +} + +.pis-code { + font-weight:bold; +} + +.station { + text-transform:uppercase; + overflow-wrap:anywhere } \ No newline at end of file diff --git a/sw.js b/sw.js index b975e29..8151cc7 100644 --- a/sw.js +++ b/sw.js @@ -1,6 +1,6 @@ /* Service Worker */ -const appVersion = "2.0.0-dev" +const appVersion = "1.2.4-dev-pis" const cacheName = `owlboard-${appVersion}`; const cacheIDs = [cacheName]; const cacheFiles = [ @@ -13,6 +13,7 @@ const cacheFiles = [ "/issue.html", "/find-code.html", "/settings.html", + "/pis.html", "/manifest.json", "/styles/fonts/firamono/firamono-500.woff2", "/styles/fonts/firamono/firamono-regular.woff2", @@ -24,6 +25,7 @@ const cacheFiles = [ "/styles/issue.css", "/styles/main.css", "/styles/settings.css", + "/styles/pis.css", "/js/find-code.js", "/js/index.js", "/js/issue.js", @@ -32,6 +34,7 @@ const cacheFiles = [ "/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", -- 2.34.1 From b37cbdb1d0b0e5df633181af3de63a209f97ca32 Mon Sep 17 00:00:00 2001 From: Fred Boniface Date: Tue, 25 Apr 2023 19:30:54 +0100 Subject: [PATCH 24/51] Fix array.join() --- js/pis.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/js/pis.js b/js/pis.js index 0d59d54..0d63305 100644 --- a/js/pis.js +++ b/js/pis.js @@ -35,7 +35,7 @@ async function insertData(json) { let results = 0 for(var i = 0; i < json.length; i++) { // Hopefully can style output with CSS tableData += `${json[i]['code']} - ${json[i]['stops']}` + ${json[i]['stops'].join(', ')}` results++ } tableData += "" -- 2.34.1 From 255382710f19c2adb5b878ee8d69d6398a99a428 Mon Sep 17 00:00:00 2001 From: Fred Boniface Date: Tue, 25 Apr 2023 20:50:19 +0100 Subject: [PATCH 25/51] Style & Script fixes --- js/pis.js | 6 +++--- styles/pis.css | 14 ++++++++++++-- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/js/pis.js b/js/pis.js index 0d63305..1bb214a 100644 --- a/js/pis.js +++ b/js/pis.js @@ -36,13 +36,13 @@ async function insertData(json) { for(var i = 0; i < json.length; i++) { // Hopefully can style output with CSS tableData += `${json[i]['code']} ${json[i]['stops'].join(', ')}` + log(`Count prior to incrementing: ${results}`) results++ + log(`Count after incrementing: ${results}`) } tableData += "" div.insertAdjacentHTML("beforeend", tableData) - if (results > 1) { - document.getElementById('result-count').textContent = results.toString() - } + document.getElementById('result-count').textContent = results.toString() } async function noData() { diff --git a/styles/pis.css b/styles/pis.css index 3039e47..f9cccf0 100644 --- a/styles/pis.css +++ b/styles/pis.css @@ -13,6 +13,14 @@ text-align: center; } +td, th { + border-bottom: 1px solid; +} + +#reset { + margin-top: 25px +} + #reset { margin-top: 25px; } @@ -22,6 +30,8 @@ } .station { - text-transform:uppercase; - overflow-wrap:anywhere + text-transform: uppercase; + overflow-wrap: anywhere; + font-family: firamono, monospace; + line-height: 1.2; } \ No newline at end of file -- 2.34.1 From 28e306cbdba0a1afae66d79e87155b82bdf1428f Mon Sep 17 00:00:00 2001 From: Fred Boniface Date: Tue, 25 Apr 2023 20:56:59 +0100 Subject: [PATCH 26/51] Bump version, add auth required --- js/pis.js | 2 -- pis.html | 2 +- styles/main.css | 4 ++++ sw.js | 2 +- 4 files changed, 6 insertions(+), 4 deletions(-) diff --git a/js/pis.js b/js/pis.js index 1bb214a..e373729 100644 --- a/js/pis.js +++ b/js/pis.js @@ -36,9 +36,7 @@ async function insertData(json) { for(var i = 0; i < json.length; i++) { // Hopefully can style output with CSS tableData += `${json[i]['code']} ${json[i]['stops'].join(', ')}` - log(`Count prior to incrementing: ${results}`) results++ - log(`Count after incrementing: ${results}`) } tableData += "" div.insertAdjacentHTML("beforeend", tableData) diff --git a/pis.html b/pis.html index 0b04c0b..6eb0f16 100644 --- a/pis.html +++ b/pis.html @@ -46,7 +46,7 @@

Enter a services start and end station CRS codes to see code options and stopping patterns.

Currently supported (Beta): GWR Bristol Metro region only.

- +

You must be logged into the free staff version for this feature





diff --git a/styles/main.css b/styles/main.css index e32ff31..7b9944c 100644 --- a/styles/main.css +++ b/styles/main.css @@ -301,6 +301,10 @@ label { transition: 0.5s; } +#auth-required { + color: crimson; +} + /* Footer Styles */ footer { background-color: var(--accent-color); diff --git a/sw.js b/sw.js index 8151cc7..fb60144 100644 --- a/sw.js +++ b/sw.js @@ -1,6 +1,6 @@ /* Service Worker */ -const appVersion = "1.2.4-dev-pis" +const appVersion = "PIS-DEV-23042501" const cacheName = `owlboard-${appVersion}`; const cacheIDs = [cacheName]; const cacheFiles = [ -- 2.34.1 From f1372ff8a93d0c77d4902810c9c2941759ea0aa7 Mon Sep 17 00:00:00 2001 From: Fred Boniface Date: Tue, 25 Apr 2023 21:13:05 +0100 Subject: [PATCH 27/51] Bump version string, adjust style --- pis.html | 2 +- styles/main.css | 2 +- styles/pis.css | 1 + sw.js | 2 +- 4 files changed, 4 insertions(+), 3 deletions(-) diff --git a/pis.html b/pis.html index 6eb0f16..91c5050 100644 --- a/pis.html +++ b/pis.html @@ -46,7 +46,7 @@

Enter a services start and end station CRS codes to see code options and stopping patterns.

Currently supported (Beta): GWR Bristol Metro region only.

-

You must be logged into the free staff version for this feature

+

You will need to be logged into a free rail staff version account for this feature once it has finished testing.





diff --git a/styles/main.css b/styles/main.css index 7b9944c..e8a921f 100644 --- a/styles/main.css +++ b/styles/main.css @@ -302,7 +302,7 @@ label { } #auth-required { - color: crimson; + color: var(--main-warning-color); } /* Footer Styles */ diff --git a/styles/pis.css b/styles/pis.css index f9cccf0..9ad13f0 100644 --- a/styles/pis.css +++ b/styles/pis.css @@ -8,6 +8,7 @@ #result-table { margin: auto; + color: var(--second-text-color); width: 85%; max-width: 700px; text-align: center; diff --git a/sw.js b/sw.js index fb60144..085af27 100644 --- a/sw.js +++ b/sw.js @@ -1,6 +1,6 @@ /* Service Worker */ -const appVersion = "PIS-DEV-23042501" +const appVersion = "PIS-DEV-23042502" const cacheName = `owlboard-${appVersion}`; const cacheIDs = [cacheName]; const cacheFiles = [ -- 2.34.1 From 0f22707fc3b24a2e13f1b43db7fbed0fda317d46 Mon Sep 17 00:00:00 2001 From: Fred Boniface Date: Tue, 25 Apr 2023 21:16:25 +0100 Subject: [PATCH 28/51] Adjustments --- pis.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pis.html b/pis.html index 91c5050..449072a 100644 --- a/pis.html +++ b/pis.html @@ -63,7 +63,7 @@ \ No newline at end of file -- 2.34.1 From 90734cd09892f736d781a2ab8bc232df3f1c1bd4 Mon Sep 17 00:00:00 2001 From: Fred Boniface Date: Fri, 28 Apr 2023 13:45:52 +0100 Subject: [PATCH 29/51] Remove duplicate - merge error --- js/lib.main.js | 21 --------------------- 1 file changed, 21 deletions(-) diff --git a/js/lib.main.js b/js/lib.main.js index 81403f2..1b60e7a 100644 --- a/js/lib.main.js +++ b/js/lib.main.js @@ -150,27 +150,6 @@ async function getApi(path,auth = false) { } } -async function getApi(path,auth = false) { - let apiVer = 'v1' - let url = `https://${window.location.origin}/api/${apiVer}/${path}` - log(`getApi: Fetching from endpoint: ${url}, Auth=${auth}`) - try { - var resp = await fetch(url) - if (resp != 200) { - return false - } - if (!resp.ok) { - return false - } - if (resp.json() === "[]") { - return 'empty' - } - return resp.json(); - } catch(err) { - return false - } -} - async function vibe(type) { let canVibrate = "vibrate" in navigator || "mozVibrate" in navigator if (canVibrate && !("vibrate" in navigator)){ -- 2.34.1 From f525466b84f4be4338f0330ca5b2a866d2963ca7 Mon Sep 17 00:00:00 2001 From: Fred Boniface Date: Fri, 28 Apr 2023 13:52:26 +0100 Subject: [PATCH 30/51] Ad auth option to getApi() --- js/lib.main.js | 17 ++++++++++++++++- js/pis.js | 1 + pis.html | 2 +- 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/js/lib.main.js b/js/lib.main.js index 1b60e7a..7fd6cb3 100644 --- a/js/lib.main.js +++ b/js/lib.main.js @@ -130,8 +130,23 @@ async function getApi(path,auth = false) { let apiVer = 'v1' let url = `${window.location.origin}/api/${apiVer}/${path}` log(`getApi: Fetching from endpoint: ${url}, Auth=${auth}`) + if (auth) { + let key = localStorage.getItem('uuid') + var options = { + method: "GET", + redirect: "follow", + headers: { + "uuid": key + } + } + } else { + var options = { + method: "GET", + redirect: "follow" + } + } try { - var resp = await fetch(url) + var resp = await fetch(url, options) var json = await resp.json() log(`resp.status: ${resp.status}`) log(`resp.json: ${json}`) diff --git a/js/pis.js b/js/pis.js index e373729..9456b31 100644 --- a/js/pis.js +++ b/js/pis.js @@ -1,4 +1,5 @@ hideLoading() +versionDisplay() async function findByOrigDest() { showLoading() diff --git a/pis.html b/pis.html index 449072a..9d38db2 100644 --- a/pis.html +++ b/pis.html @@ -63,7 +63,7 @@ \ No newline at end of file -- 2.34.1 From ad38085e64095fc781ed7f17748d35433da3e9bd Mon Sep 17 00:00:00 2001 From: Fred Boniface Date: Fri, 28 Apr 2023 13:56:04 +0100 Subject: [PATCH 31/51] Add function to hide the login required notice --- js/lib.main.js | 7 +++++++ pis.html | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/js/lib.main.js b/js/lib.main.js index 7fd6cb3..d510fae 100644 --- a/js/lib.main.js +++ b/js/lib.main.js @@ -165,6 +165,13 @@ async function getApi(path,auth = false) { } } +async function showHideAuthNotice() { + let uuid = localStorage.getItem("uuid") + if (uuid) { + document.getElementById('auth-notice').style = 'display:none' + } +} + async function vibe(type) { let canVibrate = "vibrate" in navigator || "mozVibrate" in navigator if (canVibrate && !("vibrate" in navigator)){ diff --git a/pis.html b/pis.html index 9d38db2..be5505a 100644 --- a/pis.html +++ b/pis.html @@ -46,7 +46,7 @@

Enter a services start and end station CRS codes to see code options and stopping patterns.

Currently supported (Beta): GWR Bristol Metro region only.

-

You will need to be logged into a free rail staff version account for this feature once it has finished testing.

+

You need to be logged into a free rail staff version account for this feature.





-- 2.34.1 From 8194ac0f5b0d5d62b9fa14a26d42ade281db932c Mon Sep 17 00:00:00 2001 From: Fred Boniface Date: Fri, 28 Apr 2023 13:56:24 +0100 Subject: [PATCH 32/51] Call showHieAuthNotice() on pis.js --- js/pis.js | 1 + 1 file changed, 1 insertion(+) diff --git a/js/pis.js b/js/pis.js index 9456b31..75989c9 100644 --- a/js/pis.js +++ b/js/pis.js @@ -1,5 +1,6 @@ hideLoading() versionDisplay() +showHideAuthNotice() async function findByOrigDest() { showLoading() -- 2.34.1 From 218e95b0487e5c2c84f82ea2aa1a2a3147e38c2f Mon Sep 17 00:00:00 2001 From: Fred Boniface Date: Fri, 28 Apr 2023 13:57:06 +0100 Subject: [PATCH 33/51] Fix id name --- js/lib.main.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/js/lib.main.js b/js/lib.main.js index d510fae..16a84b5 100644 --- a/js/lib.main.js +++ b/js/lib.main.js @@ -168,7 +168,7 @@ async function getApi(path,auth = false) { async function showHideAuthNotice() { let uuid = localStorage.getItem("uuid") if (uuid) { - document.getElementById('auth-notice').style = 'display:none' + document.getElementById('auth-required').style = 'display:none' } } -- 2.34.1 From fbb4702b696af4a26ce06bba03369196bd6d4309 Mon Sep 17 00:00:00 2001 From: Fred Boniface Date: Sun, 30 Apr 2023 20:27:04 +0100 Subject: [PATCH 34/51] Adjust frontend version display on stats --- js/stat.js | 2 +- stat.html | 2 +- sw.js | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/js/stat.js b/js/stat.js index 8a02453..7f0ea17 100644 --- a/js/stat.js +++ b/js/stat.js @@ -1,6 +1,7 @@ init(); async function init() { // The page init function + versionDisplay() display(await get()) } @@ -26,5 +27,4 @@ async function display(data) { // Parses and displays data from API document.getElementById('meta').textContent = dat.meta || "0"; document.getElementById('pis').textContent = dat.pis document.getElementById('ver-dbman').textContent = ver.dbmanager || "Unknown"; - document.getElementById('ver-web').textContent = localStorage.getItem('ver-web') || "Unknown"; } \ No newline at end of file diff --git a/stat.html b/stat.html index 245269f..7d04c51 100644 --- a/stat.html +++ b/stat.html @@ -78,7 +78,7 @@ web-frontend - + Unknown

The statistics represent hits & queries from all instances in the stack.

diff --git a/sw.js b/sw.js index 085af27..3a8f45e 100644 --- a/sw.js +++ b/sw.js @@ -1,6 +1,6 @@ /* Service Worker */ -const appVersion = "PIS-DEV-23042502" +const appVersion = "PIS-DEV-23043001" const cacheName = `owlboard-${appVersion}`; const cacheIDs = [cacheName]; const cacheFiles = [ -- 2.34.1 From 92f621b6f90d2613c20c145e3750cdb3b9e4561b Mon Sep 17 00:00:00 2001 From: Fred Boniface Date: Sun, 30 Apr 2023 20:28:30 +0100 Subject: [PATCH 35/51] Add auth flag to PIS.js --- js/pis.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/js/pis.js b/js/pis.js index 75989c9..97cfb88 100644 --- a/js/pis.js +++ b/js/pis.js @@ -7,7 +7,7 @@ async function findByOrigDest() { const formData = await fetchOrigDest() log(`findByOrigDest: Searching for PIS Code for ${JSON.stringify(formData)}`) const endpoint = `pis/origdest/${formData.origin}/${formData.destination}` - const json = await getApi(endpoint) + const json = await getApi(endpoint, auth = true) if (json == false) { await noData() } else { -- 2.34.1 From a7b8fb36d4ca72e77708d129ced0fe2d156b5f41 Mon Sep 17 00:00:00 2001 From: Fred Boniface Date: Sun, 30 Apr 2023 21:10:37 +0100 Subject: [PATCH 36/51] Adjust PIS Styling --- js/lib.main.js | 2 +- js/pis.js | 11 +++++++++-- pis.html | 18 ++++++++++++------ styles/pis.css | 13 ++++++++++--- 4 files changed, 32 insertions(+), 12 deletions(-) diff --git a/js/lib.main.js b/js/lib.main.js index 16a84b5..c443cdf 100644 --- a/js/lib.main.js +++ b/js/lib.main.js @@ -151,7 +151,7 @@ async function getApi(path,auth = false) { log(`resp.status: ${resp.status}`) log(`resp.json: ${json}`) if (resp.status != 200) { - return false + return resp.status } if (!resp.ok) { return false diff --git a/js/pis.js b/js/pis.js index 97cfb88..66fa9e1 100644 --- a/js/pis.js +++ b/js/pis.js @@ -9,7 +9,9 @@ async function findByOrigDest() { const endpoint = `pis/origdest/${formData.origin}/${formData.destination}` const json = await getApi(endpoint, auth = true) if (json == false) { - await noData() + await displayNoData() + } else if (json == 401) { + await displayUnauthorised() } else { await insertData(json) } @@ -45,11 +47,16 @@ async function insertData(json) { document.getElementById('result-count').textContent = results.toString() } -async function noData() { +async function displayNoData() { const msg = '

No results found

' document.getElementById('result-box').insertAdjacentHTML("beforeend", msg) } +async function displayUnauthorised() { + const msg = '

Unauthorised - please ensure you are logged into the rail staff version

' + document.getElementById('result-box').insertAdjacentHTML("beforeend", msg) +} + async function reset() { document.getElementById('origin').value = "" document.getElementById('destination').value = "" diff --git a/pis.html b/pis.html index be5505a..920f643 100644 --- a/pis.html +++ b/pis.html @@ -45,13 +45,19 @@

Enter a services start and end station CRS codes to see code options and stopping patterns.

-

Currently supported (Beta): GWR Bristol Metro region only.

+

Currently supported (Beta): GWR: Bristol Metro, WOS & CDF Southbound.

You need to be logged into a free rail staff version account for this feature.

-
-

-
-

- +
+
+
+ +
+
+
+

+
+
+
diff --git a/styles/pis.css b/styles/pis.css index 9ad13f0..e486351 100644 --- a/styles/pis.css +++ b/styles/pis.css @@ -1,5 +1,12 @@ -#crs-boxes { - display: block; +#crs-inputs { + display: flex; + justify-content: center; +} + +.pis-input { + width: 55%; + max-width: 200px; + margin: auto; } #result-box { @@ -19,7 +26,7 @@ td, th { } #reset { - margin-top: 25px + margin-top: 15px } #reset { -- 2.34.1 From ab452d985c64d24b987b8c66e330a33f65ee1234 Mon Sep 17 00:00:00 2001 From: Fred Boniface Date: Sun, 30 Apr 2023 21:18:46 +0100 Subject: [PATCH 37/51] Fixes --- js/pis.js | 1 + pis.html | 23 ++++++++++++----------- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/js/pis.js b/js/pis.js index 66fa9e1..066a597 100644 --- a/js/pis.js +++ b/js/pis.js @@ -63,4 +63,5 @@ async function reset() { 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 } \ No newline at end of file diff --git a/pis.html b/pis.html index 920f643..66c019e 100644 --- a/pis.html +++ b/pis.html @@ -43,21 +43,22 @@
-

Enter a services start and end station CRS codes to see code options and - stopping patterns.

+

Enter a services start and end station CRS codes to see code options and stopping patterns.

Currently supported (Beta): GWR: Bristol Metro, WOS & CDF Southbound.

You need to be logged into a free rail staff version account for this feature.

-
-
-
- -
-
-
-

+ +
+
+
+ +
+
+
+

+
+ -
-- 2.34.1 From 1d365ea3740a38d5b9e582731dd57b40faa8a8fe Mon Sep 17 00:00:00 2001 From: Fred Boniface Date: Sun, 30 Apr 2023 21:29:51 +0100 Subject: [PATCH 38/51] Fix getApi error handling --- js/lib.main.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/js/lib.main.js b/js/lib.main.js index c443cdf..6dc50bd 100644 --- a/js/lib.main.js +++ b/js/lib.main.js @@ -151,17 +151,17 @@ async function getApi(path,auth = false) { 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 } - if (json === "[]") { - return 'empty' - } return json; } catch(err) { - return false + log(`lib.main: getApi: Caught fetch error. Status: ${resp.status}`) + return resp.status } } -- 2.34.1 From 2dbdbb2441e66582e4b4a478b3dc2c8c60021f96 Mon Sep 17 00:00:00 2001 From: Fred Boniface Date: Sun, 30 Apr 2023 21:30:10 +0100 Subject: [PATCH 39/51] Remove unavailable placeholder on reginstration box --- settings.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/settings.html b/settings.html index 4e0487d..72cd726 100644 --- a/settings.html +++ b/settings.html @@ -71,7 +71,7 @@


Enter your work email address:

-
+

One registration confirmation email will be sent which will include more details about your account

Your address will not be stored

If your domain is not authorised and you are a using a railway company email address, -- 2.34.1 From 75f4290ba3010420b410070d1fe51d5424dc4b51 Mon Sep 17 00:00:00 2001 From: Fred Boniface Date: Sun, 30 Apr 2023 21:39:25 +0100 Subject: [PATCH 40/51] Adjust robots meta tag --- auth.html | 1 + board-staff.html | 1 + board.html | 1 + js/pis.js | 16 ++++++++++------ 4 files changed, 13 insertions(+), 6 deletions(-) diff --git a/auth.html b/auth.html index 7572510..14e365a 100644 --- a/auth.html +++ b/auth.html @@ -3,6 +3,7 @@ + diff --git a/board-staff.html b/board-staff.html index 111d695..9afc110 100644 --- a/board-staff.html +++ b/board-staff.html @@ -4,6 +4,7 @@ + diff --git a/board.html b/board.html index bbac91e..2c64824 100644 --- a/board.html +++ b/board.html @@ -5,6 +5,7 @@ + diff --git a/js/pis.js b/js/pis.js index 066a597..e749674 100644 --- a/js/pis.js +++ b/js/pis.js @@ -58,10 +58,14 @@ async function displayUnauthorised() { } async function reset() { - 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 + 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`) + } } \ No newline at end of file -- 2.34.1 From 35605cb216a5706705e007ecc0c63d1d7fcc511d Mon Sep 17 00:00:00 2001 From: Fred Boniface Date: Sun, 30 Apr 2023 21:55:56 +0100 Subject: [PATCH 41/51] Add eslint --- .dockerignore | 6 +- .eslintrc.js | 30 ++ .gitignore | 1 + auth.html | 12 +- board-staff.html | 16 +- board.html | 18 +- js/auth.js | 4 +- package-lock.json | 1125 +++++++++++++++++++++++++++++++++++++++++++++ package.json | 14 + pis.html | 12 +- stat.html | 2 +- 11 files changed, 1207 insertions(+), 33 deletions(-) create mode 100644 .eslintrc.js create mode 100644 .gitignore create mode 100644 package-lock.json create mode 100644 package.json diff --git a/.dockerignore b/.dockerignore index 9a715f5..f06a337 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,2 +1,6 @@ .dockerignore -Dockerfile \ No newline at end of file +Dockerfile +package.json +package-lock.json +.eslintrc.js +node_modules \ No newline at end of file diff --git a/.eslintrc.js b/.eslintrc.js new file mode 100644 index 0000000..3a42aef --- /dev/null +++ b/.eslintrc.js @@ -0,0 +1,30 @@ +module.exports = { + 'env': { + 'browser': true, + 'es2021': true + }, + 'extends': 'eslint:recommended', + 'overrides': [ + ], + 'parserOptions': { + 'ecmaVersion': 'latest' + }, + 'rules': { + 'indent': [ + 'error', + 4 + ], + 'linebreak-style': [ + 'error', + 'unix' + ], + 'quotes': [ + 'error', + 'single' + ], + 'semi': [ + 'error', + 'never' + ] + } +} diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..b512c09 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +node_modules \ No newline at end of file diff --git a/auth.html b/auth.html index 14e365a..13990db 100644 --- a/auth.html +++ b/auth.html @@ -1,17 +1,17 @@ - - - + + + - - - + + + OwlBoard diff --git a/board-staff.html b/board-staff.html index 9afc110..fe8f827 100644 --- a/board-staff.html +++ b/board-staff.html @@ -1,19 +1,19 @@ - - + + - + OwlBoard - Loading - - - - + + + + @@ -28,7 +28,7 @@