Commits

joberschweiber  committed 17dc105

Revamp following

  • Participants
  • Parent commits 7f34ce4

Comments (0)

Files changed (8)

File rhodecode/config/routing.py

     def check_repo(environ, match_dict):
         """
         check for valid repository for proper 404 handling
-        
+
         :param environ:
         :param match_dict:
         """
     def check_group(environ, match_dict):
         """
         check for valid repositories group for proper 404 handling
-        
+
         :param environ:
         :param match_dict:
         """
     rmap.connect('changeset_home', '/{repo_name:.*}/changeset/{revision}',
                 controller='changeset', revision='tip',
                 conditions=dict(function=check_repo))
-    
+
     rmap.connect('changeset_comment', '/{repo_name:.*}/changeset/{revision}/comment',
                 controller='changeset', revision='tip', action='comment',
                 conditions=dict(function=check_repo))
-    
+
     rmap.connect('changeset_comment_delete', '/{repo_name:.*}/changeset/comment/{comment_id}/delete',
                 controller='changeset', action='delete_comment',
                 conditions=dict(function=check_repo))
     rmap.connect('raw_changeset_home',
                  '/{repo_name:.*}/raw-changeset/{revision}',
                  controller='changeset', action='raw_changeset',
-                 revision='tip', conditions=dict(function=check_repo))            
+                 revision='tip', conditions=dict(function=check_repo))
 
     rmap.connect('summary_home', '/{repo_name:.*}/summary',
                 controller='summary', conditions=dict(function=check_repo))
                 controller='settings', action='fork',
                 conditions=dict(function=check_repo))
 
+    rmap.connect('repo_follow_home', '/{repo_name:.*}/follow',
+                 controller='followers', action='follow',
+                 conditions=dict(function=check_repo))
+
     rmap.connect('repo_followers_home', '/{repo_name:.*}/followers',
                  controller='followers', action='followers',
                  conditions=dict(function=check_repo))

File rhodecode/controllers/followers.py

 import logging
 
 from pylons import tmpl_context as c, request
+from pylons.i18n.translation import _
+
+import rhodecode.lib.helpers as h
 
 from rhodecode.lib.helpers import Page
 from rhodecode.lib.auth import LoginRequired, HasRepoPermissionAnyDecorator
-from rhodecode.lib.base import BaseRepoController, render
+from rhodecode.lib.base import BaseRepoController, render, redirect
 from rhodecode.model.db import Repository, User, UserFollowing
 
+from sqlalchemy import *
+
 log = logging.getLogger(__name__)
 
 
     def __before__(self):
         super(FollowersController, self).__before__()
 
+    def follow(self, repo_name):
+        if self.scm_model.toggle_following_repo(c.rhodecode_db_repo.repo_id, c.rhodecode_user.user_id):
+            h.flash(_('You are now following this repository.'), category='success')
+        else:
+            h.flash(_('You are no longer following this repository.'), category='success')
+        return redirect(h.url('files_home', repo_name=repo_name))
+
     def followers(self, repo_name):
         p = int(request.params.get('page', 1))
         repo_id = c.rhodecode_db_repo.repo_id

File rhodecode/lib/base.py

 
             c.repository_followers = self.scm_model.get_followers(c.repo_name)
             c.repository_forks = self.scm_model.get_forks(c.repo_name)
+            c.following_repository = self.scm_model.is_following_repo(c.repo_name, c.rhodecode_user.user_id)
 
             if self.rhodecode_user.username == 'default':
                 #for default(anonymous) user we don't need to pass credentials

File rhodecode/lib/helpers.py

 def combining_link(forward, ext, *sources, **options):
     # taken from http://blog.ufsoft.org/webhelpers-and-javascript-minification
 
-    @beaker_cache(key='sources', expire='never', type='dbm')
+    #@beaker_cache(key='sources', expire='never', type='dbm')
     def combine_sources(sources, fs_root):
         if len(sources) < 2:
             log.debug('No need to combine, only one source provided')

File rhodecode/model/scm.py

         repos_list = {}
 
         for name, path in get_filesystem_repos(repos_path, recursive=True):
-            
+
             # name need to be decomposed and put back together using the /
             # since this is internal storage separator for rhodecode
             name = Repository.url_sep().join(name.split(os.sep))
-            
+
             try:
                 if name in repos_list:
                     raise RepositoryError('Duplicate repository name %s '
                 action_logger(UserTemp(user_id),
                               'stopped_following_repo',
                               RepoTemp(follow_repo_id))
-                return
+                return False
             except:
                 log.error(traceback.format_exc())
                 self.sa.rollback()
             action_logger(UserTemp(user_id),
                           'started_following_repo',
                           RepoTemp(follow_repo_id))
+            return True
         except:
             log.error(traceback.format_exc())
             self.sa.rollback()
             .scalar()
 
         return ret
-

File rhodecode/public/css/style.css

     text-decoration: none;
 }
 
+header .followers-forks .stats {
+    float: right;
+    margin-left: 10px;
+}
+
+header .followers-forks .stats span {
+    float: left;
+    display: block;
+    border: 1px solid #ccc;
+    padding: 3px;
+    padding-bottom: 4px;
+}
+
+header .followers-forks .stats .left {
+    border-radius: 3px 0px 0px 3px;
+    -moz-border-radius: 3px 0px 0px 3px;
+    -webkit-border-radius: 3px 0px 0px 3px;
+}
+
+header .followers-forks .stats .right {
+    border-left: 0;
+    border-radius: 0px 3px 3px 0px;
+    -moz-border-radius: 0px 3px 3px 0px;
+    -webkit-border-radius: 0px 3px 3px 0px;
+}
+
 a.browser-dir {
     background: url('../images/icons/folder_16.png') no-repeat;
     padding-left: 20px;

File rhodecode/templates/base/base.html

 
 <%def name="breadcrumbs_links()">
   <div class="followers-forks">
-    <a class="btn x-small" href="${h.url('repo_followers_home', repo_name=c.repo_name)}">
-      <img src="${h.url('/images/icons/heart.png')}" /> <span>${c.repository_followers} ${_('Follower(s)')}</span>
+    <div class="stats">
+      <span class="left">
+        <a href="${h.url('repo_followers_home', repo_name=c.repo_name)}">
+          <img src="${h.url('/images/icons/heart.png')}" /> ${c.repository_followers}
+        </a>
+      </span>
+      <span class="right">
+        <a href="${h.url('repo_forks_home', repo_name=c.repo_name)}">
+          <img src="${h.url('/images/icons/arrow_divide.png')}" /> ${c.repository_forks}
+        </a>
+      </span>
+    </div>
+    <a class="btn x-small" href="${h.url('repo_follow_home', repo_name=c.repo_name)}">
+      <img src="${h.url('/images/icons/heart.png')}" />
+      %if c.following_repository:
+      <span>${_('Unfollow')}</span>
+      %else:
+      <span>${_('Follow')}</span>
+      %endif
     </a>
-    <a class="btn x-small" href="${h.url('repo_forks_home', repo_name=c.repo_name)}">
-      <img src="${h.url('/images/icons/arrow_divide.png')}" /> <span>${c.repository_forks} ${_('Fork(s)')}</span>
+    <a class="btn x-small" href="${h.url('repo_fork_home', repo_name=c.repo_name)}">
+      <img src="${h.url('/images/icons/arrow_divide.png')}" /> <span>Fork</span>
     </a>
   </div>
   ${h.repo_link(c.dbrepo.groups_and_repo)}

File rhodecode/templates/journal/journal.html

                               ${entry.follows_user.full_contact}
                             %endif
 
-                            %if entry.follows_repo_id:
+                            %if entry.follows_repo_id and entry.follows_repository:
 
                               <div style="float:left;padding-right:5px">
                           <span id="follow_toggle_${entry.follows_repository.repo_id}" class="following" title="${_('Stop following this repository')}"