List notifications
This commit is contained in:
1 parent
43529a9e64
commit
a9cc7a457b
7 files changed
+109
-42
No files matched your search
@@ -33,6 +33,19 @@ class CoreNotifier(Notification):
|
||||
'id': {'desc': 'Notification id you want to mark as read.', 'type': 'int (comma separated)'},
|
||||
},
|
||||
})
|
||||
|
||||
addApiView('notification.list', self.listView, docs = {
|
||||
'desc': 'Get list of notifications',
|
||||
'params': {
|
||||
'limit_offset': {'desc': 'Limit and offset the notification list. Examples: "50" or "50,30"'},
|
||||
},
|
||||
'return': {'type': 'object', 'example': """{
|
||||
'success': True,
|
||||
'empty': bool, any notification returned or not,
|
||||
'notifications': array, notifications found,
|
||||
}"""}
|
||||
})
|
||||
|
||||
addApiView('notification.listener', self.listener)
|
||||
|
||||
self.registerEvents()
|
||||
@@ -57,6 +70,32 @@ class CoreNotifier(Notification):
|
||||
'success': True
|
||||
})
|
||||
|
||||
def listView(self):
|
||||
|
||||
db = get_session()
|
||||
limit_offset = getParam('limit_offset', None)
|
||||
|
||||
q = db.query(Notif)
|
||||
|
||||
if limit_offset:
|
||||
splt = limit_offset.split(',')
|
||||
limit = splt[0]
|
||||
offset = 0 if len(splt) is 1 else splt[1]
|
||||
q = q.limit(limit).offset(offset)
|
||||
|
||||
results = q.all()
|
||||
notifications = []
|
||||
for n in results:
|
||||
ndict = n.to_dict()
|
||||
ndict['type'] = 'notification'
|
||||
notifications.append(ndict)
|
||||
|
||||
return jsonified({
|
||||
'success': True,
|
||||
'empty': len(notifications) == 0,
|
||||
'notifications': notifications
|
||||
})
|
||||
|
||||
def notify(self, message = '', data = {}):
|
||||
|
||||
db = get_session()
|
||||
@@ -93,7 +132,10 @@ class CoreNotifier(Notification):
|
||||
# Get unread
|
||||
if getParam('init'):
|
||||
db = get_session()
|
||||
notifications = db.query(Notif).filter_by(read = False).all()
|
||||
|
||||
notifications = db.query(Notif) \
|
||||
.filter(or_(Notif.read == False, Notif.added > (time.time() - 259200))) \
|
||||
.all()
|
||||
for n in notifications:
|
||||
ndict = n.to_dict()
|
||||
ndict['type'] = 'notification'
|
||||
|
||||
@@ -26,10 +26,10 @@ var NotificationBase = new Class({
|
||||
$(App.block.notification).inject(App.getBlock('search'), 'after');
|
||||
self.badge = new Element('div.badge').inject(App.block.notification, 'top').hide();
|
||||
|
||||
App.getBlock('notification').addLink(new Element('a.more', {
|
||||
/* App.getBlock('notification').addLink(new Element('a.more', {
|
||||
'href': App.createUrl('notifications'),
|
||||
'text': 'See more notifications'
|
||||
}));
|
||||
'text': 'Show older notifications'
|
||||
})); */
|
||||
})
|
||||
|
||||
},
|
||||
@@ -41,7 +41,7 @@ var NotificationBase = new Class({
|
||||
added.setTime(result.added*1000)
|
||||
|
||||
result.el = App.getBlock('notification').addLink(
|
||||
new Element('span').adopt(
|
||||
new Element('span.'+(result.read ? 'read' : '' )).adopt(
|
||||
new Element('span.message', {'text': result.message}),
|
||||
new Element('span.added', {'text': added.timeDiffInWords(), 'title': added})
|
||||
)
|
||||
@@ -51,11 +51,6 @@ var NotificationBase = new Class({
|
||||
if(!result.read)
|
||||
self.setBadge(self.notifications.filter(function(n){ return !n.read}).length)
|
||||
|
||||
if(self.notifications.length >= 5){
|
||||
var n = self.notifications[self.notifications.length-5];
|
||||
n.el.destroy();
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
setBadge: function(value){
|
||||
@@ -76,14 +71,15 @@ var NotificationBase = new Class({
|
||||
ids.include(n.id)
|
||||
})
|
||||
|
||||
Api.request('notification.markread', {
|
||||
'data': {
|
||||
'ids': ids.join(',')
|
||||
},
|
||||
'onSuccess': function(){
|
||||
self.setBadge('')
|
||||
}
|
||||
})
|
||||
if(ids.length > 0)
|
||||
Api.request('notification.markread', {
|
||||
'data': {
|
||||
'ids': ids.join(',')
|
||||
},
|
||||
'onSuccess': function(){
|
||||
self.setBadge('')
|
||||
}
|
||||
})
|
||||
|
||||
},
|
||||
|
||||
|
||||
Reference in new issue
Block a user