Skip to content

Commit

Permalink
Merge pull request #404 from conveyal/dev
Browse files Browse the repository at this point in the history
v1.1.1
  • Loading branch information
trevorgerhardt authored Mar 31, 2017
2 parents 280cbc9 + 05cca7b commit 98ca222
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 16 deletions.
18 changes: 3 additions & 15 deletions client/service-alerts-view/index.js
Original file line number Diff line number Diff line change
@@ -1,32 +1,20 @@
var moment = require('moment')

var AlertRow = require('./row')
var view = require('../view')

/**
* Expose `View`
*/

var View = module.exports = view(require('./template.html'), function (view, model) {
model.on('change serviceAlerts', (alerts) => {
alerts = (alerts || []).filter(function (alert) {
var today = moment()
var fromDate = moment.utc(alert.fromDate)
var toDate = moment.utc(alert.toDate)
return !fromDate.isAfter(today, 'days') && !toDate.isBefore(today, 'days')
})
view.emit('change alerts', alerts)
})
})
var View = module.exports = view(require('./template.html'))

View.prototype.hasAlerts = function () {
return this.model.alerts && this.model.alerts.length > 0
return this.model.serviceAlerts && this.model.serviceAlerts.length > 0
}

/**
* Set the routes view
*/

View.prototype['alerts-view'] = function () {
View.prototype['serviceAlerts-view'] = function () {
return AlertRow
}
2 changes: 1 addition & 1 deletion client/service-alerts-view/template.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<div class="ServiceAlerts" data-visible="hasAlerts">
<div data-each="alerts"></div>
<div data-each="serviceAlerts"></div>
</div>
10 changes: 10 additions & 0 deletions client/session/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
var moment = require('moment')

var analytics = require('../analytics')
var store = require('../browser-store')
var Commuter = require('../commuter')
Expand Down Expand Up @@ -167,6 +169,14 @@ session.load = function (ctx, next) {
if (err) {
console.log('error loading service alerts', err)
}

const today = moment()
alerts = (alerts || []).filter(function (alert) {
const fromDate = moment.utc(alert.fromDate)
const toDate = moment.utc(alert.toDate)
return !fromDate.isAfter(today, 'days') && !toDate.isBefore(today, 'days')
})

session.serviceAlerts(alerts)
})

Expand Down

0 comments on commit 98ca222

Please sign in to comment.