From 05b2f920a4d5d34c3af6f0e35d1c1073da3edbf1 Mon Sep 17 00:00:00 2001 From: Martin Donnelly Date: Thu, 14 Jun 2018 09:20:19 +0100 Subject: [PATCH] added birmingham international , fixed a stupid scotrail bug and added a catch all for unhandled exceptions on the server --- gulp/backbone.js | 2 +- package-lock.json | 49 +++++++++++++++++++++++++++++++++++++++++---- package.json | 3 +++ server.js | 6 +++++- src/css/custom.scss | 8 +++++++- src/js/app.js | 4 +++- src/js/route.js | 8 ++++---- tools/convert.js | 20 +++++++++++------- 8 files changed, 81 insertions(+), 19 deletions(-) diff --git a/gulp/backbone.js b/gulp/backbone.js index fdac2bf..0c25017 100644 --- a/gulp/backbone.js +++ b/gulp/backbone.js @@ -20,7 +20,7 @@ gulp.task('bundleBackbone', function () { return b.bundle() .pipe(source('app.js')) .pipe(buffer()) - .pipe(stripDebug()) + // .pipe(stripDebug()) .pipe(rename('bundle.js')) .pipe(sourcemaps.init({ 'loadMaps': true })) diff --git a/package-lock.json b/package-lock.json index a8104e5..7529baa 100644 --- a/package-lock.json +++ b/package-lock.json @@ -152,8 +152,7 @@ "amdefine": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/amdefine/-/amdefine-1.0.1.tgz", - "integrity": "sha1-SlKCrBZHKek2Gbz9OtFR+BfOkfU=", - "dev": true + "integrity": "sha1-SlKCrBZHKek2Gbz9OtFR+BfOkfU=" }, "ansi-cyan": { "version": "0.1.1", @@ -2173,6 +2172,25 @@ "integrity": "sha1-E3kY1teCg/ffemt8WmPhQOaUJeY=", "dev": true }, + "compressjs": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/compressjs/-/compressjs-1.0.3.tgz", + "integrity": "sha1-ldt03VuQOM+AvKMhqw7eJxtJWbY=", + "requires": { + "amdefine": "1.0.1", + "commander": "2.8.1" + }, + "dependencies": { + "commander": { + "version": "2.8.1", + "resolved": "https://registry.npmjs.org/commander/-/commander-2.8.1.tgz", + "integrity": "sha1-Br42f+v9oMMwqh4qBy09yXYkJdQ=", + "requires": { + "graceful-readlink": "1.0.1" + } + } + } + }, "concat-map": { "version": "0.0.1", "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz", @@ -5305,8 +5323,7 @@ "graceful-readlink": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/graceful-readlink/-/graceful-readlink-1.0.1.tgz", - "integrity": "sha1-TK+tdrxi8C+gObL5Tpo906ORpyU=", - "dev": true + "integrity": "sha1-TK+tdrxi8C+gObL5Tpo906ORpyU=" }, "group-array": { "version": "0.3.3", @@ -7676,6 +7693,15 @@ "integrity": "sha1-RsP+yMGJKxKwgz25vHYiF226s0s=", "dev": true }, + "json-lzw": { + "version": "0.3.2", + "resolved": "https://registry.npmjs.org/json-lzw/-/json-lzw-0.3.2.tgz", + "integrity": "sha1-1z50iajT1xkIAes+ZQV8FrsdG6E=", + "requires": { + "jsonpack": "1.1.5", + "node-lzw": "0.3.1" + } + }, "json-schema": { "version": "0.2.3", "resolved": "https://registry.npmjs.org/json-schema/-/json-schema-0.2.3.tgz", @@ -7731,6 +7757,11 @@ "resolved": "https://registry.npmjs.org/jsonify/-/jsonify-0.0.0.tgz", "integrity": "sha1-LHS27kHZPKUbe1qu6PUDYx0lKnM=" }, + "jsonpack": { + "version": "1.1.5", + "resolved": "https://registry.npmjs.org/jsonpack/-/jsonpack-1.1.5.tgz", + "integrity": "sha1-1CsNz9kaxY7zEQ+W0sWZQEw9wnw=" + }, "jsonparse": { "version": "1.3.1", "resolved": "https://registry.npmjs.org/jsonparse/-/jsonparse-1.3.1.tgz", @@ -8484,6 +8515,11 @@ "es5-ext": "0.10.37" } }, + "lz77": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/lz77/-/lz77-1.1.0.tgz", + "integrity": "sha1-FvMwoUx99YktqCSAwLbP7LzKd+M=" + }, "macaddress": { "version": "0.2.8", "resolved": "https://registry.npmjs.org/macaddress/-/macaddress-0.2.8.tgz", @@ -9252,6 +9288,11 @@ } } }, + "node-lzw": { + "version": "0.3.1", + "resolved": "https://registry.npmjs.org/node-lzw/-/node-lzw-0.3.1.tgz", + "integrity": "sha1-9Q43lol2rKgzIAKLkfEB30pDay0=" + }, "node-sass": { "version": "4.7.2", "resolved": "https://registry.npmjs.org/node-sass/-/node-sass-4.7.2.tgz", diff --git a/package.json b/package.json index 16500ac..68b5d7c 100644 --- a/package.json +++ b/package.json @@ -14,11 +14,14 @@ "babelify": "^8.0.0", "backbone": "^1.3.3", "browserify": "^14.5.0", + "compressjs": "^1.0.3", "cors": "^2.8.4", "es6-promise": "^4.1.1", "express": "^4.16.2", "jquery": "^3.2.1", + "json-lzw": "^0.3.2", "log4js": "^2.4.1", + "lz77": "^1.1.0", "minibus": "^3.1.0", "muicss": "^0.9.33", "underscore": "^1.8.3" diff --git a/server.js b/server.js index f603cd8..41f1911 100644 --- a/server.js +++ b/server.js @@ -1,5 +1,5 @@ const express = require('express'); -const cors = require('cors') +const cors = require('cors'); const path = require('path'); const apicache = require('apicache'); @@ -25,6 +25,10 @@ app.use('/getnexttraintimes', cors(), cache('60 seconds'), train.getNextTrainTim app.use('/getroute', cors(), cache('60 seconds'), train.getRoute); app.use('/getnews', cors(), cache('30 minutes'), train.getNews); +process.on('uncaughtException', err => { + logger.error(err); +}); + app.listen(port, (err) => { if (err) return logger.error('Server error:', err); diff --git a/src/css/custom.scss b/src/css/custom.scss index b753431..253cb15 100644 --- a/src/css/custom.scss +++ b/src/css/custom.scss @@ -101,13 +101,19 @@ li { font-size:125%; } -#trains { +#trains, #trainResults { overflow-y: auto; transition: all 0.5s; -webkit-transition: all 0.5s; } +.tableBody { + transition: all 0.5s; + -webkit-transition: all 0.5s; + +} + .unsliced { height:455px; } diff --git a/src/js/app.js b/src/js/app.js index b1068ee..e061c76 100644 --- a/src/js/app.js +++ b/src/js/app.js @@ -20,7 +20,9 @@ const { RouteModel, RouteView } = require('./route'); { 'from': 'ptk', 'to': 'dbe' }, { 'from': 'glc', 'to': 'eus' }, { 'from': 'eus', 'to': 'glc' }, - { 'from': 'pad', 'to': 'hxx' } + { 'from': 'pad', 'to': 'hxx' }, + { 'from': 'glc', 'to': 'bhi' }, + { 'from': 'bhi', 'to': 'glc' }, ], 'views':{} diff --git a/src/js/route.js b/src/js/route.js index ec04ae8..56628c6 100644 --- a/src/js/route.js +++ b/src/js/route.js @@ -220,7 +220,7 @@ const RouteView = Backbone.View.extend({ // we have national rail messages so put a box at the top //
for (const item of route.nrccMessages) { - const msg = item.value.replace('href=', 'data-url='); + const msg = item.value.replace('href=', 'data-url=').replace(' ">', '">'); nrMessages = `${nrMessages}
${msg}
`; } @@ -233,14 +233,14 @@ ${nrMessages} Status Platform`; - ws = `${thead}${ws}`; + ws = `${thead}${ws}`; this.$traintext.empty().html(ws); this.$traintext.removeClass('mui--hide').addClass('mui--show'); - if (this.$trains.hasClass('unsliced')) + if (this.$trains.hasClass('unsliced')) this.$trains.addClass('sliced').removeClass('unsliced'); - + // this.$trains.css("background-color", "yellow"); // this.$trains.css("height", "300px"); }, diff --git a/tools/convert.js b/tools/convert.js index c7b14b2..f8f2811 100644 --- a/tools/convert.js +++ b/tools/convert.js @@ -1,11 +1,14 @@ const { promisify } = require('util'); const jsonfile = require('jsonfile'); const logger = require('log4js').getLogger(); +const lz77 = require('lz77'); +var lzw = require('json-lzw'); logger.level = 'trace'; -const file = 'src/work/stations.json'; -const outFile = 'src/work/stationsMap.json'; +const file = '../src/work/stations.json'; +const outFile = '../src/work/stationsMap.json'; +const compressed = '../src/work/stations.lzw'; const readFile = promisify(jsonfile.readFile); const writeFile = promisify(jsonfile.writeFile); @@ -14,15 +17,18 @@ function doConvert(obj) { const tempArray = []; for(const item of obj.locations) - if ((item.lat !== 0) && (item.long !== 0)) { - // logger.debug(item.name); - tempArray.push([item.crs, item.name]); - } + if ((item.lat !== 0) && (item.lon !== 0)) + // logger.debug(item.name); + tempArray.push({ 'crs':item.crs, 'name':item.name, 'lat':item.lat, 'long':item.lon }); - //const locMap = new Map(tempArray); + // const locMap = new Map(tempArray); // logger.debug(locMap); + const test = lz77.compress(JSON.stringify(tempArray), { 'minStringLength':3 }); + + console.log(test); + writeFile(outFile, tempArray) .then( () => { logger.debug('Saved...');