Skip to content

Commit

Permalink
fix issue update race condition
Browse files Browse the repository at this point in the history
fixes: #6191
  • Loading branch information
silverwind committed Feb 26, 2019
1 parent 7afe81f commit dee5852
Showing 1 changed file with 27 additions and 23 deletions.
50 changes: 27 additions & 23 deletions public/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -216,17 +216,19 @@ function initBranchSelector() {
});
}

function updateIssuesMeta(url, action, issueIds, elementId, afterSuccess) {
$.ajax({
type: "POST",
url: url,
data: {
"_csrf": csrf,
"action": action,
"issue_ids": issueIds,
"id": elementId
},
success: afterSuccess
function updateIssuesMeta(url, action, issueIds, elementId) {
return new Promise(function(resolve) {
$.ajax({
type: "POST",
url: url,
data: {
"_csrf": csrf,
"action": action,
"issue_ids": issueIds,
"id": elementId
},
success: resolve,
})
})
}

Expand Down Expand Up @@ -348,6 +350,10 @@ function uploadFile(file, callback) {
xhr.send(formData);
}

function reload() {
window.location.reload();
}

function initImagePaste(target) {
target.each(function(i, field) {
field.addEventListener('paste', function(event){
Expand Down Expand Up @@ -385,18 +391,20 @@ function initCommentForm() {
$('.' + selector).dropdown('setting', 'onHide', function(){
hasLabelUpdateAction = $listMenu.data('action') == 'update'; // Update the var
if (hasLabelUpdateAction) {
var promises = [];
for (var elementId in labels) {
if (labels.hasOwnProperty(elementId)) {
var label = labels[elementId];
updateIssuesMeta(
var promise = updateIssuesMeta(
label["update-url"],
label["action"],
label["issue-id"],
elementId
);
promises.push(promise);
}
}
location.reload();
Promise.all(promises).then(reload);
}
});

Expand Down Expand Up @@ -519,8 +527,7 @@ function initCommentForm() {
"",
$menu.data('issue-id'),
$(this).data('id'),
function() { location.reload(); }
);
).then(reload);
}
switch (input_id) {
case '#milestone_id':
Expand All @@ -546,8 +553,7 @@ function initCommentForm() {
"",
$menu.data('issue-id'),
$(this).data('id'),
function() { location.reload(); }
);
).then(reload);
}

$list.find('.selected').html('');
Expand Down Expand Up @@ -801,7 +807,7 @@ function initRepository() {
function (data) {
$editInput.val(data.title);
$issueTitle.text(data.title);
location.reload();
reload();
});
return false;
});
Expand Down Expand Up @@ -1786,7 +1792,7 @@ function u2fRegistered(resp) {
data: JSON.stringify(resp),
contentType: "application/json; charset=utf-8",
success: function(){
window.location.reload();
reload();
},
fail: function (xhr, textStatus) {
u2fError(1);
Expand Down Expand Up @@ -2073,9 +2079,7 @@ $(document).ready(function () {
return this.dataset.issueId;
}).get().join();
var url = this.dataset.url
updateIssuesMeta(url, action, issueIDs, elementId, function() {
location.reload();
});
updateIssuesMeta(url, action, issueIDs, elementId).then(reload);
});

buttonsClickOnEnter();
Expand Down Expand Up @@ -2912,7 +2916,7 @@ function updateDeadline(deadlineString) {
contentType: 'application/json',
type: 'POST',
success: function () {
window.location.reload();
reload();
},
error: function () {
$('#deadline-loader').removeClass('loading');
Expand Down

0 comments on commit dee5852

Please sign in to comment.