pull-requests: moved force refresh to update commits button.

- this action make more sense right after updating pull-request with latest state of commits
- moving out of merge checks which shouldn't have this action as it's confusing
This commit is contained in:
Marcin Kuzminski 2019-11-26 12:21:13 +01:00
parent 152fa83aba
commit 18a751f846
6 changed files with 149 additions and 21 deletions

View file

@ -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(

View file

@ -1051,12 +1051,14 @@ class RepoPullRequestsView(RepoAppView, DataGridAppView):
_ = 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, DataGridAppView):
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, DataGridAppView):
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):

View file

@ -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;

View file

@ -343,18 +343,29 @@ var _updatePullRequest = function(repo_name, pull_request_id, postData) {
} 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);
};
};

View file

@ -68,8 +68,6 @@
<div class="pull-request-merge-refresh">
<a href="#refreshChecks" onclick="refreshMergeChecks(); return false;">${_('refresh checks')}</a>
/
<a class="tooltip" title="Force refresh of the merge workspace in case current status seems wrong." href="${h.route_path('pullrequest_show', repo_name=c.repo_name, pull_request_id=c.pull_request.pull_request_id,_query={"force_refresh":1})}">forced recheck</a>
</div>
</div>

View file

@ -405,7 +405,30 @@
<div class="pull-right">
% if c.allowed_to_update and not c.pull_request.is_closed():
<a id="update_commits" class="btn btn-primary no-margin pull-right">${_('Update commits')}</a>
<div class="btn-group btn-group-actions">
<a id="update_commits" class="btn btn-primary no-margin" onclick="updateController.updateCommits(this); return false">
${_('Update commits')}
</a>
<a id="update_commits_switcher" class="btn btn-primary" style="margin-left: -1px" data-toggle="dropdown" aria-pressed="false" role="button">
<i class="icon-down"></i>
</a>
<div class="btn-action-switcher-container" id="update-commits-switcher">
<ul class="btn-action-switcher" role="menu">
<li>
<a href="#forceUpdate" onclick="updateController.forceUpdateCommits(this); return false">
${_('Force update commits')}
</a>
<div class="action-help-block">
${_('Update commits and force refresh this pull request.')}
</div>
</li>
</ul>
</div>
</div>
% else:
<a class="tooltip btn disabled pull-right" disabled="disabled" title="${_('Update is disabled for current view')}">${_('Update commits')}</a>
% 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");