Marcin Kuzminski committed 1cd0a0c

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

  • Participants
  • Parent commits 620669b

Comments (0)

Files changed (2)

File rhodecode/controllers/

 from rhodecode.model.db import Repository
 from rhodecode.model.pull_request import PullRequestModel
+from webob.exc import HTTPBadRequest
 log = logging.getLogger(__name__)
     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
         except RepositoryError, e:
             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):
         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.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]

File rhodecode/templates/pullrequests/pullrequest.html

   PullRequestAutoComplete('user', 'reviewers_container', _USERS_AC_DATA, _GROUPS_AC_DATA);
   var other_repos_info = ${c.other_repos_info|n};
   var loadPreview = function(){
       var url = "${h.url('compare_url',
+      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;