2015-09-11 14:41:01 +05:30
|
|
|
class Groups::MilestonesController < Groups::ApplicationController
|
|
|
|
before_action :authorize_group_milestone!, only: :update
|
2014-09-02 18:07:02 +05:30
|
|
|
|
|
|
|
def index
|
2015-04-26 12:48:37 +05:30
|
|
|
project_milestones = case params[:state]
|
|
|
|
when 'all'; state
|
|
|
|
when 'closed'; state('closed')
|
|
|
|
else state('active')
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|
|
|
|
@group_milestones = Milestones::GroupService.new(project_milestones).execute
|
2015-04-26 12:48:37 +05:30
|
|
|
@group_milestones = Kaminari.paginate_array(@group_milestones).page(params[:page]).per(PER_PAGE)
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
def show
|
|
|
|
project_milestones = Milestone.where(project_id: group.projects).order("due_date ASC")
|
|
|
|
@group_milestone = Milestones::GroupService.new(project_milestones).milestone(title)
|
|
|
|
end
|
|
|
|
|
|
|
|
def update
|
|
|
|
project_milestones = Milestone.where(project_id: group.projects).order("due_date ASC")
|
|
|
|
@group_milestones = Milestones::GroupService.new(project_milestones).milestone(title)
|
|
|
|
|
|
|
|
@group_milestones.milestones.each do |milestone|
|
|
|
|
Milestones::UpdateService.new(milestone.project, current_user, params[:milestone]).execute(milestone)
|
|
|
|
end
|
|
|
|
|
|
|
|
respond_to do |format|
|
|
|
|
format.js
|
|
|
|
format.html do
|
|
|
|
redirect_to group_milestones_path(group)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def group
|
|
|
|
@group ||= Group.find_by(path: params[:group_id])
|
|
|
|
end
|
|
|
|
|
|
|
|
def title
|
|
|
|
params[:title]
|
|
|
|
end
|
|
|
|
|
2015-04-26 12:48:37 +05:30
|
|
|
def state(state = nil)
|
2014-09-02 18:07:02 +05:30
|
|
|
conditions = { project_id: group.projects }
|
|
|
|
conditions.reverse_merge!(state: state) if state
|
|
|
|
Milestone.where(conditions).order("title ASC")
|
|
|
|
end
|
|
|
|
|
|
|
|
def authorize_group_milestone!
|
2015-04-26 12:48:37 +05:30
|
|
|
return render_404 unless can?(current_user, :admin_group, group)
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|
|
|
|
end
|