class AgentsController < ApplicationController include DotHelper def index @agents = current_user.agents.page(params[:page]) respond_to do |format| format.html format.json { render json: @agents } end end def handle_details_post @agent = current_user.agents.find(params[:id]) if @agent.respond_to?(:handle_details_post) render :json => @agent.handle_details_post(params) || {} else @agent.error "#handle_details_post called on an instance of #{@agent.class} that does not define it." head 500 end end def run agent = current_user.agents.find(params[:id]) Agent.async_check(agent.id) if params[:return] == "show" redirect_to agent_path(agent), notice: "Agent run queued" else redirect_to agents_path, notice: "Agent run queued" end end def disable agent = current_user.agents.find(params[:id]) # save_successful = false # Enable/Disable the agent if params[:disable] == "true" agent.disabled = true save_successful = agent.save message = "Agent '#{agent.name}' disabled" elsif params[:disable] == "false" agent.disabled = false save_successful = agent.save message = "Agent '#{agent.name}' enabled" end # Handle save errors if save_successful != true agent_status = "enabled" if agent.disabled? agent_status = "disabled" end message = "Something went wrong. Agent '#{agent.name}' is still #{agent_status} #{save_successful}" end if params[:return] == "show" redirect_to agent_path(agent), notice: message else redirect_to agents_path, notice: message end end def type_details agent = Agent.build_for_type(params[:type], current_user, {}) render :json => { :can_be_scheduled => agent.can_be_scheduled?, :can_receive_events => agent.can_receive_events?, :can_create_events => agent.can_create_events?, :options => agent.default_options, :description_html => agent.html_description } end def event_descriptions html = current_user.agents.find(params[:ids].split(",")).group_by(&:type).map { |type, agents| agents.map(&:html_event_description).uniq.map { |desc| "
#{type}
" + desc + "