changeset 2847:1cd0a0c05f42 beta

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
author Marcin Kuzminski <marcin@python-works.com>
date Wed, 19 Sep 2012 00:03:43 +0200
parents 620669b2a88b
children f3aee4585f39
files rhodecode/controllers/compare.py rhodecode/templates/pullrequests/pullrequest.html
diffstat 2 files changed, 19 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/rhodecode/controllers/compare.py	Mon Sep 17 22:19:55 2012 +0200
+++ b/rhodecode/controllers/compare.py	Wed Sep 19 00:03:43 2012 +0200
@@ -39,6 +39,7 @@
 
 from rhodecode.model.db import Repository
 from rhodecode.model.pull_request import PullRequestModel
+from webob.exc import HTTPBadRequest
 
 log = logging.getLogger(__name__)
 
@@ -51,10 +52,12 @@
     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
@@ -73,7 +76,9 @@
         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):
 
@@ -97,9 +102,9 @@
         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
@@ -110,7 +115,7 @@
         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]
--- a/rhodecode/templates/pullrequests/pullrequest.html	Mon Sep 17 22:19:55 2012 +0200
+++ b/rhodecode/templates/pullrequests/pullrequest.html	Wed Sep 19 00:03:43 2012 +0200
@@ -135,6 +135,7 @@
   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',
@@ -167,6 +168,12 @@
         }
       }
 
+      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;