@@ -1,9 +1,13 @@ |
||
| 1 | 1 |
class DiagramsController < ApplicationController |
| 2 | 2 |
def show |
| 3 |
- @agents = if params[:scenario_id].present? |
|
| 4 |
- current_user.scenarios.find(params[:scenario_id]).agents.includes(:receivers) |
|
| 5 |
- else |
|
| 6 |
- current_user.agents.includes(:receivers) |
|
| 7 |
- end |
|
| 3 |
+ if params[:scenario_id].present? |
|
| 4 |
+ @scenario = current_user.scenarios.find(params[:scenario_id]) |
|
| 5 |
+ agents = @scenario.agents |
|
| 6 |
+ else |
|
| 7 |
+ agents = current_user.agents |
|
| 8 |
+ end |
|
| 9 |
+ @disabled_agents = agents.inactive |
|
| 10 |
+ agents = agents.active if params[:exclude_disabled].present? |
|
| 11 |
+ @agents = agents.includes(:receivers) |
|
| 8 | 12 |
end |
| 9 | 13 |
end |
@@ -60,7 +60,8 @@ class Agent < ActiveRecord::Base |
||
| 60 | 60 |
has_many :scenario_memberships, :dependent => :destroy, :inverse_of => :agent |
| 61 | 61 |
has_many :scenarios, :through => :scenario_memberships, :inverse_of => :agents |
| 62 | 62 |
|
| 63 |
- scope :active, -> { where(disabled: false) }
|
|
| 63 |
+ scope :active, -> { where(disabled: false) }
|
|
| 64 |
+ scope :inactive, -> { where(disabled: true) }
|
|
| 64 | 65 |
|
| 65 | 66 |
scope :of_type, lambda { |type|
|
| 66 | 67 |
type = case type |
@@ -9,7 +9,14 @@ |
||
| 9 | 9 |
<h2>Agent Event Flow</h2> |
| 10 | 10 |
</div> |
| 11 | 11 |
<div class="btn-group"> |
| 12 |
- <%= link_to icon_tag('glyphicon-chevron-left') + ' Back'.html_safe, (params[:scenario_id] ? scenario_path(params[:scenario_id]) : agents_path), class: "btn btn-default" %>
|
|
| 12 |
+ <%= link_to icon_tag('glyphicon-chevron-left') + ' Back'.html_safe, (@scenario ? scenario_path(@scenario) : agents_path), class: "btn btn-default" %>
|
|
| 13 |
+ <% if (num_disabled = @disabled_agents.count).nonzero? -%> |
|
| 14 |
+ <% if params[:exclude_disabled] %> |
|
| 15 |
+ <%= 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 %>
|
|
| 16 |
+ <% else %> |
|
| 17 |
+ <%= 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 %>
|
|
| 18 |
+ <% end %> |
|
| 19 |
+ <% end %> |
|
| 13 | 20 |
</div> |
| 14 | 21 |
|
| 15 | 22 |
<div class='digraph'> |