Commit c223fb1a authored by Marin Jankovski's avatar Marin Jankovski

Start building group milestone show page.

parent b6425f33
...@@ -13,14 +13,16 @@ class Groups::MilestonesController < ApplicationController ...@@ -13,14 +13,16 @@ class Groups::MilestonesController < ApplicationController
def show def show
project_milestones = Milestone.where(project_id: group.projects) project_milestones = Milestone.where(project_id: group.projects)
@group_milestones = Milestones::GroupService.new(project_milestones).milestone(title) @group_milestone = Milestones::GroupService.new(project_milestones).milestone(title)
@project_issues = @group_milestone.filter_by(params[:status], "issues")
@project_merge_requests = @group_milestone.filter_by(params[:status], "merge_requests")
end end
def update def update
project_milestones = Milestone.where(project_id: group.projects) project_milestones = Milestone.where(project_id: group.projects)
@group_milestones = Milestones::GroupService.new(project_milestones).milestone(title) @group_milestones = Milestones::GroupService.new(project_milestones).milestone(title)
@group_milestones.each do |milestone| @group_milestones.milestones.each do |milestone|
Milestones::UpdateService.new(milestone.project, current_user, params[:milestone]).execute(milestone) Milestones::UpdateService.new(milestone.project, current_user, params[:milestone]).execute(milestone)
end end
......
...@@ -9,6 +9,10 @@ class GroupMilestone ...@@ -9,6 +9,10 @@ class GroupMilestone
@title @title
end end
def safe_title
@title.gsub(".", "-")
end
def milestones def milestones
@milestones @milestones
end end
...@@ -25,6 +29,10 @@ class GroupMilestone ...@@ -25,6 +29,10 @@ class GroupMilestone
milestones.map{ |milestone| milestone.merge_requests.count }.sum milestones.map{ |milestone| milestone.merge_requests.count }.sum
end end
def open_items_count
milestones.map{ |milestone| milestone.open_items_count }.sum
end
def closed_items_count def closed_items_count
milestones.map{ |milestone| milestone.closed_items_count }.sum milestones.map{ |milestone| milestone.closed_items_count }.sum
end end
...@@ -42,10 +50,69 @@ class GroupMilestone ...@@ -42,10 +50,69 @@ class GroupMilestone
def state def state
state = milestones.map{ |milestone| milestone.state } state = milestones.map{ |milestone| milestone.state }
if state.count("active") == state.size if state.count('active') == state.size
'active' 'active'
else else
'closed' 'closed'
end end
end end
def active?
state == 'active'
end
def closed?
state == 'closed'
end
def opened_unassigned_issues
milestones.map{ |milestone| milestone.issues.opened.unassigned }
end
def opened_assigned_issues
milestones.map{ |milestone| milestone.issues.opened.assigned }
end
def closed_issues
milestones.map{ |milestone| milestone.issues.closed }
end
def participants
milestones.map{ |milestone| milestone.participants.uniq }.reject(&:empty?).flatten
end
def filter_by(filter, entity)
if entity
milestones = self.milestones.sort_by(&:project_id)
entities = {}
milestones.each do |project_milestone|
next unless project_milestone.send(entity).any?
project_name = project_milestone.project.name
entities_by_state = state_filter(filter, project_milestone.send(entity))
entities.store(project_name, entities_by_state)
end
entities
else
{}
end
end
def state_filter(filter, entities)
if entities.present?
sorted_entities = entities.sort_by(&:position)
entities_by_state = case filter
when 'active'; sorted_entities.group_by(&:state)['opened']
when 'closed'; sorted_entities.group_by(&:state)['closed']
else sorted_entities
end
if entities_by_state.blank?
[]
else
entities_by_state
end
else
[]
end
end
end end
...@@ -5,16 +5,22 @@ module Milestones ...@@ -5,16 +5,22 @@ module Milestones
end end
def execute def execute
@project_milestones.map{ |title, milestone| GroupMilestone.new(title, milestone) } build(@project_milestones)
end end
def milestone(title) def milestone(title)
if title if title
@project_milestones[title] group_milestone = @project_milestones[title].group_by(&:title)
build(group_milestone).first
else else
nil nil
end end
end end
private
def build(milestone)
milestone.map{ |title, milestones| GroupMilestone.new(title, milestones) }
end
end end
end end
%li{ id: dom_id(issue, 'sortable'), class: 'issue-row', 'data-iid' => issue.iid }
%span.str-truncated
- project = issue.project
= link_to [project, issue] do
%span.cgray ##{issue.iid}
= link_to_gfm issue.title, [project, issue]
.pull-right.assignee-icon
- if issue.assignee
= image_tag avatar_icon(issue.assignee.email, 16), class: "avatar s16"
.panel.panel-default
.panel-heading= name
%ul{ class: "well-list issues-sortable-list" }
- issues.each do |issue|
= render 'issue', issue: issue
%li{ id: dom_id(merge_request, 'sortable'), class: 'mr-row', 'data-iid' => merge_request.iid }
%span.str-truncated
- project = merge_request.project
= link_to [project, merge_request] do
%span.cgray ##{merge_request.iid}
= link_to_gfm truncate(merge_request.title, length: 60), [project, merge_request]
.panel.panel-default
.panel-heading= name
%ul{ class: "well-list merge_requests-sortable-list" }
- merge_requests.sort_by(&:position).each do |merge_request|
= render 'merge_request', merge_request: merge_request
...@@ -22,21 +22,20 @@ ...@@ -22,21 +22,20 @@
.nothing-here-block No milestones to show .nothing-here-block No milestones to show
- else - else
- @group_milestones.each do |milestone| - @group_milestones.each do |milestone|
%li{class: "milestone milestone-#{milestone.state == 'closed' ? 'closed' : 'open'}", id: dom_id(milestone.milestones.first) } %li{class: "milestone milestone-#{milestone.closed? ? 'closed' : 'open'}", id: dom_id(milestone.milestones.first) }
.pull-right .pull-right
- safe_title = milestone.title.gsub(".", "-") - if milestone.closed?
- if milestone.state == 'closed' = link_to 'Reopen Milestone', group_milestone_path(@group, milestone.safe_title, milestone: {state_event: :activate }), method: :put, class: "btn btn-small btn-grouped"
= link_to 'Reopen Milestone', group_milestone_path(@group, safe_title, milestone: {state_event: :activate }), method: :put, class: "btn btn-small btn-grouped"
- else - else
= link_to 'Close Milestone', group_milestone_path(@group, safe_title, milestone: {state_event: :close }), method: :put, class: "btn btn-small btn-remove" = link_to 'Close Milestone', group_milestone_path(@group, milestone.safe_title, milestone: {state_event: :close }), method: :put, class: "btn btn-small btn-remove"
%h4 %h4
= link_to_gfm truncate(milestone.title, length: 100), group_milestone_path(@group, safe_title) = link_to_gfm truncate(milestone.title, length: 100), group_milestone_path(@group, milestone.safe_title)
%div %div
%div %div
= link_to root_path do = link_to group_milestone_path(@group, milestone.safe_title) do
= pluralize milestone.issue_count, 'Issue' = pluralize milestone.issue_count, 'Issue'
&nbsp; &nbsp;
= link_to root_path do = link_to group_milestone_path(@group, milestone.safe_title) do
= pluralize milestone.merge_requests_count, 'Merge Request' = pluralize milestone.merge_requests_count, 'Merge Request'
&nbsp; &nbsp;
%span.light #{milestone.percent_complete}% complete %span.light #{milestone.percent_complete}% complete
......
%h3.page-title
Milestone #{@group_milestone.title}
.pull-right
- if @group_milestone.active?
= link_to 'Close Milestone', group_milestone_path(@group, @group_milestone.safe_title, milestone: {state_event: :close }), method: :put, class: "btn btn-small btn-remove"
- else
= link_to 'Reopen Milestone', group_milestone_path(@group, @group_milestone.safe_title, milestone: {state_event: :activate }), method: :put, class: "btn btn-small btn-grouped"
- if (@group_milestone.total_items_count == @group_milestone.closed_items_count) && @group_milestone.active?
.alert.alert-success
%span All issues for this milestone are closed. You may close the milestone now.
.back-link
= link_to group_milestones_path(@group) do
&larr; To milestones list
.issue-box{ class: "issue-box-#{@group_milestone.closed? ? 'closed' : 'open'}" }
.state.clearfix
.state-label
- if @group_milestone.closed?
Closed
- else
Open
%h4.title
= gfm escape_once(@group_milestone.title)
.context
%p
Progress:
#{@group_milestone.closed_items_count} closed
&ndash;
#{@group_milestone.open_items_count} open
.progress.progress-info
.progress-bar{style: "width: #{@group_milestone.percent_complete}%;"}
%ul.nav.nav-tabs
%li.active
= link_to '#tab-issues', 'data-toggle' => 'tab' do
Issues
%span.badge= @group_milestone.issue_count
%li
= link_to '#tab-merge-requests', 'data-toggle' => 'tab' do
Merge Requests
%span.badge= @group_milestone.merge_requests_count
%li
= link_to '#tab-participants', 'data-toggle' => 'tab' do
Participants
%span.badge= @group_milestone.participants.count
.tab-content
.tab-pane.active#tab-issues
.row
.col-md-4.responsive-side
= render 'groups/filter', entity: 'milestone'
.col-md-8
- @project_issues.each do |name, issues|
= render 'issues', name: name, issues: issues
.tab-pane#tab-merge-requests
.row
.col-md-4.responsive-side
= render 'groups/filter', entity: 'milestone'
.col-md-8
- @project_merge_requests.each do |name, merge_requests|
= render 'merge_requests', name: name, merge_requests: merge_requests
.tab-pane#tab-participants
%ul.bordered-list
- @group_milestone.participants.each do |user|
%li
= link_to user, title: user.name, class: "darken" do
= image_tag avatar_icon(user.email, 32), class: "avatar s32"
%strong= truncate(user.name, lenght: 40)
%br
%small.cgray= user.username
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