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
This commit is contained in:
Phil Hughes 2016-03-23 16:44:09 +00:00
parent f4238634d3
commit 7ff6af19cc
6 changed files with 36 additions and 23 deletions

View file

@ -145,11 +145,10 @@ class GitLabDropdown
selector = ".dropdown-page-one .dropdown-content a"
@dropdown.on "click", selector, (e) ->
e.preventDefault()
self.rowClicked $(@)
selected = self.rowClicked $(@)
if self.options.clicked
self.options.clicked.call(@,e)
self.options.clicked(selected)
toggleLoading: ->
$('.dropdown-menu', @dropdown).toggleClass LOADING_CLASS
@ -288,6 +287,10 @@ class GitLabDropdown
if el.hasClass(ACTIVE_CLASS)
el.removeClass(ACTIVE_CLASS)
field.remove()
# Toggle the dropdown label
if @options.toggleLabel
$(@el).find(".dropdown-toggle-text").text @options.toggleLabel
else
fieldName = @options.fieldName
selectedIndex = el.parent().index()
@ -304,7 +307,7 @@ class GitLabDropdown
@dropdown.parent().find("input[name='#{fieldName}']").remove()
# Toggle active class for the tick mark
el.toggleClass "is-active"
el.addClass ACTIVE_CLASS
# Toggle the dropdown label
if @options.toggleLabel
@ -318,6 +321,10 @@ class GitLabDropdown
.attr('id', @options.inputId)
@dropdown.before input
@dropdown.parent().find("input[name='#{fieldName}']").val value
return selectedObject
selectFirstRow: ->
selector = '.dropdown-content li:first-child a'
if @dropdown.find(".dropdown-toggle-page").length

View file

@ -1,7 +1,6 @@
@Issues =
init: ->
Issues.initSearch()
Issues.initSelects()
Issues.initChecks()
$("body").on "ajax:success", ".close_issue, .reopen_issue", ->
@ -17,18 +16,9 @@
$(this).html totalIssues - 1
reload: ->
Issues.initSelects()
Issues.initChecks()
$('#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: ->
$(".check_all_issues").click ->
$(".selected_issue").prop("checked", @checked)

View file

@ -231,13 +231,14 @@ class @LabelsSelect
saveLabelData()
multiSelect: $dropdown.hasClass 'js-multiselect'
clicked: ->
clicked: (label) ->
page = $('body').data 'page'
isIssueIndex = page is 'projects:issues:index'
isMRIndex = page is page is 'projects:merge_requests:index'
if $dropdown.hasClass('js-filter-submit') and (isIssueIndex or isMRIndex)
selectedLabel = label.title
Issues.filterResults $dropdown.closest('form')
else if $dropdown.hasClass 'js-filter-submit'
$dropdown.closest('form').submit()

View file

@ -27,6 +27,18 @@ class @MilestoneSelect
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(
data: (term, callback) ->
$.ajax(
@ -73,11 +85,13 @@ class @MilestoneSelect
hidden: ->
$selectbox.hide()
$value.show()
clicked: (e) ->
clicked: (selected) ->
if $dropdown.hasClass 'js-filter-bulk-update'
return
if $dropdown.hasClass 'js-filter-submit'
if selected.title?
selectedMilestone = selected.title
$dropdown.parents('form').submit()
else
selected = $selectbox

View file

@ -133,7 +133,7 @@ class @UsersSelect
$selectbox.hide()
$value.show()
clicked: ->
clicked: (user) ->
page = $('body').data 'page'
isIssueIndex = page is 'projects:issues:index'
isMRIndex = page is page is 'projects:merge_requests:index'
@ -141,6 +141,7 @@ class @UsersSelect
return
if $dropdown.hasClass('js-filter-submit') and (isIssueIndex or isMRIndex)
selectedId = user.id
Issues.filterResults $dropdown.closest('form')
else if $dropdown.hasClass 'js-filter-submit'
$dropdown.closest('form').submit()

View file

@ -243,7 +243,7 @@ class IssuableFinder
end
def filter_by_upcoming_milestone?
params[:milestone_title] == '#upcoming'
params[:milestone_title] == 'Upcoming'
end
def by_milestone(items)
@ -252,7 +252,7 @@ class IssuableFinder
items = items.where(milestone_id: [-1, nil])
elsif filter_by_upcoming_milestone?
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
items = items.joins(:milestone).where(milestones: { title: params[:milestone_title] })