# HG changeset patch # User Marcin Kuzminski # Date 2019-05-10 15:47:39 # Node ID 4c16050dc829971d3fa3e19740ef3796a81f5e59 # Parent 8a8aadb391650ece8e1efd65c618bf8b3e396ad6 repositories: bring back watch action in summary view diff --git a/rhodecode/apps/_base/__init__.py b/rhodecode/apps/_base/__init__.py --- a/rhodecode/apps/_base/__init__.py +++ b/rhodecode/apps/_base/__init__.py @@ -237,6 +237,8 @@ class RepoAppView(BaseAppView): c.rhodecode_db_repo = self.db_repo c.repo_name = self.db_repo_name c.repository_pull_requests = self.db_repo_pull_requests + c.repository_is_user_following = ScmModel().is_following_repo( + self.db_repo_name, self._rhodecode_user.user_id) self.path_filter = PathFilter(None) c.repository_requirements_missing = {} diff --git a/rhodecode/apps/journal/views.py b/rhodecode/apps/journal/views.py --- a/rhodecode/apps/journal/views.py +++ b/rhodecode/apps/journal/views.py @@ -297,8 +297,7 @@ class JournalView(BaseAppView): user_id = self.request.POST.get('follows_user_id') if user_id: try: - ScmModel().toggle_following_user( - user_id, self._rhodecode_user.user_id) + ScmModel().toggle_following_user(user_id, self._rhodecode_user.user_id) Session().commit() return 'ok' except Exception: @@ -307,8 +306,7 @@ class JournalView(BaseAppView): repo_id = self.request.POST.get('follows_repo_id') if repo_id: try: - ScmModel().toggle_following_repo( - repo_id, self._rhodecode_user.user_id) + ScmModel().toggle_following_repo(repo_id, self._rhodecode_user.user_id) Session().commit() return 'ok' except Exception: diff --git a/rhodecode/apps/my_account/views/my_account.py b/rhodecode/apps/my_account/views/my_account.py --- a/rhodecode/apps/my_account/views/my_account.py +++ b/rhodecode/apps/my_account/views/my_account.py @@ -360,7 +360,7 @@ class MyAccountView(BaseAppView, DataGri 'repository.read', 'repository.write', 'repository.admin']) repos_data = RepoModel().get_repos_as_dict( - repo_list=repo_list, admin=admin) + repo_list=repo_list, admin=admin, short_name=False) # json used to render the grid return json.dumps(repos_data) diff --git a/rhodecode/apps/repository/views/repo_summary.py b/rhodecode/apps/repository/views/repo_summary.py --- a/rhodecode/apps/repository/views/repo_summary.py +++ b/rhodecode/apps/repository/views/repo_summary.py @@ -233,8 +233,6 @@ class RepoSummaryView(RepoAppView): c.enable_downloads = self.db_repo.enable_downloads c.repository_followers = scm_model.get_followers(self.db_repo) c.repository_forks = scm_model.get_forks(self.db_repo) - c.repository_is_user_following = scm_model.is_following_repo( - self.db_repo_name, self._rhodecode_user.user_id) # first interaction with the VCS instance after here... if c.repository_requirements_missing: diff --git a/rhodecode/model/repo.py b/rhodecode/model/repo.py --- a/rhodecode/model/repo.py +++ b/rhodecode/model/repo.py @@ -199,7 +199,7 @@ class RepoModel(BaseModel): repo.update_commit_cache() def get_repos_as_dict(self, repo_list=None, admin=False, - super_user_actions=False): + super_user_actions=False, short_name=None): _render = get_current_request().get_partial_renderer( 'rhodecode:templates/data_table/_dt_elements.mako') c = _render.get_call_context() @@ -208,8 +208,12 @@ class RepoModel(BaseModel): return _render('quick_menu', repo_name) def repo_lnk(name, rtype, rstate, private, archived, fork_of): + if short_name is not None: + short_name_var = short_name + else: + short_name_var = not admin return _render('repo_name', name, rtype, rstate, private, archived, fork_of, - short_name=not admin, admin=False) + short_name=short_name_var, admin=False) def last_change(last_change): if admin and isinstance(last_change, datetime.datetime) and not last_change.tzinfo: diff --git a/rhodecode/public/js/src/rhodecode/followers.js b/rhodecode/public/js/src/rhodecode/followers.js --- a/rhodecode/public/js/src/rhodecode/followers.js +++ b/rhodecode/public/js/src/rhodecode/followers.js @@ -16,58 +16,44 @@ // # RhodeCode Enterprise Edition, including its added features, Support services, // # and proprietary license terms, please see https://rhodecode.com/licenses/ -var onSuccessFollow = function(target){ - var f = $(target); - var f_cnt = $('#current_followers_count'); +var onSuccessFollow = function (target) { + var targetEl = $(target); - if(f.hasClass('follow')){ - f.removeClass('follow'); - f.addClass('following'); - f.attr('title', _gettext('Stop following this repository')); - $(f).html(_gettext('Unfollow')); - if(f_cnt.length){ - var cnt = Number(f_cnt.html())+1; - f_cnt.html(cnt); + var callback = function () { + targetEl.animate({'opacity': 1.00}, 200); + if (targetEl.hasClass('watching')) { + targetEl.removeClass('watching'); + targetEl.attr('title', _gettext('Stopped watching this repository')); + $(targetEl).html(_gettext('Watch')); + } else { + targetEl.addClass('watching'); + targetEl.attr('title', _gettext('Started watching this repository')); + $(targetEl).html(_gettext('Unwatch')); } - } - else{ - f.removeClass('following'); - f.addClass('follow'); - f.attr('title', _gettext('Start following this repository')); - $(f).html(_gettext('Follow')); - if(f_cnt.length){ - var cnt = Number(f_cnt.html())-1; - f_cnt.html(cnt); - } - } + }; + targetEl.animate({'opacity': 0.15}, 200, callback); }; -// TODO:: check if the function is needed. 0 usage found -var toggleFollowingUser = function(target,follows_user_id,token,user_id){ + +var toggleFollowingUser = function (target, follows_user_id) { var args = { 'follows_user_id': follows_user_id, - 'auth_token': token, 'csrf_token': CSRF_TOKEN }; - if(user_id != undefined){ - args.user_id = user_id - } - ajaxPOST(pyroutes.url('toggle_following'), args, function(){ + + ajaxPOST(pyroutes.url('toggle_following'), args, function () { onSuccessFollow(target); }); return false; }; -var toggleFollowingRepo = function(target,follows_repo_id,token,user_id){ +var toggleFollowingRepo = function (target, follows_repo_id) { var args = { 'follows_repo_id': follows_repo_id, - 'auth_token': token, 'csrf_token': CSRF_TOKEN }; - if(user_id != undefined){ - args.user_id = user_id - } - ajaxPOST(pyroutes.url('toggle_following'), args, function(){ + + ajaxPOST(pyroutes.url('toggle_following'), args, function () { onSuccessFollow(target); }); return false; diff --git a/rhodecode/templates/base/base.mako b/rhodecode/templates/base/base.mako --- a/rhodecode/templates/base/base.mako +++ b/rhodecode/templates/base/base.mako @@ -217,6 +217,15 @@
%if c.rhodecode_user.username != h.DEFAULT_USER: RSS + + + % if c.repository_is_user_following: + Unwatch + % else: + Watch + % endif + + %else: RSS %endif