Show More
@@ -60,19 +60,23 b' class NotificationsController(BaseContro' | |||
|
60 | 60 | """GET /_admin/notifications: All items in the collection""" |
|
61 | 61 | # url('notifications') |
|
62 | 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 | 65 | p = int(request.params.get('page', 1)) |
|
65 | 66 | c.notifications = Page(notif, page=p, items_per_page=10) |
|
67 | c.pull_request_type = Notification.TYPE_PULL_REQUEST | |
|
66 | 68 | return render('admin/notifications/notifications.html') |
|
67 | 69 | |
|
68 | 70 | def mark_all_read(self): |
|
69 | 71 | if request.environ.get('HTTP_X_PARTIAL_XHR'): |
|
70 | 72 | nm = NotificationModel() |
|
71 | 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 | 76 | Session.commit() |
|
74 | 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 | 80 | c.notifications = Page(notif, page=1, items_per_page=10) |
|
77 | 81 | return render('admin/notifications/notifications_data.html') |
|
78 | 82 |
@@ -36,6 +36,7 b' from rhodecode.config.conf import DATETI' | |||
|
36 | 36 | from rhodecode.lib import helpers as h |
|
37 | 37 | from rhodecode.model import BaseModel |
|
38 | 38 | from rhodecode.model.db import Notification, User, UserNotification |
|
39 | from sqlalchemy.orm import joinedload | |
|
39 | 40 | |
|
40 | 41 | log = logging.getLogger(__name__) |
|
41 | 42 | |
@@ -136,15 +137,41 b' class NotificationModel(BaseModel):' | |||
|
136 | 137 | log.error(traceback.format_exc()) |
|
137 | 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 | 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 | 161 | user = self._get_user(user) |
|
145 | UserNotification.query()\ | |
|
162 | q = UserNotification.query()\ | |
|
163 | .filter(UserNotification.user == user)\ | |
|
146 | 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 | 176 | def get_unread_cnt_for_user(self, user): |
|
150 | 177 | user = self._get_user(user) |
@@ -176,7 +203,8 b' class NotificationModel(BaseModel):' | |||
|
176 | 203 | notification.TYPE_CHANGESET_COMMENT: _('commented on commit'), |
|
177 | 204 | notification.TYPE_MESSAGE: _('sent message'), |
|
178 | 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 | 210 | tmpl = "%(user)s %(action)s %(when)s" |
@@ -26,8 +26,8 b'' | |||
|
26 | 26 | </div> |
|
27 | 27 | %if c.notifications: |
|
28 | 28 | <div style="padding:14px 18px;text-align: right;float:left"> |
|
29 | <span id='all' class="ui-btn">${_('All')}</span> | |
|
30 | <span id='pull_request' class="ui-btn">${_('Pull requests')}</span> | |
|
29 | <span id='all' class="ui-btn"><a href="${h.url.current()}">${_('All')}</a></span> | |
|
30 | <span id='pull_request' class="ui-btn"><a href="${h.url.current(type=c.pull_request_type)}">${_('Pull requests')}</a></span> | |
|
31 | 31 | </div> |
|
32 | 32 | <div style="padding:14px 18px;text-align: right;float:right"> |
|
33 | 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 | 44 | deleteNotification(url_del,notification_id) |
|
45 | 45 | }) |
|
46 | 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 | 48 | ypjax(url,'notification_data',function(){ |
|
49 | 49 | var notification_counter = YUD.get('notification_counter'); |
|
50 | 50 | if(notification_counter){ |
General Comments 0
You need to be logged in to leave comments.
Login now