##// END OF EJS Templates
mark all read button for notifications
marcink -
r1791:2aee0dc1 beta
parent child Browse files
Show More
@@ -0,0 +1,28 b''
1
2 % if c.notifications:
3 <%
4 unread = lambda n:{False:'unread'}.get(n)
5 %>
6 <div class="table">
7 <div class="notification-list">
8 %for notification in c.notifications:
9 <div id="notification_${notification.notification.notification_id}" class="container ${unread(notification.read)}">
10 <div class="notification-header">
11 <div class="gravatar">
12 <img alt="gravatar" src="${h.gravatar_url(h.email(notification.notification.created_by_user.email),24)}"/>
13 </div>
14 <div class="desc ${unread(notification.read)}">
15 <a href="${url('notification', notification_id=notification.notification.notification_id)}">${notification.notification.description}</a>
16 </div>
17 <div class="delete-notifications">
18 <span id="${notification.notification.notification_id}" class="delete-notification delete_icon action"></span>
19 </div>
20 </div>
21 <div class="notification-subject">${h.literal(notification.notification.subject)}</div>
22 </div>
23 %endfor
24 </div>
25 </div>
26 %else:
27 <div class="table">${_('No notifications here yet')}</div>
28 %endif No newline at end of file
@@ -26,7 +26,7 b' def make_map(config):'
26 def check_repo(environ, match_dict):
26 def check_repo(environ, match_dict):
27 """
27 """
28 check for valid repository for proper 404 handling
28 check for valid repository for proper 404 handling
29
29
30 :param environ:
30 :param environ:
31 :param match_dict:
31 :param match_dict:
32 """
32 """
@@ -37,7 +37,7 b' def make_map(config):'
37 def check_group(environ, match_dict):
37 def check_group(environ, match_dict):
38 """
38 """
39 check for valid repositories group for proper 404 handling
39 check for valid repositories group for proper 404 handling
40
40
41 :param environ:
41 :param environ:
42 :param match_dict:
42 :param match_dict:
43 """
43 """
@@ -45,7 +45,6 b' def make_map(config):'
45
45
46 return is_valid_repos_group(repos_group_name, config['base_path'])
46 return is_valid_repos_group(repos_group_name, config['base_path'])
47
47
48
49 def check_int(environ, match_dict):
48 def check_int(environ, match_dict):
50 return match_dict.get('id').isdigit()
49 return match_dict.get('id').isdigit()
51
50
@@ -274,7 +273,6 b' def make_map(config):'
274 m.connect("admin_settings_create_repository", "/create_repository",
273 m.connect("admin_settings_create_repository", "/create_repository",
275 action="create_repository", conditions=dict(method=["GET"]))
274 action="create_repository", conditions=dict(method=["GET"]))
276
275
277
278 #NOTIFICATION REST ROUTES
276 #NOTIFICATION REST ROUTES
279 with rmap.submapper(path_prefix=ADMIN_PREFIX,
277 with rmap.submapper(path_prefix=ADMIN_PREFIX,
280 controller='admin/notifications') as m:
278 controller='admin/notifications') as m:
@@ -282,6 +280,8 b' def make_map(config):'
282 action="create", conditions=dict(method=["POST"]))
280 action="create", conditions=dict(method=["POST"]))
283 m.connect("notifications", "/notifications",
281 m.connect("notifications", "/notifications",
284 action="index", conditions=dict(method=["GET"]))
282 action="index", conditions=dict(method=["GET"]))
283 m.connect("notifications_mark_all_read", "/notifications/mark_all_read",
284 action="mark_all_read", conditions=dict(method=["GET"]))
285 m.connect("formatted_notifications", "/notifications.{format}",
285 m.connect("formatted_notifications", "/notifications.{format}",
286 action="index", conditions=dict(method=["GET"]))
286 action="index", conditions=dict(method=["GET"]))
287 m.connect("new_notification", "/notifications/new",
287 m.connect("new_notification", "/notifications/new",
@@ -1,6 +1,7 b''
1 import logging
1 import logging
2 import traceback
2 import traceback
3
3
4 from pylons import request
4 from pylons import tmpl_context as c, url
5 from pylons import tmpl_context as c, url
5 from pylons.controllers.util import redirect
6 from pylons.controllers.util import redirect
6
7
@@ -15,6 +16,7 b' from rhodecode.model.meta import Session'
15
16
16 log = logging.getLogger(__name__)
17 log = logging.getLogger(__name__)
17
18
19
18 class NotificationsController(BaseController):
20 class NotificationsController(BaseController):
19 """REST Controller styled on the Atom Publishing Protocol"""
21 """REST Controller styled on the Atom Publishing Protocol"""
20 # To properly map this controller, ensure your config/routing.py
22 # To properly map this controller, ensure your config/routing.py
@@ -27,7 +29,6 b' class NotificationsController(BaseContro'
27 def __before__(self):
29 def __before__(self):
28 super(NotificationsController, self).__before__()
30 super(NotificationsController, self).__before__()
29
31
30
31 def index(self, format='html'):
32 def index(self, format='html'):
32 """GET /_admin/notifications: All items in the collection"""
33 """GET /_admin/notifications: All items in the collection"""
33 # url('notifications')
34 # url('notifications')
@@ -36,6 +37,16 b' class NotificationsController(BaseContro'
36 .get_for_user(self.rhodecode_user.user_id)
37 .get_for_user(self.rhodecode_user.user_id)
37 return render('admin/notifications/notifications.html')
38 return render('admin/notifications/notifications.html')
38
39
40 def mark_all_read(self):
41 if request.environ.get('HTTP_X_PARTIAL_XHR'):
42 nm = NotificationModel()
43 # mark all read
44 nm.mark_all_read_for_user(self.rhodecode_user.user_id)
45 Session.commit()
46 c.user = self.rhodecode_user
47 c.notifications = nm.get_for_user(self.rhodecode_user.user_id)
48 return render('admin/notifications/notifications_data.html')
49
39 def create(self):
50 def create(self):
40 """POST /_admin/notifications: Create a new item"""
51 """POST /_admin/notifications: Create a new item"""
41 # url('notifications')
52 # url('notifications')
@@ -134,6 +134,12 b' class NotificationModel(BaseModel):'
134 user = self.__get_user(user)
134 user = self.__get_user(user)
135 return user.notifications
135 return user.notifications
136
136
137 def mark_all_read_for_user(self, user):
138 user = self.__get_user(user)
139 UserNotification.query()\
140 .filter(UserNotification.read==False)\
141 .update({'read': True})
142
137 def get_unread_cnt_for_user(self, user):
143 def get_unread_cnt_for_user(self, user):
138 user = self.__get_user(user)
144 user = self.__get_user(user)
139 return UserNotification.query()\
145 return UserNotification.query()\
@@ -24,39 +24,22 b''
24 </li>
24 </li>
25 </ul>
25 </ul>
26 </div>
26 </div>
27 % if c.notifications:
27 <div style="padding:10px 15px;text-align: right">
28 <%
28 <span id='mark_all_read' class="ui-btn">${_('Mark all read')}</span>
29 unread = lambda n:{False:'unread'}.get(n)
29 </div>
30 %>
30 <div id='notification_data'>
31 <div class="table">
31 <%include file='notifications_data.html'/>
32 <div class="notification-list">
32 </div>
33 %for notification in c.notifications:
34 <div id="notification_${notification.notification.notification_id}" class="container ${unread(notification.read)}">
35 <div class="notification-header">
36 <div class="gravatar">
37 <img alt="gravatar" src="${h.gravatar_url(h.email(notification.notification.created_by_user.email),24)}"/>
38 </div>
39 <div class="desc ${unread(notification.read)}">
40 <a href="${url('notification', notification_id=notification.notification.notification_id)}">${notification.notification.description}</a>
41 </div>
42 <div class="delete-notifications">
43 <span id="${notification.notification.notification_id}" class="delete-notification delete_icon action"></span>
44 </div>
45 </div>
46 <div class="notification-subject">${h.literal(notification.notification.subject)}</div>
47 </div>
48 %endfor
49 </div>
50 </div>
51 %else:
52 <div class="table">${_('No notifications here yet')}</div>
53 %endif
54 </div>
33 </div>
55 <script type="text/javascript">
34 <script type="text/javascript">
56 var url = "${url('notification', notification_id='__NOTIFICATION_ID__')}";
35 var url = "${url('notification', notification_id='__NOTIFICATION_ID__')}";
57 YUE.on(YUQ('.delete-notification'),'click',function(e){
36 YUE.on(YUQ('.delete-notification'),'click',function(e){
58 var notification_id = e.currentTarget.id;
37 var notification_id = e.currentTarget.id;
59 deleteNotification(url,notification_id)
38 deleteNotification(url,notification_id)
60 })
39 })
40 YUE.on('mark_all_read','click',function(e){
41 var url = "${h.url('notifications_mark_all_read')}";
42 ypjax(url,'notification_data',function(){YUD.get('notification_counter').innerHTML=0});
43 })
61 </script>
44 </script>
62 </%def>
45 </%def>
@@ -53,7 +53,7 b''
53 ${h.link_to(c.rhodecode_user.username,h.url('admin_settings_my_account'),title='%s %s'%(c.rhodecode_user.name,c.rhodecode_user.lastname))}
53 ${h.link_to(c.rhodecode_user.username,h.url('admin_settings_my_account'),title='%s %s'%(c.rhodecode_user.name,c.rhodecode_user.lastname))}
54 </div>
54 </div>
55 <div class="notifications">
55 <div class="notifications">
56 <a href="${h.url('notifications')}">${c.unread_notifications}</a>
56 <a id="notification_counter" href="${h.url('notifications')}">${c.unread_notifications}</a>
57 </div>
57 </div>
58 %endif
58 %endif
59 </div>
59 </div>
General Comments 0
You need to be logged in to leave comments. Login now