Project

General

Profile

Feature #258 » feature258.patch

Bash Shell, 05/17/2010 01:26 AM

View differences:

app/controllers/hosts_controller.rb
before_filter :ajax_methods, :only => [:environment_selected, :architecture_selected, :os_selected]
before_filter :load_tabs, :manage_tabs, :only => :index
before_filter :find_multiple, :only => [:multiple_actions, :update_multiple_parameters,
:select_multiple_hostgroup, :multiple_parameters]
:select_multiple_hostgroup, :select_multiple_environment, :multiple_parameters]
helper :hosts
......
redirect_to(hosts_path)
end
def select_multiple_environment
end
def update_multiple_environment
# simple validations
if (id=params["environment"]["id"]).empty?
flash[:foreman_error] = 'No Environment selected!'
redirect_to(select_multiple_environment_hosts_path) and return
end
if (ev = Environment.find id).nil?
flash[:foreman_error] = 'Empty Environment selected!'
redirect_to(select_multiple_environment_hosts_path) and return
end
#update the hosts
Host.find(session[:selected]).each do |host|
host.environment=ev
host.save(perform_validation = false)
end
session[:selected] = []
flash[:foreman_notice] = 'Updated hosts: Changed Environment'
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/_selected_hosts.html.erb
<%= host.name %>
</td>
<td><%=h host.try(:hostgroup) %></td>
<td><%=h host.try(:environment) %></td>
</tr>
<% end %>
</table>
app/views/hosts/multiple_actions.html.erb
<h2>Choose the action you want to apply to the selected Hosts:</h2>
<%= 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 %>
app/views/hosts/select_multiple_environment.html.erb
<%= render 'selected_hosts', :hosts => @hosts %>
<% form_for :environment, :url => update_multiple_environment_hosts_path do |f| %>
<%= f.collection_select :id, Environment.all, :id, :name, :include_blank => "Select Environment" %>
<%= f.submit "Change Environment!" %></p>
<% end %>
config/routes.rb
:storeconfig_klasses => :get, :externalNodes => :get, :setBuild => :get, :puppetrun => :get},
: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, :reset_multiple => :get}
:update_multiple_hostgroup => :post, :select_multiple_environment => :get, :update_multiple_environment => :post,
:reset_multiple => :get}
map.dashboard '/dashboard', :controller => 'dashboard'
map.audit '/audit', :controller => 'audit'
map.statistics '/statistics', :controller => 'statistics'
(2-2/2)