Changeset - 1cd0a0c05f42
[Not reviewed]
beta
0 2 0
Marcin Kuzminski - 13 years ago 2012-09-19 00:03:43
marcin@python-works.com
swap the select values with revisions dynamically when switching the repos on pull request view
- fix the partial ajax request that should never do redirect
2 files changed with 19 insertions and 7 deletions:
0 comments (0 inline, 0 general)
rhodecode/controllers/compare.py
Show inline comments
 
@@ -30,96 +30,101 @@ from webob.exc import HTTPNotFound
 
from pylons import request, response, session, tmpl_context as c, url
 
from pylons.controllers.util import abort, redirect
 
from pylons.i18n.translation import _
 

	
 
from rhodecode.lib.vcs.exceptions import EmptyRepositoryError, RepositoryError
 
from rhodecode.lib import helpers as h
 
from rhodecode.lib.base import BaseRepoController, render
 
from rhodecode.lib.auth import LoginRequired, HasRepoPermissionAnyDecorator
 
from rhodecode.lib import diffs
 

	
 
from rhodecode.model.db import Repository
 
from rhodecode.model.pull_request import PullRequestModel
 
from webob.exc import HTTPBadRequest
 

	
 
log = logging.getLogger(__name__)
 

	
 

	
 
class CompareController(BaseRepoController):
 

	
 
    @LoginRequired()
 
    @HasRepoPermissionAnyDecorator('repository.read', 'repository.write',
 
                                   'repository.admin')
 
    def __before__(self):
 
        super(CompareController, self).__before__()
 

	
 
    def __get_cs_or_redirect(self, rev, repo, redirect_after=True):
 
    def __get_cs_or_redirect(self, rev, repo, redirect_after=True,
 
                             partial=False):
 
        """
 
        Safe way to get changeset if error occur it redirects to changeset with
 
        proper message
 
        proper message. If partial is set then don't do redirect raise Exception
 
        instead
 

	
 
        :param rev: revision to fetch
 
        :param repo: repo instance
 
        """
 

	
 
        try:
 
            type_, rev = rev
 
            return repo.scm_instance.get_changeset(rev)
 
        except EmptyRepositoryError, e:
 
            if not redirect_after:
 
                return None
 
            h.flash(h.literal(_('There are no changesets yet')),
 
                    category='warning')
 
            redirect(url('summary_home', repo_name=repo.repo_name))
 

	
 
        except RepositoryError, e:
 
            log.error(traceback.format_exc())
 
            h.flash(str(e), category='warning')
 
            redirect(h.url('summary_home', repo_name=repo.repo_name))
 
            if not partial:
 
                redirect(h.url('summary_home', repo_name=repo.repo_name))
 
            raise HTTPBadRequest()
 

	
 
    def index(self, org_ref_type, org_ref, other_ref_type, other_ref):
 

	
 
        org_repo = c.rhodecode_db_repo.repo_name
 
        org_ref = (org_ref_type, org_ref)
 
        other_ref = (other_ref_type, other_ref)
 
        other_repo = request.GET.get('repo', org_repo)
 

	
 
        c.swap_url = h.url('compare_url', repo_name=other_repo,
 
              org_ref_type=other_ref[0], org_ref=other_ref[1],
 
              other_ref_type=org_ref[0], other_ref=org_ref[1],
 
              repo=org_repo)
 

	
 
        c.org_repo = org_repo = Repository.get_by_repo_name(org_repo)
 
        c.other_repo = other_repo = Repository.get_by_repo_name(other_repo)
 

	
 
        if c.org_repo is None or c.other_repo is None:
 
            log.error('Could not found repo %s or %s' % (org_repo, other_repo))
 
            raise HTTPNotFound
 

	
 
        if c.org_repo.scm_instance.alias != 'hg':
 
            log.error('Review not available for GIT REPOS')
 
            raise HTTPNotFound
 

	
 
        self.__get_cs_or_redirect(rev=org_ref, repo=org_repo)
 
        self.__get_cs_or_redirect(rev=other_ref, repo=other_repo)
 
        partial = request.environ.get('HTTP_X_PARTIAL_XHR')
 
        self.__get_cs_or_redirect(rev=org_ref, repo=org_repo, partial=partial)
 
        self.__get_cs_or_redirect(rev=other_ref, repo=other_repo, partial=partial)
 

	
 
        c.cs_ranges, discovery_data = PullRequestModel().get_compare_data(
 
                                       org_repo, org_ref, other_repo, other_ref
 
                                      )
 

	
 
        c.statuses = c.rhodecode_db_repo.statuses([x.raw_id for x in
 
                                                   c.cs_ranges])
 
        c.target_repo = c.repo_name
 
        # defines that we need hidden inputs with changesets
 
        c.as_form = request.GET.get('as_form', False)
 
        if request.environ.get('HTTP_X_PARTIAL_XHR'):
 
        if partial:
 
            return render('compare/compare_cs.html')
 

	
 
        c.org_ref = org_ref[1]
 
        c.other_ref = other_ref[1]
 
        # diff needs to have swapped org with other to generate proper diff
 
        _diff = diffs.differ(other_repo, other_ref, org_repo, org_ref,
 
                             discovery_data)
 
        diff_processor = diffs.DiffProcessor(_diff, format='gitdiff')
 
        _parsed = diff_processor.prepare()
 

	
 
        c.files = []
 
        c.changes = {}
rhodecode/templates/pullrequests/pullrequest.html
Show inline comments
 
@@ -126,24 +126,25 @@
 
        </div>
 
    </div>
 
    ${h.end_form()}
 

	
 
</div>
 

	
 
<script type="text/javascript">
 
  var _USERS_AC_DATA = ${c.users_array|n};
 
  var _GROUPS_AC_DATA = ${c.users_groups_array|n};
 
  PullRequestAutoComplete('user', 'reviewers_container', _USERS_AC_DATA, _GROUPS_AC_DATA);
 

	
 
  var other_repos_info = ${c.other_repos_info|n};
 
  
 
  var loadPreview = function(){
 
	  YUD.setStyle(YUD.get('pull_request_overview_url').parentElement,'display','none');
 
      var url = "${h.url('compare_url',
 
    	                 repo_name='org_repo',
 
    	                 org_ref_type='org_ref_type', org_ref='org_ref',
 
                         other_ref_type='other_ref_type', other_ref='other_ref',
 
                         repo='other_repo',
 
                         as_form=True)}";
 

	
 
      var select_refs = YUQ('#pull_request_form select.refs')
 

	
 
      for(var i=0;i<select_refs.length;i++){
 
@@ -158,24 +159,30 @@
 

	
 
          key = select_ref.name;
 
          val = select_ref_data[1];
 
          url = url.replace(key,val);
 

	
 
        }else{
 
          key = select_ref.name;
 
          val = select_ref.value;
 
          url = url.replace(key,val);
 
        }
 
      }
 

	
 
      YUE.on('other_repo', 'change', function(e){
 
    	  var repo_name = e.currentTarget.value;
 
    	  // replace the <select> of changed repo
 
    	  YUD.get('other_ref').innerHTML = other_repos_info[repo_name]['revs'];
 
      });
 
      
 
      ypjax(url,'pull_request_overview', function(data){
 
    	  var sel_box = YUQ('#pull_request_form #other_repo')[0];
 
    	  var repo_name = sel_box.options[sel_box.selectedIndex].value;
 
    	  YUD.get('pull_request_overview_url').href = url;
 
    	  YUD.setStyle(YUD.get('pull_request_overview_url').parentElement,'display','');
 
    	  YUD.get('other_repo_gravatar').src = other_repos_info[repo_name]['gravatar'];
 
    	  YUD.get('other_repo_desc').innerHTML = other_repos_info[repo_name]['description'];
 
    	  YUD.get('other_ref').innerHTML = other_repos_info[repo_name]['revs'];
 
      })
 
  }
 
  YUE.on('refresh','click',function(e){
 
     loadPreview()
0 comments (0 inline, 0 general)