Commit 9846332f authored by Phil Hughes's avatar Phil Hughes

Convered compare.js to axios

parent 33517d54
/* eslint-disable func-names, space-before-function-paren, wrap-iife, quotes, no-var, object-shorthand, consistent-return, no-unused-vars, comma-dangle, vars-on-top, prefer-template, max-len */ /* eslint-disable func-names, space-before-function-paren, wrap-iife, quotes, no-var, object-shorthand, consistent-return, no-unused-vars, comma-dangle, vars-on-top, prefer-template, max-len */
import { localTimeAgo } from './lib/utils/datetime_utility'; import { localTimeAgo } from './lib/utils/datetime_utility';
import axios from './lib/utils/axios_utils';
export default class Compare { export default class Compare {
constructor(opts) { constructor(opts) {
...@@ -41,17 +42,14 @@ export default class Compare { ...@@ -41,17 +42,14 @@ export default class Compare {
} }
getTargetProject() { getTargetProject() {
return $.ajax({ $('.mr_target_commit').empty();
url: this.opts.targetProjectUrl,
data: { return axios.get(this.opts.targetProjectUrl, {
target_project_id: $("input[name='merge_request[target_project_id]']").val() params: {
}, target_project_id: $("input[name='merge_request[target_project_id]']").val(),
beforeSend: function() {
return $('.mr_target_commit').empty();
}, },
success: function(html) { }).then(({ data }) => {
return $('.js-target-branch-dropdown .dropdown-content').html(html); $('.js-target-branch-dropdown .dropdown-content').html(data);
}
}); });
} }
...@@ -68,22 +66,19 @@ export default class Compare { ...@@ -68,22 +66,19 @@ export default class Compare {
}); });
} }
static sendAjax(url, loading, target, data) { static sendAjax(url, loading, target, params) {
var $target; const $target = $(target);
$target = $(target);
return $.ajax({
url: url,
data: data,
beforeSend: function() {
loading.show(); loading.show();
return $target.empty(); $target.empty();
},
success: function(html) { return axios.get(url, {
params,
}).then(({ data }) => {
loading.hide(); loading.hide();
$target.html(html); $target.html(data);
var className = '.' + $target[0].className.replace(' ', '.'); var className = '.' + $target[0].className.replace(' ', '.');
localTimeAgo($('.js-timeago', className)); localTimeAgo($('.js-timeago', className));
}
}); });
} }
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment