Commit 7ff6af19 authored by Phil Hughes's avatar Phil Hughes

Dropdown bug fixes

Added back upcoming to milestone filter
Fixed bug that would cause the currently selected value to disappear on filters
Fixed bug that throw an error when filtering by upcoming when there is only a milestone in the past
parent f4238634
...@@ -145,11 +145,10 @@ class GitLabDropdown ...@@ -145,11 +145,10 @@ class GitLabDropdown
selector = ".dropdown-page-one .dropdown-content a" selector = ".dropdown-page-one .dropdown-content a"
@dropdown.on "click", selector, (e) -> @dropdown.on "click", selector, (e) ->
e.preventDefault() selected = self.rowClicked $(@)
self.rowClicked $(@)
if self.options.clicked if self.options.clicked
self.options.clicked.call(@,e) self.options.clicked(selected)
toggleLoading: -> toggleLoading: ->
$('.dropdown-menu', @dropdown).toggleClass LOADING_CLASS $('.dropdown-menu', @dropdown).toggleClass LOADING_CLASS
...@@ -288,6 +287,10 @@ class GitLabDropdown ...@@ -288,6 +287,10 @@ class GitLabDropdown
if el.hasClass(ACTIVE_CLASS) if el.hasClass(ACTIVE_CLASS)
el.removeClass(ACTIVE_CLASS) el.removeClass(ACTIVE_CLASS)
field.remove() field.remove()
# Toggle the dropdown label
if @options.toggleLabel
$(@el).find(".dropdown-toggle-text").text @options.toggleLabel
else else
fieldName = @options.fieldName fieldName = @options.fieldName
selectedIndex = el.parent().index() selectedIndex = el.parent().index()
...@@ -304,7 +307,7 @@ class GitLabDropdown ...@@ -304,7 +307,7 @@ class GitLabDropdown
@dropdown.parent().find("input[name='#{fieldName}']").remove() @dropdown.parent().find("input[name='#{fieldName}']").remove()
# Toggle active class for the tick mark # Toggle active class for the tick mark
el.toggleClass "is-active" el.addClass ACTIVE_CLASS
# Toggle the dropdown label # Toggle the dropdown label
if @options.toggleLabel if @options.toggleLabel
...@@ -313,11 +316,15 @@ class GitLabDropdown ...@@ -313,11 +316,15 @@ class GitLabDropdown
if !field.length if !field.length
# Create hidden input for form # Create hidden input for form
input = "<input type='hidden' name='#{fieldName}' value='#{value}' />" input = "<input type='hidden' name='#{fieldName}' value='#{value}' />"
if @options.inputId? if @options.inputId?
input = $(input) input = $(input)
.attr('id', @options.inputId) .attr('id', @options.inputId)
@dropdown.before input @dropdown.before input
@dropdown.parent().find("input[name='#{fieldName}']").val value
return selectedObject
selectFirstRow: -> selectFirstRow: ->
selector = '.dropdown-content li:first-child a' selector = '.dropdown-content li:first-child a'
if @dropdown.find(".dropdown-toggle-page").length if @dropdown.find(".dropdown-toggle-page").length
......
@Issues = @Issues =
init: -> init: ->
Issues.initSearch() Issues.initSearch()
Issues.initSelects()
Issues.initChecks() Issues.initChecks()
$("body").on "ajax:success", ".close_issue, .reopen_issue", -> $("body").on "ajax:success", ".close_issue, .reopen_issue", ->
...@@ -17,18 +16,9 @@ ...@@ -17,18 +16,9 @@
$(this).html totalIssues - 1 $(this).html totalIssues - 1
reload: -> reload: ->
Issues.initSelects()
Issues.initChecks() Issues.initChecks()
$('#filter_issue_search').val($('#issue_search').val()) $('#filter_issue_search').val($('#issue_search').val())
initSelects: ->
$("select#update_state_event").select2(width: 'resolve', dropdownAutoWidth: true)
$("select#update_assignee_id").select2(width: 'resolve', dropdownAutoWidth: true)
$("select#update_milestone_id").select2(width: 'resolve', dropdownAutoWidth: true)
$("select#label_name").select2(width: 'resolve', dropdownAutoWidth: true)
$("#milestone_id, #assignee_id, #label_name").on "change", ->
$(this).closest("form").submit()
initChecks: -> initChecks: ->
$(".check_all_issues").click -> $(".check_all_issues").click ->
$(".selected_issue").prop("checked", @checked) $(".selected_issue").prop("checked", @checked)
......
...@@ -231,13 +231,14 @@ class @LabelsSelect ...@@ -231,13 +231,14 @@ class @LabelsSelect
saveLabelData() saveLabelData()
multiSelect: $dropdown.hasClass 'js-multiselect' multiSelect: $dropdown.hasClass 'js-multiselect'
clicked: (label) ->
clicked: ->
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'
if $dropdown.hasClass('js-filter-submit') and (isIssueIndex or isMRIndex) if $dropdown.hasClass('js-filter-submit') and (isIssueIndex or isMRIndex)
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'
$dropdown.closest('form').submit() $dropdown.closest('form').submit()
......
...@@ -27,6 +27,18 @@ class @MilestoneSelect ...@@ -27,6 +27,18 @@ class @MilestoneSelect
milestoneLinkNoneTemplate = '<div class="light">None</div>' milestoneLinkNoneTemplate = '<div class="light">None</div>'
extraOptions = [{
isAny: true
title: 'Any Milestone'
}, {
id: '0'
title: 'No Milestone'
}, {
upcoming: true
id: '#upcoming'
title: 'Upcoming'
}]
$dropdown.glDropdown( $dropdown.glDropdown(
data: (term, callback) -> data: (term, callback) ->
$.ajax( $.ajax(
...@@ -73,11 +85,13 @@ class @MilestoneSelect ...@@ -73,11 +85,13 @@ class @MilestoneSelect
hidden: -> hidden: ->
$selectbox.hide() $selectbox.hide()
$value.show() $value.show()
clicked: (e) -> clicked: (selected) ->
if $dropdown.hasClass 'js-filter-bulk-update' if $dropdown.hasClass 'js-filter-bulk-update'
return return
if $dropdown.hasClass 'js-filter-submit' if $dropdown.hasClass 'js-filter-submit'
if selected.title?
selectedMilestone = selected.title
$dropdown.parents('form').submit() $dropdown.parents('form').submit()
else else
selected = $selectbox selected = $selectbox
...@@ -104,4 +118,4 @@ class @MilestoneSelect ...@@ -104,4 +118,4 @@ class @MilestoneSelect
$value.html(milestoneLinkTemplate(data.milestone)) $value.html(milestoneLinkTemplate(data.milestone))
else else
$value.html(milestoneLinkNoneTemplate) $value.html(milestoneLinkNoneTemplate)
) )
\ No newline at end of file
...@@ -133,7 +133,7 @@ class @UsersSelect ...@@ -133,7 +133,7 @@ class @UsersSelect
$selectbox.hide() $selectbox.hide()
$value.show() $value.show()
clicked: -> clicked: (user) ->
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'
...@@ -141,6 +141,7 @@ class @UsersSelect ...@@ -141,6 +141,7 @@ class @UsersSelect
return return
if $dropdown.hasClass('js-filter-submit') and (isIssueIndex or isMRIndex) if $dropdown.hasClass('js-filter-submit') and (isIssueIndex or isMRIndex)
selectedId = user.id
Issues.filterResults $dropdown.closest('form') Issues.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()
......
...@@ -243,7 +243,7 @@ class IssuableFinder ...@@ -243,7 +243,7 @@ class IssuableFinder
end end
def filter_by_upcoming_milestone? def filter_by_upcoming_milestone?
params[:milestone_title] == '#upcoming' params[:milestone_title] == 'Upcoming'
end end
def by_milestone(items) def by_milestone(items)
...@@ -252,7 +252,7 @@ class IssuableFinder ...@@ -252,7 +252,7 @@ class IssuableFinder
items = items.where(milestone_id: [-1, nil]) items = items.where(milestone_id: [-1, nil])
elsif filter_by_upcoming_milestone? elsif filter_by_upcoming_milestone?
upcoming = Milestone.where(project_id: projects).upcoming upcoming = Milestone.where(project_id: projects).upcoming
items = items.joins(:milestone).where(milestones: { title: upcoming.title }) items = items.joins(:milestone).where(milestones: { title: upcoming.try(:title) })
else else
items = items.joins(:milestone).where(milestones: { title: params[:milestone_title] }) items = items.joins(:milestone).where(milestones: { title: params[:milestone_title] })
......
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