From c8c0b465d9796b526d268ea0e641fd7ba00e44bb Mon Sep 17 00:00:00 2001 From: Jules Laplace Date: Thu, 6 Oct 2016 14:46:54 -0400 Subject: displaying list of notifications, slight css tweaks --- examples/lib/okpush/db.js | 16 ++++---- examples/lib/okpush/index.js | 45 +++++++++++++++------ examples/lib/okpush/templates/index.liquid | 63 +++++++++++++++++++++++++++++- 3 files changed, 102 insertions(+), 22 deletions(-) (limited to 'examples/lib/okpush') diff --git a/examples/lib/okpush/db.js b/examples/lib/okpush/db.js index 7727825..75beb65 100644 --- a/examples/lib/okpush/db.js +++ b/examples/lib/okpush/db.js @@ -26,7 +26,7 @@ function init (config) { required: true, lowercase: true, }, - last_fired: { + last_push: { type: 'Date', required: true, } @@ -65,21 +65,21 @@ function removeDevices (tokens) { function updateNotification (key, cb) { var now = new Date - Notification.findOrCreate({key: key}, {last_fired: now}, function(err, note, created){ + Notification.findOrCreate({key: key}, {last_push: now}, function(err, note, created){ if (err) { console.error("Error finding/creating notification", err) cb(err, false) return } else if (! created) { - note.last_fired = now + note.last_push = now note.save() cb(null, note) } cb(null, note) }) } -function getAllNotifications (cb) { +function getNotifications (cb) { Notification.find( wrapNotificationCallback(cb) ) } @@ -93,7 +93,7 @@ function wrapDeviceCallback (cb) { return _.pick(item, ['type', 'token']) }) - return callback(null, items) + return cb(null, items) } } function wrapNotificationCallback (cb) { @@ -101,10 +101,10 @@ function wrapNotificationCallback (cb) { if (err) return cb(err, null) var items = _.map(items, function (item) { - return _.pick(item, ['key', 'last_fired']) + return _.pick(item, ['key', 'last_push']) }) - return callback(null, items) + return cb(null, items) } } module.exports = { @@ -114,5 +114,5 @@ module.exports = { removeDevice: removeDevice, removeDevices: removeDevices, updateNotification: updateNotification, - getAllNotifications: getAllNotifications, + getNotifications: getNotifications, } \ No newline at end of file diff --git a/examples/lib/okpush/index.js b/examples/lib/okpush/index.js index d77eb8a..3ff8bb5 100644 --- a/examples/lib/okpush/index.js +++ b/examples/lib/okpush/index.js @@ -46,23 +46,42 @@ function OKPush (options) { apn.init(config) db.init(config) -// router.use('/admin/', passport.initialize()) -// router.all('/admin/(:path*)?', passport.authenticate('digest', { -// session: false -// })) + router.use('/admin/', passport.initialize()) + // monkeypatch because of this app.use(router) shit.. obnoxious + router.all('/admin/(:path*)?', function (req, res, next) { + // req.url = "/_services/push" + req.url + req.newUrl = req.url + req.url = req.originalUrl + next() + }) + router.all('/admin/(:path*)?', passport.authenticate('digest', { + session: false + })) + router.all('/admin/(:path*)?', function (req, res, next) { + req.url = req.newUrl + next() + }) + // pass in admin middleware! - router.get('/admin/', function (req, res) { - var data = { - meta: meta, - notifications: config.notifications, - } - templates['index'].render(data).then(function(rendered) { - res.send(rendered); - }).fail(error(req, res, 500)) + router.get('/admin', function (req, res) { + db.getNotifications(function(err, notes){ + var data = { + meta: meta, + notifications: config.notifications, + } + notes.forEach(function(note){ + if (note.key in data.notifications) { + data.notifications[ note.key ].last_push = note.last_push + } + }) + templates['index'].render(data).then(function(rendered) { + res.send(rendered); + }).fail(error(req, res, 500)) + }) }) - router.post('/send', function (req, res) { + router.post('/admin/send', function (req, res) { var key = req.body.key var opt = options.config.notifications[key] var note = apn.buildPayload(opt, options.config.bundleId) diff --git a/examples/lib/okpush/templates/index.liquid b/examples/lib/okpush/templates/index.liquid index 388a95b..e0547c3 100644 --- a/examples/lib/okpush/templates/index.liquid +++ b/examples/lib/okpush/templates/index.liquid @@ -2,10 +2,71 @@ {% include 'partials/flash' %} + + -
+
+ +

Push Notifications

+ + + + + + + + + {% for pair in notifications %} + {% assign name = pair[0] %} + {% assign spec = pair[1] %} + + + + + + + {% endfor %} +
KeyMessageLast Push
+ {{name | escape}} + + {{spec.alert}} + + {% unless spec.last_fired %} + Never + {% else %} + {{spec.last_fired}} + {% endunless %} + + +
+
+ {% include 'partials/tail' %} -- cgit v1.2.3-70-g09d2