From 05cca7b92c5210edfd553863cf94d7a011c5c0ef Mon Sep 17 00:00:00 2001 From: Trevor Gerhardt Date: Fri, 31 Mar 2017 14:55:26 +0200 Subject: [PATCH] fix(alerts): Fix service alerts updating. --- client/service-alerts-view/index.js | 18 +++--------------- client/service-alerts-view/template.html | 2 +- client/session/index.js | 10 ++++++++++ 3 files changed, 14 insertions(+), 16 deletions(-) diff --git a/client/service-alerts-view/index.js b/client/service-alerts-view/index.js index dc542731d..c29031a71 100644 --- a/client/service-alerts-view/index.js +++ b/client/service-alerts-view/index.js @@ -1,5 +1,3 @@ -var moment = require('moment') - var AlertRow = require('./row') var view = require('../view') @@ -7,26 +5,16 @@ 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 } diff --git a/client/service-alerts-view/template.html b/client/service-alerts-view/template.html index d84bb64ed..339810b9a 100644 --- a/client/service-alerts-view/template.html +++ b/client/service-alerts-view/template.html @@ -1,3 +1,3 @@
-
+
diff --git a/client/session/index.js b/client/session/index.js index c10cb1362..a4ca41b28 100644 --- a/client/session/index.js +++ b/client/session/index.js @@ -1,3 +1,5 @@ +var moment = require('moment') + var analytics = require('../analytics') var store = require('../browser-store') var Commuter = require('../commuter') @@ -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) })