summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJules Laplace <jules@okfoc.us>2017-02-19 01:23:53 +0100
committerJules Laplace <jules@okfoc.us>2017-02-19 01:23:53 +0100
commitcf85cc2b75b9c3ead3a693b6fa0feeca5b9e70ba (patch)
tree160499d95dac5d1df01b45490b735d2b60e814e1
parentd6be5583190174bd45c417b934b36e4469ab3441 (diff)
counts
-rw-r--r--lib/okpush/db.js17
-rw-r--r--lib/okpush/index.js35
-rw-r--r--lib/okpush/templates/index.liquid6
3 files changed, 38 insertions, 20 deletions
diff --git a/lib/okpush/db.js b/lib/okpush/db.js
index ad18b7b3..f64acf69 100644
--- a/lib/okpush/db.js
+++ b/lib/okpush/db.js
@@ -77,8 +77,21 @@ function getAllTokens (channel, cb) {
function removeToken (data) {
PushToken.find(data).remove().exec()
}
-function getDeviceCount (channel, cb) {
- PushToken.count({ channel: channel }, cb)
+function getDeviceCount (channels, cb) {
+ var countz = {}
+ get_next()
+ function get_next() {
+ var channel = channels.pop()
+ PushToken.count({ channel: channel }, function(err, count){
+ countz[channel] = count
+ if (channels.length) {
+ return get_next()
+ }
+ else {
+ cb(countz)
+ }
+ })
+ }
}
/* notifications */
diff --git a/lib/okpush/index.js b/lib/okpush/index.js
index 2fe59932..df9c8265 100644
--- a/lib/okpush/index.js
+++ b/lib/okpush/index.js
@@ -50,37 +50,40 @@ function OKPush (options) {
apn.init(config)
db.init(config)
- router.use('/admin/', passport.initialize())
+// router.use('/admin/', passport.initialize())
router.use('/public/', express.static(path.join(__dirname, './public')));
// monkeypatch because of app.use(router) .. obnoxious
- router.all('/admin/(:path*)?', function (req, res, next) {
- 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()
- })
+// router.all('/admin/(:path*)?', function (req, res, next) {
+// console.log(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) {
- // change this to get notification counts for each channel
db.getNotifications(function(err, notes){
- db.getDeviceCount(function(err, count){
+ var channels = Object.keys(config.notifications)
+ db.getDeviceCount(channels, function(count){
var data = {
meta: meta,
notifications: config.notifications,
- device_count: count,
}
notes.forEach(function(note){
if (note.key in data.notifications) {
data.notifications[ note.key ].last_push = note.last_push
}
+ if (note.key in count) {
+ data.notifications[ note.key ].count = count[note.key]
+ }
})
templates['index'].render(data).then(function(rendered) {
res.send(rendered);
diff --git a/lib/okpush/templates/index.liquid b/lib/okpush/templates/index.liquid
index 10772b55..1db77a58 100644
--- a/lib/okpush/templates/index.liquid
+++ b/lib/okpush/templates/index.liquid
@@ -34,13 +34,12 @@ tr:nth-child(2n+1) {
<h2>Push Notifications</h2>
- <div class="device-count" data-count="{{ device_count }}">Device count: {{ device_count }}</div>
-
<table class="notifications" cellpadding="0" cellspacing="0">
<tr>
<th>Key</th>
<th>Message</th>
<th>Last Push</th>
+ <th>Registrations</th>
<th></th>
</tr>
{% for pair in notifications %}
@@ -61,6 +60,9 @@ tr:nth-child(2n+1) {
{% endunless %}
</td>
<td>
+ {{spec.count}}
+ </td>
+ <td>
<button data-key="{{name}}" class="btn">send</button>
</td>
</tr>