diff options
| -rw-r--r-- | index.js | 8 | ||||
| -rw-r--r-- | lib/okpush/index.js | 26 | ||||
| -rw-r--r-- | lib/okpush/public/push.js | 21 | ||||
| -rw-r--r-- | lib/okpush/templates/index.liquid | 15 | ||||
| -rw-r--r-- | lib/okpush/templates/new.liquid | 45 |
5 files changed, 99 insertions, 16 deletions
@@ -85,7 +85,7 @@ var app = okcms.createApp({ push: { lib: require("./lib/okpush"), mongodbUrl: "mongodb://localhost/okpush_stone", - production: true, + production: false, apn_development: { cert: path.join(__dirname, "./lib/okpush/certs/aps_development_cert.pem"), key: path.join(__dirname, "./lib/okpush/certs/aps_development_key.pem"), @@ -94,10 +94,10 @@ var app = okcms.createApp({ } }, apn_production: { - cert: path.join(__dirname, "./lib/okpush/certs/aps_production_cert.pem"), - key: path.join(__dirname, "./lib/okpush/certs/aps_production_key.pem"), + // cert: path.join(__dirname, "./lib/okpush/certs/aps_production_cert.pem"), + // key: path.join(__dirname, "./lib/okpush/certs/aps_production_key.pem"), connection: { - gateway: "gateway.push.apple.com", + // gateway: "gateway.push.apple.com", } }, bundleId: "us.okfoc.stoneisland", diff --git a/lib/okpush/index.js b/lib/okpush/index.js index cf2e928f..08ab15ae 100644 --- a/lib/okpush/index.js +++ b/lib/okpush/index.js @@ -46,6 +46,7 @@ function OKPush (options) { var templates = {} templates['index'] = templateProvider.getTemplate('index') + templates['new'] = templateProvider.getTemplate('new') apn.init(config) db.init(config) @@ -92,8 +93,14 @@ function OKPush (options) { }) }) + router.get('/new', function (req, res) { + templates['new'].render(data).then(function(rendered) { + res.send(rendered); + }).fail(error(req, res, 500)) + }) + router.get('/list', function(req, res){ - db.getAllTokens("hub", function(err, hubz){ + db.getAllTokens('hub', function(err, hubz){ res.json(hubz) }) }) @@ -108,6 +115,23 @@ function OKPush (options) { }) }) + router.post('/custom', bodyParser.urlencoded({ extended: false }), function (req, res) { + var message = req.body.message + var url = req.body.url + if (! message || ! url) { + return res.sendStatus(500) + } + var opt = { + alert: message, + payload: { 'url': url }, + } + var note = apn.buildPayload(opt, options.config.bundleId) + apn.push('hub', note) + db.addNotification(channel, function(){ + res.sendStatus(200) + }) + }) + // should work without middleware router.post('/add', bodyParser.urlencoded({ extended: false }), function (req, res) { console.log(req.body) diff --git a/lib/okpush/public/push.js b/lib/okpush/public/push.js index e75fc7f4..ca32fa98 100644 --- a/lib/okpush/public/push.js +++ b/lib/okpush/public/push.js @@ -27,6 +27,27 @@ $(function(){ } }) }) + + $('#custom').submit(function(e){ + e.preventDefault() + var message = $("#message").val().trim() + var url = $("#url").val() + var msg = "This will send this push notification to everyone. Click OK to confirm.\n\n" + message + if (! confirm(msg)) return + + $.ajax({ + type: "POST", + url: "/_services/push/custom", + data: { + message: message, + url: url, + }, + success: function(){ + alert("Push notification sent.") + } + }) + + }) }) function capitalize (string) { diff --git a/lib/okpush/templates/index.liquid b/lib/okpush/templates/index.liquid index 124fb4ee..ec639646 100644 --- a/lib/okpush/templates/index.liquid +++ b/lib/okpush/templates/index.liquid @@ -11,9 +11,6 @@ th { th:nth-child(2) { min-width: 300px; } -th:nth-child(3) { - min-width: 170px; -} table,tr,th,td { margin: 0; padding: 0; @@ -33,12 +30,15 @@ tr:nth-child(2n+1) { <section class="main resource"> <h2>Push Notifications</h2> + + <p> + <a href="/_services/push/new">Send custom push notification</a> + </p> <table class="notifications" cellpadding="0" cellspacing="0"> <tr> <th>Key</th> <th>Message</th> - <th>Last Push</th> <th>Tokens</th> <th></th> </tr> @@ -52,13 +52,6 @@ tr:nth-child(2n+1) { <td> {{spec.alert}} </td> - <td class="notification-date"> - {% unless spec.last_push %} - Never - {% else %} - {{ spec.last_push | date: "%a %d-%b-%Y %H:%M" }} - {% endunless %} - </td> <td> {{spec.count}} </td> diff --git a/lib/okpush/templates/new.liquid b/lib/okpush/templates/new.liquid new file mode 100644 index 00000000..b16d0ae0 --- /dev/null +++ b/lib/okpush/templates/new.liquid @@ -0,0 +1,45 @@ +{% include 'partials/head' %} + +{% include 'partials/flash' %} + +<style> +</style> + +<nav class="resource-nav"> + <a href="/admin/" class="btn">Back</a> +</nav> + +<section class="main resource"> + + <h2>Custom Push Notification</h2> + + <form id='custom'> + + <div> + <label for='message'>Message</label> + <input type='text' name='message' id='message'> + </div> + + <div> + <label for='url'>Destination</label> + <select id='url' name='url'> + <option>/</option> + <option selected>/store</option> + <option>/hub</option> + <option>/story</option> + <option>/archive</option> + </select> + (will open after push is tapped) + </div> + + <div> + <input type='submit' value='Send Push Notification'> + </div> + + </form> + +</section> + +{% include 'partials/tail' %} + +<script src="public/push.js"></script>
\ No newline at end of file |
