Mainly frontend

This commit is contained in:
Fred Boniface 2022-12-08 15:21:59 +00:00
parent fccb00232c
commit c4d668be81
20 changed files with 75 additions and 175 deletions

View File

@ -12,67 +12,42 @@ const keys = require('/srv/keys/owlboard/keys.configs');
const axios = require('axios');
const zlib = require('zlib');
async function initCorpus() {
let gzipData = await getCorpusAgain();
async function init() {
var gzipData = await get();
console.log(gzipData);
var rawData = await extract(gzipData);
console.log(rawData);
var cleanData = await clean(rawData);
console.log(cleanData)
return cleanData;
}
async function getCorpus() {
async function get() {
authHead = Buffer.from(`${keys.nr_user}:${keys.nr_pass}`).toString('base64');
const url = 'https://datafeeds.networkrail.co.uk/ntrod/SupportingFileAuthenticate?type=CORPUS'
const options = {
method: 'get',
timeout: 3000,
timeout: 20000,
headers: {'Authorization': `Basic ${authHead}`},
responseType: 'arraybuffer'
};
return await axios.get(url, options).then(function (response){console.log(response.data);return response.data;});
var { output } = await axios.get(url, options)
console.log(output)
return output;
}
async function getCorpusAgain() {
authHead = Buffer.from(`${keys.nr_user}:${keys.nr_pass}`).toString('base64');
const decomp = zlib.createGunzip();
const getReq = axios.create({
method: 'get',
baseURL: 'https://datafeeds.networkrail.co.uk/ntrod/SupportingFileAuthenticate?type=CORPUS',
timeout: 3000,
headers: {'Authorization': `Basic ${authHead}`},
responseType: 'arraybuffer'
});
let download = await getReq().then(function (response){
return response.data;
})
zlib.gunzip(download, function (_err, output){
let string = output.toString()
let obj = JSON.parse(string)
//console.log(obj);
return obj; // Find out how to get data out of callback -> See pinned tab on laptop2.ws
})
}
async function init() { // PSUEDOCODE
var zipData = await get();
var rawData = extract(zipData);
var cleanData = clean(rawData)
}
async function get() {
}
async function extract() {
async function extract(input) {
var { data } = zlib.Gunzip(input);
let string = data.toString()
let obj = JSON.parse(string)
//console.log(obj);
return obj; // Find out how to get data out of callback -> See pinned tab on laptop2.ws
}
async function clean() {
return "Empty Function: clean()"
}
module.exports = {
initCorpus,
getCorpusAgain,
getCorpus,
init
}

5
static/board.html Normal file
View File

@ -0,0 +1,5 @@
<html lang="en">
<head>
<title id="pgTitle">OwlBoard - Loading</title>
</head>
</html>

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 27 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 48 KiB

View File

Before

Width:  |  Height:  |  Size: 70 KiB

After

Width:  |  Height:  |  Size: 70 KiB

View File

Before

Width:  |  Height:  |  Size: 14 KiB

After

Width:  |  Height:  |  Size: 14 KiB

View File

Before

Width:  |  Height:  |  Size: 21 KiB

After

Width:  |  Height:  |  Size: 21 KiB

View File

Before

Width:  |  Height:  |  Size: 29 KiB

After

Width:  |  Height:  |  Size: 29 KiB

View File

Before

Width:  |  Height:  |  Size: 35 KiB

After

Width:  |  Height:  |  Size: 35 KiB

View File

Before

Width:  |  Height:  |  Size: 11 KiB

After

Width:  |  Height:  |  Size: 11 KiB

View File

Before

Width:  |  Height:  |  Size: 48 KiB

After

Width:  |  Height:  |  Size: 48 KiB

View File

@ -1,32 +1,30 @@
<!DOCTYPE html>
<html>
<html lang="en">
<head>
<meta charset="UTF-8"/>
<meta name="description" content="Athena - Live train departures for traincrew."/>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="application-name" content="Athena">
<meta name="author" content="Frederick Boniface">
<link rel="stylesheet" type="text/css" href="/styles/style.css"/>
<link rel="icon" type="image/png" href="/assets/icons/favicon.ico"/>
<link rel="manifest" type="application/json" href="/manifest.json"/>
<script src="/js/nav.js"></script> <title>Athena</title>
<script src="/js/tiploc-finder.js" async></script>
<meta name="description" content="OwlBoard - Live train departures for traincrew."/>
<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="#155bb7">
<link rel="stylesheet" type="text/css" href="/styles/style.css"/>
<link rel="icon" type="image/png" href="/images/logo/logo-sq-256.png"/>
<link rel="manifest" type="application/json" href="/manifest.json"/>
<script src="/js/nav.js"></script>
<title>OwlBoard</title>
</head>
<body>
<!-- Popup Menu -->
<div id="menubar_hamburger" class="hide_micro">
<button class="sidebar_control" id="sidebar_open_short" onclick="sidebarOpen()">&#9776;</button>
<button class="sidebar_control" id="sidebar_close_short" onclick="sidebarClose()">&times;</button>
<div id="menubar_hamburger" class="hide_micro">
<button aria-label="Menu" class="sidebar_control" id="sidebar_open_short" onclick="sidebarOpen()">&#9776;</button>
<button aria-label="Close Menu" class="sidebar_control" id="sidebar_close_short" onclick="sidebarClose()">&times;</button>
</div>
<div id="sidebar">
<a href="/">Home</a>
<a href="/help.php">Help</a>
<a href="/issue.php">Report Issue</a>
<a href="/help.html">Help</a>
<a href="/issue.html">Report Issue</a>
</div>
<!-- Main Content Begins -->
@ -61,8 +59,8 @@
<br>
<br>
<div class="text-description">
<p>This is an Alpha release and is under testing.</p>
<p>Some features may not work and some stations may not be available.</p>
<p>This is a development release and is under testing.</p>
<p>Many features do not yet work.</p>
</div>
<!-- Footer -->

View File

View File

@ -1,90 +0,0 @@
const url = "https://tiger.worldline.global/";
const view = "/staff;scrollbar=true";
console.group("Athena - Departure Boards")
console.info("Initialising");
/* Get lookup data from JSON file */
let dataGlobal;
const getData = async () => {
console.info("Loading Tiger lookup file");
// Probably put a loading wheel here!
const response = await fetch("./assets/tiger_codes.json");
const data = await response.json();
dataGlobal = data;
return data;
};
(async () => {
await getData();
console.info("Lookup file loaded");
console.info(dataGlobal);
console.info("Initialisation complete");
// Probably end the loading wheel here.
console.groupEnd();
})();
/* Read Lookup textbox entry and call the gotoInfoBoard() function */
function getTextEntry() {
console.group("Athena: function: getTextEntry()");
console.info("Getting contents of textbox 'crs-lookup'");
let forLookup = document.getElementById("crs-lookup").value;
console.info("You have entered: " + forLookup.toUpperCase());
console.info("Calling gotoInfoBoard(" + forLookup.toLowerCase() + ")");
console.groupEnd()
gotoInfoBoard(forLookup);
};
/* Runs basic validation of data type and then process that and finally
redirects to Tiger using a built URL */
function gotoInfoBoard(station) {
// Firstly start a console group for the function
console.group("Athena: function: gotoInfoBoard(" + station.toLowerCase() + ")");
//Determins if code is TIPLOC and if so redirects immediately
if (station.length > 3 && station.length < 8) {
console.info(station.length + "characters, presumed to be tiploc.");
console.info("Redirecting to " + station + " departure board");
window.location = url + station.toUpperCase() + view;
//If code is CRS then process further to determine the TIPLOC then redirect
} else if (station.length == 3) {
console.info("CRS entered: " + station.toUpperCase() + ", required lookup");
console.info("Finding object");
let crs_to_find = station.toLowerCase();
console.debug("Converted string to lower case:" + crs_to_find);
//Check if the entered CRS exists in the lookup file
console.info("Checking if CRS code exists in lookup data")
let hasKey = dataGlobal.hasOwnProperty(crs_to_find);
if (hasKey) { //If key exists then log and continue
console.info(crs_to_find.toUpperCase() + " does exist in lookup file");
} else { //If key does not exist then stop further processing
console.warn(crs_to_find.toUpperCase() + "does not exist in lookup file");
console.error(crs_to_find.toUpperCase() + " is an incorrect code or not supported.");
alert(crs_to_find.toUpperCase() + " is not a valid or supported CRS, " +
"please see the help section for more information");
console.groupEnd();
return 0;
}
let crs_obj = dataGlobal[crs_to_find];
console.info("Isolating TIPLOC from Object");
let tiploc = crs_obj['tiploc']; // crs_obj['tiploc']??
console.info("TIPLOC: " + tiploc);
console.info("Redirecting to " + tiploc + " departure board");
window.location = url + tiploc.toUpperCase() + view;
//If the code cannot be validated as CRS or TIPLOC then throw an alert and log
} else {
console.error("Please only enter:\n - A 3 character CRS code,\n - A 4-7 " +
"character TIPLOC code.\n\nPartial codes or station names cannot be looked "+
"up.");
alert("Please only enter:\n - A 3 character CRS code,\n - A 4-7 " +
"character TIPLOC code.\n\nPartial codes or station names cannot be looked "+
"up.");
}
// Lastly close the log group at the end of the Function and return.
console.groupEnd();
return 0;
}

View File

@ -1,10 +1,10 @@
{
"name": "OwlBoards",
"short_name": "OwlBoards",
"name": "OwlBoard",
"short_name": "OwlBoard",
"start_url": "/",
"scope": "/",
"display": "standalone",
"background_color": "#ffffff",
"background_color": "#404c55",
"description": "Live station departures - aimed at train-crew.",
"categories": "travel,utilities",
"lang": "en",
@ -12,46 +12,56 @@
"theme_color": "#155bb7",
"icons": [
{
"src": "/images/app-icons/app-1200.png",
"src": "/images/app-icons/maskable/app-1200.png",
"sizes": "1200x1200",
"type": "image/png",
"purpose": "any maskable"
"purpose": "maskable"
},
{
"src": "/images/app-icons/app-768.png",
"src": "/images/app-icons/maskable/app-768.png",
"sizes": "768x768",
"type": "image/png",
"purpose": "any maskable"
"purpose": "maskable"
},
{
"src": "/images/app-icons/app-512.png",
"src": "/images/app-icons/maskable/app-512.png",
"sizes": "512x512",
"type": "image/png",
"purpose": "any maskable"
"purpose": "maskable"
},
{
"src": "/images/app-icons/app-384.png",
"src": "/images/app-icons/maskable/app-384.png",
"sizes": "384x384",
"type": "image/png",
"purpose": "any maskable"
"purpose": "maskable"
},
{
"src": "/images/app-icons/app-256.png",
"src": "/images/app-icons/maskable/app-256.png",
"sizes": "256x256",
"type": "image/png",
"purpose": "any maskable"
"purpose": "maskable"
},
{
"src": "/images/app-icons/app-128.png",
"src": "/images/app-icons/maskable/app-128.png",
"sizes": "128x128",
"type": "image/png",
"purpose": "any maskable"
"purpose": "maskable"
},
{
"src": "/images/app-icons/app-76.png",
"src": "/images/app-icons/maskable/app-76.png",
"sizes": "76x76",
"type": "image/png",
"purpose": "any maskable"
"purpose": "maskable"
},
{
"src": "/images/app-icons/any/app-512.png",
"sizes": "512x512",
"type": "image/png"
},
{
"src": "/images/app-icons/any/app-256.png",
"sizes": "256x256",
"type": "image/png"
}
]
}

0
static/report.html Normal file
View File

0
static/styles/boards.css Normal file
View File

View File

@ -18,9 +18,9 @@
/* COLOR VARS */
:root {
--main-bg-color: #5d5d74;
--main-bg-color: #404c55;
--accent-color: #007979;
--overlay-color: #7fa6e6de;
--overlay-color: #3c6f79de;
--main-text-color: #00b7b7;
--link-color: azure;
--link-visited-color: azure;
@ -33,10 +33,11 @@ body {
padding-bottom: 60px; /*Footer height*/
}
.titleimg {
width: 80%;
width: 45%;
padding-top: 20px;
padding-bottom: 20px;
max-width: 500px;
min-width: 200px;
transition: 0.2s;
}
.lookup-box {
@ -129,7 +130,7 @@ body {
}
.sidebar_control {
background-color: transparent;
color: var(--accent-color);
color: var(--link-color);
border: none;
font-family: sans-serif;
font-size: larger;
@ -170,6 +171,7 @@ body {
footer {
background-color: var(--accent-color);
font-family: firamono, monospace;
font-size: smaller;
color: white;
width: 100%;
position: fixed;