Changeset - a04fe5986109
[Not reviewed]
beta
0 6 0
Marcin Kuzminski - 14 years ago 2011-05-23 00:00:03
marcin@python-works.com
#47 implemented basic gui for browsing repo groups
6 files changed with 86 insertions and 8 deletions:
0 comments (0 inline, 0 general)
rhodecode/controllers/admin/repos_groups.py
Show inline comments
 
@@ -31,59 +31,63 @@ class ReposGroupsController(BaseControll
 
    def update(self, id):
 
        """PUT /repos_groups/id: Update an existing item"""
 
        # Forms posted to this method should contain a hidden field:
 
        #    <input type="hidden" name="_method" value="PUT" />
 
        # Or using helpers:
 
        #    h.form(url('repos_group', id=ID),
 
        #           method='put')
 
        # url('repos_group', id=ID)
 

	
 
    def delete(self, id):
 
        """DELETE /repos_groups/id: Delete an existing item"""
 
        # Forms posted to this method should contain a hidden field:
 
        #    <input type="hidden" name="_method" value="DELETE" />
 
        # Or using helpers:
 
        #    h.form(url('repos_group', id=ID),
 
        #           method='delete')
 
        # url('repos_group', id=ID)
 

	
 
    def show(self, id, format='html'):
 
        """GET /repos_groups/id: Show a specific item"""
 
        # url('repos_group', id=ID)
 

	
 
        c.group = Group.get(id)
 
        if c.group:
 
            c.group_repos = c.group.repositories
 
            c.group_repos = c.group.repositories.all()
 
        else:
 
            return redirect(url('repos_group'))
 

	
 
        sortables = ['name', 'description', 'last_change', 'tip', 'owner']
 
        current_sort = request.GET.get('sort', 'name')
 
        current_sort_slug = current_sort.replace('-', '')
 

	
 
        if current_sort_slug not in sortables:
 
            c.sort_by = 'name'
 
            current_sort_slug = c.sort_by
 
        else:
 
            c.sort_by = current_sort
 
        c.sort_slug = current_sort_slug
 

	
 
        sort_key = current_sort_slug + '_sort'
 

	
 
        #overwrite our cached list with current filter
 
        gr_filter = [r.repo_name for r in c.group_repos]
 
        c.cached_repo_list = self.scm_model.get_repos(all_repos=gr_filter)
 

	
 
        if c.sort_by.startswith('-'):
 
            c.repos_list = sorted(c.cached_repo_list, key=itemgetter(sort_key),
 
                                  reverse=True)
 
        else:
 
            c.repos_list = sorted(c.cached_repo_list, key=itemgetter(sort_key),
 
                                  reverse=False)
 

	
 
        c.repo_cnt = len(c.repos_list)
 

	
 

	
 
        c.groups = self.sa.query(Group).order_by(Group.group_name)\
 
            .filter(Group.group_parent_id == id).all()
 

	
 
        return render('admin/repos_groups/repos_groups.html')
 

	
 
    def edit(self, id, format='html'):
 
        """GET /repos_groups/id/edit: Form to edit an existing item"""
 
        # url('edit_repos_group', id=ID)
rhodecode/controllers/home.py
Show inline comments
 
@@ -10,66 +10,72 @@
 
    :copyright: (C) 2009-2011 Marcin Kuzminski <marcin@python-works.com>
 
    :license: GPLv3, see COPYING for more details.
 
"""
 
# This program is free software: you can redistribute it and/or modify
 
# it under the terms of the GNU General Public License as published by
 
# the Free Software Foundation, either version 3 of the License, or
 
# (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 operator import itemgetter
 

	
 
from pylons import tmpl_context as c, request
 
from paste.httpexceptions import HTTPBadRequest
 

	
 
from rhodecode.lib.auth import LoginRequired
 
from rhodecode.lib.base import BaseController, render
 

	
 
from rhodecode.model.db import Group
 

	
 
log = logging.getLogger(__name__)
 

	
 

	
 
class HomeController(BaseController):
 

	
 
    @LoginRequired()
 
    def __before__(self):
 
        super(HomeController, self).__before__()
 

	
 
    def index(self):
 
        sortables = ['name', 'description', 'last_change', 'tip', 'owner']
 
        current_sort = request.GET.get('sort', 'name')
 
        current_sort_slug = current_sort.replace('-', '')
 

	
 
        if current_sort_slug not in sortables:
 
            c.sort_by = 'name'
 
            current_sort_slug = c.sort_by
 
        else:
 
            c.sort_by = current_sort
 
        c.sort_slug = current_sort_slug
 

	
 
        sort_key = current_sort_slug + '_sort'
 

	
 
        if c.sort_by.startswith('-'):
 
            c.repos_list = sorted(c.cached_repo_list, key=itemgetter(sort_key),
 
                                  reverse=True)
 
        else:
 
            c.repos_list = sorted(c.cached_repo_list, key=itemgetter(sort_key),
 
                                  reverse=False)
 

	
 
        c.repo_cnt = len(c.repos_list)
 

	
 

	
 
        c.groups = self.sa.query(Group)\
 
            .filter(Group.group_parent_id == None).all()
 

	
 

	
 
        return render('/index.html')
 

	
 
    def repo_switcher(self):
 
        if request.is_xhr:
 
            c.repos_list = sorted(c.cached_repo_list,
 
                                  key=itemgetter('name_sort'), reverse=False)
 
            return render('/repo_switcher_list.html')
 
        else:
 
            return HTTPBadRequest()
rhodecode/model/db.py
Show inline comments
 
@@ -276,88 +276,90 @@ class Repository(Base):
 
    def groups_with_parents(self):
 
        groups = []
 
        if self.group is None:
 
            return groups
 

	
 
        cur_gr = self.group
 
        groups.insert(0, cur_gr)
 
        while 1:
 
            gr = getattr(cur_gr, 'parent_group', None)
 
            cur_gr = cur_gr.parent_group
 
            if gr is None:
 
                break
 
            groups.insert(0, gr)
 

	
 
        return groups
 

	
 
    @property
 
    def groups_and_repo(self):
 
        return self.groups_with_parents, self.just_name
 

	
 

	
 
class Group(Base):
 
    __tablename__ = 'groups'
 
    __table_args__ = (UniqueConstraint('group_name'), {'useexisting':True},)
 
    __mapper_args__ = {'order_by':'group_name'}
 

	
 
    group_id = Column("group_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
 
    group_name = Column("group_name", String(length=255, convert_unicode=False, assert_unicode=None), nullable=False, unique=True, default=None)
 
    group_parent_id = Column("group_parent_id", Integer(), ForeignKey('groups.group_id'), nullable=True, unique=None, default=None)
 
    group_description = Column("group_description", String(length=10000, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
 

	
 
    parent_group = relationship('Group', remote_side=group_id)
 

	
 

	
 
    def __init__(self, group_name='', parent_group=None):
 
        self.group_name = group_name
 
        self.parent_group = parent_group
 

	
 
    def __repr__(self):
 
        return "<%s('%s:%s')>" % (self.__class__.__name__, self.group_id,
 
                                  self.group_name)
 

	
 
    @property
 
    def parents(self):
 
        groups = []
 
        if self.parent_group is None:
 
            return groups
 
        cur_gr = self.parent_group
 
        groups.insert(0, cur_gr)
 
        while 1:
 
            gr = getattr(cur_gr, 'parent_group', None)
 
            cur_gr = cur_gr.parent_group
 
            if gr is None:
 
                break
 
            groups.insert(0, gr)
 
        return groups
 

	
 

	
 
    @property
 
    def full_path(self):
 
        return '/'.join([g.group_name for g in self.parents] +
 
                        [self.group_name])
 

	
 
    @property
 
    def repositories(self):
 
        return Session.query(Repository).filter(Repository.group == self).all()
 
        return Session.query(Repository).filter(Repository.group == self)
 

	
 
class Permission(Base):
 
    __tablename__ = 'permissions'
 
    __table_args__ = {'useexisting':True}
 
    permission_id = Column("permission_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
 
    permission_name = Column("permission_name", String(length=255, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
 
    permission_longname = Column("permission_longname", String(length=255, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
 

	
 
    def __repr__(self):
 
        return "<%s('%s:%s')>" % (self.__class__.__name__,
 
                                  self.permission_id, self.permission_name)
 

	
 
    @classmethod
 
    def get_by_key(cls, key):
 
        return Session.query(cls).filter(cls.permission_name == key).scalar()
 

	
 
class RepoToPerm(Base):
 
    __tablename__ = 'repo_to_perm'
 
    __table_args__ = (UniqueConstraint('user_id', 'repository_id'), {'useexisting':True})
 
    repo_to_perm_id = Column("repo_to_perm_id", Integer(), nullable=False, unique=True, default=None, primary_key=True)
 
    user_id = Column("user_id", Integer(), ForeignKey('users.user_id'), nullable=False, unique=None, default=None)
 
    permission_id = Column("permission_id", Integer(), ForeignKey('permissions.permission_id'), nullable=False, unique=None, default=None)
 
    repository_id = Column("repository_id", Integer(), ForeignKey('repositories.repo_id'), nullable=False, unique=None, default=None)
 

	
rhodecode/model/scm.py
Show inline comments
 
@@ -98,56 +98,58 @@ class ScmModel(BaseModel):
 

	
 
        baseui = make_ui('db')
 
        repos_list = {}
 

	
 
        for name, path in get_filesystem_repos(repos_path, recursive=True):
 
            try:
 
                if name in repos_list:
 
                    raise RepositoryError('Duplicate repository name %s '
 
                                    'found in %s' % (name, path))
 
                else:
 

	
 
                    klass = get_backend(path[0])
 

	
 
                    if path[0] == 'hg' and path[0] in BACKENDS.keys():
 
                        repos_list[name] = klass(path[1], baseui=baseui)
 

	
 
                    if path[0] == 'git' and path[0] in BACKENDS.keys():
 
                        repos_list[name] = klass(path[1])
 
            except OSError:
 
                continue
 

	
 
        return repos_list
 

	
 
    def get_repos(self, all_repos=None):
 
        """Get all repos from db and for each repo create it's
 
        """
 
        Get all repos from db and for each repo create it's
 
        backend instance and fill that backed with information from database
 

	
 
        :param all_repos: give specific repositories list, good for filtering
 
            this have to be a list of  just the repository names
 
        :param all_repos: list of repository names as strings
 
            give specific repositories list, good for filtering
 
        """
 
        if all_repos is None:
 
            repos = self.sa.query(Repository)\
 
                        .filter(Repository.group_id == None)\
 
                        .order_by(Repository.repo_name).all()
 
            all_repos = [r.repo_name for r in repos]
 

	
 
        #get the repositories that should be invalidated
 
        invalidation_list = [str(x.cache_key) for x in \
 
                             self.sa.query(CacheInvalidation.cache_key)\
 
                             .filter(CacheInvalidation.cache_active == False)\
 
                             .all()]
 
        for r_name in all_repos:
 
            r_dbr = self.get(r_name, invalidation_list)
 
            if r_dbr is not None:
 
                repo, dbrepo = r_dbr
 

	
 
                if repo is None or dbrepo is None:
 
                    log.error('Repository "%s" looks somehow corrupted '
 
                              'fs-repo:%s,db-repo:%s both values should be '
 
                              'present', r_name, repo, dbrepo)
 
                    continue
 
                last_change = repo.last_change
 
                tip = h.get_changeset_safe(repo, 'tip')
 

	
 
                tmp_d = {}
 
                tmp_d['name'] = dbrepo.repo_name
 
                tmp_d['name_sort'] = tmp_d['name'].lower()
rhodecode/templates/admin/repos_groups/repos_groups.html
Show inline comments
 
## -*- coding: utf-8 -*-
 
<%inherit file="/base/base.html"/>
 

	
 
<%def name="title()">
 
    ${_('Repository group')} - ${c.rhodecode_name}
 
</%def>
 

	
 

	
 
<%def name="breadcrumbs_links()">
 
    ${_('Group')} &raquo; ${c.group.group_name} - ${_(' %s repositories' % c.repo_cnt)} 
 
    ${_('Repository Groups')} 
 
    %if c.group.parent_group:
 
        &raquo; ${h.link_to(c.group.parent_group.group_name,h.url('repos_group',id=c.group.parent_group.group_id))}
 
    %endif
 
    
 
    &raquo; "${c.group.group_name}" ${_('with %s repositories' % c.repo_cnt)} 
 
</%def>
 
<%def name="page_nav()">
 
    ${self.menu('admin')}
 
</%def>
 
<%def name="main()">
 
    <%def name="get_sort(name)">
 
        <%name_slug = name.lower().replace(' ','_') %>
 
        
 
        %if name_slug == c.sort_slug:
 
          %if c.sort_by.startswith('-'):
 
            <a href="?sort=${name_slug}">${name}&uarr;</a>
 
          %else:
 
            <a href="?sort=-${name_slug}">${name}&darr;</a>
 
          %endif:
 
        %else:
 
            <a href="?sort=${name_slug}">${name}</a>
 
        %endif
 
    </%def>
 
<div class="box">
 
    <!-- box / title -->
 
    <div class="title">
 
        ${self.breadcrumbs()}       
 
    </div>
 
    <!-- end box / title -->
 
        <div class="table">
 
           % if c.groups:
 
            <table>
 
            
 
                <thead>
 
                    <tr>
 
                        <th class="left"><a href="#">${_('Group name')}</a></th>
 
                        <th class="left"><a href="#">${_('Description')}</a></th>
 
                        <th class="left"><a href="#">${_('Number of repositories')}</a></th>
 
                    </tr>
 
                </thead>
 
                
 
                ## REPO GROUPS
 
                
 
                % for gr in c.groups:
 
                  <tr>
 
                      <td>
 
                          <div style="white-space: nowrap">
 
                          <img class="icon" alt="${_('Repositories group')}" src="${h.url('/images/icons/database_link.png')}"/>
 
                          ${h.link_to(gr.group_name,url('repos_group',id=gr.group_id))}
 
                          </div>
 
                      </td>
 
                      <td>${gr.group_description}</td>
 
                      <td><b>${gr.repositories.count()}</b></td>
 
                  </tr>
 
                % endfor            
 
                
 
            </table>
 
            <div style="height: 20px"></div>
 
            % endif        
 
            <table>
 
            <thead>
 
                <tr>
 
                    <th class="left">${get_sort(_('Name'))}</th>
 
                    <th class="left">${get_sort(_('Description'))}</th>
 
                    <th class="left">${get_sort(_('Last change'))}</th>
 
                    <th class="left">${get_sort(_('Tip'))}</th>
 
                    <th class="left">${get_sort(_('Owner'))}</th>
 
                    <th class="left">${_('RSS')}</th>
 
                    <th class="left">${_('Atom')}</th>
 
                </tr>
 
            </thead>
 
            <tbody>
 
            %for cnt,repo in enumerate(c.repos_list):
 
                <tr class="parity${cnt%2}">
 
                    <td>
 
                    <div style="white-space: nowrap">
 
                     ## TYPE OF REPO
 
                     %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:
 
                       
 
@@ -91,31 +125,31 @@
 
                        ${h.link_to('r%s:%s' % (repo['rev'],h.short_id(repo['tip'])),
 
                        h.url('changeset_home',repo_name=repo['name'],revision=repo['tip']),
 
                        class_="tooltip",
 
                        title=h.tooltip(repo['last_msg']))}
 
                        %else:
 
                            ${_('No changesets yet')}
 
                        %endif    
 
                    </td>
 
                    <td title="${repo['contact']}">${h.person(repo['contact'])}</td>
 
                    <td>
 
                      %if c.rhodecode_user.username != 'default':
 
                        <a title="${_('Subscribe to %s rss feed')%repo['name']}" class="rss_icon"  href="${h.url('rss_feed_home',repo_name=repo['name'],api_key=c.rhodecode_user.api_key)}"></a>
 
                      %else:
 
                        <a title="${_('Subscribe to %s rss feed')%repo['name']}" class="rss_icon"  href="${h.url('rss_feed_home',repo_name=repo['name'])}"></a>
 
                      %endif:                       
 
                    </td>        
 
                    <td>
 
                      %if c.rhodecode_user.username != 'default':
 
                        <a title="${_('Subscribe to %s atom feed')%repo['name']}"  class="atom_icon" href="${h.url('atom_feed_home',repo_name=repo['name'],api_key=c.rhodecode_user.api_key)}"></a>
 
                      %else:
 
                        <a title="${_('Subscribe to %s atom feed')%repo['name']}"  class="atom_icon" href="${h.url('atom_feed_home',repo_name=repo['name'])}"></a>
 
                      %endif:
 
                    </td>
 
                </tr>
 
            %endfor
 
            %endfor          
 
            </tbody>
 
            </table>
 
            </div>
 
</div> 
 
           
 
</%def>    
rhodecode/templates/index.html
Show inline comments
 
@@ -25,48 +25,77 @@
 
	</%def>
 
	
 
    <div class="box">
 
	    <!-- box / title -->
 
	    <div class="title">
 
	        <h5><input class="top-right-rounded-corner top-left-rounded-corner 
 
	                           bottom-left-rounded-corner bottom-right-rounded-corner" 
 
	                    id="q_filter" size="15" type="text" name="filter" 
 
	                    value="${_('quick filter...')}"/>
 
	        
 
	        ${_('Dashboard')}  - <span id="repo_count">${c.repo_cnt}</span> ${_('repositories')} 
 
	        </h5>
 
	        %if c.rhodecode_user.username != 'default':
 
		        %if h.HasPermissionAny('hg.admin','hg.create.repository')():
 
		        <ul class="links">
 
		          <li>
 
		            <span>${h.link_to(_('ADD NEW REPOSITORY'),h.url('admin_settings_create_repository'))}</span>
 
		          </li>          
 
		        </ul>  	        
 
		        %endif
 
		    %endif
 
	    </div>
 
	    <!-- end box / title -->
 
        <div class="table">
 
           % if c.groups:
 
            <table>
 
            
 
                <thead>
 
                    <tr>
 
                        <th class="left"><a href="#">${_('Group name')}</a></th>
 
                        <th class="left"><a href="#">${_('Description')}</a></th>
 
                        <th class="left"><a href="#">${_('Number of repositories')}</a></th>
 
                    </tr>
 
                </thead>
 
                
 
                ## REPO GROUPS
 
                
 
                % for gr in c.groups:
 
                  <tr>
 
                      <td>
 
                          <div style="white-space: nowrap">
 
                          <img class="icon" alt="${_('Repositories group')}" src="${h.url('/images/icons/database_link.png')}"/>
 
                          ${h.link_to(gr.group_name,url('repos_group',id=gr.group_id))}
 
                          </div>
 
                      </td>
 
                      <td>${gr.group_description}</td>
 
                      <td><b>${gr.repositories.count()}</b></td>
 
                  </tr>
 
                % endfor            
 
                
 
            </table>
 
            <div style="height: 20px"></div>
 
            % endif
 
            <table>
 
            <thead>
 
	            <tr>
 
			        <th class="left">${get_sort(_('Name'))}</th>
 
			        <th class="left">${get_sort(_('Description'))}</th>
 
			        <th class="left">${get_sort(_('Last change'))}</th>
 
			        <th class="left">${get_sort(_('Tip'))}</th>
 
			        <th class="left">${get_sort(_('Owner'))}</th>
 
			        <th class="left">${_('RSS')}</th>
 
			        <th class="left">${_('Atom')}</th>
 
	            </tr>
 
            </thead>
 
            <tbody>
 
		    %for cnt,repo in enumerate(c.repos_list):
 
		        <tr class="parity${cnt%2}">
 
		            <td>
 
		            <div style="white-space: nowrap">
 
		             ## TYPE OF REPO
 
		             %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:
 
		               
 
@@ -105,48 +134,49 @@
 
		                h.url('changeset_home',repo_name=repo['name'],revision=repo['tip']),
 
		                class_="tooltip",
 
		                title=h.tooltip(repo['last_msg']))}
 
		            	%else:
 
		            		${_('No changesets yet')}
 
		            	%endif    
 
		            </td>
 
		            <td title="${repo['contact']}">${h.person(repo['contact'])}</td>
 
		            <td>
 
		              %if c.rhodecode_user.username != 'default':
 
		                <a title="${_('Subscribe to %s rss feed')%repo['name']}" class="rss_icon"  href="${h.url('rss_feed_home',repo_name=repo['name'],api_key=c.rhodecode_user.api_key)}"></a>
 
                      %else:
 
                        <a title="${_('Subscribe to %s rss feed')%repo['name']}" class="rss_icon"  href="${h.url('rss_feed_home',repo_name=repo['name'])}"></a>
 
                      %endif:		                
 
		            </td>        
 
		            <td>
 
		              %if c.rhodecode_user.username != 'default':
 
		                <a title="${_('Subscribe to %s atom feed')%repo['name']}"  class="atom_icon" href="${h.url('atom_feed_home',repo_name=repo['name'],api_key=c.rhodecode_user.api_key)}"></a>
 
		              %else:
 
		                <a title="${_('Subscribe to %s atom feed')%repo['name']}"  class="atom_icon" href="${h.url('atom_feed_home',repo_name=repo['name'])}"></a>
 
		              %endif:
 
		            </td>
 
		        </tr>
 
		    %endfor
 
		    
 
            </tbody>
 
            </table>
 
            </div>
 
    </div>
 
    
 
    
 
    <script type="text/javascript">
 
     var D = YAHOO.util.Dom;
 
     var E = YAHOO.util.Event;
 
     var S = YAHOO.util.Selector;
 
     
 
     var q_filter = D.get('q_filter');
 
     var F = YAHOO.namespace('q_filter'); 
 
     
 
     E.on(q_filter,'click',function(){
 
    	q_filter.value = '';
 
     });
 

	
 
     F.filterTimeout = null;
 
     
 
     F.updateFilter  = function() { 
 
    	// Reset timeout 
 
        F.filterTimeout = null;
 
    	
0 comments (0 inline, 0 general)