##// END OF EJS Templates
Added pull requests filter into notification inbox....
marcink -
r2433:74f2910f codereview
parent child Browse files
Show More
@@ -60,19 +60,23 b' class NotificationsController(BaseContro'
60 """GET /_admin/notifications: All items in the collection"""
60 """GET /_admin/notifications: All items in the collection"""
61 # url('notifications')
61 # url('notifications')
62 c.user = self.rhodecode_user
62 c.user = self.rhodecode_user
63 notif = NotificationModel().get_for_user(self.rhodecode_user.user_id)
63 notif = NotificationModel().get_for_user(self.rhodecode_user.user_id,
64 filter_=request.GET)
64 p = int(request.params.get('page', 1))
65 p = int(request.params.get('page', 1))
65 c.notifications = Page(notif, page=p, items_per_page=10)
66 c.notifications = Page(notif, page=p, items_per_page=10)
67 c.pull_request_type = Notification.TYPE_PULL_REQUEST
66 return render('admin/notifications/notifications.html')
68 return render('admin/notifications/notifications.html')
67
69
68 def mark_all_read(self):
70 def mark_all_read(self):
69 if request.environ.get('HTTP_X_PARTIAL_XHR'):
71 if request.environ.get('HTTP_X_PARTIAL_XHR'):
70 nm = NotificationModel()
72 nm = NotificationModel()
71 # mark all read
73 # mark all read
72 nm.mark_all_read_for_user(self.rhodecode_user.user_id)
74 nm.mark_all_read_for_user(self.rhodecode_user.user_id,
75 filter_=request.GET)
73 Session.commit()
76 Session.commit()
74 c.user = self.rhodecode_user
77 c.user = self.rhodecode_user
75 notif = nm.get_for_user(self.rhodecode_user.user_id)
78 notif = nm.get_for_user(self.rhodecode_user.user_id,
79 filter_=request.GET)
76 c.notifications = Page(notif, page=1, items_per_page=10)
80 c.notifications = Page(notif, page=1, items_per_page=10)
77 return render('admin/notifications/notifications_data.html')
81 return render('admin/notifications/notifications_data.html')
78
82
@@ -36,6 +36,7 b' from rhodecode.config.conf import DATETI'
36 from rhodecode.lib import helpers as h
36 from rhodecode.lib import helpers as h
37 from rhodecode.model import BaseModel
37 from rhodecode.model import BaseModel
38 from rhodecode.model.db import Notification, User, UserNotification
38 from rhodecode.model.db import Notification, User, UserNotification
39 from sqlalchemy.orm import joinedload
39
40
40 log = logging.getLogger(__name__)
41 log = logging.getLogger(__name__)
41
42
@@ -136,15 +137,41 b' class NotificationModel(BaseModel):'
136 log.error(traceback.format_exc())
137 log.error(traceback.format_exc())
137 raise
138 raise
138
139
139 def get_for_user(self, user):
140 def get_for_user(self, user, filter_=None):
141 """
142 Get mentions for given user, filter them if filter dict is given
143
144 :param user:
145 :type user:
146 :param filter:
147 """
140 user = self._get_user(user)
148 user = self._get_user(user)
141 return user.notifications
149
150 q = UserNotification.query()\
151 .filter(UserNotification.user == user)\
152 .join((Notification, UserNotification.notification_id ==
153 Notification.notification_id))
154
155 if filter_:
156 q = q.filter(Notification.type_ == filter_.get('type'))
142
157
143 def mark_all_read_for_user(self, user):
158 return q.all()
159
160 def mark_all_read_for_user(self, user, filter_=None):
144 user = self._get_user(user)
161 user = self._get_user(user)
145 UserNotification.query()\
162 q = UserNotification.query()\
163 .filter(UserNotification.user == user)\
146 .filter(UserNotification.read == False)\
164 .filter(UserNotification.read == False)\
147 .update({'read': True})
165 .join((Notification, UserNotification.notification_id ==
166 Notification.notification_id))
167 if filter_:
168 q = q.filter(Notification.type_ == filter_.get('type'))
169
170 # this is a little inefficient but sqlalchemy doesn't support
171 # update on joined tables :(
172 for obj in q.all():
173 obj.read = True
174 self.sa.add(obj)
148
175
149 def get_unread_cnt_for_user(self, user):
176 def get_unread_cnt_for_user(self, user):
150 user = self._get_user(user)
177 user = self._get_user(user)
@@ -176,7 +203,8 b' class NotificationModel(BaseModel):'
176 notification.TYPE_CHANGESET_COMMENT: _('commented on commit'),
203 notification.TYPE_CHANGESET_COMMENT: _('commented on commit'),
177 notification.TYPE_MESSAGE: _('sent message'),
204 notification.TYPE_MESSAGE: _('sent message'),
178 notification.TYPE_MENTION: _('mentioned you'),
205 notification.TYPE_MENTION: _('mentioned you'),
179 notification.TYPE_REGISTRATION: _('registered in RhodeCode')
206 notification.TYPE_REGISTRATION: _('registered in RhodeCode'),
207 notification.TYPE_PULL_REQUEST: _('opened new pull request')
180 }
208 }
181
209
182 tmpl = "%(user)s %(action)s %(when)s"
210 tmpl = "%(user)s %(action)s %(when)s"
@@ -26,8 +26,8 b''
26 </div>
26 </div>
27 %if c.notifications:
27 %if c.notifications:
28 <div style="padding:14px 18px;text-align: right;float:left">
28 <div style="padding:14px 18px;text-align: right;float:left">
29 <span id='all' class="ui-btn">${_('All')}</span>
29 <span id='all' class="ui-btn"><a href="${h.url.current()}">${_('All')}</a></span>
30 <span id='pull_request' class="ui-btn">${_('Pull requests')}</span>
30 <span id='pull_request' class="ui-btn"><a href="${h.url.current(type=c.pull_request_type)}">${_('Pull requests')}</a></span>
31 </div>
31 </div>
32 <div style="padding:14px 18px;text-align: right;float:right">
32 <div style="padding:14px 18px;text-align: right;float:right">
33 <span id='mark_all_read' class="ui-btn">${_('Mark all read')}</span>
33 <span id='mark_all_read' class="ui-btn">${_('Mark all read')}</span>
@@ -44,7 +44,7 b" YUE.on(YUQ('.delete-notification'),'clic"
44 deleteNotification(url_del,notification_id)
44 deleteNotification(url_del,notification_id)
45 })
45 })
46 YUE.on('mark_all_read','click',function(e){
46 YUE.on('mark_all_read','click',function(e){
47 var url = "${h.url('notifications_mark_all_read')}";
47 var url = "${h.url('notifications_mark_all_read', **request.GET)}";
48 ypjax(url,'notification_data',function(){
48 ypjax(url,'notification_data',function(){
49 var notification_counter = YUD.get('notification_counter');
49 var notification_counter = YUD.get('notification_counter');
50 if(notification_counter){
50 if(notification_counter){
General Comments 0
You need to be logged in to leave comments. Login now