Class: Projects::MilestonesController

Inherits:
ApplicationController show all
Defined in:
app/controllers/projects/milestones_controller.rb

Instance Method Summary collapse

Methods inherited from ApplicationController

#redirect_back_or_default

Methods included from PageLayoutHelper

#blank_container, #container_class, #fluid_layout, #header_title, #nav, #page_card_attributes, #page_card_meta_tags, #page_description, #page_image, #page_title, #sidebar

Methods included from GitlabRoutingHelper

#activity_project_path, #edit_project_path, #edit_project_url, #issue_path, #issue_url, #merge_request_path, #merge_request_url, #milestone_path, #project_builds_path, #project_commits_path, #project_files_path, #project_path, #project_pipelines_path, #project_snippet_url, #project_url, #runner_path, #runners_path, #toggle_subscription_path

Methods included from Gitlab::GonHelper

#add_gon_variables

Methods included from Gitlab::CurrentSettings

#current_application_settings, #fake_application_settings

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Projects::ApplicationController

Instance Method Details

#createObject


44
45
46
47
48
49
50
51
52
53
# File 'app/controllers/projects/milestones_controller.rb', line 44

def create
  @milestone = Milestones::CreateService.new(project, current_user, milestone_params).execute

  if @milestone.save
    redirect_to namespace_project_milestone_path(@project.namespace,
                                                 @project, @milestone)
  else
    render "new"
  end
end

#destroyObject


71
72
73
74
75
76
77
78
79
80
# File 'app/controllers/projects/milestones_controller.rb', line 71

def destroy
  return access_denied! unless can?(current_user, :admin_milestone, @project)

  Milestones::DestroyService.new(project, current_user).execute(milestone)

  respond_to do |format|
    format.html { redirect_to namespace_project_milestones_path }
    format.js { render nothing: true }
  end
end

#editObject


37
38
39
# File 'app/controllers/projects/milestones_controller.rb', line 37

def edit
  respond_with(@milestone)
end

#indexObject


13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'app/controllers/projects/milestones_controller.rb', line 13

def index
  @milestones =
    case params[:state]
    when 'all' then @project.milestones.reorder(due_date: :desc, title: :asc)
    when 'closed' then @project.milestones.closed.reorder(due_date: :desc, title: :asc)
    else @project.milestones.active.reorder(due_date: :asc, title: :asc)
    end

  @milestones = @milestones.includes(:project)
  respond_to do |format|
    format.html do
      @milestones = @milestones.page(params[:page])
    end
    format.json do
      render json: @milestones.to_json(methods: :name)
    end
  end
end

#newObject


32
33
34
35
# File 'app/controllers/projects/milestones_controller.rb', line 32

def new
  @milestone = @project.milestones.new
  respond_with(@milestone)
end

#showObject


41
42
# File 'app/controllers/projects/milestones_controller.rb', line 41

def show
end

#sort_issuesObject


82
83
84
85
86
# File 'app/controllers/projects/milestones_controller.rb', line 82

def sort_issues
  @milestone.sort_issues(params['sortable_issue'].map(&:to_i))

  render json: { saved: true }
end

#sort_merge_requestsObject


88
89
90
91
92
93
94
95
96
# File 'app/controllers/projects/milestones_controller.rb', line 88

def sort_merge_requests
  @merge_requests = @milestone.merge_requests.where(id: params['sortable_merge_request'])
  @merge_requests.each do |merge_request|
    merge_request.position = params['sortable_merge_request'].index(merge_request.id.to_s) + 1
    merge_request.save
  end

  render json: { saved: true }
end

#updateObject


55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'app/controllers/projects/milestones_controller.rb', line 55

def update
  @milestone = Milestones::UpdateService.new(project, current_user, milestone_params).execute(milestone)

  respond_to do |format|
    format.js
    format.html do
      if @milestone.valid?
        redirect_to namespace_project_milestone_path(@project.namespace,
                                                 @project, @milestone)
      else
        render :edit
      end
    end
  end
end