Fix dropdown title when No Label selected.

This commit is contained in:
Fatih Acet 2016-10-04 17:52:35 +03:00
parent 88857a2c3b
commit 20408363ee
2 changed files with 41 additions and 23 deletions

View file

@ -79,7 +79,8 @@
if (data.labels.length) { if (data.labels.length) {
template = labelHTMLTemplate(data); template = labelHTMLTemplate(data);
labelCount = data.labels.length; labelCount = data.labels.length;
} else { }
else {
template = labelNoneHTMLTemplate; template = labelNoneHTMLTemplate;
} }
$value.removeAttr('style').html(template); $value.removeAttr('style').html(template);
@ -96,7 +97,8 @@
} }
labelTooltipTitle = labelTitles.join(', '); labelTooltipTitle = labelTitles.join(', ');
} else { }
else {
labelTooltipTitle = ''; labelTooltipTitle = '';
$sidebarLabelTooltip.tooltip('destroy'); $sidebarLabelTooltip.tooltip('destroy');
} }
@ -200,14 +202,16 @@
return color + " " + percentFirst + "%," + color + " " + percentSecond + "% "; return color + " " + percentFirst + "%," + color + " " + percentSecond + "% ";
}).join(','); }).join(',');
color = "linear-gradient(" + color + ")"; color = "linear-gradient(" + color + ")";
} else { }
else {
if (label.color != null) { if (label.color != null) {
color = label.color[0]; color = label.color[0];
} }
} }
if (color) { if (color) {
colorEl = "<span class='dropdown-label-box' style='background: " + color + "'></span>"; colorEl = "<span class='dropdown-label-box' style='background: " + color + "'></span>";
} else { }
else {
colorEl = ''; colorEl = '';
} }
// We need to identify which items are actually labels // We need to identify which items are actually labels
@ -227,23 +231,29 @@
filterable: true, filterable: true,
selected: $dropdown.data('selected') || [], selected: $dropdown.data('selected') || [],
toggleLabel: function(selected, el) { toggleLabel: function(selected, el) {
var isSelected = el !== null ? el.hasClass('is-active') : false, var isSelected = el !== null ? el.hasClass('is-active') : false;
title = selected.title; var title = selected.title;
var selectedLabels = this.selected;
if (isSelected) { if (selected.id === 0) {
this.selected = [];
return 'No Label';
}
else if (isSelected) {
this.selected.push(title); this.selected.push(title);
} else { }
else {
var index = this.selected.indexOf(title); var index = this.selected.indexOf(title);
this.selected.splice(index, 1); this.selected.splice(index, 1);
} }
var selectedLabels = this.selected;
if (selectedLabels.length === 1) { if (selectedLabels.length === 1) {
return selectedLabels; return selectedLabels;
} else if (selectedLabels.length > 1) { }
else if (selectedLabels.length) {
return selectedLabels[0] + " +" + (selectedLabels.length - 1) + " more"; return selectedLabels[0] + " +" + (selectedLabels.length - 1) + " more";
} else { }
else {
return defaultLabel; return defaultLabel;
} }
}, },
@ -257,7 +267,8 @@
if ($dropdown.hasClass("js-filter-submit") && (label.isAny == null)) { if ($dropdown.hasClass("js-filter-submit") && (label.isAny == null)) {
return label.title; return label.title;
} else { }
else {
return label.id; return label.id;
} }
}, },
@ -281,9 +292,11 @@
if ($dropdown.hasClass('js-filter-submit') && (isIssueIndex || isMRIndex)) { if ($dropdown.hasClass('js-filter-submit') && (isIssueIndex || isMRIndex)) {
selectedLabels = $dropdown.closest('form').find("input:hidden[name='" + ($dropdown.data('fieldName')) + "']"); selectedLabels = $dropdown.closest('form').find("input:hidden[name='" + ($dropdown.data('fieldName')) + "']");
Issuable.filterResults($dropdown.closest('form')); Issuable.filterResults($dropdown.closest('form'));
} else if ($dropdown.hasClass('js-filter-submit')) { }
else if ($dropdown.hasClass('js-filter-submit')) {
$dropdown.closest('form').submit(); $dropdown.closest('form').submit();
} else { }
else {
if (!$dropdown.hasClass('js-filter-bulk-update')) { if (!$dropdown.hasClass('js-filter-bulk-update')) {
saveLabelData(); saveLabelData();
} }
@ -317,9 +330,11 @@
if (page === 'projects:boards:show') { if (page === 'projects:boards:show') {
if (label.isAny) { if (label.isAny) {
gl.issueBoards.BoardsStore.state.filters['label_name'] = []; gl.issueBoards.BoardsStore.state.filters['label_name'] = [];
} else if ($el.hasClass('is-active')) { }
else if ($el.hasClass('is-active')) {
gl.issueBoards.BoardsStore.state.filters['label_name'].push(label.title); gl.issueBoards.BoardsStore.state.filters['label_name'].push(label.title);
} else { }
else {
var filters = gl.issueBoards.BoardsStore.state.filters['label_name']; var filters = gl.issueBoards.BoardsStore.state.filters['label_name'];
filters = filters.filter(function (filteredLabel) { filters = filters.filter(function (filteredLabel) {
return filteredLabel !== label.title; return filteredLabel !== label.title;
@ -330,17 +345,21 @@
gl.issueBoards.BoardsStore.updateFiltersUrl(); gl.issueBoards.BoardsStore.updateFiltersUrl();
e.preventDefault(); e.preventDefault();
return; return;
} else if ($dropdown.hasClass('js-filter-submit') && (isIssueIndex || isMRIndex)) { }
else if ($dropdown.hasClass('js-filter-submit') && (isIssueIndex || isMRIndex)) {
if (!$dropdown.hasClass('js-multiselect')) { if (!$dropdown.hasClass('js-multiselect')) {
selectedLabel = label.title; selectedLabel = label.title;
return Issuable.filterResults($dropdown.closest('form')); return Issuable.filterResults($dropdown.closest('form'));
} }
} else if ($dropdown.hasClass('js-filter-submit')) { }
else if ($dropdown.hasClass('js-filter-submit')) {
return $dropdown.closest('form').submit(); return $dropdown.closest('form').submit();
} else { }
else {
if ($dropdown.hasClass('js-multiselect')) { if ($dropdown.hasClass('js-multiselect')) {
} else { }
else {
return saveLabelData(); return saveLabelData();
} }
} }

View file

@ -35,8 +35,7 @@
return $.ajax({ return $.ajax({
url: milestonesUrl url: milestonesUrl
}).done(function(data) { }).done(function(data) {
var extraOptions; var extraOptions = [];
extraOptions = [];
if (showAny) { if (showAny) {
extraOptions.push({ extraOptions.push({
id: 0, id: 0,