diff --git a/rhodecode/apps/repository/tests/test_repo_pullrequests.py b/rhodecode/apps/repository/tests/test_repo_pullrequests.py --- a/rhodecode/apps/repository/tests/test_repo_pullrequests.py +++ b/rhodecode/apps/repository/tests/test_repo_pullrequests.py @@ -968,7 +968,7 @@ class TestPullrequestsView(object): 'csrf_token': csrf_token}) assert response.status_int == 200 - assert response.body == 'true' + assert response.body == '{"response": true, "redirect_url": null}' # Make sure that after update, it won't raise 500 errors response = self.app.get(route_path( diff --git a/rhodecode/apps/repository/views/repo_pull_requests.py b/rhodecode/apps/repository/views/repo_pull_requests.py --- a/rhodecode/apps/repository/views/repo_pull_requests.py +++ b/rhodecode/apps/repository/views/repo_pull_requests.py @@ -1051,12 +1051,14 @@ class RepoPullRequestsView(RepoAppView, _ = self.request.translate self.load_default_context() + redirect_url = None if pull_request.is_closed(): log.debug('update: forbidden because pull request is closed') msg = _(u'Cannot update closed pull requests.') h.flash(msg, category='error') - return True + return {'response': True, + 'redirect_url': redirect_url} if pull_request.pull_request_state != PullRequest.STATE_CREATED: log.debug('update: forbidden because pull request is in state %s', @@ -1065,13 +1067,15 @@ class RepoPullRequestsView(RepoAppView, u'Current state is: `{}`').format(PullRequest.STATE_CREATED, pull_request.pull_request_state) h.flash(msg, category='error') - return True + return {'response': True, + 'redirect_url': redirect_url} # only owner or admin can update it allowed_to_update = PullRequestModel().check_user_update( pull_request, self._rhodecode_user) if allowed_to_update: controls = peppercorn.parse(self.request.POST.items()) + force_refresh = str2bool(self.request.POST.get('force_refresh')) if 'review_members' in controls: self._update_reviewers( @@ -1079,11 +1083,18 @@ class RepoPullRequestsView(RepoAppView, pull_request.reviewer_data) elif str2bool(self.request.POST.get('update_commits', 'false')): self._update_commits(pull_request) + if force_refresh: + redirect_url = h.route_path( + 'pullrequest_show', repo_name=self.db_repo_name, + pull_request_id=pull_request.pull_request_id, + _query={"force_refresh": 1}) elif str2bool(self.request.POST.get('edit_pull_request', 'false')): self._edit_pull_request(pull_request) else: raise HTTPBadRequest() - return True + + return {'response': True, + 'redirect_url': redirect_url} raise HTTPForbidden() def _edit_pull_request(self, pull_request): diff --git a/rhodecode/public/css/buttons.less b/rhodecode/public/css/buttons.less --- a/rhodecode/public/css/buttons.less +++ b/rhodecode/public/css/buttons.less @@ -249,6 +249,54 @@ input[type="button"] { } + +.btn-group-actions { + position: relative; + z-index: 100; + + &:not(.open) .btn-action-switcher-container { + display: none; + } +} + + +.btn-action-switcher-container{ + position: absolute; + top: 30px; + left: 0px; +} + +.btn-action-switcher { + display: block; + position: relative; + z-index: 300; + min-width: 240px; + max-width: 500px; + margin-top: 4px; + margin-bottom: 24px; + font-size: 14px; + font-weight: 400; + padding: 8px 0; + background-color: #fff; + border: 1px solid @grey4; + border-radius: 3px; + box-shadow: @dropdown-shadow; + + li { + display: block; + text-align: left; + list-style: none; + padding: 5px 10px; + } + + li .action-help-block { + font-size: 10px; + line-height: normal; + color: @grey4; + } + +} + .btn-link { background: transparent; border: none; diff --git a/rhodecode/public/js/src/rhodecode/pullrequests.js b/rhodecode/public/js/src/rhodecode/pullrequests.js --- a/rhodecode/public/js/src/rhodecode/pullrequests.js +++ b/rhodecode/public/js/src/rhodecode/pullrequests.js @@ -343,18 +343,29 @@ var _updatePullRequest = function(repo_n } else { postData.csrf_token = CSRF_TOKEN; } + var success = function(o) { - window.location.reload(); + var redirectUrl = o['redirect_url']; + if (redirectUrl !== undefined && redirectUrl !== null && redirectUrl !== '') { + window.location = redirectUrl; + } else { + window.location.reload(); + } }; + ajaxPOST(url, postData, success); }; /** * PULL REQUEST update commits */ -var updateCommits = function(repo_name, pull_request_id) { +var updateCommits = function(repo_name, pull_request_id, force) { var postData = { - 'update_commits': true}; + 'update_commits': true + }; + if (force !== undefined && force === true) { + postData['force_refresh'] = true + } _updatePullRequest(repo_name, pull_request_id, postData); }; @@ -549,4 +560,49 @@ VersionController = function () { return false } +}; + + +UpdatePrController = function () { + var self = this; + this.$updateCommits = $('#update_commits'); + this.$updateCommitsSwitcher = $('#update_commits_switcher'); + + this.lockUpdateButton = function (label) { + self.$updateCommits.attr('disabled', 'disabled'); + self.$updateCommitsSwitcher.attr('disabled', 'disabled'); + + self.$updateCommits.addClass('disabled'); + self.$updateCommitsSwitcher.addClass('disabled'); + + self.$updateCommits.removeClass('btn-primary'); + self.$updateCommitsSwitcher.removeClass('btn-primary'); + + self.$updateCommits.text(_gettext(label)); + }; + + this.isUpdateLocked = function () { + return self.$updateCommits.attr('disabled') !== undefined; + }; + + this.updateCommits = function (curNode) { + if (self.isUpdateLocked()) { + return + } + self.lockUpdateButton(_gettext('Updating...')); + updateCommits( + templateContext.repo_name, + templateContext.pull_request_data.pull_request_id); + }; + + this.forceUpdateCommits = function () { + if (self.isUpdateLocked()) { + return + } + self.lockUpdateButton(_gettext('Force updating...')); + var force = true; + updateCommits( + templateContext.repo_name, + templateContext.pull_request_data.pull_request_id, force); + }; }; \ No newline at end of file diff --git a/rhodecode/templates/pullrequests/pullrequest_merge_checks.mako b/rhodecode/templates/pullrequests/pullrequest_merge_checks.mako --- a/rhodecode/templates/pullrequests/pullrequest_merge_checks.mako +++ b/rhodecode/templates/pullrequests/pullrequest_merge_checks.mako @@ -68,8 +68,6 @@
${_('refresh checks')} - / - forced recheck
diff --git a/rhodecode/templates/pullrequests/pullrequest_show.mako b/rhodecode/templates/pullrequests/pullrequest_show.mako --- a/rhodecode/templates/pullrequests/pullrequest_show.mako +++ b/rhodecode/templates/pullrequests/pullrequest_show.mako @@ -405,7 +405,30 @@
% if c.allowed_to_update and not c.pull_request.is_closed(): - ${_('Update commits')} + +
+ + ${_('Update commits')} + + + + + + +
+ +
+
+ % else: ${_('Update commits')} % endif @@ -584,6 +607,8 @@ reviewersController = new ReviewersController(); commitsController = new CommitsController(); + updateController = new UpdatePrController(); + $(function(){ // custom code mirror @@ -746,17 +771,7 @@ "${c.repo_name}", "${c.pull_request.pull_request_id}"); }); - $('#update_commits').on('click', function(e){ - var isDisabled = !$(e.currentTarget).attr('disabled'); - $(e.currentTarget).attr('disabled', 'disabled'); - $(e.currentTarget).addClass('disabled'); - $(e.currentTarget).removeClass('btn-primary'); - $(e.currentTarget).text(_gettext('Updating...')); - if(isDisabled){ - updateCommits( - "${c.repo_name}", "${c.pull_request.pull_request_id}"); - } - }); + // fixing issue with caches on firefox $('#update_commits').removeAttr("disabled");