summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGreg Smethells <smethells@icloud.com>2015-11-30 14:47:44 -0600
committerGreg Smethells <smethells@icloud.com>2015-12-03 08:53:34 -0600
commitdbbd2b863b402e460ac1dc90f852fcae617a2351 (patch)
tree64f4c67ede3405ee0b4a53bceeb8f6cf5ca8e126
parent76b2250c60c410121cccaea584ca5345fa30e69b (diff)
downloadgitlab-ce-dbbd2b863b402e460ac1dc90f852fcae617a2351.tar.gz
sort milestones by due_date
-rw-r--r--CHANGELOG1
-rw-r--r--app/controllers/concerns/global_milestones.rb2
-rw-r--r--app/finders/milestones_finder.rb2
-rw-r--r--app/helpers/milestones_helper.rb2
-rw-r--r--app/models/global_milestone.rb31
-rw-r--r--app/views/dashboard/milestones/_milestone.html.haml11
-rw-r--r--app/views/projects/milestones/_milestone.html.haml6
-rw-r--r--app/views/shared/_milestone_expired.html.haml5
8 files changed, 49 insertions, 11 deletions
diff --git a/CHANGELOG b/CHANGELOG
index db812796b69..aad58af6678 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -6,6 +6,7 @@ v 8.3.0 (unreleased)
- Trim leading and trailing whitespace of milestone and issueable titles (Jose Corcuera)
- Add ignore whitespace change option to commit view
- Fire update hook from GitLab
+ - Fix: sort milestones by due date once again (Greg Smethells)
v 8.2.2
- Fix 404 in redirection after removing a project (Stan Hu)
diff --git a/app/controllers/concerns/global_milestones.rb b/app/controllers/concerns/global_milestones.rb
index b428249acd3..3e4c0e63601 100644
--- a/app/controllers/concerns/global_milestones.rb
+++ b/app/controllers/concerns/global_milestones.rb
@@ -2,8 +2,10 @@ module GlobalMilestones
extend ActiveSupport::Concern
def milestones
+ epoch = DateTime.parse('1970-01-01')
@milestones = MilestonesFinder.new.execute(@projects, params)
@milestones = GlobalMilestone.build_collection(@milestones)
+ @milestones = @milestones.sort_by { |x| x.due_date.nil? ? epoch : x.due_date }
@milestones = Kaminari.paginate_array(@milestones).page(params[:page]).per(ApplicationController::PER_PAGE)
end
diff --git a/app/finders/milestones_finder.rb b/app/finders/milestones_finder.rb
index b704e878903..630c73c2a94 100644
--- a/app/finders/milestones_finder.rb
+++ b/app/finders/milestones_finder.rb
@@ -1,7 +1,7 @@
class MilestonesFinder
def execute(projects, params)
milestones = Milestone.of_projects(projects)
- milestones = milestones.order("due_date ASC")
+ milestones = milestones.reorder("due_date ASC")
case params[:state]
when 'closed' then milestones.closed
diff --git a/app/helpers/milestones_helper.rb b/app/helpers/milestones_helper.rb
index ad43892b639..a42cbcff182 100644
--- a/app/helpers/milestones_helper.rb
+++ b/app/helpers/milestones_helper.rb
@@ -28,7 +28,9 @@ module MilestonesHelper
Milestone.where(project_id: @projects)
end.active
+ epoch = DateTime.parse('1970-01-01')
grouped_milestones = GlobalMilestone.build_collection(milestones)
+ grouped_milestones = grouped_milestones.sort_by { |x| x.due_date.nil? ? epoch : x.due_date }
grouped_milestones.unshift(Milestone::None)
grouped_milestones.unshift(Milestone::Any)
diff --git a/app/models/global_milestone.rb b/app/models/global_milestone.rb
index 1321ccd963f..33ddb265fba 100644
--- a/app/models/global_milestone.rb
+++ b/app/models/global_milestone.rb
@@ -19,6 +19,14 @@ class GlobalMilestone
@title.parameterize
end
+ def expired?
+ if due_date
+ due_date.past?
+ else
+ false
+ end
+ end
+
def projects
milestones.map { |milestone| milestone.project }
end
@@ -98,4 +106,25 @@ class GlobalMilestone
def complete?
total_items_count == closed_items_count
end
-end
+
+ def due_date
+ return @due_date if defined?(@due_date)
+
+ @due_date =
+ if @milestones.all? { |x| x.due_date == @milestones.first.due_date }
+ @milestones.first.due_date
+ else
+ nil
+ end
+ end
+
+ def expires_at
+ if due_date
+ if due_date.past?
+ "expired at #{due_date.stamp("Aug 21, 2011")}"
+ else
+ "expires at #{due_date.stamp("Aug 21, 2011")}"
+ end
+ end
+ end
+end \ No newline at end of file
diff --git a/app/views/dashboard/milestones/_milestone.html.haml b/app/views/dashboard/milestones/_milestone.html.haml
index 55080d6b3fe..7c882a32702 100644
--- a/app/views/dashboard/milestones/_milestone.html.haml
+++ b/app/views/dashboard/milestones/_milestone.html.haml
@@ -16,7 +16,10 @@
= milestone_progress_bar(milestone)
.row
.col-sm-6
- - milestone.milestones.each do |milestone|
- = link_to milestone_path(milestone) do
- %span.label.label-gray
- = milestone.project.name_with_namespace
+ .expiration
+ = render 'shared/milestone_expired', milestone: milestone
+ .projects
+ - milestone.milestones.each do |milestone|
+ = link_to milestone_path(milestone) do
+ %span.label.label-gray
+ = milestone.project.name_with_namespace
diff --git a/app/views/projects/milestones/_milestone.html.haml b/app/views/projects/milestones/_milestone.html.haml
index 334172b976f..d6a44c9f0a1 100644
--- a/app/views/projects/milestones/_milestone.html.haml
+++ b/app/views/projects/milestones/_milestone.html.haml
@@ -18,11 +18,7 @@
.row
.col-sm-6
- - if milestone.expired? and not milestone.closed?
- %span.cred (Expired)
- - if milestone.expires_at
- %span
- = milestone.expires_at
+ = render 'shared/milestone_expired', milestone: milestone
.col-sm-6
- if can?(current_user, :admin_milestone, milestone.project) and milestone.active?
= link_to edit_namespace_project_milestone_path(milestone.project.namespace, milestone.project, milestone), class: "btn btn-xs edit-milestone-link btn-grouped" do
diff --git a/app/views/shared/_milestone_expired.html.haml b/app/views/shared/_milestone_expired.html.haml
new file mode 100644
index 00000000000..b8eef15fbec
--- /dev/null
+++ b/app/views/shared/_milestone_expired.html.haml
@@ -0,0 +1,5 @@
+- if milestone.expired? and not milestone.closed?
+ %span.cred (Expired)
+- if milestone.expires_at
+ %span
+ = milestone.expires_at