diff options
author | Phil Hughes <me@iamphill.com> | 2018-01-30 17:23:27 +0000 |
---|---|---|
committer | Phil Hughes <me@iamphill.com> | 2018-01-30 17:23:27 +0000 |
commit | 58eb3c55c9d15bd604b926ffeae9401f0b70c53c (patch) | |
tree | 06c8a2ef5eb02166b143c3677ebc2d0e198f431c /app/assets/javascripts/merge_request_tabs.js | |
parent | 8750507b5db62e7821380d075d46d1a1c4eaca9d (diff) | |
download | gitlab-ce-58eb3c55c9d15bd604b926ffeae9401f0b70c53c.tar.gz |
Converted merge_request_tabs.js to axios
Diffstat (limited to 'app/assets/javascripts/merge_request_tabs.js')
-rw-r--r-- | app/assets/javascripts/merge_request_tabs.js | 39 |
1 files changed, 18 insertions, 21 deletions
diff --git a/app/assets/javascripts/merge_request_tabs.js b/app/assets/javascripts/merge_request_tabs.js index acfc62fe5cb..f69506a0471 100644 --- a/app/assets/javascripts/merge_request_tabs.js +++ b/app/assets/javascripts/merge_request_tabs.js @@ -1,6 +1,7 @@ /* eslint-disable no-new, class-methods-use-this */ import Cookies from 'js-cookie'; +import axios from './lib/utils/axios_utils'; import Flash from './flash'; import BlobForkSuggestion from './blob/blob_fork_suggestion'; import initChangesDropdown from './init_changes_dropdown'; @@ -244,15 +245,19 @@ export default class MergeRequestTabs { if (this.commitsLoaded) { return; } - this.ajaxGet({ - url: `${source}.json`, - success: (data) => { + + this.toggleLoading(true) + + axios.get(`${source}.json`) + .then(({ data }) => { document.querySelector('div#commits').innerHTML = data.html; localTimeAgo($('.js-timeago', 'div#commits')); this.commitsLoaded = true; this.scrollToElement('#commits'); - }, - }); + + this.toggleLoading(false); + }) + .catch(() => new Flash('An error occurred while fetching this tab.', 'alert')); } mountPipelinesView() { @@ -283,9 +288,10 @@ export default class MergeRequestTabs { // some pages like MergeRequestsController#new has query parameters on that anchor const urlPathname = parseUrlPathname(source); - this.ajaxGet({ - url: `${urlPathname}.json${location.search}`, - success: (data) => { + this.toggleLoading(true); + + axios.get(`${urlPathname}.json${location.search}`) + .then(({ data }) => { const $container = $('#diffs'); $container.html(data.html); @@ -335,8 +341,10 @@ export default class MergeRequestTabs { // (discussion and diff tabs) and `:target` only applies to the first anchor.addClass('target'); } - }, - }); + + this.toggleLoading(false); + }) + .catch(() => Flash('An error occurred while fetching this tab.', 'alert')); } // Show or hide the loading spinner @@ -346,17 +354,6 @@ export default class MergeRequestTabs { $('.mr-loading-status .loading').toggle(status); } - ajaxGet(options) { - const defaults = { - beforeSend: () => this.toggleLoading(true), - error: () => new Flash('An error occurred while fetching this tab.', 'alert'), - complete: () => this.toggleLoading(false), - dataType: 'json', - type: 'GET', - }; - $.ajax($.extend({}, defaults, options)); - } - diffViewType() { return $('.inline-parallel-buttons a.active').data('view-type'); } |