Commit 88024b17 authored by Phil Hughes's avatar Phil Hughes

Standardised the output of the JSON to always include the name

The frontend will then always use the name as the ID - like previous
parent 3aeda8c9
......@@ -50,19 +50,22 @@ class @MilestoneSelect
extraOptions = []
if showAny
extraOptions.push(
isAny: true
id: 0
name: ''
title: 'Any Milestone'
)
if showNo
extraOptions.push(
id: '0'
id: -1
name: 'No Milestone'
title: 'No Milestone'
)
if showUpcoming
extraOptions.push(
id: '#upcoming'
id: -2
name: '#upcoming'
title: 'Upcoming'
)
>>>>>>> Updated to only include upcoming on filters
......@@ -84,14 +87,11 @@ class @MilestoneSelect
milestone.title
id: (milestone) ->
if !useId
if !milestone.isAny?
milestone.title
else
''
milestone.name
else
milestone.id
isSelected: (milestone) ->
milestone.title is selectedMilestone
milestone.name is selectedMilestone
hidden: ->
$selectbox.hide()
$value.show()
......@@ -99,8 +99,10 @@ class @MilestoneSelect
if $dropdown.hasClass 'js-filter-bulk-update'
return
if $dropdown.hasClass 'js-filter-submit'
if selected.title?
if $dropdown.hasClass('js-filter-submit') and (isIssueIndex or isMRIndex)
if selected.name?
selectedMilestone = selected.name
else if selected.title?
selectedMilestone = selected.title
$dropdown.parents('form').submit()
else
......
......@@ -24,7 +24,7 @@ class Projects::MilestonesController < Projects::ApplicationController
@milestones = @milestones.page(params[:page])
end
format.json do
render json: @milestones
render json: @milestones.to_json(methods: :name)
end
end
end
......
......@@ -243,7 +243,7 @@ class IssuableFinder
end
def filter_by_upcoming_milestone?
params[:milestone_title] == 'Upcoming'
params[:milestone_title] == Milestone::Upcoming.name
end
def by_milestone(items)
......
......@@ -47,6 +47,20 @@ module IssuablesHelper
end
end
def milestone_dropdown_label(milestone_title, default_label)
milestone_title = if milestone_title == Milestone::Upcoming.name
Milestone::Upcoming.title
else
milestone_title
end
if !milestone_title.nil? && !milestone_title.empty?
h(milestone_title)
else
default_label
end
end
private
def sidebar_gutter_collapsed?
......
......@@ -14,6 +14,7 @@ class GlobalMilestone
def initialize(title, milestones)
@title = title
@name = title
@milestones = milestones
end
......
- if params[:milestone_title]
= hidden_field_tag(:milestone_title, params[:milestone_title])
= dropdown_tag(h(params[:milestone_title].presence || "Milestone"), options: { title: "Filter by milestone", toggle_class: 'js-milestone-select js-filter-submit', filter: true, dropdown_class: "dropdown-menu-selectable",
= dropdown_tag(milestone_dropdown_label(params[:milestone_title], "Milestone"), options: { title: "Filter by milestone", toggle_class: 'js-milestone-select js-filter-submit', filter: true, dropdown_class: "dropdown-menu-selectable",
placeholder: "Search milestones", footer_content: @project.present?, data: { show_no: true, show_any: true, show_upcoming: true, field_name: "milestone_title", selected: params[:milestone_title], project_id: @project.try(:id), milestones: milestones_filter_dropdown_path, default_label: "Milestone" } }) do
- if @project
%ul.dropdown-footer-list
......
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