notifications page + ajaxify route + css styling

v1.18.x
Julian Lam 11 years ago
parent 5c70b2b307
commit 705571de8c

@ -0,0 +1,3 @@
{
"title": "Notifications"
}

@ -0,0 +1,16 @@
define(function() {
var Notifications = {};
Notifications.init = function() {
var listEl = $('.notifications-list');
$('span.timeago').timeago();
// Allow the user to click anywhere in the LI
listEl.on('click', 'li', function(e) {
this.querySelector('a').click();
});
}
return Notifications;
});

@ -0,0 +1,14 @@
<h2>[[notifications:title]]</h2>
<button type="button" class="btn btn-default">Mark All as Read</button>
<ul class="notifications-list">
<!-- BEGIN notifications -->
<li data-nid="{notifications.nid}">
<p class="timestamp">
<span class="timeago" title="{notifications.datetimeISO}"></span>
</p>
<a href="..{notifications.path}">{notifications.text}</a>
</li>
<!-- END notifications -->
</ul>

@ -154,6 +154,16 @@ var user = require('./../user.js'),
});
});
app.get('/notifications', function(req, res) {
if (req.user && req.user.uid) {
user.notifications.getAll(req.user.uid, null, null, function(err, notifications) {
res.json({
notifications: notifications
});
});
} else res.send(403);
});
app.get('/confirm/:id', function (req, res) {
user.email.confirm(req.params.id, function (data) {
if (data.status === 'ok') {

@ -945,6 +945,36 @@ var utils = require('./../public/src/utils.js'),
callback(notifications);
});
},
getAll: function(uid, limit, before, callback) {
var now = new Date();
if (!limit || parseInt(limit) <= 0) limit = 25;
if (before) before = new Date(parseInt(before, 10));
RDB.multi()
.zrevrangebyscore('uid:' + uid + ':notifications:read', before ? before.getTime(): now.getTime(), -Infinity, 'LIMIT', 0, limit)
.zrevrangebyscore('uid:' + uid + ':notifications:unread', before ? before.getTime(): now.getTime(), -Infinity, 'LIMIT', 0, limit)
.exec(function(err, results) {
// Merge the read and unread notifications
var nids = results[0].concat(results[1]);
async.map(nids, function(nid, next) {
notifications.get(nid, function(notif_data) {
next(null, notif_data);
});
}, function(err, notifs) {
notifs = notifs.sort(function(a, b) {
return parseInt(b.datetime, 10) - parseInt(a.datetime, 10);
}).map(function(notif) {
notif.datetimeISO = new Date(parseInt(notif.datetime, 10)).toISOString();
return notif;
});
callback(err, notifs);
})
});
},
getUnreadCount: function(uid, callback) {
RDB.zcount('uid:' + uid + ':notifications:unread', 0, 10, callback);
},

@ -282,7 +282,7 @@ var express = require('express'),
// Basic Routes (entirely client-side parsed, goal is to move the rest of the crap in this file into this one section)
(function () {
var routes = ['login', 'register', 'account', 'recent', 'unread', 'popular', 'active', '403', '404'];
var routes = ['login', 'register', 'account', 'recent', 'unread', 'notifications', '403', '404'];
for (var i = 0, ii = routes.length; i < ii; i++) {
(function (route) {

Loading…
Cancel
Save