Class: Houston::Roadmaps::MilestonesController

Inherits:
ApplicationController
  • Object
show all
Defined in:
app/controllers/houston/roadmaps/milestones_controller.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#milestoneObject (readonly)

Returns the value of attribute milestone.



4
5
6
# File 'app/controllers/houston/roadmaps/milestones_controller.rb', line 4

def milestone
  @milestone
end

Instance Method Details

#add_ticketObject



50
51
52
53
54
55
# File 'app/controllers/houston/roadmaps/milestones_controller.rb', line 50

def add_ticket
  authorize! :update_tickets, milestone
  ticket = Ticket.find params[:ticket_id]
  ticket.update_attribute :milestone_id, milestone.id
  head :ok
end

#closeObject



43
44
45
46
47
# File 'app/controllers/houston/roadmaps/milestones_controller.rb', line 43

def close
  authorize! :update, milestone
  milestone.close!
  render json: {}
end

#createObject



20
21
22
23
24
25
26
27
28
29
# File 'app/controllers/houston/roadmaps/milestones_controller.rb', line 20

def create
  project = Project.find(params[:projectId])
  authorize! :create, project.milestones.build
  milestone = project.create_milestone!(milestone_attributes)
  if milestone.persisted?
    render json: Houston::Roadmaps::MilestonePresenter.new(milestone), status: :created
  else
    render json: milestone.errors, status: :unprocessable_entity
  end
end

#create_ticketObject



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'app/controllers/houston/roadmaps/milestones_controller.rb', line 58

def create_ticket
  authorize! :update_tickets, milestone
  authorize! :create, milestone.tickets.build

  ticket = project.create_ticket!(
    milestone_id: milestone.id,
    type: "Feature",
    summary: params[:summary],
    reporter: current_user)

  if ticket.persisted?
    render json: TicketPresenter.new(ticket), status: :created, location: ticket.ticket_tracker_ticket_url
  else
    render json: ticket.errors, status: :unprocessable_entity
  end
end

#remove_ticketObject



76
77
78
79
80
81
# File 'app/controllers/houston/roadmaps/milestones_controller.rb', line 76

def remove_ticket
  authorize! :update_tickets, milestone
  ticket = Ticket.find params[:ticket_id]
  ticket.update_attribute :milestone_id, nil
  head :ok
end

#showObject



11
12
13
14
15
16
17
# File 'app/controllers/houston/roadmaps/milestones_controller.rb', line 11

def show
  authorize! :read, milestone
  @project = milestone.project
  @title = "#{milestone.name}#{@project.name}"
  @tickets = milestone.tickets.includes(:project, :tasks, :reporter)
  @open_tickets = @project.tickets.open.includes(:tasks, :reporter)
end

#updateObject



32
33
34
35
36
37
38
39
40
# File 'app/controllers/houston/roadmaps/milestones_controller.rb', line 32

def update
  authorize! :update, milestone
  milestone.updated_by = current_user if milestone.respond_to?(:updated_by=)
  if milestone.update_attributes(milestone_attributes)
    render json: Houston::Roadmaps::MilestonePresenter.new(milestone)
  else
    render json: milestone.errors, status: :unprocessable_entity
  end
end

#update_orderObject



84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'app/controllers/houston/roadmaps/milestones_controller.rb', line 84

def update_order
  authorize! :update_tickets, milestone

  ids = Array.wrap(params[:order]).map(&:to_i).reject(&:zero?)

  ::Ticket.transaction do
    milestone.tickets.where(::Ticket.arel_table[:id].not_in(ids))
      .update_all("extended_attributes = extended_attributes || 'milestoneSequence=>NULL'::hstore")

    ids.each_with_index do |id, i|
      ::Ticket.unscoped.where(id: id).update_all("extended_attributes = extended_attributes || 'milestoneSequence=>#{i+1}'::hstore")
    end
  end

  head :ok
end