diff options
| -rw-r--r-- | examples/lib/okpush/db.js | 16 | ||||
| -rw-r--r-- | examples/lib/okpush/index.js | 45 | ||||
| -rw-r--r-- | examples/lib/okpush/templates/index.liquid | 63 | ||||
| -rw-r--r-- | themes/okadmin/public/css/main.css | 9 | ||||
| -rw-r--r-- | themes/okadmin/templates/partials/inputs.liquid | 1 |
5 files changed, 110 insertions, 24 deletions
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' %} +<style> +th { + min-width: 100px; + text-align: left; + background: #ddd; +} +th:nth-child(2) { + min-width: 300px; +} +table,tr,th,td { + margin: 0; + padding: 0; +} +th,td { + padding: 5px; +} +tr:nth-child(2n+1) { + background: #f8f8f8; +} +</style> + <nav class="resource-nav"> + <a href="/admin/" class="btn">Back</a> </nav> -<section class="main resource resource-new"> +<section class="main resource"> + + <h2>Push Notifications</h2> + + <table class="notifications" cellpadding="0" cellspacing="0"> + <tr> + <th>Key</th> + <th>Message</th> + <th>Last Push</th> + <th></th> + </tr> + {% for pair in notifications %} + {% assign name = pair[0] %} + {% assign spec = pair[1] %} + <tr> + <td> + {{name | escape}} + </td> + <td> + {{spec.alert}} + </td> + <td> + {% unless spec.last_fired %} + Never + {% else %} + {{spec.last_fired}} + {% endunless %} + </td> + <td> + <button data-key="{{name}}" class="btn">send</button> + </td> + </tr> + {% endfor %} + </table> + </section> +<script> +$(function(){ + $(" +}) +</script> {% include 'partials/tail' %} diff --git a/themes/okadmin/public/css/main.css b/themes/okadmin/public/css/main.css index 15d96ac..3aec0ac 100644 --- a/themes/okadmin/public/css/main.css +++ b/themes/okadmin/public/css/main.css @@ -163,7 +163,7 @@ h2 { /* Makes the button look like a link */ -.main.index .resource-category button { +button, .btn { background: #000; color: white; border: none; @@ -437,8 +437,13 @@ input[type=submit] { display: block; width: 1em; height: 2em; - background: #ddd; + background: #f8f8f8; float: left; + clear: left; +} + +li .handle { + background: #ddd; } .main.resource form .links li { diff --git a/themes/okadmin/templates/partials/inputs.liquid b/themes/okadmin/templates/partials/inputs.liquid index 4750630..55afb51 100644 --- a/themes/okadmin/templates/partials/inputs.liquid +++ b/themes/okadmin/templates/partials/inputs.liquid @@ -109,6 +109,7 @@ {% endfor %} </ol> + <div class="handle"></div> <input type="text" class="link-input-new link-text" placeholder="Link text"> |
