Merge pull request #422 from drcapulet/route-changes

Break Diagram into it's own controller, nest resources
This commit is contained in:
Andrew Cantino 2014-07-31 20:18:14 -07:00
commit 4442ef27e5
11 changed files with 25 additions and 20 deletions

View file

@ -98,14 +98,6 @@ class AgentsController < ApplicationController
@agent = current_user.agents.find(params[:id])
end
def diagram
@agents = if params[:scenario_id].present?
current_user.scenarios.find(params[:scenario_id]).agents.includes(:receivers)
else
current_user.agents.includes(:receivers)
end
end
def create
@agent = Agent.build_for_type(params[:agent].delete(:type),
current_user,

View file

@ -0,0 +1,9 @@
class DiagramsController < ApplicationController
def show
@agents = if params[:scenario_id].present?
current_user.scenarios.find(params[:scenario_id]).agents.includes(:receivers)
else
current_user.agents.includes(:receivers)
end
end
end

View file

@ -2,8 +2,8 @@ class EventsController < ApplicationController
before_filter :load_event, :except => :index
def index
if params[:agent]
@agent = current_user.agents.find(params[:agent])
if params[:agent_id]
@agent = current_user.agents.find(params[:agent_id])
@events = @agent.events.page(params[:page])
else
@events = current_user.events.preload(:agent).page(params[:page])

View file

@ -53,7 +53,7 @@
</td>
<td class='<%= "agent-disabled" if agent.disabled? %>'>
<% if agent.can_create_events? %>
<%= link_to(agent.events_count || 0, events_path(:agent => agent.to_param)) %>
<%= link_to(agent.events_count || 0, agent_events_path(agent)) %>
<% else %>
<span class='not-applicable'></span>
<% end %>

View file

@ -12,9 +12,8 @@
<div class="btn-group">
<%= link_to '<span class="glyphicon glyphicon-plus"></span> New Agent'.html_safe, new_agent_path, class: "btn btn-default" %>
<%= link_to '<span class="glyphicon glyphicon-refresh"></span> Run event propagation'.html_safe, propagate_agents_path, method: 'post', class: "btn btn-default" %>
<%= link_to '<span class="glyphicon glyphicon-random"></span> View diagram'.html_safe, diagram_agents_path, class: "btn btn-default" %>
<%= link_to '<span class="glyphicon glyphicon-random"></span> View diagram'.html_safe, diagram_path, class: "btn btn-default" %>
</div>
</div>
</div>
</div>

View file

@ -15,7 +15,7 @@
<li><a href="#logs" data-toggle="tab" data-agent-id="<%= @agent.id %>" class='<%= @agent.recent_error_logs? ? 'recent-errors' : '' %>'><span class='glyphicon glyphicon-list-alt'></span> Logs</a></li>
<% if @agent.can_create_events? && @agent.events.count > 0 %>
<li><%= link_to '<span class="glyphicon glyphicon-random"></span> Events'.html_safe, events_path(:agent => @agent.to_param) %></li>
<li><%= link_to '<span class="glyphicon glyphicon-random"></span> Events'.html_safe, agent_events_path(@agent) %></li>
<% else %>
<li class='disabled'><a><span class='glyphicon glyphicon-random'></span> Events</a></li>
<% end %>
@ -103,7 +103,7 @@
<% if @agent.can_create_events? %>
<p>
<b>Events created:</b>
<%= link_to @agent.events.count, events_path(:agent => @agent.to_param) %>
<%= link_to @agent.events.count, agent_events_path(@agent) %>
</p>
<% end %>

View file

@ -41,7 +41,7 @@
agentPaths["New Agent"] = <%= Utils.jsonify new_agent_path %>;
agentPaths["Account"] = <%= Utils.jsonify edit_user_registration_path %>;
agentPaths["Events Index"] = <%= Utils.jsonify events_path %>;
agentPaths["View Agent Diagram"] = <%= Utils.jsonify diagram_agents_path %>;
agentPaths["View Agent Diagram"] = <%= Utils.jsonify diagram_path %>;
agentPaths["Run Event Propagation"] = { url: <%= Utils.jsonify propagate_agents_path %>, method: 'POST' };

View file

@ -15,7 +15,7 @@
<div class="btn-group">
<%= link_to '<span class="glyphicon glyphicon-chevron-left"></span> Back'.html_safe, scenarios_path, class: "btn btn-default" %>
<%= link_to '<span class="glyphicon glyphicon-random"></span> View Diagram'.html_safe, diagram_agents_path(:scenario_id => @scenario.to_param), class: "btn btn-default" %>
<%= link_to '<span class="glyphicon glyphicon-random"></span> View Diagram'.html_safe, scenario_diagram_path(@scenario), class: "btn btn-default" %>
<%= link_to '<span class="glyphicon glyphicon-edit"></span> Edit'.html_safe, edit_scenario_path(@scenario), class: "btn btn-default" %>
<% if @scenario.source_url.present? %>
<%= link_to '<span class="glyphicon glyphicon-plus"></span> Update'.html_safe, new_scenario_imports_path(:url => @scenario.source_url), class: "btn btn-default" %>

View file

@ -11,7 +11,6 @@ Huginn::Application.routes.draw do
post :propagate
get :type_details
get :event_descriptions
get :diagram
end
resources :logs, :only => [:index] do
@ -19,8 +18,12 @@ Huginn::Application.routes.draw do
delete :clear
end
end
resources :events, :only => [:index]
end
resource :diagram, :only => [:show]
resources :events, :only => [:index, :show, :destroy] do
member do
post :reemit
@ -36,6 +39,8 @@ Huginn::Application.routes.draw do
get :share
get :export
end
resource :diagram, :only => [:show]
end
resources :user_credentials, :except => :show

View file

@ -15,12 +15,12 @@ describe EventsController do
it "can filter by Agent" do
sign_in users(:bob)
get :index, :agent => agents(:bob_website_agent)
get :index, :agent_id => agents(:bob_website_agent)
assigns(:events).length.should == agents(:bob_website_agent).events.length
assigns(:events).all? {|i| i.agent.should == agents(:bob_website_agent) }.should be_true
lambda {
get :index, :agent => agents(:jane_website_agent)
get :index, :agent_id => agents(:jane_website_agent)
}.should raise_error(ActiveRecord::RecordNotFound)
end
end