diff --git a/app/controllers/agents_controller.rb b/app/controllers/agents_controller.rb index 7adda59f2a..56770830d3 100644 --- a/app/controllers/agents_controller.rb +++ b/app/controllers/agents_controller.rb @@ -7,6 +7,22 @@ def index set_table_sort sorts: %w[name created_at last_check_at last_event_at last_receive_at], default: { created_at: :desc } @agents = current_user.agents.preload(:scenarios, :controllers).reorder(table_sort).page(params[:page]) + @shared_agents = Agent.shared - @agents + + if show_only_enabled_agents? + @agents = @agents.where(disabled: false) + end + + respond_to do |format| + format.html + format.json { render json: @agents } + end + end + + def shared + set_table_sort sorts: %w[name users.username created_at last_check_at last_event_at last_receive_at], default: { created_at: :desc } + + @agents = Agent.shared.preload(:scenarios, :controllers).reorder(table_sort).page(params[:page]) if show_only_enabled_agents? @agents = @agents.where(disabled: false) diff --git a/app/views/agents/_shared_table.html.erb b/app/views/agents/_shared_table.html.erb new file mode 100644 index 0000000000..b45e48b9f1 --- /dev/null +++ b/app/views/agents/_shared_table.html.erb @@ -0,0 +1,103 @@ +
+ + + + + + + + + + + + + + + + <% agents.each do |agent| %> + + + + + + + + + + + + + + <% end %> +
<%= sortable_column 'name', 'asc' %><%= sortable_column 'created_at', 'desc', name: 'Age' %>Schedule<%= sortable_column 'last_check_at', name: 'Last Check' %><%= sortable_column 'last_event_at', name: 'Last Event Out' %><%= sortable_column 'last_receive_at', name: 'Last Event In' %>Events CreatedWorking?<%= sortable_column 'users.username', 'asc', name: 'User' %>
+ <%= agent_type_icon(agent, agents) %> + + <% if current_user == agent.user %> + <%= link_to agent.name, agent_path(agent, return: (defined?(return_to) && return_to) || request.path) %> + <% else %> + <%= agent.name %> + <% end %> +
+ <%= agent.short_type.titleize %> + <% if current_user == agent.user %> + <% if agent.scenarios.present? %> + + <%= scenario_links(agent) %> + + <% end %> + <% end %> +
+ <%= time_ago_in_words agent.created_at %> + + <% if agent.can_be_scheduled? %> + <%= agent_schedule(agent, ',
') %> + <% else %> + + <% end %> +
+ <% if agent.can_be_scheduled? %> + <%= agent.last_check_at ? time_ago_in_words(agent.last_check_at) + " ago" : "never" %> + <% else %> + + <% end %> + + <% if agent.can_create_events? %> + <%= agent.last_event_at ? time_ago_in_words(agent.last_event_at) + " ago" : "never" %> + <% else %> + + <% end %> + + <% if agent.can_receive_events? %> + <%= agent.last_receive_at ? time_ago_in_words(agent.last_receive_at) + " ago" : "never" %> + <% else %> + + <% end %> + + <% if agent.can_create_events? %> + <%= link_to(agent.events_count || 0, agent_events_path(agent, return: (defined?(return_to) && return_to) || request.path)) %> + <% else %> + + <% end %> + <%= working(agent) %> + <% if current_user == agent.user %> + <%= agent.user.username %> + <% else %> + <%= link_to agent.user.username, edit_admin_user_path(agent.user, return: (defined?(return_to) && return_to) || request.path) %> + <% end %> + + <% if current_user == agent.user %> +
+ + <%= render 'agents/action_menu', agent: agent, return_to: (defined?(return_to) && return_to) || request.path %> +
+ <% else %> + <%#= link_to 'Become User', switch_user_admin_user_path(agent.user), class: "btn btn-sm btn-default btn-info" %> + <% end %> +
+
+ +<% if defined? agents.preload %> +<%= paginate agents, :theme => 'twitter-bootstrap-3' %> +<% end %> \ No newline at end of file diff --git a/app/views/agents/_table.html.erb b/app/views/agents/_table.html.erb index 293250306e..119f9d518c 100644 --- a/app/views/agents/_table.html.erb +++ b/app/views/agents/_table.html.erb @@ -13,10 +13,10 @@ - <% @agents.each do |agent| %> + <% agents.each do |agent| %> - <%= agent_type_icon(agent, @agents) %> + <%= agent_type_icon(agent, agents) %> <%= link_to agent.name, agent_path(agent, return: (defined?(return_to) && return_to) || request.path) %> @@ -80,4 +80,6 @@ -<%= paginate @agents, :theme => 'twitter-bootstrap-3' %> +<% if defined? agents.preload %> +<%= paginate agents, :theme => 'twitter-bootstrap-3' %> +<% end %> diff --git a/app/views/agents/index.html.erb b/app/views/agents/index.html.erb index 02f47001c3..302e81a6b9 100644 --- a/app/views/agents/index.html.erb +++ b/app/views/agents/index.html.erb @@ -5,7 +5,7 @@

Your Agents

- <%= render 'agents/table' %> + <%= render partial: 'agents/table', locals: {agents: @agents} %>
@@ -15,6 +15,10 @@ <%= link_to icon_tag('glyphicon-random') + ' View diagram', diagram_path, class: "btn btn-default" %> <%= link_to icon_tag('glyphicon-adjust') + toggle_disabled_text, toggle_visibility_agents_path, method: :put, class: "btn btn-default visibility-enabler" %> + +
+ <%= link_to 'Shared Agents', shared_agents_path, class: "btn btn-default" %> +
diff --git a/app/views/agents/shared.html.erb b/app/views/agents/shared.html.erb new file mode 100644 index 0000000000..73a8a349d4 --- /dev/null +++ b/app/views/agents/shared.html.erb @@ -0,0 +1,17 @@ +
+
+
+ + + <%= render partial: 'agents/shared_table', locals: {agents: @agents} %> + +
+ +
+ <%= link_to 'My Agents', agents_path, class: "btn btn-default" %> +
+
+
+
diff --git a/app/views/scenarios/show.html.erb b/app/views/scenarios/show.html.erb index de12f0f5fc..416e2ab04e 100644 --- a/app/views/scenarios/show.html.erb +++ b/app/views/scenarios/show.html.erb @@ -10,7 +10,7 @@
<%= markdown(@scenario.description) %>
<% end %> - <%= render 'agents/table', :return_to => scenario_path(@scenario) %> + <%= render partial: 'agents/table', locals: {agents: @agents}, :return_to => scenario_path(@scenario) %>
diff --git a/config/routes.rb b/config/routes.rb index e4ade4471c..88d05c2ae5 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -9,6 +9,7 @@ end collection do + get :shared put :toggle_visibility post :propagate get :type_details diff --git a/spec/controllers/agents_controller_spec.rb b/spec/controllers/agents_controller_spec.rb index e8f758bf3f..17c531c5c4 100644 --- a/spec/controllers/agents_controller_spec.rb +++ b/spec/controllers/agents_controller_spec.rb @@ -26,6 +26,10 @@ def valid_attributes(options = {}) end end + describe "GET all" do + pending("it returns all Agents if the current user is an admin") + end + describe "POST handle_details_post" do it "passes control to handle_details_post on the agent" do sign_in users(:bob)