Feature #308 ยป 0001-Fixes-308-Added-action-to-destroy-multiple-hosts-at-.patch
app/controllers/hosts_controller.rb | ||
---|---|---|
before_filter :find_hosts, :only => :query
|
||
before_filter :ajax_methods, :only => [:environment_selected, :architecture_selected, :os_selected]
|
||
before_filter :find_multiple, :only => [:multiple_actions, :update_multiple_parameters,
|
||
:select_multiple_hostgroup, :select_multiple_environment, :multiple_parameters]
|
||
:select_multiple_hostgroup, :select_multiple_environment, :multiple_parameters, :multiple_destroy]
|
||
helper :hosts, :reports
|
||
... | ... | |
redirect_to(hosts_path)
|
||
end
|
||
def multiple_destroy
|
||
end
|
||
def submit_multiple_destroy
|
||
# destroy the hosts
|
||
Host.find(session[:selected]).each do |host|
|
||
host.destroy
|
||
end
|
||
session[:selected] = []
|
||
flash[:foreman_notice] = 'Destroyed selected hosts'
|
||
redirect_to(hosts_path)
|
||
end
|
||
# AJAX method to update our session each time a host has been selected
|
||
# we are using AJAX and JS as the user might select multiple hosts across different pages (or requests).
|
||
def save_checkbox
|
app/views/hosts/multiple_actions.html.erb | ||
---|---|---|
<%= link_to 'Change Group', select_multiple_hostgroup_hosts_path %> |
|
||
<%= link_to 'Change Environment', select_multiple_environment_hosts_path %> |
|
||
<%= link_to 'Edit Parameters', multiple_parameters_hosts_path %>
|
||
<%= link_to 'Edit Parameters', multiple_parameters_hosts_path %> |
|
||
<%= link_to 'Destroy Hosts', multiple_destroy_hosts_path %>
|
app/views/hosts/multiple_destroy.html.erb | ||
---|---|---|
<%= render 'selected_hosts', :hosts => @hosts %>
|
||
<% form_tag submit_multiple_destroy_hosts_path do -%>
|
||
<%= submit_tag "DESTROY SELECTED HOSTS!" %></p>
|
||
<% end %>
|
config/routes.rb | ||
---|---|---|
:collection => { :show_search => :get, :multiple_actions => :get, :multiple_parameters => :get,
|
||
:update_multiple_parameters => :post, :save_checkbox => :post, :select_multiple_hostgroup => :get,
|
||
:update_multiple_hostgroup => :post, :select_multiple_environment => :get, :update_multiple_environment => :post,
|
||
:multiple_destroy => :get, :submit_multiple_destroy => :post,
|
||
:reset_multiple => :get}
|
||
map.dashboard '/dashboard', :controller => 'dashboard'
|
||
map.statistics '/statistics', :controller => 'statistics'
|