Compare commits
6 Commits
0d18fd6c26
...
a178a0b66b
Author | SHA1 | Date |
---|---|---|
Fred Boniface | a178a0b66b | |
Fred Boniface | 4463e8c8f1 | |
Fred Boniface | 2147d2f106 | |
Fred Boniface | 4c6d66c5d9 | |
Fred Boniface | 908ded08a7 | |
Fred Boniface | eb828896d0 |
4
app.js
4
app.js
|
@ -14,7 +14,8 @@ const version = require('./src/configs/version.configs'); // Version Strings
|
|||
const listRtr = require('./src/routes/list.routes'); // /list endpoints
|
||||
const ldbRtr = require('./src/routes/ldb.routes'); // /ldb endpoints
|
||||
const kubeRtr = require('./src/routes/kube.routes'); // /kube endpoints
|
||||
const initDb = require('./src/utils/dbinit.utils') // DB Init Utility
|
||||
const findRtr = require('./src/routes/find.routes'); // /find endpoints
|
||||
const initDb = require('./src/utils/dbinit.utils'); // DB Init Utility
|
||||
|
||||
// Set Server Configurations
|
||||
const srvListen = process.env.OWL_SRV_LISTEN || "0.0.0.0"
|
||||
|
@ -51,6 +52,7 @@ app.use(express.static('static')); //Serve static content from /static
|
|||
app.use('/api/v1/list', listRtr);
|
||||
app.use('/api/v1/ldb', ldbRtr);
|
||||
app.use('/api/v1/kube', kubeRtr);
|
||||
app.use('/api/v1/find', findRtr);
|
||||
|
||||
// Start Express
|
||||
app.listen(srvPort, srvListen, (error) =>{
|
||||
|
|
|
@ -0,0 +1,58 @@
|
|||
const find = require('../services/find.services');
|
||||
|
||||
async function findName(req, res, next){
|
||||
try {
|
||||
var id = req.params.id
|
||||
res.json(await find.name(id))
|
||||
} catch (err) {
|
||||
console.error(`Unknown Error`, err.message);
|
||||
next(err);
|
||||
}
|
||||
}
|
||||
|
||||
async function findCrs(req, res, next){
|
||||
try {
|
||||
var id = req.params.id
|
||||
res.json(await find.crs(id))
|
||||
} catch (err) {
|
||||
console.error(`Unknown Error`, err.message);
|
||||
next(err);
|
||||
}
|
||||
}
|
||||
|
||||
async function findNlc(req, res, next){
|
||||
try {
|
||||
var id = req.params.id
|
||||
res.json(await find.nlc(id))
|
||||
} catch (err) {
|
||||
console.error(`Unknown Error`, err.message);
|
||||
next(err);
|
||||
}
|
||||
}
|
||||
|
||||
async function findTiploc(req, res, next){
|
||||
try {
|
||||
var id = req.params.id
|
||||
res.json(await find.tiploc(id))
|
||||
} catch (err) {
|
||||
console.error(`Unknown Error`, err.message);
|
||||
next(err);
|
||||
}
|
||||
}
|
||||
|
||||
async function findStanox(req, res, next){
|
||||
try {
|
||||
var id = req.params.id
|
||||
res.json(await find.stanox(id))
|
||||
} catch (err) {
|
||||
console.error(`Unknown Error`, err.message);
|
||||
next(err);
|
||||
}
|
||||
}
|
||||
module.exports = {
|
||||
findName,
|
||||
findCrs,
|
||||
findNlc,
|
||||
findTiploc,
|
||||
findStanox
|
||||
}
|
|
@ -0,0 +1,23 @@
|
|||
const express = require('express');
|
||||
const router = express.Router();
|
||||
const findController = require('../controllers/find.controllers');
|
||||
|
||||
/* GET programming languages. */
|
||||
//router.get('/', programmingLanguagesController.get);
|
||||
|
||||
/* POST programming language */
|
||||
//router.post('/', programmingLanguagesController.create);
|
||||
|
||||
/* PUT programming language */
|
||||
//router.put('/:id', programmingLanguagesController.update);
|
||||
|
||||
/* DELETE programming language */
|
||||
//router.delete('/:id', programmingLanguagesController.remove);
|
||||
|
||||
router.get('/name/:id', findController.findName);
|
||||
router.get('/crs/:id', findController.findCrs);
|
||||
router.get('/nlc/:id', findController.findNlc);
|
||||
router.get('/tiploc/:id', findController.findTiploc);
|
||||
router.get('/stanox/:id', findController.findStanox);
|
||||
|
||||
module.exports = router;
|
|
@ -0,0 +1,59 @@
|
|||
// Parse and return a find request
|
||||
|
||||
const log = require('../utils/log.utils'); // Log Helper
|
||||
const db = require('../services/dbAccess.services');
|
||||
const san = require('../utils/sanitizer.utils')
|
||||
|
||||
// DB Query: query(collection, query)
|
||||
|
||||
// Define collection as all queries are for the "corpus" collection.
|
||||
const col = "corpus"
|
||||
|
||||
async function name(id){
|
||||
log.out(`findServices.name: Finding station name: ${id}`)
|
||||
var name = san.cleanApiEndpointTxt(id.toUpperCase())
|
||||
query = {NLCDESC: name}
|
||||
var data = await db.query(col,query)
|
||||
return data
|
||||
}
|
||||
|
||||
async function crs(id){
|
||||
log.out(`findServices.crs: Finding crs: ${id}`)
|
||||
var crs = san.cleanApiEndpointTxt(id.toUpperCase())
|
||||
query = {'3ALPHA': crs}
|
||||
var data = await db.query(col,query)
|
||||
return data
|
||||
}
|
||||
|
||||
async function nlc(id){
|
||||
log.out(`findServices.nlc: Finding nlc: ${id}`)
|
||||
var nlc = san.cleanApiEndpointNum(id)
|
||||
query = {NLC: parseInt(nlc)}
|
||||
log.out(`findServices.nlc: NLC Converted to int: ${query}`)
|
||||
var data = await db.query(col,query)
|
||||
return data
|
||||
}
|
||||
|
||||
async function tiploc(id){
|
||||
log.out(`findServices.tiploc: Finding tiploc: ${id}`)
|
||||
var tiploc = san.cleanApiEndpointTxt(id.toUpperCase())
|
||||
query = {TIPLOC: tiploc}
|
||||
var data = await db.query(col,query)
|
||||
return data
|
||||
}
|
||||
|
||||
async function stanox(id){
|
||||
log.out(`findServices.stanox: Finding stanox: ${id}`)
|
||||
var stanox = san.cleanApiEndpointNum(id)
|
||||
query = {STANOX: String(stanox)}
|
||||
var data = await db.query(col,query)
|
||||
return data
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
name,
|
||||
crs,
|
||||
nlc,
|
||||
tiploc,
|
||||
stanox
|
||||
}
|
|
@ -16,7 +16,7 @@ const ldbKey = process.env.OWL_LDB_KEY
|
|||
const ldbsvKey = process.env.OWL_LDB_SVKEY
|
||||
|
||||
async function get(body, id){
|
||||
var cleanId = san.cleanApiEndpoint(id);
|
||||
var cleanId = san.cleanApiEndpointTxt(id);
|
||||
var obj = await util.checkCrs(cleanId);
|
||||
try {
|
||||
var crs = obj[0]['3ALPHA'];
|
||||
|
|
|
@ -61,7 +61,7 @@ async function build(db){ // `db` must be one of: `corpus`, `stations`, `all`.
|
|||
await dbAccess.dropCollection("corpus");
|
||||
dbAccess.putCorpus(corpusAll);
|
||||
|
||||
log.out(`dbInitUtils.build: Updateing corpus meta`)
|
||||
log.out(`dbInitUtils.build: Updating corpus meta`)
|
||||
dbAccess.updateMeta("collection", "corpus", time.jsUnix(Date.now()));
|
||||
}
|
||||
if (db === "stations") {
|
||||
|
|
|
@ -16,14 +16,23 @@ string.addDash("@abcd efgh"); // @abcd-efgh
|
|||
string.removeSpace("@abcd efgh"); // @abcdefgh
|
||||
*/
|
||||
|
||||
function cleanApiEndpoint(input) {
|
||||
var output = clean.sanitize(input)
|
||||
function cleanApiEndpointTxt(input) {
|
||||
var output = clean.sanitize.keepSpace(input)
|
||||
if (output != input){
|
||||
log.out(`sanitizerUtils.cleanApiEndpoint: WARN: Sanitizing changed string. Input = ${input}`);
|
||||
}
|
||||
return output
|
||||
}
|
||||
|
||||
function cleanApiEndpointNum(input) {
|
||||
var output = clean.sanitize.keepNumber(input)
|
||||
if (output != input){
|
||||
log.out(`sanitizerUtils.cleanApiEndpointNum: WARN: Sanitizing changed string. Input = ${input}`);
|
||||
}
|
||||
return output
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
cleanApiEndpoint
|
||||
cleanApiEndpointTxt,
|
||||
cleanApiEndpointNum
|
||||
}
|
|
@ -0,0 +1,52 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8"/>
|
||||
<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"/>
|
||||
<title>OwlBoard - Code Lookup</title>
|
||||
<script src="./js/find-code.js"></script>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
|
||||
<div id="top_button" class="hide_micro">
|
||||
<button aria-label="Back" class="sidebar_control" onclick="history.back()">⇦</button>
|
||||
</div>
|
||||
|
||||
<picture>
|
||||
<source media="(min-width:800px)" secset="./images/logo/logo-full-715.webp" type="image/webp">
|
||||
<source media="(min-width:800px)" srcset="./images/logo/logo-full-715.png" type="image/png">
|
||||
<source media="(min-width:700px)" srcset="./images/logo/logo-full-512.webp" type="image/webp">
|
||||
<source media="(min-width:700px)" srcset="./images/logo/logo-full-512.png" type="image/png">
|
||||
<source media="(min-width:450px)" srcset="./images/logo/logo-full-256.webp" type="image/png">
|
||||
<source media="(min-width:450px)" srcset="./images/logo/logo-full-256.png" type="image/png">
|
||||
<img class="titleimg" src="./images/logo/logo-full-512.png" alt="OwlBoard Logo">
|
||||
</picture>
|
||||
<h2>Code Lookup</h2>
|
||||
<p>Enter one known code in the relevant box below and hit submit.
|
||||
Where they exist, the other code types will be filled in.</p>
|
||||
<p>You cannot yet lookup by Station name as the values are not unique.</p>
|
||||
<p>Station name search will be added in the future.</p>
|
||||
<label for="name">Station name:</label><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>
|
||||
<input type="number" class="small-lookup-box" id="nlc" name="nlc" min="100000" max="999999"><br>
|
||||
<label for="tiploc">TIPLOC:</label><br>
|
||||
<input type="text" class="small-lookup-box" id="tiploc" name="tiploc" maxlength="7"><br>
|
||||
<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="submit" value="Find" class="lookup-button" onclick="fetchEntry()">
|
||||
<input type="submit" value="Clear" class="lookup-button" onclick="clearForm()">
|
||||
</body>
|
||||
</html>
|
|
@ -14,6 +14,11 @@
|
|||
</head>
|
||||
|
||||
<body>
|
||||
|
||||
<div id="top_button" class="hide_micro">
|
||||
<button aria-label="Back" class="sidebar_control" onclick="history.back()">⇦</button>
|
||||
</div>
|
||||
|
||||
<picture>
|
||||
<source media="(min-width:800px)" secset="./images/logo/logo-full-715.webp" type="image/webp">
|
||||
<source media="(min-width:800px)" srcset="./images/logo/logo-full-715.png" type="image/png">
|
||||
|
|
|
@ -17,12 +17,13 @@
|
|||
<body>
|
||||
|
||||
<!-- Popup Menu -->
|
||||
<div id="menubar_hamburger" class="hide_micro">
|
||||
<div id="top_button" class="hide_micro">
|
||||
<button aria-label="Menu" class="sidebar_control" id="sidebar_open_short" onclick="sidebarOpen()">☰</button>
|
||||
<button aria-label="Close Menu" class="sidebar_control" id="sidebar_close_short" onclick="sidebarClose()">×</button>
|
||||
</div>
|
||||
<div id="sidebar">
|
||||
<a href="/">Home</a>
|
||||
<a href="/find-code.html">Code Search</a>
|
||||
<a href="/help.html">Help</a>
|
||||
<a href="/issue.html">Report Issue</a>
|
||||
</div>
|
||||
|
@ -71,7 +72,7 @@
|
|||
|
||||
<!-- Footer -->
|
||||
<footer>
|
||||
<p>Created by <a href="https://fredboniface.co.uk" target="_blank" rel="noreferrer noopener">Fred Boniface</a> - v1.0.0-devel</p>
|
||||
<p>Created by <a href="https://fredboniface.co.uk" target="_blank" rel="noreferrer noopener">Fred Boniface</a> - v0.0.1-devel</p>
|
||||
</footer>
|
||||
|
||||
</body>
|
||||
|
|
|
@ -0,0 +1,21 @@
|
|||
<html>
|
||||
<head>
|
||||
<meta charset="UTF-8"/>
|
||||
<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"/>
|
||||
<title>OwlBoard - Report</title>
|
||||
</head>
|
||||
<body>
|
||||
<div id="top_button" class="hide_micro">
|
||||
<button aria-label="Back" class="sidebar_control" onclick="history.back()">⇦</button>
|
||||
</div>
|
||||
|
||||
<p>This page is (temporarily) intentionally blank.</p>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,86 @@
|
|||
async function fetchEntry(){
|
||||
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,
|
||||
crs: crs.value,
|
||||
nlc: nlc.value,
|
||||
tiploc: tiploc.value,
|
||||
stanox: stanox.value
|
||||
}
|
||||
|
||||
console.log(`Read values: ${JSON.stringify(values)}`)
|
||||
|
||||
parseData(values)
|
||||
}
|
||||
|
||||
async function parseData(values){
|
||||
if (values.crs != ""){
|
||||
var data = await getData("crs", values.crs)
|
||||
} else if (values.nlc != ""){
|
||||
var data = await getData("nlc", values.nlc)
|
||||
} else if (values.tiploc != ""){
|
||||
var data = await getData("tiploc", values.tiploc)
|
||||
} else if (values.stanox != ""){
|
||||
var data = await getData("stanox", values.stanox)
|
||||
} else if (values.name != ""){
|
||||
var data = await getData("name", values.name)
|
||||
} else {
|
||||
errorNoData()
|
||||
data = {status: "failed"}
|
||||
return
|
||||
}
|
||||
|
||||
displayData(data);
|
||||
}
|
||||
|
||||
async function getData(type, value){
|
||||
console.log(`Looking for: ${type} ${value}`)
|
||||
try {
|
||||
var url = `${window.location.origin}/api/v1/find/${type}/${value}`;
|
||||
var resp = await fetch(url);
|
||||
console.log(`Response: ${resp.json}`)
|
||||
return await resp.json()
|
||||
} catch (err) {
|
||||
errorFetch(err)
|
||||
}
|
||||
}
|
||||
|
||||
async function displayData(data){
|
||||
if (data.status === "failed" || data == ""){
|
||||
errorNotFound()
|
||||
}
|
||||
document.getElementById("name").value = data['0']['NLCDESC']
|
||||
document.getElementById("3alpha").value = data['0']['3ALPHA']
|
||||
document.getElementById("nlc").value = data['0']['NLC']
|
||||
document.getElementById("tiploc").value = data['0']['TIPLOC']
|
||||
document.getElementById("stanox").value = data['0']['STANOX']
|
||||
// document.getElementById("stanme").value = data['0']['STANME'] // NOT PRESENT IN CORPUS
|
||||
}
|
||||
|
||||
async function clearForm(){
|
||||
document.getElementById("name").value = ""
|
||||
document.getElementById("3alpha").value = ""
|
||||
document.getElementById("nlc").value = ""
|
||||
document.getElementById("tiploc").value = ""
|
||||
document.getElementById("stanox").value = ""
|
||||
}
|
||||
|
||||
async function errorNoData(){
|
||||
console.log("No data entered")
|
||||
window.alert("You haven't entered any data")
|
||||
}
|
||||
|
||||
async function errorFetch(err){
|
||||
console.log("Error fetching data")
|
||||
console.log(err)
|
||||
}
|
||||
|
||||
async function errorNotFound(){
|
||||
console.log("Location not found")
|
||||
window.alert("No location was found. Check and try again.")
|
||||
}
|
|
@ -1,8 +0,0 @@
|
|||
<html>
|
||||
<head>
|
||||
<title>Report an Issue</title>
|
||||
</head>
|
||||
<body>
|
||||
<p>This page is (temporarily) intentionally blank.</p>
|
||||
</body>
|
||||
</html>
|
|
@ -68,6 +68,19 @@ body a:visited {color:var(--link-visited-color)}
|
|||
font-family: urwgothic, sans-serif;
|
||||
transition: 0.2s;
|
||||
}
|
||||
label {
|
||||
font-weight: 900;
|
||||
}
|
||||
.small-lookup-box {
|
||||
text-align: center;
|
||||
border: black;
|
||||
border-radius: 40px;
|
||||
padding: 10px;
|
||||
margin-bottom: 10px;
|
||||
text-transform: uppercase;
|
||||
font-family: urwgothic, sans-serif;
|
||||
transition: 0.2s;
|
||||
}
|
||||
.form-text-small {
|
||||
text-align: center;
|
||||
border: black;
|
||||
|
@ -143,7 +156,7 @@ body a:visited {color:var(--link-visited-color)}
|
|||
cursor: pointer;
|
||||
}
|
||||
/* START MENU STYLE */
|
||||
#menubar_hamburger {
|
||||
#top_button {
|
||||
position: absolute;
|
||||
top: 2px;
|
||||
right: 0;
|
||||
|
@ -155,6 +168,7 @@ body a:visited {color:var(--link-visited-color)}
|
|||
border: none;
|
||||
font-family: sans-serif;
|
||||
font-size: larger;
|
||||
cursor: pointer;
|
||||
}
|
||||
#sidebar_open_short {display: block;}
|
||||
#sidebar_close_short {
|
||||
|
|
Reference in New Issue