Class: Houston::Roadmaps::MilestonesController
- Inherits:
-
ApplicationController
- Object
- ApplicationController
- Houston::Roadmaps::MilestonesController
- Defined in:
- app/controllers/houston/roadmaps/milestones_controller.rb
Instance Attribute Summary collapse
-
#milestone ⇒ Object
readonly
Returns the value of attribute milestone.
Instance Method Summary collapse
- #add_ticket ⇒ Object
- #close ⇒ Object
- #create ⇒ Object
- #create_ticket ⇒ Object
- #remove_ticket ⇒ Object
- #show ⇒ Object
- #update ⇒ Object
- #update_order ⇒ Object
Instance Attribute Details
#milestone ⇒ Object (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_ticket ⇒ Object
50 51 52 53 54 55 |
# File 'app/controllers/houston/roadmaps/milestones_controller.rb', line 50 def add_ticket :update_tickets, milestone ticket = Ticket.find params[:ticket_id] ticket.update_attribute :milestone_id, milestone.id head :ok end |
#close ⇒ Object
43 44 45 46 47 |
# File 'app/controllers/houston/roadmaps/milestones_controller.rb', line 43 def close :update, milestone milestone.close! render json: {} end |
#create ⇒ Object
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]) :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_ticket ⇒ Object
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 :update_tickets, milestone :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_ticket ⇒ Object
76 77 78 79 80 81 |
# File 'app/controllers/houston/roadmaps/milestones_controller.rb', line 76 def remove_ticket :update_tickets, milestone ticket = Ticket.find params[:ticket_id] ticket.update_attribute :milestone_id, nil head :ok end |
#show ⇒ Object
11 12 13 14 15 16 17 |
# File 'app/controllers/houston/roadmaps/milestones_controller.rb', line 11 def show :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 |
#update ⇒ Object
32 33 34 35 36 37 38 39 40 |
# File 'app/controllers/houston/roadmaps/milestones_controller.rb', line 32 def update :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_order ⇒ Object
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 :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 |