Skip to content

Commit

Permalink
Merge pull request huginn#827 from cantino/diagram_toggle_disabled
Browse files Browse the repository at this point in the history
Allow toggling disabled agents on an Agent Diagram
  • Loading branch information
knu committed May 22, 2015
2 parents 42e53c4 + b4a7dce commit 5743087
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 7 deletions.
14 changes: 9 additions & 5 deletions app/controllers/diagrams_controller.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
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
if params[:scenario_id].present?
@scenario = current_user.scenarios.find(params[:scenario_id])
agents = @scenario.agents
else
agents = current_user.agents
end
@disabled_agents = agents.inactive
agents = agents.active if params[:exclude_disabled].present?
@agents = agents.includes(:receivers)
end
end
3 changes: 2 additions & 1 deletion app/models/agent.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ class Agent < ActiveRecord::Base
has_many :scenario_memberships, :dependent => :destroy, :inverse_of => :agent
has_many :scenarios, :through => :scenario_memberships, :inverse_of => :agents

scope :active, -> { where(disabled: false) }
scope :active, -> { where(disabled: false) }
scope :inactive, -> { where(disabled: true) }

scope :of_type, lambda { |type|
type = case type
Expand Down
9 changes: 8 additions & 1 deletion app/views/diagrams/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,14 @@
<h2>Agent Event Flow</h2>
</div>
<div class="btn-group">
<%= link_to icon_tag('glyphicon-chevron-left') + ' Back'.html_safe, (params[:scenario_id] ? scenario_path(params[:scenario_id]) : agents_path), class: "btn btn-default" %>
<%= link_to icon_tag('glyphicon-chevron-left') + ' Back'.html_safe, (@scenario ? scenario_path(@scenario) : agents_path), class: "btn btn-default" %>
<% if (num_disabled = @disabled_agents.count).nonzero? -%>
<% if params[:exclude_disabled] %>
<%= link_to @scenario ? scenario_diagram_path(@scenario) : diagram_path, class: 'btn btn-default' do %><%= icon_tag('glyphicon-eye-open') %> Show <%= pluralize(num_disabled, 'disabled Agent') %><% end %>
<% else %>
<%= link_to @scenario ? scenario_diagram_path(@scenario, exclude_disabled: true) : diagram_path(exclude_disabled: true), class: 'btn btn-default' do %><%= icon_tag('glyphicon-eye-close') %> Hide <%= pluralize(num_disabled, 'disabled Agent') %><% end %>
<% end %>
<% end %>
</div>

<div class='digraph'>
Expand Down

0 comments on commit 5743087

Please sign in to comment.