Added traffic component
This commit is contained in:
parent
df9075f078
commit
9eef9cd8bb
@ -154,7 +154,7 @@ app.get('/agenda', cache('15 minutes'), (req, res) => {
|
||||
});
|
||||
});
|
||||
|
||||
app.get('/traffic', cache('1 hour'), (req, res) => {
|
||||
app.get('/traffic', cache('5 minutes'), (req, res) => {
|
||||
logger.debug(req.query);
|
||||
if (req.query.hasOwnProperty('olat')) {
|
||||
|
||||
|
@ -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.378' };
|
||||
const CACHE_VERSION = { 'version': '0.0.391' };
|
||||
const dataCacheName = 'jubileeData-v1';
|
||||
const cacheName = 'jubilee-final-1';
|
||||
const filesToCache = [
|
||||
|
@ -80,9 +80,9 @@ const LocationModel = Backbone.Model.extend({
|
||||
'formatter': null // 'gpx', 'string', ...
|
||||
};
|
||||
const geocoder = NodeGeocoder(options);
|
||||
|
||||
//55.872407, -3.549003
|
||||
const homeDistance = distance(55.942673, -4.556334, latitude, longitude);
|
||||
const workDistance = distance(55.861939, -4.259338, latitude, longitude);
|
||||
const workDistance = distance(55.872407, -3.549003, latitude, longitude);
|
||||
const atHome = (homeDistance < 0.10);
|
||||
const atWork = (workDistance < 0.10);
|
||||
const atHomeOrWork = (atHome || atWork);
|
||||
|
@ -26,8 +26,8 @@ const TrafficModel = Backbone.Model.extend({
|
||||
|
||||
// ( ((hour >= 7) && (hour <= 9)) || ((hour >= 17) && (hour <= 19)) )
|
||||
//
|
||||
console.log('this.updateID', this.updateID);
|
||||
if (this.updateID === 0) {
|
||||
console.log('this.has(\'latlong\')', this.has('latlong'));
|
||||
if (this.has('latlong')) {
|
||||
this.updateID = 1;
|
||||
this.getTraffic();
|
||||
}
|
||||
@ -54,13 +54,18 @@ const TrafficModel = Backbone.Model.extend({
|
||||
let qs;
|
||||
|
||||
let mode = 0;
|
||||
if (!this.has('latlong'))
|
||||
return;
|
||||
|
||||
// 55.872407, -3.549003
|
||||
|
||||
|
||||
// const latlong = { 'lat':latitude, 'lon':longitude };
|
||||
if ((hour >= 7) && (hour <= 9)) {
|
||||
this.set('dest', 'Work');
|
||||
mode = 1;
|
||||
qs = {
|
||||
'olat': latlong.lat, 'olon': latlong.lon, 'dlat': 55.861939, 'dlon': -4.259338
|
||||
'olat': latlong.lat, 'olon': latlong.lon, 'dlat': 55.872407, 'dlon': -3.549003
|
||||
};
|
||||
}
|
||||
else if ((hour >= 17) && (hour <= 19)) {
|
||||
@ -95,7 +100,7 @@ const TrafficModel = Backbone.Model.extend({
|
||||
}
|
||||
}.bind(this));
|
||||
}, 'logUpdate': function() {
|
||||
console.log('>> Agenda logging:');
|
||||
console.log('>> Traffic logging:');
|
||||
|
||||
const time = new Date().getTime() ;
|
||||
|
||||
@ -112,22 +117,22 @@ const TrafficView = Backbone.View.extend({
|
||||
this.location = options.location;
|
||||
|
||||
this.location.bind('change:llFixed', this.updateLocation, this);
|
||||
this.model.bind('change:timestamp change:mode', this.render, this);
|
||||
this.model.bind('change:timestamp', this.render, this);
|
||||
this.model.bind('change:mode', this.render, this);
|
||||
this.eventBus.on('focused', this.focused, this);
|
||||
|
||||
}, 'focused': function() {
|
||||
console.log('>> Traffic received focus msg');
|
||||
console.log(this.model.get('time'));
|
||||
if (typeof this.model.get('time') === 'undefined') {
|
||||
if (typeof this.model.get('time') === 'undefined')
|
||||
return;
|
||||
}
|
||||
|
||||
const now = new Date().getTime();
|
||||
const since = now - this.model.get('time');
|
||||
|
||||
console.log(`Traffic was last updated: ${TimeFormat.fromMs(since, 'hh:mm')} ago`);
|
||||
|
||||
if (since > (60 * 1000 * 10) )
|
||||
this.model.set('update', now);
|
||||
this.model.set('update', now);
|
||||
},
|
||||
'template': _.template(`
|
||||
<div class="">
|
||||
@ -148,13 +153,14 @@ const TrafficView = Backbone.View.extend({
|
||||
console.log('>> Nearby No location yet');
|
||||
},
|
||||
'render': function() {
|
||||
console.info('>> Traffic:Render');
|
||||
console.log('>> Traffic:Render');
|
||||
|
||||
this.$el.empty();
|
||||
|
||||
if (this.model.get('mode') === 0)
|
||||
this.$el.parent().hide();
|
||||
else {
|
||||
else
|
||||
if (this.model.has('readable')) {
|
||||
console.log(this.template(this.model.attributes));
|
||||
this.$el.html(this.template(this.model.attributes));
|
||||
this.$el.parent().show();
|
||||
|
Loading…
Reference in New Issue
Block a user