Commit e684480e authored by Jacob Schatz's avatar Jacob Schatz

Proper selecting multiple labels.

parent 19b9df2d
...@@ -49,11 +49,49 @@ ...@@ -49,11 +49,49 @@
Issues.filterResults $("#issue_search_form") Issues.filterResults $("#issue_search_form")
, 500) , 500)
filterResults: (form, inputs) => filterResults: (form) =>
console.log('form', form) # Assume for now there is only 1 multi select field
# Find the hidden inputs with square brackets
$multiInputs = form.find('input[name$="[]"]')
if $multiInputs.length
# get the name of one of them
multiInputName = $multiInputs
.first()
.attr('name')
# get the singular name by
# removing the square brackets from the name
singularName = multiInputName.replace('[]','')
# clone the form so we can mess around with it.
$clonedForm = form.clone()
# get those inputs from the cloned form
$inputs = $clonedForm
.find("input[name='#{multiInputName}']")
# make a comma seperated list of labels
commaSeperated = $inputs
.map( -> $(this).val())
.get()
.join(',')
# append on a hidden input with the comma
# seperated values in it
$clonedForm.append(
$('<input />')
.attr('type','hidden')
.attr('name', singularName)
.val(commaSeperated)
)
# remove the multi inputs from the
# cloned form so they don't get serialized
$inputs.remove()
# serialize the cloned form
formData = $clonedForm.serialize()
else
formData = form.serialize()
$('.issues-holder, .merge-requests-holder').css("opacity", '0.5') $('.issues-holder, .merge-requests-holder').css("opacity", '0.5')
formAction = form.attr('action') formAction = form.attr('action')
formData = form.serialize()
issuesUrl = formAction issuesUrl = formAction
issuesUrl += ("#{if formAction.indexOf("?") < 0 then '?' else '&'}") issuesUrl += ("#{if formAction.indexOf("?") < 0 then '?' else '&'}")
issuesUrl += formData issuesUrl += formData
......
...@@ -6,7 +6,7 @@ class @LabelsSelect ...@@ -6,7 +6,7 @@ class @LabelsSelect
labelUrl = $dropdown.data('labels') labelUrl = $dropdown.data('labels')
issueUpdateURL = $dropdown.data('issueUpdate') issueUpdateURL = $dropdown.data('issueUpdate')
selectedLabel = $dropdown.data('selected') selectedLabel = $dropdown.data('selected')
if selectedLabel? if selectedLabel? and not $dropdown.hasClass 'js-multiselect'
selectedLabel = selectedLabel.split(',') selectedLabel = selectedLabel.split(',')
newLabelField = $('#new_label_name') newLabelField = $('#new_label_name')
newColorField = $('#new_label_color') newColorField = $('#new_label_color')
...@@ -246,7 +246,12 @@ class @LabelsSelect ...@@ -246,7 +246,12 @@ class @LabelsSelect
selectedLabels = $dropdown selectedLabels = $dropdown
.closest('form') .closest('form')
.find("input[type='hidden'][name='#{$dropdown.data('field-name')}']") .find("input[type='hidden'][name='#{$dropdown.data('field-name')}']")
Issues.filterResults $dropdown.closest('form'), selectedLabels Issues.filterResults(
$dropdown.closest('form'),
selectedLabels,
$dropdown.data('singularFieldName'),
$dropdown.data('fieldName')
)
else if $dropdown.hasClass('js-filter-submit') else if $dropdown.hasClass('js-filter-submit')
$dropdown.closest('form').submit() $dropdown.closest('form').submit()
else else
...@@ -257,18 +262,14 @@ class @LabelsSelect ...@@ -257,18 +262,14 @@ class @LabelsSelect
page = $('body').data 'page' page = $('body').data 'page'
isIssueIndex = page is 'projects:issues:index' isIssueIndex = page is 'projects:issues:index'
isMRIndex = page is page is 'projects:merge_requests:index' isMRIndex = page is page is 'projects:merge_requests:index'
console.log 'clicked'
if $dropdown.hasClass('js-filter-submit') and (isIssueIndex or isMRIndex) if $dropdown.hasClass('js-filter-submit') and (isIssueIndex or isMRIndex)
if not $dropdown.hasClass 'js-multiselect' if not $dropdown.hasClass 'js-multiselect'
selectedLabel = label.title selectedLabel = label.title
Issues.filterResults $dropdown.closest('form') Issues.filterResults $dropdown.closest('form')
else if $dropdown.hasClass 'js-filter-submit' else if $dropdown.hasClass 'js-filter-submit'
console.log 'clicked else if'
$dropdown.closest('form').submit() $dropdown.closest('form').submit()
else else
console.log 'clicked else'
if $dropdown.hasClass 'js-multiselect' if $dropdown.hasClass 'js-multiselect'
console.log 'clicked else --> if'
return return
else else
saveLabelData() saveLabelData()
......
...@@ -16,6 +16,19 @@ module IssuablesHelper ...@@ -16,6 +16,19 @@ module IssuablesHelper
base_issuable_scope(issuable).where('iid > ?', issuable.iid).last base_issuable_scope(issuable).where('iid > ?', issuable.iid).last
end end
def multi_label_name(current_labels, default_label)
if current_labels.presence
if current_labels.include? ','
labels = current_labels.split(',')
"#{labels[0]} +#{labels.count - 1} more"
else
current_labels
end
else
default_label
end
end
def issuable_json_path(issuable) def issuable_json_path(issuable)
project = issuable.project project = issuable.project
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
%button.dropdown-menu-toggle.js-label-select.js-filter-submit.js-extra-options{type: "button", data: {toggle: "dropdown", field_name: "label_name", show_no: "true", show_any: "true", selected: params[:label_name], project_id: @project.try(:id), labels: labels_filter_path, default_label: "Label"}} %button.dropdown-menu-toggle.js-label-select.js-filter-submit.js-extra-options{type: "button", data: {toggle: "dropdown", field_name: "label_name", show_no: "true", show_any: "true", selected: params[:label_name], project_id: @project.try(:id), labels: labels_filter_path, default_label: "Label"}}
%button.dropdown-menu-toggle.js-label-select.js-filter-submit.js-multiselect.js-extra-options{type: "button", data: {toggle: "dropdown", field_name: "label_name[]", show_no: "true", show_any: "true", selected: params[:label_name], project_id: @project.try(:id), labels: labels_filter_path, default_label: "Label"}} %button.dropdown-menu-toggle.js-label-select.js-filter-submit.js-multiselect.js-extra-options{type: "button", data: {toggle: "dropdown", field_name: "label_name[]", show_no: "true", show_any: "true", selected: params[:label_name], project_id: @project.try(:id), labels: labels_filter_path, default_label: "Label"}}
%span.dropdown-toggle-text %span.dropdown-toggle-text
= h(params[:label_name].presence || "Label") = h(multi_label_name(params[:label_name], "Label"))
= icon('chevron-down') = icon('chevron-down')
.dropdown-menu.dropdown-select.dropdown-menu-paging.dropdown-menu-labels.dropdown-menu-selectable .dropdown-menu.dropdown-select.dropdown-menu-paging.dropdown-menu-labels.dropdown-menu-selectable
.dropdown-page-one .dropdown-page-one
......
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