Class: SprintsController

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from ApplicationController

#after_sign_in_path_for, #api_authenticate!, #current_project, #expire_revision!, #followed_projects, #no_cache, #read_revision, #require_login, #return_or_cache_revision!, #revision, #save_current_project, #set_current_project, #unfurling?

Methods included from UrlHelper

#edit_release_path, #edit_release_url, #feature_path, #github_commit_range_url, #github_commit_url, #github_project_url, #github_url?, #goldmine_case_number_url, #link_to_project_feature, #new_release_url, #release_path, #release_url, #releases_path

Instance Attribute Details

#sprintObject (readonly)

Returns the value of attribute sprint.



2
3
4
# File 'app/controllers/sprints_controller.rb', line 2

def sprint
  @sprint
end

#taskObject (readonly)

Returns the value of attribute task.



2
3
4
# File 'app/controllers/sprints_controller.rb', line 2

def task
  @task
end

Instance Method Details

#add_taskObject



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'app/controllers/sprints_controller.rb', line 44

def add_task
  authorize! :update, sprint

  if sprint.completed?
    render json: {base: ["The Sprint is completed. You cannot add or remove tasks."]}, status: :unprocessable_entity
    return
  end

  if sprint.locked? && !task.ticket_id.in?(sprint.ticket_ids)
    render json: {base: ["The Sprint is locked. You can add tasks for tickets that are already in the Sprint, but you can't add new tickets to the Sprint."]}, status: :unprocessable_entity
    return
  end

  # Putting a task into a Sprint implies that you're able to estimate this ticket
  task.ticket.able_to_estimate! if task.ticket.respond_to?(:able_to_estimate!)

  if task.completed? && task.completed_at < sprint.starts_at
    render json: {base: ["Task ##{task.shorthand} cannot be added to the Sprint because it was completed before the Sprint began"]}, status: :unprocessable_entity
  elsif task.effort.nil? or task.effort.zero?
    render json: {base: ["Task ##{task.shorthand} cannot be added to the Sprint because it has no effort"]}, status: :unprocessable_entity
  else
    sprint.tasks.add task
    task.check_out!(sprint, current_user) unless task.checked_out?(sprint)
    render json: SprintTaskPresenter.new(sprint, task).to_json
  end
end

#currentObject



9
10
11
12
# File 'app/controllers/sprints_controller.rb', line 9

def current
  @sprint = Sprint.current || Sprint.create!
  redirect_to sprint
end

#dashboardObject



24
25
26
27
28
29
30
31
32
33
34
# File 'app/controllers/sprints_controller.rb', line 24

def dashboard
  @title = "Sprint"
  @sprint = Sprint.find_by_id(params[:id]) || Sprint.current || Sprint.create!

  respond_to do |format|
    format.json { render json: {
      start: @sprint.start_date,
      tasks: SprintTaskPresenter.new(@sprint).as_json } }
    format.html { render layout: "dashboard" }
  end
end

#lockObject



37
38
39
40
41
# File 'app/controllers/sprints_controller.rb', line 37

def lock
  authorize! :manage, sprint
  sprint.lock!
  head :ok
end

#remove_taskObject



71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'app/controllers/sprints_controller.rb', line 71

def remove_task
  authorize! :update, sprint

  if sprint.completed?
    render json: {base: ["The Sprint is completed. You cannot add or remove tasks."]}, status: :unprocessable_entity
    return
  end

  if sprint.locked?
    render json: {base: ["The Sprint is locked; tasks cannot be removed"]}, status: :unprocessable_entity
    return
  end

  SprintTask.where(sprint_id: sprint.id, task_id: task.id).delete_all
  head :ok
end

#showObject



15
16
17
18
19
20
21
# File 'app/controllers/sprints_controller.rb', line 15

def show
  authorize! :read, sprint
  @title = "Sprint #{sprint.end_date.strftime("%-m/%-d")}"
  @open_tasks = Task.joins(:ticket => :project).merge(Ticket.open) unless sprint.completed?
  @tasks = @sprint.tasks
  render template: "sprints/show"
end