Commit 7530827e authored by tiagonbotelho's avatar tiagonbotelho

fixes issues for mr acceptance

parent b9d13c11
...@@ -94,10 +94,6 @@ class IssuableFinder ...@@ -94,10 +94,6 @@ class IssuableFinder
params[:milestone_title].present? params[:milestone_title].present?
end end
def upcoming?
params[:milestone_title] == 'Upcoming'
end
def filter_by_no_milestone? def filter_by_no_milestone?
milestones? && params[:milestone_title] == Milestone::None.title milestones? && params[:milestone_title] == Milestone::None.title
end end
...@@ -248,14 +244,17 @@ class IssuableFinder ...@@ -248,14 +244,17 @@ class IssuableFinder
items items
end end
def upcoming?
params[:milestone_title] == '#upcoming' && projects
end
def by_milestone(items) def by_milestone(items)
if milestones? if milestones?
if filter_by_no_milestone? if filter_by_no_milestone?
items = items.where(milestone_id: [-1, nil]) items = items.where(milestone_id: [-1, nil])
elsif upcoming? elsif upcoming?
upcoming = Milestone.where(project_id: projects) upcoming = Milestone.upcoming(projects)
.where('due_date > ?', Time.now).order(due_date: :asc).first items = items.joins(:milestone).where(milestones: { title: upcoming.title })
items = items.joins(:milestone).where(milestone: { title: upcoming.title })
else else
items = items.joins(:milestone).where(milestones: { title: params[:milestone_title] }) items = items.joins(:milestone).where(milestones: { title: params[:milestone_title] })
......
...@@ -19,7 +19,7 @@ class Milestone < ActiveRecord::Base ...@@ -19,7 +19,7 @@ class Milestone < ActiveRecord::Base
MilestoneStruct = Struct.new(:title, :name, :id) MilestoneStruct = Struct.new(:title, :name, :id)
None = MilestoneStruct.new('No Milestone', 'No Milestone', 0) None = MilestoneStruct.new('No Milestone', 'No Milestone', 0)
Any = MilestoneStruct.new('Any Milestone', '', -1) Any = MilestoneStruct.new('Any Milestone', '', -1)
Upcoming = MilestoneStruct.new('Upcoming', '', -2) Upcoming = MilestoneStruct.new('Upcoming', '#upcoming', -2)
include InternalId include InternalId
include Sortable include Sortable
...@@ -82,6 +82,11 @@ class Milestone < ActiveRecord::Base ...@@ -82,6 +82,11 @@ class Milestone < ActiveRecord::Base
super("milestones", /(?<milestone>\d+)/) super("milestones", /(?<milestone>\d+)/)
end end
def self.upcoming(projects)
self.where(project_id: projects)
.where('due_date > ?', Time.now). order(due_date: :asc).first
end
def to_reference(from_project = nil) def to_reference(from_project = nil)
escaped_title = self.title.gsub("]", "\\]") escaped_title = self.title.gsub("]", "\\]")
......
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