Changeset - fcbc35ecb024
[Not reviewed]
beta
0 3 0
Marcin Kuzminski - 14 years ago 2011-11-29 08:55:30
marcin@python-works.com
personal Journal UI
- added my repos and watched repos with filtering
3 files changed with 153 insertions and 36 deletions:
0 comments (0 inline, 0 general)
rhodecode/controllers/journal.py
Show inline comments
 
@@ -16,70 +16,79 @@
 
# (at your option) any later version.
 
#
 
# This program is distributed in the hope that it will be useful,
 
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
# GNU General Public License for more details.
 
#
 
# You should have received a copy of the GNU General Public License
 
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
import logging
 
from itertools import groupby
 

	
 
from sqlalchemy import or_
 
from sqlalchemy.orm import joinedload
 
from webhelpers.paginate import Page
 
from webhelpers.feedgenerator import Atom1Feed, Rss201rev2Feed
 

	
 
from paste.httpexceptions import HTTPBadRequest
 
from pylons import request, tmpl_context as c, response, url
 
from pylons.i18n.translation import _
 

	
 
import rhodecode.lib.helpers as h
 
from rhodecode.lib.auth import LoginRequired, NotAnonymous
 
from rhodecode.lib.base import BaseController, render
 
from rhodecode.model.db import UserLog, UserFollowing
 
from rhodecode.model.db import UserLog, UserFollowing, Repository, User
 
from rhodecode.model.meta import Session
 
from sqlalchemy.sql.expression import func
 
from rhodecode.model.scm import ScmModel
 

	
 
log = logging.getLogger(__name__)
 

	
 

	
 
class JournalController(BaseController):
 

	
 
    def __before__(self):
 
        super(JournalController, self).__before__()
 
        self.rhodecode_user = self.rhodecode_user
 
        self.title = _('%s public journal %s feed') % (c.rhodecode_name, '%s')
 
        self.language = 'en-us'
 
        self.ttl = "5"
 
        self.feed_nr = 20
 

	
 
    @LoginRequired()
 
    @NotAnonymous()
 
    def index(self):
 
        # Return a rendered template
 
        p = int(request.params.get('page', 1))
 

	
 
        c.user = User.get(self.rhodecode_user.user_id)
 
        all_repos = self.sa.query(Repository)\
 
                     .filter(Repository.user_id == c.user.user_id)\
 
                     .order_by(func.lower(Repository.repo_name)).all()
 

	
 
        c.user_repos = ScmModel().get_repos(all_repos)
 

	
 
        c.following = self.sa.query(UserFollowing)\
 
            .filter(UserFollowing.user_id == self.rhodecode_user.user_id)\
 
            .options(joinedload(UserFollowing.follows_repository))\
 
            .all()
 

	
 
        journal = self._get_journal_data(c.following)
 

	
 
        c.journal_pager = Page(journal, page=p, items_per_page=20)
 

	
 
        c.journal_day_aggreagate = self._get_daily_aggregate(c.journal_pager)
 

	
 
        c.journal_data = render('journal/journal_data.html')
 
        if request.environ.get('HTTP_X_PARTIAL_XHR'):
 
            return c.journal_data
 
        return render('journal/journal.html')
 

	
 
    def _get_daily_aggregate(self, journal):
 
        groups = []
 
        for k, g in groupby(journal, lambda x: x.action_as_day):
 
            user_group = []
 
            for k2, g2 in groupby(list(g), lambda x: x.user.email):
 
                l = list(g2)
 
                user_group.append((l[0].user, l))
 

	
rhodecode/public/css/style.css
Show inline comments
 
@@ -737,48 +737,52 @@ div.options a {
 
	background-image: -khtml-gradient(linear, left top, left bottom, from(#fceec1),
 
		to(#eedc94) );
 
	background-image: -moz-linear-gradient(top, #003b76, #00376e);
 
	background-image: -ms-linear-gradient(top, #003b76, #00376e);
 
	background-image: -webkit-gradient(linear, left top, left bottom, color-stop(0%, #003b76),
 
		color-stop(100%, #00376e) );
 
	background-image: -webkit-linear-gradient(top, #003b76, #00376e) );
 
	background-image: -o-linear-gradient(top, #003b76, #00376e) );
 
	background-image: linear-gradient(top, #003b76, #00376e);
 
	filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#003b76',
 
		endColorstr='#00376e', GradientType=0 );
 
	margin: 0 0 20px;
 
	padding: 0;
 
}
 
 
#content div.box div.title h5 {
 
	float: left;
 
	border: none;
 
	color: #fff;
 
	text-transform: uppercase;
 
	margin: 0;
 
	padding: 11px 0 11px 10px;
 
}
 
 
#content div.box div.title .link-white{
 
	color: #FFFFFF;
 
}
 
 
#content div.box div.title ul.links li {
 
	list-style: none;
 
	float: left;
 
	margin: 0;
 
	padding: 0;
 
}
 
 
#content div.box div.title ul.links li a {
 
	border-left: 1px solid #316293;
 
	color: #FFFFFF;
 
	display: block;
 
	float: left;
 
	font-size: 13px;
 
	font-weight: 700;
 
	height: 1%;
 
	margin: 0;
 
	padding: 11px 22px 12px;
 
	text-decoration: none;
 
}
 
 
#content div.box h1,#content div.box h2,#content div.box h3,#content div.box h4,#content div.box h5,#content div.box h6
 
	{
 
	clear: both;
 
	overflow: hidden;
rhodecode/templates/journal/journal.html
Show inline comments
 
@@ -6,64 +6,168 @@
 
<%def name="breadcrumbs()">
 
	${c.rhodecode_name}
 
</%def>
 
<%def name="page_nav()">
 
	${self.menu('home')}
 
</%def>
 
<%def name="main()">
 
	
 
    <div class="box box-left">
 
	    <!-- box / title -->
 
	    <div class="title">
 
	        <h5>${_('Journal')}</h5>
 
	    </div>
 
		<script type="text/javascript">
 
		function show_more_event(){
 
		YUE.on(YUD.getElementsByClassName('show_more'),'click',function(e){
 
		    var el = e.target;
 
		    YUD.setStyle(YUD.get(el.id.substring(1)),'display','');
 
		    YUD.setStyle(el.parentNode,'display','none');
 
		});
 
		}
 
		</script> 	    
 
	    <div id="journal">${c.journal_data}</div>
 
    </div>
 
    
 
    <div class="box box-right">
 
        <!-- box / title -->
 
        <div class="title">
 
            <h5>${_('Following')}</h5>
 
            <h5> 
 
            <input class="q_filter_box" id="q_filter" size="15" type="text" name="filter" value="${_('quick filter...')}"/>        
 
            <a id="show_my" class="link-white" href="#my">${_('My repositories')}</a> / <a id="show_watched" class="link-white" href="#watched">${_('Watched')}</a>
 
            </h5>
 
             %if h.HasPermissionAny('hg.admin','hg.create.repository')():
 
             <ul class="links">
 
               <li>
 
                 <span>${h.link_to(_('ADD REPOSITORY'),h.url('admin_settings_create_repository'))}</span>
 
               </li>          
 
             </ul>           
 
             %endif        
 
        </div>
 
        <!-- end box / title -->
 
        <div id="my" class="table">
 
            <table>
 
            <thead>
 
                <tr>
 
                <th class="left">${_('Name')}</th>
 
                <th class="left">${_('revision')}</th>
 
                <th colspan="2" class="left">${_('action')}</th>            
 
            </thead>
 
             <tbody>
 
             %if c.user_repos:
 
                 %for repo in c.user_repos:
 
                    <tr>
 
                        <td>
 
                         %if repo['dbrepo']['repo_type'] =='hg':
 
                           <img class="icon" title="${_('Mercurial repository')}" alt="${_('Mercurial repository')}" src="${h.url('/images/icons/hgicon.png')}"/>
 
                         %elif repo['dbrepo']['repo_type'] =='git':
 
                           <img class="icon" title="${_('Git repository')}" alt="${_('Git repository')}" src="${h.url('/images/icons/giticon.png')}"/>
 
                         %else:
 
                           
 
                         %endif                     
 
                         %if repo['dbrepo']['private']:
 
                            <img class="icon" alt="${_('private')}" src="${h.url('/images/icons/lock.png')}"/>
 
                         %else:
 
                            <img class="icon" alt="${_('public')}" src="${h.url('/images/icons/lock_open.png')}"/>
 
                         %endif
 
                                                         
 
                        ${h.link_to(repo['name'], h.url('summary_home',repo_name=repo['name']),class_="repo_name")}
 
                        %if repo['dbrepo_fork']:
 
                            <a href="${h.url('summary_home',repo_name=repo['dbrepo_fork']['repo_name'])}">
 
                            <img class="icon" alt="${_('public')}"
 
                            title="${_('Fork of')} ${repo['dbrepo_fork']['repo_name']}" 
 
                            src="${h.url('/images/icons/arrow_divide.png')}"/></a>
 
                        %endif                  
 
                        </td> 
 
                        <td><span class="tooltip" title="${repo['last_change']}">${("r%s:%s") % (repo['rev'],h.short_id(repo['tip']))}</span></td>
 
                        <td><a href="${h.url('repo_settings_home',repo_name=repo['name'])}" title="${_('edit')}"><img class="icon" alt="${_('private')}" src="${h.url('/images/icons/application_form_edit.png')}"/></a></td>
 
                        <td>
 
                          ${h.form(url('repo_settings_delete', repo_name=repo['name']),method='delete')}
 
                            ${h.submit('remove_%s' % repo['name'],'',class_="delete_icon action_button",onclick="return confirm('Confirm to delete this repository');")}
 
                          ${h.end_form()}               
 
                        </td>
 
                    </tr>
 
                 %endfor
 
             %else:
 
                <div style="padding:5px 0px 10px 0px;">
 
                ${_('No repositories yet')} 
 
                %if h.HasPermissionAny('hg.admin','hg.create.repository')():
 
                    ${h.link_to(_('create one now'),h.url('admin_settings_create_repository'),class_="ui-button-small")}
 
                %endif
 
                </div>
 
             %endif
 
             </tbody>
 
             </table>
 
        </div>
 
        <div>
 
		%if c.following:
 
		    %for entry in c.following:
 
		        <div class="currently_following">
 
		            %if entry.follows_user_id:
 
		              <img title="${_('following user')}" alt="${_('user')}" src="${h.url('/images/icons/user.png')}"/>
 
		              ${entry.follows_user.full_contact}
 
		            %endif
 
		            
 
		            %if entry.follows_repo_id:
 
		              
 
		              <div style="float:left;padding-right:5px">
 
                      <span id="follow_toggle_${entry.follows_repository.repo_id}" class="following" title="${_('Stop following this repository')}"
 
                            onclick="javascript:toggleFollowingRepo(this,${entry.follows_repository.repo_id},'${str(h.get_token())}')">
 
                      </span>		            
 
		              </div>
 
		              %if entry.follows_repository.private:
 
		                <img class="icon" title="${_('private repository')}" alt="${_('private repository')}" src="${h.url('/images/icons/lock.png')}"/>
 
		              %else:
 
		                <img class="icon" title="${_('public repository')}" alt="${_('public repository')}" src="${h.url('/images/icons/lock_open.png')}"/>
 
		              %endif
 
		              
 
		              ${h.link_to(entry.follows_repository.repo_name,h.url('summary_home',
 
		                repo_name=entry.follows_repository.repo_name))}
 
		              
 
		            %endif
 
		        </div>
 
		    %endfor
 
		%else:
 
		    ${_('You are not following any users or repositories')}
 
		%endif
 
        </div>
 
    </div>    
 
    
 
        <div id="watched" class="table" style="display:none">
 
          <table>
 
          <thead>
 
              <tr>
 
              <th class="left">${_('Name')}</th>
 
          </thead>
 
           <tbody>        
 
          %if c.following:
 
              %for entry in c.following:
 
              <tr>
 
                <td>
 
                      %if entry.follows_user_id:
 
                        <img title="${_('following user')}" alt="${_('user')}" src="${h.url('/images/icons/user.png')}"/>
 
                        ${entry.follows_user.full_contact}
 
                      %endif
 
                      
 
                      %if entry.follows_repo_id:
 
                        
 
                        <div style="float:right;padding-right:5px">
 
                        <span id="follow_toggle_${entry.follows_repository.repo_id}" class="following" title="${_('Stop following this repository')}"
 
                              onclick="javascript:toggleFollowingRepo(this,${entry.follows_repository.repo_id},'${str(h.get_token())}')">
 
                        </span>                   
 
                        </div>
 
                        
 
                         %if entry.follows_repository.repo_type == 'hg':
 
                           <img class="icon" title="${_('Mercurial repository')}" alt="${_('Mercurial repository')}" src="${h.url('/images/icons/hgicon.png')}"/>
 
                         %elif entry.follows_repository.repo_type == 'git':
 
                           <img class="icon" title="${_('Git repository')}" alt="${_('Git repository')}" src="${h.url('/images/icons/giticon.png')}"/>
 
                         %endif                        
 
                        
 
                        %if entry.follows_repository.private:
 
                          <img class="icon" title="${_('private repository')}" alt="${_('private repository')}" src="${h.url('/images/icons/lock.png')}"/>
 
                        %else:
 
                          <img class="icon" title="${_('public repository')}" alt="${_('public repository')}" src="${h.url('/images/icons/lock_open.png')}"/>
 
                        %endif
 
                        <span class="watched_repo">
 
                            ${h.link_to(entry.follows_repository.repo_name,h.url('summary_home',repo_name=entry.follows_repository.repo_name))}
 
                        </span>
 
                      %endif
 
                </td>
 
              </tr>
 
              %endfor
 
          %else:
 
          </tbody>
 
              ${_('You are not following any users or repositories')}
 
          %endif   
 
          </table>     
 
        </div> 
 
    <script type="text/javascript">
 
    YUE.on('show_my','click',function(e){
 
        YUD.setStyle('watched','display','none');
 
        YUD.setStyle('my','display','');
 
        var nodes = YUQ('#my tr td a.repo_name');
 
        var target = 'q_filter';
 
        var func = function(node){
 
            return node.parentNode.parentNode;
 
        }
 
        q_filter(target,nodes,func);        
 
        YUE.preventDefault(e);
 
    })
 
    YUE.on('show_watched','click',function(e){
 
        YUD.setStyle('my','display','none');
 
        YUD.setStyle('watched','display','');
 
        var nodes = YUQ('#watched .watched_repo a');
 
        var target = 'q_filter';
 
        var func = function(node){
 
            return node.parentNode.parentNode;
 
        }
 
        q_filter(target,nodes,func);        
 
        YUE.preventDefault(e);        
 
    })
 
    </script>    
 
</%def>    
0 comments (0 inline, 0 general)