Changeset - 2aee0dc1784e
[Not reviewed]
beta
0 5 1
Marcin Kuzminski - 14 years ago 2011-12-19 01:31:22
marcin@python-works.com
mark all read button for notifications
6 files changed with 57 insertions and 29 deletions:
0 comments (0 inline, 0 general)
rhodecode/config/routing.py
Show inline comments
 
@@ -45,7 +45,6 @@ def make_map(config):
 

	
 
        return is_valid_repos_group(repos_group_name, config['base_path'])
 

	
 

	
 
    def check_int(environ, match_dict):
 
        return match_dict.get('id').isdigit()
 

	
 
@@ -274,7 +273,6 @@ def make_map(config):
 
        m.connect("admin_settings_create_repository", "/create_repository",
 
                  action="create_repository", conditions=dict(method=["GET"]))
 

	
 

	
 
    #NOTIFICATION REST ROUTES
 
    with rmap.submapper(path_prefix=ADMIN_PREFIX,
 
                        controller='admin/notifications') as m:
 
@@ -282,6 +280,8 @@ def make_map(config):
 
                  action="create", conditions=dict(method=["POST"]))
 
        m.connect("notifications", "/notifications",
 
                  action="index", conditions=dict(method=["GET"]))
 
        m.connect("notifications_mark_all_read", "/notifications/mark_all_read",
 
                  action="mark_all_read", conditions=dict(method=["GET"]))
 
        m.connect("formatted_notifications", "/notifications.{format}",
 
                  action="index", conditions=dict(method=["GET"]))
 
        m.connect("new_notification", "/notifications/new",
rhodecode/controllers/admin/notifications.py
Show inline comments
 
import logging
 
import traceback
 

	
 
from pylons import request
 
from pylons import tmpl_context as c, url
 
from pylons.controllers.util import redirect
 

	
 
@@ -15,6 +16,7 @@ from rhodecode.model.meta import Session
 

	
 
log = logging.getLogger(__name__)
 

	
 

	
 
class NotificationsController(BaseController):
 
    """REST Controller styled on the Atom Publishing Protocol"""
 
    # To properly map this controller, ensure your config/routing.py
 
@@ -27,7 +29,6 @@ class NotificationsController(BaseContro
 
    def __before__(self):
 
        super(NotificationsController, self).__before__()
 

	
 

	
 
    def index(self, format='html'):
 
        """GET /_admin/notifications: All items in the collection"""
 
        # url('notifications')
 
@@ -36,6 +37,16 @@ class NotificationsController(BaseContro
 
                            .get_for_user(self.rhodecode_user.user_id)
 
        return render('admin/notifications/notifications.html')
 

	
 
    def mark_all_read(self):
 
        if request.environ.get('HTTP_X_PARTIAL_XHR'):
 
            nm = NotificationModel()
 
            # mark all read
 
            nm.mark_all_read_for_user(self.rhodecode_user.user_id)
 
            Session.commit()
 
            c.user = self.rhodecode_user
 
            c.notifications = nm.get_for_user(self.rhodecode_user.user_id)
 
            return render('admin/notifications/notifications_data.html')
 

	
 
    def create(self):
 
        """POST /_admin/notifications: Create a new item"""
 
        # url('notifications')
rhodecode/model/notification.py
Show inline comments
 
@@ -134,6 +134,12 @@ class NotificationModel(BaseModel):
 
        user = self.__get_user(user)
 
        return user.notifications
 

	
 
    def mark_all_read_for_user(self, user):
 
        user = self.__get_user(user)
 
        UserNotification.query()\
 
            .filter(UserNotification.read==False)\
 
            .update({'read': True})
 

	
 
    def get_unread_cnt_for_user(self, user):
 
        user = self.__get_user(user)
 
        return UserNotification.query()\
rhodecode/templates/admin/notifications/notifications.html
Show inline comments
 
@@ -24,33 +24,12 @@
 
            </li>          
 
        </ul>            
 
    </div>
 
    % if c.notifications:
 
    <%
 
    unread = lambda n:{False:'unread'}.get(n)
 
    %>
 
    <div class="table">
 
      <div class="notification-list">
 
      %for notification in c.notifications:
 
        <div id="notification_${notification.notification.notification_id}" class="container ${unread(notification.read)}">
 
          <div class="notification-header">
 
            <div class="gravatar">
 
                <img alt="gravatar" src="${h.gravatar_url(h.email(notification.notification.created_by_user.email),24)}"/>
 
      <div style="padding:10px 15px;text-align: right">
 
      <span id='mark_all_read' class="ui-btn">${_('Mark all read')}</span>
 
            </div>
 
            <div class="desc ${unread(notification.read)}">
 
            <a href="${url('notification', notification_id=notification.notification.notification_id)}">${notification.notification.description}</a>
 
            </div>
 
            <div class="delete-notifications">
 
              <span id="${notification.notification.notification_id}" class="delete-notification delete_icon action"></span>
 
            </div>
 
  <div id='notification_data'>
 
    <%include file='notifications_data.html'/>
 
          </div>
 
          <div class="notification-subject">${h.literal(notification.notification.subject)}</div>
 
        </div>
 
      %endfor
 
      </div>
 
    </div>
 
    %else:
 
        <div class="table">${_('No notifications here yet')}</div>
 
    %endif
 
</div>
 
<script type="text/javascript">
 
var url = "${url('notification', notification_id='__NOTIFICATION_ID__')}";
 
@@ -58,5 +37,9 @@ var url = "${url('notification', notific
 
	   var notification_id = e.currentTarget.id;
 
	   deleteNotification(url,notification_id)
 
   })
 
 YUE.on('mark_all_read','click',function(e){
 
	    var url = "${h.url('notifications_mark_all_read')}";
 
	    ypjax(url,'notification_data',function(){YUD.get('notification_counter').innerHTML=0});
 
 })
 
</script>
 
</%def>  
rhodecode/templates/admin/notifications/notifications_data.html
Show inline comments
 
new file 100644
 

	
 
% if c.notifications:
 
<%
 
unread = lambda n:{False:'unread'}.get(n)
 
%>
 
<div class="table">
 
  <div class="notification-list">
 
  %for notification in c.notifications:
 
    <div id="notification_${notification.notification.notification_id}" class="container ${unread(notification.read)}">
 
      <div class="notification-header">
 
        <div class="gravatar">
 
            <img alt="gravatar" src="${h.gravatar_url(h.email(notification.notification.created_by_user.email),24)}"/>
 
        </div>
 
        <div class="desc ${unread(notification.read)}">
 
        <a href="${url('notification', notification_id=notification.notification.notification_id)}">${notification.notification.description}</a>
 
        </div>
 
        <div class="delete-notifications">
 
          <span id="${notification.notification.notification_id}" class="delete-notification delete_icon action"></span>
 
        </div>
 
      </div>
 
      <div class="notification-subject">${h.literal(notification.notification.subject)}</div>
 
    </div>
 
  %endfor
 
  </div>
 
</div>
 
%else:
 
    <div class="table">${_('No notifications here yet')}</div>
 
%endif
 
\ No newline at end of file
rhodecode/templates/base/base.html
Show inline comments
 
@@ -53,7 +53,7 @@
 
            ${h.link_to(c.rhodecode_user.username,h.url('admin_settings_my_account'),title='%s %s'%(c.rhodecode_user.name,c.rhodecode_user.lastname))}
 
            </div>
 
            <div class="notifications">
 
            <a href="${h.url('notifications')}">${c.unread_notifications}</a>
 
            <a id="notification_counter" href="${h.url('notifications')}">${c.unread_notifications}</a>
 
            </div>
 
          %endif
 
          </div>	
0 comments (0 inline, 0 general)