From 9fa076439ccdc68b185a7ec57ee16fc15f70ef07 Mon Sep 17 00:00:00 2001 From: Martin Donnelly Date: Sat, 19 Jan 2019 22:47:39 +0000 Subject: [PATCH] swapped manifest file and added bumper --- gulp/backbone.js | 21 +++++++++++++++++++++ gulpfile.js | 3 +++ src/js/route.js | 8 +++++++- src/js/train.js | 14 +++++++++++++- src/service-worker.js | 2 +- 5 files changed, 45 insertions(+), 3 deletions(-) diff --git a/gulp/backbone.js b/gulp/backbone.js index bda5857..5a17637 100644 --- a/gulp/backbone.js +++ b/gulp/backbone.js @@ -32,6 +32,27 @@ gulp.task('bundleBackbone', function () { .pipe(gulp.dest('./live/js')); }); +gulp.task('liveBackbone', function () { + // set up the browserify instance on a task basis + const b = browserify({ + 'debug': true, + 'entries': './src/js/app.js' + }); + + return b.bundle() + .pipe(source('app.js')) + .pipe(buffer()) + .pipe(stripDebug()) + .pipe(rename('bundle.js')) + + .pipe(sourcemaps.init({ 'loadMaps': true })) + // Add transformation tasks to the pipeline here. + // .pipe(uglify()) + .on('error', gutil.log) + .pipe(sourcemaps.write('.')) + .pipe(gulp.dest('./live/js')); +}); + gulp.task('bump', function() { gulp.src('src/service-worker.js') .pipe(bump({ 'key': 'version' })) diff --git a/gulpfile.js b/gulpfile.js index 71232d1..d32219d 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -5,3 +5,6 @@ const requireDir = require('require-dir'); requireDir('./gulp'); gulp.task('default', ['bundleBackbone', 'styles', 'copy', 'customMUI', 'vendor', 'fonts', 'gotham', 'fujicons']); + + +gulp.task('live', ['liveBackbone', 'styles', 'copy', 'customMUI', 'vendor', 'fonts', 'gotham', 'fujicons']); diff --git a/src/js/route.js b/src/js/route.js index 5f1f5da..bf21bcd 100644 --- a/src/js/route.js +++ b/src/js/route.js @@ -3,6 +3,12 @@ const _ = require('underscore'); const Backbone = require('backbone'); const { createPanel, addPanel } = require('./libs/panel'); +function minuteFloor() { + const now = new Date(); + + return parseInt(~~(now.getTime() / 60000) * 60000, 10).toString(32); +} + const RouteModel = Backbone.Model.extend({ 'initialize': function () { const fromStation = this.get('from'); @@ -48,7 +54,7 @@ const RouteModel = Backbone.Model.extend({ this.interval = setTimeout(routeUpdateFn.bind(this), mod + 10); }, 'getRoute': function () { - const url = `/gettrains?from=${ this.get('from') }&to=${ this.get('to')}`; + const url = `/gettrains?from=${ this.get('from') }&to=${ this.get('to')}&m=${minuteFloor()}`; const self = this; $.ajax({ diff --git a/src/js/train.js b/src/js/train.js index b3c311f..7373661 100644 --- a/src/js/train.js +++ b/src/js/train.js @@ -10,6 +10,18 @@ const _ = require('underscore'); const Backbone = require('backbone'); const { findStation } = require('./stations'); +function hourFloor() { + const now = new Date(); + + return parseInt(~~(now.getTime() / 3600000) * 3600000, 10).toString(32); +} + +function minuteFloor() { + const now = new Date(); + + return parseInt(~~(now.getTime() / 60000) * 60000, 10).toString(32); +} + const TrainModel = Backbone.Model.extend({ 'defaults': function (obj) { // return a new object @@ -58,7 +70,7 @@ const TrainModel = Backbone.Model.extend({ const bus = this.get('bus'); $.ajax({ 'type': 'GET', - 'url': url, + 'url': `${url}&m=${minuteFloor()}`, 'data': '', 'dataType': 'json', 'timeout': 10000, diff --git a/src/service-worker.js b/src/service-worker.js index 64b077b..e45e13d 100644 --- a/src/service-worker.js +++ b/src/service-worker.js @@ -11,7 +11,7 @@ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. -const CACHE_VERSION = { 'version': '0.0.18' }; +const CACHE_VERSION = { 'version': '0.0.21' }; const PRECACHE = `traintimesData-v${CACHE_VERSION.version}`; const cacheName = `traintimePWA-final-${CACHE_VERSION.version}`; const RUNTIME = 'runtime';