Commit 05a3479c authored by Phil Hughes's avatar Phil Hughes

Converted labels_select.js to axios

parent d5041184
...@@ -2,9 +2,12 @@ ...@@ -2,9 +2,12 @@
/* global Issuable */ /* global Issuable */
/* global ListLabel */ /* global ListLabel */
import _ from 'underscore'; import _ from 'underscore';
import { __ } from './locale';
import axios from './lib/utils/axios_utils';
import IssuableBulkUpdateActions from './issuable_bulk_update_actions'; import IssuableBulkUpdateActions from './issuable_bulk_update_actions';
import DropdownUtils from './filtered_search/dropdown_utils'; import DropdownUtils from './filtered_search/dropdown_utils';
import CreateLabelDropdown from './create_label'; import CreateLabelDropdown from './create_label';
import flash from './flash';
export default class LabelsSelect { export default class LabelsSelect {
constructor(els, options = {}) { constructor(els, options = {}) {
...@@ -82,99 +85,96 @@ export default class LabelsSelect { ...@@ -82,99 +85,96 @@ export default class LabelsSelect {
} }
$loading.removeClass('hidden').fadeIn(); $loading.removeClass('hidden').fadeIn();
$dropdown.trigger('loading.gl.dropdown'); $dropdown.trigger('loading.gl.dropdown');
return $.ajax({ axios.put(issueUpdateURL, data)
type: 'PUT', .then(({ data }) => {
url: issueUpdateURL, var labelCount, template, labelTooltipTitle, labelTitles;
dataType: 'JSON', $loading.fadeOut();
data: data $dropdown.trigger('loaded.gl.dropdown');
}).done(function(data) { $selectbox.hide();
var labelCount, template, labelTooltipTitle, labelTitles; data.issueURLSplit = issueURLSplit;
$loading.fadeOut(); labelCount = 0;
$dropdown.trigger('loaded.gl.dropdown'); if (data.labels.length) {
$selectbox.hide(); template = labelHTMLTemplate(data);
data.issueURLSplit = issueURLSplit; labelCount = data.labels.length;
labelCount = 0;
if (data.labels.length) {
template = labelHTMLTemplate(data);
labelCount = data.labels.length;
}
else {
template = labelNoneHTMLTemplate;
}
$value.removeAttr('style').html(template);
$sidebarCollapsedValue.text(labelCount);
if (data.labels.length) {
labelTitles = data.labels.map(function(label) {
return label.title;
});
if (labelTitles.length > 5) {
labelTitles = labelTitles.slice(0, 5);
labelTitles.push('and ' + (data.labels.length - 5) + ' more');
} }
else {
labelTooltipTitle = labelTitles.join(', '); template = labelNoneHTMLTemplate;
} }
else { $value.removeAttr('style').html(template);
labelTooltipTitle = ''; $sidebarCollapsedValue.text(labelCount);
$sidebarLabelTooltip.tooltip('destroy');
} if (data.labels.length) {
labelTitles = data.labels.map(function(label) {
$sidebarLabelTooltip return label.title;
.attr('title', labelTooltipTitle) });
.tooltip('fixTitle');
if (labelTitles.length > 5) {
$('.has-tooltip', $value).tooltip({ labelTitles = labelTitles.slice(0, 5);
container: 'body' labelTitles.push('and ' + (data.labels.length - 5) + ' more');
}); }
});
labelTooltipTitle = labelTitles.join(', ');
}
else {
labelTooltipTitle = '';
$sidebarLabelTooltip.tooltip('destroy');
}
$sidebarLabelTooltip
.attr('title', labelTooltipTitle)
.tooltip('fixTitle');
$('.has-tooltip', $value).tooltip({
container: 'body'
});
})
.catch(() => flash(__('Error saving label update.')));
}; };
$dropdown.glDropdown({ $dropdown.glDropdown({
showMenuAbove: showMenuAbove, showMenuAbove: showMenuAbove,
data: function(term, callback) { data: function(term, callback) {
return $.ajax({ axios.get(labelUrl)
url: labelUrl .then((res) => {
}).done(function(data) { let data = _.chain(res.data).groupBy(function(label) {
data = _.chain(data).groupBy(function(label) { return label.title;
return label.title; }).map(function(label) {
}).map(function(label) { var color;
var color; color = _.map(label, function(dup) {
color = _.map(label, function(dup) { return dup.color;
return dup.color;
});
return {
id: label[0].id,
title: label[0].title,
color: color,
duplicate: color.length > 1
};
}).value();
if ($dropdown.hasClass('js-extra-options')) {
var extraData = [];
if (showNo) {
extraData.unshift({
id: 0,
title: 'No Label'
});
}
if (showAny) {
extraData.unshift({
isAny: true,
title: 'Any Label'
}); });
return {
id: label[0].id,
title: label[0].title,
color: color,
duplicate: color.length > 1
};
}).value();
if ($dropdown.hasClass('js-extra-options')) {
var extraData = [];
if (showNo) {
extraData.unshift({
id: 0,
title: 'No Label'
});
}
if (showAny) {
extraData.unshift({
isAny: true,
title: 'Any Label'
});
}
if (extraData.length) {
extraData.push('divider');
data = extraData.concat(data);
}
} }
if (extraData.length) {
extraData.push('divider'); callback(data);
data = extraData.concat(data); if (showMenuAbove) {
$dropdown.data('glDropdown').positionMenuAbove();
} }
} })
.catch(() => flash(__('Error fetching labels.')));
callback(data);
if (showMenuAbove) {
$dropdown.data('glDropdown').positionMenuAbove();
}
});
}, },
renderRow: function(label, instance) { renderRow: function(label, instance) {
var $a, $li, color, colorEl, indeterminate, removesAll, selectedClass, spacing, i, marked, dropdownName, dropdownValue; var $a, $li, color, colorEl, indeterminate, removesAll, selectedClass, spacing, i, marked, dropdownName, dropdownValue;
......
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