From d3796b84f8f3ab9da30447eb0bac2cf9aed32b31 Mon Sep 17 00:00:00 2001 From: Marin Jankovski Date: Mon, 30 Jun 2014 12:41:27 +0200 Subject: [PATCH] Show all issues and merge requests that could be considered opened or closed, includes reopened and merged. --- .../groups/milestones_controller.rb | 2 -- app/models/group_milestone.rb | 20 +++++++++++++++++-- .../milestones/_merge_requests.html.haml | 2 +- app/views/groups/milestones/show.html.haml | 8 ++++---- 4 files changed, 23 insertions(+), 9 deletions(-) diff --git a/app/controllers/groups/milestones_controller.rb b/app/controllers/groups/milestones_controller.rb index 281b2f0c90a..4f7096c42bd 100644 --- a/app/controllers/groups/milestones_controller.rb +++ b/app/controllers/groups/milestones_controller.rb @@ -16,8 +16,6 @@ class Groups::MilestonesController < ApplicationController def show project_milestones = Milestone.where(project_id: group.projects) @group_milestone = Milestones::GroupService.new(project_milestones).milestone(title) - @issues = @group_milestone.issues - @merge_requests = @group_milestone.merge_requests end def update diff --git a/app/models/group_milestone.rb b/app/models/group_milestone.rb index 8296a0aa71b..cbd9f2a33cb 100644 --- a/app/models/group_milestone.rb +++ b/app/models/group_milestone.rb @@ -66,14 +66,30 @@ class GroupMilestone end def issues - milestones.map{ |milestone| milestone.issues }.flatten.group_by(&:state) + @group_issues ||= milestones.map{ |milestone| milestone.issues }.flatten.group_by(&:state) end def merge_requests - milestones.map{ |milestone| milestone.merge_requests }.flatten.group_by(&:state) + @group_merge_requests ||= milestones.map{ |milestone| milestone.merge_requests }.flatten.group_by(&:state) end def participants milestones.map{ |milestone| milestone.participants.uniq }.reject(&:empty?).flatten end + + def opened_issues + issues.values_at("opened", "reopened").compact.flatten + end + + def closed_issues + issues['closed'] + end + + def opened_merge_requests + merge_requests.values_at("opened", "reopened").compact.flatten + end + + def closed_merge_requests + merge_requests.values_at("closed", "merged", "locked").compact.flatten + end end diff --git a/app/views/groups/milestones/_merge_requests.html.haml b/app/views/groups/milestones/_merge_requests.html.haml index ddf7f5ee559..50057e2c636 100644 --- a/app/views/groups/milestones/_merge_requests.html.haml +++ b/app/views/groups/milestones/_merge_requests.html.haml @@ -2,5 +2,5 @@ .panel-heading= title %ul{ class: "well-list merge_requests-sortable-list" } - if merge_requests - - merge_requests.sort_by(&:position).each do |merge_request| + - merge_requests.each do |merge_request| = render 'merge_request', merge_request: merge_request diff --git a/app/views/groups/milestones/show.html.haml b/app/views/groups/milestones/show.html.haml index 7e66318e968..1ed5907b718 100644 --- a/app/views/groups/milestones/show.html.haml +++ b/app/views/groups/milestones/show.html.haml @@ -54,16 +54,16 @@ .tab-pane.active#tab-issues .row .col-md-6 - = render 'issues', title: "Open", issues: @issues["opened"] + = render 'issues', title: "Open", issues: @group_milestone.opened_issues .col-md-6 - = render 'issues', title: "Closed", issues: @issues["closed"] + = render 'issues', title: "Closed", issues: @group_milestone.closed_issues .tab-pane#tab-merge-requests .row .col-md-6 - = render 'merge_requests', title: "Open", merge_requests: @merge_requests["opened"] + = render 'merge_requests', title: "Open", merge_requests: @group_milestone.opened_merge_requests .col-md-6 - = render 'merge_requests', title: "Closed", merge_requests: @merge_requests["closed"] + = render 'merge_requests', title: "Closed", merge_requests: @group_milestone.closed_merge_requests .tab-pane#tab-participants %ul.bordered-list