Bläddra i källkod

Show the number of disabled Agents in the toggle button

Akinori MUSHA 9 år sedan
förälder
incheckning
22eb2fa9ef
3 ändrade filer med 5 tillägg och 3 borttagningar
  1. 1 0
      app/controllers/diagrams_controller.rb
  2. 2 1
      app/models/agent.rb
  3. 2 2
      app/views/diagrams/show.html.erb

+ 1 - 0
app/controllers/diagrams_controller.rb

@@ -6,6 +6,7 @@ class DiagramsController < ApplicationController
     else
       agents = current_user.agents
     end
+    @disabled_agents = agents.inactive
     agents = agents.active unless params[:include_disabled].present?
     @agents = agents.includes(:receivers)
   end

+ 2 - 1
app/models/agent.rb

@@ -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

+ 2 - 2
app/views/diagrams/show.html.erb

@@ -11,9 +11,9 @@
       <div class="btn-group">
         <%= link_to icon_tag('glyphicon-chevron-left') + ' Back'.html_safe, (@scenario ? scenario_path(@scenario) : agents_path), class: "btn btn-default" %>
         <% if params[:include_disabled] %>
-          <%= link_to @scenario ? scenario_diagram_path(@scenario) : diagram_path, class: 'btn btn-default' do %><%= icon_tag('glyphicon-eye-close') %> Hide disabled Agents<% end %>
+          <%= link_to @scenario ? scenario_diagram_path(@scenario) : diagram_path, class: 'btn btn-default' do %><%= icon_tag('glyphicon-eye-close') %> Hide <%= pluralize(@disabled_agents.count, 'disabled Agent') %><% end %>
         <% else %>
-          <%= link_to @scenario ? scenario_diagram_path(@scenario, include_disabled: true) : diagram_path(include_disabled: true), class: 'btn btn-default' do %><%= icon_tag('glyphicon-eye-open') %> Show disabled Agents<% end %>
+          <%= link_to @scenario ? scenario_diagram_path(@scenario, include_disabled: true) : diagram_path(include_disabled: true), class: 'btn btn-default' do %><%= icon_tag('glyphicon-eye-open') %> Show <%= pluralize(@disabled_agents.count, 'disabled Agent') %><% end %>
         <% end %>
       </div>