|
class MissionEditor::AgentsController < ApplicationController
before_action :set_mission_agent, only: [:show, :edit, :update, :destroy]
before_action :set_mission
# GET /mission_agents
# GET /mission_agents.json
def index
@mission_agents = MissionAgent.where(mission: @mission).where("instance_source_id is NULL")
end
# GET /mission_agents/1
# GET /mission_agents/1.json
def show
end
# GET /mission_agents/new
def new
@mission_agent = MissionAgent.new
@mission_agent.agent_steps.build
end
# GET /mission_agents/1/edit
def edit
end
# POST /mission_agents
# POST /mission_agents.json
def create
@mission_agent = MissionAgent.new(mission_agent_params)
@mission_agent.mission = @mission
respond_to do |format|
if @mission_agent.save
format.html { redirect_to mission_agents_path(@mission), notice: 'Mission agent was successfully created.' }
format.json { render action: 'show', status: :created, location: @mission_agent }
else
format.html { render action: 'new' }
format.json { render json: @mission_agent.errors, status: :unprocessable_entity }
end
end
end
# PATCH/PUT /mission_agents/1
# PATCH/PUT /mission_agents/1.json
def update
respond_to do |format|
if @mission_agent.update(mission_agent_params)
format.html { redirect_to mission_agents_path(@mission), notice: 'Mission agent was successfully updated.' }
format.json { head :no_content }
else
format.html { render action: 'edit' }
format.json { render json: @mission_agent.errors, status: :unprocessable_entity }
end
end
end
# DELETE /mission_agents/1
# DELETE /mission_agents/1.json
def destroy
@mission_agent.destroy
respond_to do |format|
format.html { redirect_to mission_agents_url }
format.json { head :no_content }
end
end
def sort_steps
params[:agent_step].each_with_index do |step, index|
AgentStep.find(step).update(position: (index + 1))
end
render nothing: true
end
private
# Use callbacks to share common setup or constraints between actions.
def set_mission_agent
@mission_agent = MissionAgent.friendly.find(params[:id])
end
def set_mission
@mission = Mission.friendly.find(params[:mission])
end
# Never trust parameters from the scary internet, only allow the white list through.
def mission_agent_params
params.require(:mission_agent).permit!
end
end
|