mirror of
https://github.com/Fishwaldo/huginn.git
synced 2025-03-15 19:31:26 +00:00
enable disable all agents within a scenario (#1506)
* tentative work on enable disable all agents within a scenario * more work with pr * more work * better names and save a line of code * coffeescript to change modal text and hidden disabled value * redoing coffeescript class to save some code * initing the function * updated coffeescript * change text from specific modal, made names more specific * updates disabled test and rubocop bug * improved test and refactored method per rubocop warnings * switched from 0 to false * switched from 0 to false and 1 to true * fixed null bug in postgresql database * fixed ruby boolean bug * moved instances into let lazy load and use proper agent fixture * putting in a different fix * using existing membership and agent and another version of test * switch back to 2 not 3 after rm an agent in yml * made test passed locally * forgot to remove debuging pp * small spacing bug * trying to get rid of newline in file * typo not agent but scenario * minor changes to syntax and naming * rm potential failure and changed update_all statement * fixing new line issue * removed unnecessary if else statement from method
This commit is contained in:
parent
8d71615972
commit
f57a3af521
6 changed files with 57 additions and 0 deletions
15
app/assets/javascripts/pages/scenario-show-page.js.coffee
Normal file
15
app/assets/javascripts/pages/scenario-show-page.js.coffee
Normal file
|
@ -0,0 +1,15 @@
|
|||
class @ScenarioShowPage
|
||||
constructor:() ->
|
||||
@changeModalText()
|
||||
|
||||
changeModalText: () ->
|
||||
$('#disable-all').click ->
|
||||
$('#enable-disable-agents .modal-body').text 'Would you like to disable all agents?'
|
||||
$('#scenario-disabled-value').val 'true'
|
||||
$('#enable-all').click ->
|
||||
$('#enable-disable-agents .modal-body').text 'Would you like to enable all agents?'
|
||||
$('#scenario-disabled-value').val 'false'
|
||||
|
||||
$ ->
|
||||
Utils.registerPage(ScenarioShowPage, forPathsMatching: /^scenarios/)
|
||||
|
|
@ -95,6 +95,16 @@ class ScenariosController < ApplicationController
|
|||
end
|
||||
end
|
||||
|
||||
def enable_or_disable_all_agents
|
||||
@scenario = current_user.scenarios.find(params[:id])
|
||||
|
||||
@scenario.agents.update_all(disabled: params[:scenario][:disabled] == 'true')
|
||||
respond_to do |format|
|
||||
format.html { redirect_to @scenario, notice: 'The agents in this scenario have been successfully updated.' }
|
||||
format.json { head :no_content }
|
||||
end
|
||||
end
|
||||
|
||||
def destroy
|
||||
@scenario = current_user.scenarios.find(params[:id])
|
||||
@scenario.destroy_with_mode(params[:mode])
|
||||
|
|
19
app/views/scenarios/_enable_agents_modal.html.erb
Normal file
19
app/views/scenarios/_enable_agents_modal.html.erb
Normal file
|
@ -0,0 +1,19 @@
|
|||
<div id="enable-disable-agents" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="enableAgentLabel" aria-hidden="true">
|
||||
<div class="modal-dialog modal-sm">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">×</span><span class="sr-only">Close</span></button>
|
||||
<h4 class="modal-title">Confirm</h4>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<%= form_for(scenario, as: :scenario, url: enable_or_disable_all_agents_scenario_path(scenario), method: 'PUT') do |f| %>
|
||||
<%= f.hidden_field :disabled, value: '', id: "scenario-disabled-value" %>
|
||||
<%= f.button 'No', class: 'btn btn-default', 'data-dismiss' => 'modal' %>
|
||||
<%= f.submit 'Yes', class: 'btn btn-primary' %>
|
||||
<% end %>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
|
@ -24,8 +24,11 @@
|
|||
<% end %>
|
||||
<%= link_to icon_tag('glyphicon-share-alt') + ' Share', share_scenario_path(@scenario), class: "btn btn-default" %>
|
||||
<%= link_to icon_tag('glyphicon-trash') + ' Delete', '#', data: { toggle: 'modal', target: "#confirm-scenario-deletion-#{@scenario.id}"}, class: "btn btn-default" %>
|
||||
<%= link_to icon_tag('glyphicon-play') + 'Enable all Agents', '#', data: { toggle: 'modal', target: "#enable-disable-agents"}, class: "btn btn-default", id: "enable-all" %>
|
||||
<%= link_to icon_tag('glyphicon-pause') + 'Disable all Agents', '#', data: { toggle: 'modal', target: "#enable-disable-agents"}, class: "btn btn-default", id: "disable-all" %>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<%= render 'scenarios/confirm_deletion_modal', scenario: @scenario %>
|
||||
<%= render 'scenarios/enable_agents_modal', scenario: @scenario %>
|
||||
|
|
|
@ -50,6 +50,7 @@ Huginn::Application.routes.draw do
|
|||
member do
|
||||
get :share
|
||||
get :export
|
||||
put :enable_or_disable_all_agents
|
||||
end
|
||||
|
||||
resource :diagram, :only => [:show]
|
||||
|
|
|
@ -140,6 +140,15 @@ describe ScenariosController do
|
|||
end
|
||||
end
|
||||
|
||||
describe 'PUT enable_or_disable_all_agents' do
|
||||
it 'updates disabled on all agents in a scenario for the current user' do
|
||||
@params = {"scenario"=>{"disabled"=>"true"}, "commit"=>"Yes", "id"=> scenarios(:bob_weather).id}
|
||||
put :enable_or_disable_all_agents, @params
|
||||
expect(agents(:bob_rain_notifier_agent).disabled).to eq(true)
|
||||
expect(response).to redirect_to(scenario_path(scenarios(:bob_weather)))
|
||||
end
|
||||
end
|
||||
|
||||
describe "DELETE destroy" do
|
||||
it "destroys only Scenarios owned by the current user" do
|
||||
expect {
|
||||
|
|
Loading…
Add table
Reference in a new issue