mirror of
https://github.com/Fishwaldo/huginn.git
synced 2025-03-15 19:31:26 +00:00
Added button to toggle visibility of disabled agents (#1464)
Added button to toggle visibility of disabled agents * Moved index code to separate file * Added cookie to allow toggling visibility of disabled agents * Filter disabled agents based on cookie * Removed js and use correct cookie name * CR changes
This commit is contained in:
parent
74d8ab9de0
commit
ad4a15d6da
8 changed files with 105 additions and 2 deletions
|
@ -66,4 +66,3 @@ class @AgentShowPage
|
|||
|
||||
$ ->
|
||||
Utils.registerPage(AgentShowPage, forPathsMatching: /^agents\/\d+/)
|
||||
|
||||
|
|
|
@ -8,12 +8,26 @@ class AgentsController < ApplicationController
|
|||
|
||||
@agents = current_user.agents.preload(:scenarios, :controllers).reorder(table_sort).page(params[:page])
|
||||
|
||||
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 toggle_visibility
|
||||
if show_only_enabled_agents?
|
||||
mark_all_agents_viewable
|
||||
else
|
||||
set_only_enabled_agents_as_viewable
|
||||
end
|
||||
|
||||
redirect_to agents_path
|
||||
end
|
||||
|
||||
def handle_details_post
|
||||
@agent = current_user.agents.find(params[:id])
|
||||
if @agent.respond_to?(:handle_details_post)
|
||||
|
@ -257,4 +271,20 @@ class AgentsController < ApplicationController
|
|||
@agent = FormConfigurableAgentPresenter.new(@agent, view_context)
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
def show_only_enabled_agents?
|
||||
!!cookies[:huginn_view_only_enabled_agents]
|
||||
end
|
||||
|
||||
def set_only_enabled_agents_as_viewable
|
||||
cookies[:huginn_view_only_enabled_agents] = {
|
||||
value: "true",
|
||||
expires: 1.year.from_now
|
||||
}
|
||||
end
|
||||
|
||||
def mark_all_agents_viewable
|
||||
cookies.delete(:huginn_view_only_enabled_agents)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -6,6 +6,14 @@ module AgentHelper
|
|||
end
|
||||
end
|
||||
|
||||
def toggle_disabled_text
|
||||
if cookies[:huginn_view_only_enabled_agents]
|
||||
" Show Disabled Agents"
|
||||
else
|
||||
" Hide Disabled Agents"
|
||||
end
|
||||
end
|
||||
|
||||
def scenario_links(agent)
|
||||
agent.scenarios.map { |scenario|
|
||||
link_to(scenario.name, scenario, class: "label", style: style_colors(scenario))
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
<%= link_to icon_tag('glyphicon-plus') + ' New Agent', new_agent_path, class: "btn btn-default" %>
|
||||
<%= link_to icon_tag('glyphicon-refresh') + ' Run event propagation', propagate_agents_path, method: 'post', class: "btn btn-default" %>
|
||||
<%= 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" %>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
@ -10,6 +10,7 @@ Huginn::Application.routes.draw do
|
|||
end
|
||||
|
||||
collection do
|
||||
put :toggle_visibility
|
||||
post :propagate
|
||||
get :type_details
|
||||
post :dry_run
|
||||
|
|
|
@ -16,6 +16,14 @@ describe AgentsController do
|
|||
get :index
|
||||
expect(assigns(:agents).all? {|i| expect(i.user).to eq(users(:bob)) }).to be_truthy
|
||||
end
|
||||
|
||||
it "should not show disabled agents if the cookie is set" do
|
||||
@request.cookies["huginn_view_only_enabled_agents"] = "true"
|
||||
|
||||
sign_in users(:bob)
|
||||
get :index
|
||||
expect(assigns(:agents).map(&:disabled).uniq).to eq([false])
|
||||
end
|
||||
end
|
||||
|
||||
describe "POST handle_details_post" do
|
||||
|
@ -67,6 +75,21 @@ describe AgentsController do
|
|||
end
|
||||
end
|
||||
|
||||
describe "PUT toggle_visibility" do
|
||||
it "should set the cookie" do
|
||||
sign_in users(:jane)
|
||||
put :toggle_visibility
|
||||
expect(response.cookies["huginn_view_only_enabled_agents"]).to eq("true")
|
||||
end
|
||||
|
||||
it "should delete the cookie" do
|
||||
@request.cookies["huginn_view_only_enabled_agents"] = "true"
|
||||
sign_in users(:jane)
|
||||
put :toggle_visibility
|
||||
expect(response.cookies["huginn_view_only_enabled_agents"]).to be_nil
|
||||
end
|
||||
end
|
||||
|
||||
describe "POST propagate" do
|
||||
before(:each) do
|
||||
sign_in users(:bob)
|
||||
|
|
22
spec/features/toggle_visibility_of_disabled_agents.rb
Normal file
22
spec/features/toggle_visibility_of_disabled_agents.rb
Normal file
|
@ -0,0 +1,22 @@
|
|||
require 'capybara_helper'
|
||||
|
||||
describe "Toggling the visibility of an agent", js: true do
|
||||
it "hides them if they are disabled" do
|
||||
login_as(users(:bob))
|
||||
visit("/agents")
|
||||
|
||||
expect {
|
||||
click_on("Show/Hide Disabled Agents")
|
||||
}.to change{ find_all(".table-striped tr").count }.by(-1)
|
||||
end
|
||||
|
||||
it "shows them when they are hidden" do
|
||||
login_as(users(:bob))
|
||||
visit("/agents")
|
||||
click_on("Show/Hide Disabled Agents")
|
||||
|
||||
expect {
|
||||
click_on("Show/Hide Disabled Agents")
|
||||
}.to change{ find_all(".table-striped tr").count }.by(1)
|
||||
end
|
||||
end
|
21
spec/fixtures/agents.yml
vendored
21
spec/fixtures/agents.yml
vendored
|
@ -32,6 +32,25 @@ bob_website_agent:
|
|||
}
|
||||
}.to_json.inspect %>
|
||||
|
||||
bob_disabled_website_agent:
|
||||
type: Agents::WebsiteAgent
|
||||
disabled: true
|
||||
user: bob
|
||||
events_count: 1
|
||||
schedule: "midnight"
|
||||
name: "Disabled ZKCD"
|
||||
guid: <%= SecureRandom.hex %>
|
||||
options: <%= {
|
||||
:url => "http://xkcd.com",
|
||||
:expected_update_period_in_days => 2,
|
||||
:mode => :on_change,
|
||||
:extract => {
|
||||
:url => {:css => "#comic img", :value => "@src"},
|
||||
:title => {:css => "#comic img", :value => "@title"}
|
||||
}
|
||||
}.to_json.inspect %>
|
||||
|
||||
|
||||
bob_weather_agent:
|
||||
type: Agents::WeatherAgent
|
||||
user: bob
|
||||
|
@ -130,7 +149,7 @@ jane_basecamp_agent:
|
|||
bob_data_output_agent:
|
||||
type: Agents::DataOutputAgent
|
||||
user: bob
|
||||
name: RSS Feed
|
||||
name: RSS Feed
|
||||
guid: <%= SecureRandom.hex %>
|
||||
options: <%= {
|
||||
expected_receive_period_in_days: 3,
|
||||
|
|
Loading…
Add table
Reference in a new issue