Commit 3ae2d90b authored by Phil Hughes's avatar Phil Hughes

Converted milestone_select.js to axios

parent d58ff943
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
/* global Issuable */ /* global Issuable */
/* global ListMilestone */ /* global ListMilestone */
import _ from 'underscore'; import _ from 'underscore';
import axios from './lib/utils/axios_utils';
import { timeFor } from './lib/utils/datetime_utility'; import { timeFor } from './lib/utils/datetime_utility';
export default class MilestoneSelect { export default class MilestoneSelect {
...@@ -52,48 +53,47 @@ export default class MilestoneSelect { ...@@ -52,48 +53,47 @@ export default class MilestoneSelect {
} }
return $dropdown.glDropdown({ return $dropdown.glDropdown({
showMenuAbove: showMenuAbove, showMenuAbove: showMenuAbove,
data: (term, callback) => $.ajax({ data: (term, callback) => axios.get(milestonesUrl)
url: milestonesUrl .then(({ data }) => {
}).done((data) => { const extraOptions = [];
const extraOptions = []; if (showAny) {
if (showAny) { extraOptions.push({
extraOptions.push({ id: 0,
id: 0, name: '',
name: '', title: 'Any Milestone'
title: 'Any Milestone' });
}); }
} if (showNo) {
if (showNo) { extraOptions.push({
extraOptions.push({ id: -1,
id: -1, name: 'No Milestone',
name: 'No Milestone', title: 'No Milestone'
title: 'No Milestone' });
}); }
} if (showUpcoming) {
if (showUpcoming) { extraOptions.push({
extraOptions.push({ id: -2,
id: -2, name: '#upcoming',
name: '#upcoming', title: 'Upcoming'
title: 'Upcoming' });
}); }
} if (showStarted) {
if (showStarted) { extraOptions.push({
extraOptions.push({ id: -3,
id: -3, name: '#started',
name: '#started', title: 'Started'
title: 'Started' });
}); }
} if (extraOptions.length) {
if (extraOptions.length) { extraOptions.push('divider');
extraOptions.push('divider'); }
}
callback(extraOptions.concat(data)); callback(extraOptions.concat(data));
if (showMenuAbove) { if (showMenuAbove) {
$dropdown.data('glDropdown').positionMenuAbove(); $dropdown.data('glDropdown').positionMenuAbove();
} }
$(`[data-milestone-id="${selectedMilestone}"] > a`).addClass('is-active'); $(`[data-milestone-id="${selectedMilestone}"] > a`).addClass('is-active');
}), }),
renderRow: milestone => ` renderRow: milestone => `
<li data-milestone-id="${milestone.name}"> <li data-milestone-id="${milestone.name}">
<a href='#' class='dropdown-menu-milestone-link'> <a href='#' class='dropdown-menu-milestone-link'>
...@@ -200,26 +200,23 @@ export default class MilestoneSelect { ...@@ -200,26 +200,23 @@ export default class MilestoneSelect {
data[abilityName].milestone_id = selected != null ? selected : null; data[abilityName].milestone_id = selected != null ? selected : null;
$loading.removeClass('hidden').fadeIn(); $loading.removeClass('hidden').fadeIn();
$dropdown.trigger('loading.gl.dropdown'); $dropdown.trigger('loading.gl.dropdown');
return $.ajax({ return axios.put(issueUpdateURL, data)
type: 'PUT', .then(({ data }) => {
url: issueUpdateURL, $dropdown.trigger('loaded.gl.dropdown');
data: data $loading.fadeOut();
}).done((data) => { $selectBox.hide();
$dropdown.trigger('loaded.gl.dropdown'); $value.css('display', '');
$loading.fadeOut(); if (data.milestone != null) {
$selectBox.hide(); data.milestone.full_path = this.currentProject.full_path;
$value.css('display', ''); data.milestone.remaining = timeFor(data.milestone.due_date);
if (data.milestone != null) { data.milestone.name = data.milestone.title;
data.milestone.full_path = this.currentProject.full_path; $value.html(milestoneLinkTemplate(data.milestone));
data.milestone.remaining = timeFor(data.milestone.due_date); return $sidebarCollapsedValue.find('span').html(collapsedSidebarLabelTemplate(data.milestone));
data.milestone.name = data.milestone.title; } else {
$value.html(milestoneLinkTemplate(data.milestone)); $value.html(milestoneLinkNoneTemplate);
return $sidebarCollapsedValue.find('span').html(collapsedSidebarLabelTemplate(data.milestone)); return $sidebarCollapsedValue.find('span').text('No');
} else { }
$value.html(milestoneLinkNoneTemplate); });
return $sidebarCollapsedValue.find('span').text('No');
}
});
} }
} }
}); });
......
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