Compare commits

..

3 Commits

Author SHA1 Message Date
Fred Boniface a7b8fb36d4 Adjust PIS Styling 2023-04-30 21:10:37 +01:00
Fred Boniface 92f621b6f9 Add auth flag to PIS.js 2023-04-30 20:28:30 +01:00
Fred Boniface fbb4702b69 Adjust frontend version display on stats 2023-04-30 20:27:04 +01:00
7 changed files with 36 additions and 16 deletions

View File

@ -151,7 +151,7 @@ async function getApi(path,auth = false) {
log(`resp.status: ${resp.status}`) log(`resp.status: ${resp.status}`)
log(`resp.json: ${json}`) log(`resp.json: ${json}`)
if (resp.status != 200) { if (resp.status != 200) {
return false return resp.status
} }
if (!resp.ok) { if (!resp.ok) {
return false return false

View File

@ -7,9 +7,11 @@ async function findByOrigDest() {
const formData = await fetchOrigDest() const formData = await fetchOrigDest()
log(`findByOrigDest: Searching for PIS Code for ${JSON.stringify(formData)}`) log(`findByOrigDest: Searching for PIS Code for ${JSON.stringify(formData)}`)
const endpoint = `pis/origdest/${formData.origin}/${formData.destination}` const endpoint = `pis/origdest/${formData.origin}/${formData.destination}`
const json = await getApi(endpoint) const json = await getApi(endpoint, auth = true)
if (json == false) { if (json == false) {
await noData() await displayNoData()
} else if (json == 401) {
await displayUnauthorised()
} else { } else {
await insertData(json) await insertData(json)
} }
@ -45,11 +47,16 @@ async function insertData(json) {
document.getElementById('result-count').textContent = results.toString() document.getElementById('result-count').textContent = results.toString()
} }
async function noData() { async function displayNoData() {
const msg = '<p id="result-table">No results found</p>' 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)
}
async function reset() { async function reset() {
document.getElementById('origin').value = "" document.getElementById('origin').value = ""
document.getElementById('destination').value = "" document.getElementById('destination').value = ""

View File

@ -1,6 +1,7 @@
init(); init();
async function init() { // The page init function async function init() { // The page init function
versionDisplay()
display(await get()) 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('meta').textContent = dat.meta || "0";
document.getElementById('pis').textContent = dat.pis document.getElementById('pis').textContent = dat.pis
document.getElementById('ver-dbman').textContent = ver.dbmanager || "Unknown"; document.getElementById('ver-dbman').textContent = ver.dbmanager || "Unknown";
document.getElementById('ver-web').textContent = localStorage.getItem('ver-web') || "Unknown";
} }

View File

@ -45,13 +45,19 @@
<div id="crs-box"> <div id="crs-box">
<p>Enter a services start and end station CRS codes to see code options and <p>Enter a services start and end station CRS codes to see code options and
stopping patterns.</p> stopping patterns.</p>
<p>Currently supported (Beta): GWR Bristol Metro region only.</p> <p>Currently supported (Beta): GWR: Bristol Metro, WOS & CDF Southbound.</p>
<p id="auth-required">You need to be logged into a free <a href="./settings.html">rail staff version</a> account for this feature.</p> <p id="auth-required">You need to be logged into a free <a href="./settings.html">rail staff version</a> account for this feature.</p>
<label for="origin">Origin:</label><br> <form id = "crs-inputs" action="javascript:findByOrigDest();">
<input type="text" class="small-lookup-box" id="origin" name="origin" maxlength="3"><br><br> <div class="crs-input">
<label for="destination">Destination:</label><br> <label for="origin">From:</label><br>
<input type="text" class="small-lookup-box" id="destination" name="destination" maxlength="3"><br><br> <input type="text" class="small-lookup-box pis-input" id="origin" name="origin" maxlength="3">
<input type="submit" value="Find" class="lookup-button" onclick="findByOrigDest()"> </div>
<div class="crs-input">
<label for="destination">To:</label><br>
<input type="text" class="small-lookup-box pis-input" id="destination" name="destination" maxlength="3"><br><br>
</div>
</form>
<input type="submit" value="Find" class="lookup-button">
</div> </div>
<div id="result-box"> <div id="result-box">

View File

@ -78,7 +78,7 @@
web-frontend web-frontend
</a> </a>
</td> </td>
<td id="ver-web"></td> <td id="ver_str">Unknown</td>
</tr> </tr>
</table> </table>
<p>The statistics represent hits & queries from all instances in the stack.</p> <p>The statistics represent hits & queries from all instances in the stack.</p>

View File

@ -1,5 +1,12 @@
#crs-boxes { #crs-inputs {
display: block; display: flex;
justify-content: center;
}
.pis-input {
width: 55%;
max-width: 200px;
margin: auto;
} }
#result-box { #result-box {
@ -19,7 +26,7 @@ td, th {
} }
#reset { #reset {
margin-top: 25px margin-top: 15px
} }
#reset { #reset {

2
sw.js
View File

@ -1,6 +1,6 @@
/* Service Worker */ /* Service Worker */
const appVersion = "PIS-DEV-23042502" const appVersion = "PIS-DEV-23043001"
const cacheName = `owlboard-${appVersion}`; const cacheName = `owlboard-${appVersion}`;
const cacheIDs = [cacheName]; const cacheIDs = [cacheName];
const cacheFiles = [ const cacheFiles = [