UI: Fix race in update issue labels and assignees (#6194)

Fix #6191 

* fix issue update race condition
* fix similar race same race when clearing assignee
* always load promise polyfill
* replace es6-promise with promise-polyfill
* move promise-polyfill to <head>
release/v1.15
silverwind 2019-02-28 23:10:08 +01:00 committed by zeripath
parent 4a2e92bcd1
commit 8e266c3193
6 changed files with 35 additions and 32 deletions

View File

@ -216,17 +216,19 @@ function initBranchSelector() {
}); });
} }
function updateIssuesMeta(url, action, issueIds, elementId, afterSuccess) { function updateIssuesMeta(url, action, issueIds, elementId) {
$.ajax({ return new Promise(function(resolve) {
type: "POST", $.ajax({
url: url, type: "POST",
data: { url: url,
"_csrf": csrf, data: {
"action": action, "_csrf": csrf,
"issue_ids": issueIds, "action": action,
"id": elementId "issue_ids": issueIds,
}, "id": elementId
success: afterSuccess },
success: resolve
})
}) })
} }
@ -348,6 +350,10 @@ function uploadFile(file, callback) {
xhr.send(formData); xhr.send(formData);
} }
function reload() {
window.location.reload();
}
function initImagePaste(target) { function initImagePaste(target) {
target.each(function(i, field) { target.each(function(i, field) {
field.addEventListener('paste', function(event){ field.addEventListener('paste', function(event){
@ -385,18 +391,20 @@ function initCommentForm() {
$('.' + selector).dropdown('setting', 'onHide', function(){ $('.' + selector).dropdown('setting', 'onHide', function(){
hasLabelUpdateAction = $listMenu.data('action') == 'update'; // Update the var hasLabelUpdateAction = $listMenu.data('action') == 'update'; // Update the var
if (hasLabelUpdateAction) { if (hasLabelUpdateAction) {
var promises = [];
for (var elementId in labels) { for (var elementId in labels) {
if (labels.hasOwnProperty(elementId)) { if (labels.hasOwnProperty(elementId)) {
var label = labels[elementId]; var label = labels[elementId];
updateIssuesMeta( var promise = updateIssuesMeta(
label["update-url"], label["update-url"],
label["action"], label["action"],
label["issue-id"], label["issue-id"],
elementId elementId
); );
promises.push(promise);
} }
} }
location.reload(); Promise.all(promises).then(reload);
} }
}); });
@ -479,8 +487,7 @@ function initCommentForm() {
"clear", "clear",
$listMenu.data('issue-id'), $listMenu.data('issue-id'),
"" ""
); ).then(reload);
$listMenu.data('action', 'update'); // Update to reload the page when we updated items
} }
$(this).parent().find('.item').each(function () { $(this).parent().find('.item').each(function () {
@ -518,9 +525,8 @@ function initCommentForm() {
$menu.data('update-url'), $menu.data('update-url'),
"", "",
$menu.data('issue-id'), $menu.data('issue-id'),
$(this).data('id'), $(this).data('id')
function() { location.reload(); } ).then(reload);
);
} }
switch (input_id) { switch (input_id) {
case '#milestone_id': case '#milestone_id':
@ -545,9 +551,8 @@ function initCommentForm() {
$menu.data('update-url'), $menu.data('update-url'),
"", "",
$menu.data('issue-id'), $menu.data('issue-id'),
$(this).data('id'), $(this).data('id')
function() { location.reload(); } ).then(reload);
);
} }
$list.find('.selected').html(''); $list.find('.selected').html('');
@ -801,7 +806,7 @@ function initRepository() {
function (data) { function (data) {
$editInput.val(data.title); $editInput.val(data.title);
$issueTitle.text(data.title); $issueTitle.text(data.title);
location.reload(); reload();
}); });
return false; return false;
}); });
@ -1786,7 +1791,7 @@ function u2fRegistered(resp) {
data: JSON.stringify(resp), data: JSON.stringify(resp),
contentType: "application/json; charset=utf-8", contentType: "application/json; charset=utf-8",
success: function(){ success: function(){
window.location.reload(); reload();
}, },
fail: function (xhr, textStatus) { fail: function (xhr, textStatus) {
u2fError(1); u2fError(1);
@ -2073,9 +2078,7 @@ $(document).ready(function () {
return this.dataset.issueId; return this.dataset.issueId;
}).get().join(); }).get().join();
var url = this.dataset.url var url = this.dataset.url
updateIssuesMeta(url, action, issueIDs, elementId, function() { updateIssuesMeta(url, action, issueIDs, elementId).then(reload);
location.reload();
});
}); });
buttonsClickOnEnter(); buttonsClickOnEnter();
@ -2912,7 +2915,7 @@ function updateDeadline(deadlineString) {
contentType: 'application/json', contentType: 'application/json',
type: 'POST', type: 'POST',
success: function () { success: function () {
window.location.reload(); reload();
}, },
error: function () { error: function () {
$('#deadline-loader').removeClass('loading'); $('#deadline-loader').removeClass('loading');

View File

@ -146,9 +146,9 @@
<td><a href="https://github.com/moment/moment/archive/2.22.2.tar.gz">0.4.1.tar.gz</a></td> <td><a href="https://github.com/moment/moment/archive/2.22.2.tar.gz">0.4.1.tar.gz</a></td>
</tr> </tr>
<tr> <tr>
<td><a href="./plugins/es6-promise/">es6-promise</a></td> <td><a href="./plugins/promise-polyfill/">promise-polyfill</a></td>
<td><a href="https://github.com/stefanpenner/es6-promise/blob/master/LICENSE">MIT</a></td> <td><a href="https://github.com/taylorhakes/promise-polyfill/blob/master/LICENSE">MIT</a></td>
<td><a href="https://github.com/stefanpenner/es6-promise/archive/v4.2.6.tar.gz">4.2.6.tar.gz</a></td> <td><a href="https://github.com/taylorhakes/promise-polyfill/archive/8.1.0.tar.gz">8.1.0.tar.gz</a></td>
</tr> </tr>
</tbody> </tbody>
</table> </table>

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1 @@
!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?n():"function"==typeof define&&define.amd?define(n):n()}(0,function(){"use strict";function e(e){var n=this.constructor;return this.then(function(t){return n.resolve(e()).then(function(){return t})},function(t){return n.resolve(e()).then(function(){return n.reject(t)})})}function n(){}function t(e){if(!(this instanceof t))throw new TypeError("Promises must be constructed via new");if("function"!=typeof e)throw new TypeError("not a function");this._state=0,this._handled=!1,this._value=undefined,this._deferreds=[],u(e,this)}function o(e,n){for(;3===e._state;)e=e._value;0!==e._state?(e._handled=!0,t._immediateFn(function(){var t=1===e._state?n.onFulfilled:n.onRejected;if(null!==t){var o;try{o=t(e._value)}catch(f){return void i(n.promise,f)}r(n.promise,o)}else(1===e._state?r:i)(n.promise,e._value)})):e._deferreds.push(n)}function r(e,n){try{if(n===e)throw new TypeError("A promise cannot be resolved with itself.");if(n&&("object"==typeof n||"function"==typeof n)){var o=n.then;if(n instanceof t)return e._state=3,e._value=n,void f(e);if("function"==typeof o)return void u(function(e,n){return function(){e.apply(n,arguments)}}(o,n),e)}e._state=1,e._value=n,f(e)}catch(r){i(e,r)}}function i(e,n){e._state=2,e._value=n,f(e)}function f(e){2===e._state&&0===e._deferreds.length&&t._immediateFn(function(){e._handled||t._unhandledRejectionFn(e._value)});for(var n=0,r=e._deferreds.length;r>n;n++)o(e,e._deferreds[n]);e._deferreds=null}function u(e,n){var t=!1;try{e(function(e){t||(t=!0,r(n,e))},function(e){t||(t=!0,i(n,e))})}catch(o){if(t)return;t=!0,i(n,o)}}var c=setTimeout;t.prototype["catch"]=function(e){return this.then(null,e)},t.prototype.then=function(e,t){var r=new this.constructor(n);return o(this,new function(e,n,t){this.onFulfilled="function"==typeof e?e:null,this.onRejected="function"==typeof n?n:null,this.promise=t}(e,t,r)),r},t.prototype["finally"]=e,t.all=function(e){return new t(function(n,t){function o(e,f){try{if(f&&("object"==typeof f||"function"==typeof f)){var u=f.then;if("function"==typeof u)return void u.call(f,function(n){o(e,n)},t)}r[e]=f,0==--i&&n(r)}catch(c){t(c)}}if(!e||"undefined"==typeof e.length)throw new TypeError("Promise.all accepts an array");var r=Array.prototype.slice.call(e);if(0===r.length)return n([]);for(var i=r.length,f=0;r.length>f;f++)o(f,r[f])})},t.resolve=function(e){return e&&"object"==typeof e&&e.constructor===t?e:new t(function(n){n(e)})},t.reject=function(e){return new t(function(n,t){t(e)})},t.race=function(e){return new t(function(n,t){for(var o=0,r=e.length;r>o;o++)e[o].then(n,t)})},t._immediateFn="function"==typeof setImmediate&&function(e){setImmediate(e)}||function(e){c(e,0)},t._unhandledRejectionFn=function(e){void 0!==console&&console&&console.warn("Possible Unhandled Promise Rejection:",e)};var l=function(){if("undefined"!=typeof self)return self;if("undefined"!=typeof window)return window;if("undefined"!=typeof global)return global;throw Error("unable to locate global object")}();"Promise"in l?l.Promise.prototype["finally"]||(l.Promise.prototype["finally"]=e):l.Promise=t});

View File

@ -122,7 +122,6 @@
<script src="{{AppSubUrl}}/vendor/plugins/semantic/semantic.min.js"></script> <script src="{{AppSubUrl}}/vendor/plugins/semantic/semantic.min.js"></script>
<script src="{{AppSubUrl}}/js/index.js?v={{MD5 AppVer}}"></script> <script src="{{AppSubUrl}}/js/index.js?v={{MD5 AppVer}}"></script>
{{if .EnableHeatmap}} {{if .EnableHeatmap}}
<script src="{{AppSubUrl}}/vendor/plugins/es6-promise/es6-promise.auto.min.js" charset="utf-8"></script>
<script src="{{AppSubUrl}}/vendor/plugins/moment/moment.min.js" charset="utf-8"></script> <script src="{{AppSubUrl}}/vendor/plugins/moment/moment.min.js" charset="utf-8"></script>
<script src="{{AppSubUrl}}/vendor/plugins/vue-calendar-heatmap/vue-calendar-heatmap.browser.js" charset="utf-8"></script> <script src="{{AppSubUrl}}/vendor/plugins/vue-calendar-heatmap/vue-calendar-heatmap.browser.js" charset="utf-8"></script>
<script type="text/javascript"> <script type="text/javascript">

View File

@ -123,6 +123,7 @@
{{end}} {{end}}
<style class="list-search-style"></style> <style class="list-search-style"></style>
<script src="{{AppSubUrl}}/vendor/plugins/promise-polyfill/polyfill.min.js"></script>
<script src="{{AppSubUrl}}/vendor/plugins/cssrelpreload/loadCSS.min.js"></script> <script src="{{AppSubUrl}}/vendor/plugins/cssrelpreload/loadCSS.min.js"></script>
<script src="{{AppSubUrl}}/vendor/plugins/cssrelpreload/cssrelpreload.min.js"></script> <script src="{{AppSubUrl}}/vendor/plugins/cssrelpreload/cssrelpreload.min.js"></script>
{{if .PageIsUserProfile}} {{if .PageIsUserProfile}}