diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js index 67c3738b9227..e6db70a0843e 100644 --- a/app/assets/javascripts/application.js +++ b/app/assets/javascripts/application.js @@ -345,35 +345,6 @@ $(function() { }); }); -function update_puppetclasses(element) { - var host_id = $('form').data('id'); - var url = $(element).attr('data-url'); - var data = serializeForm().replace('method=patch', 'method=post'); - - if (element.value == '') return; - if (url.match('hostgroups')) { - data = data + '&hostgroup_id=' + host_id; - } else { - data = data + '&host_id=' + host_id; - } - - tfm.tools.showSpinner(); - $.ajax({ - type: 'post', - url: url, - data: data, - success: function(request) { - $('#puppet_klasses').html(request); - reload_puppetclass_params(); - tfm.tools.activateTooltips(); - tfm.hostgroups.checkForUnavailablePuppetclasses(); - }, - complete: function() { - reloadOnAjaxComplete(element); - }, - }); -} - function spinner_placeholder(text) { if (text == undefined) text = ''; return ( diff --git a/app/assets/javascripts/host_edit.js b/app/assets/javascripts/host_edit.js index 18031aff48e1..c7b41b73634f 100644 --- a/app/assets/javascripts/host_edit.js +++ b/app/assets/javascripts/host_edit.js @@ -3,9 +3,6 @@ $(document).on('ContentLoad', function() { onHostEditLoad(); }); -$(document).on('AddedClass', function(event, link) { - load_puppet_class_parameters(link); -}); $(document) .on('change', '.hostgroup-select', function(evt) { hostgroup_changed(evt.target); @@ -238,44 +235,6 @@ function update_progress(data) { $('#tasks_progress').replaceWith(data); } -function load_puppet_class_parameters(item) { - var id = $(item).attr('data-class-id'); - // host_id could be either host.id OR hostgroup.id depending on which form - var host_id = $('form').data('id'); - if ($('#puppetclass_' + id + '_params_loading').length > 0) return; // already loading - if ($('[id^="#puppetclass_' + id + '_params\\["]').length > 0) return; // already loaded - var url = $(item).attr('data-url'); - var data = serializeForm().replace('method=patch', 'method=post'); - if (url.match('hostgroups')) { - data = data + '&hostgroup_id=' + host_id; - } else { - data = data + '&host_id=' + host_id; - } - - if (url == undefined) return; // no parameters - var placeholder = $( - '' + - '' + - spinner_placeholder(__('Loading parameters...')) + - '' - ); - $('#inherited_puppetclasses_parameters').append(placeholder); - $.ajax({ - url: url, - type: 'post', - data: data, - success: function(result, textstatus, xhr) { - var params = $(result); - placeholder.replaceWith(params); - params.find('a[rel="popover"]').popover(); - if (params.find('.error').length > 0) - $('#params-tab').addClass('tab-error'); - }, - }); -} - function hostgroup_changed(element) { var host_id = $('form').data('id'); var host_changed = $('form').data('type-changed'); @@ -296,7 +255,6 @@ function handleHostgroupChangeEdit(element, host_id, host_changed) { } else { // edit host set_inherited_value(element); - update_puppetclasses(element); reload_host_params(); } } @@ -431,7 +389,6 @@ function os_selected(element) { success: function(request) { $('#media_select').html(request); reload_host_params(); - reload_puppetclass_params(); }, }); update_provisioning_image(); @@ -525,18 +482,6 @@ function reload_host_params() { } } -function reload_puppetclass_params() { - var host_id = $('form.hostresource-form').data('id'); - var url2 = $('#params-tab').data('url2'); - var data = serializeForm().replace('method=patch', 'method=post'); - if (url2.match('hostgroups')) { - data = data + '&hostgroup_id=' + host_id; - } else { - data = data + '&host_id=' + host_id; - } - load_with_placeholder('inherited_puppetclasses_parameters', url2, data); -} - function load_with_placeholder(target, url, data) { if (url == undefined) return; var placeholder = $( @@ -561,7 +506,6 @@ function load_with_placeholder(target, url, data) { function onHostEditLoad() { update_interface_table(); - tfm.hostgroups.checkForUnavailablePuppetclasses(); $('#host-conflicts-modal').modal({ show: 'true', backdrop: 'static' }); $('#host-conflicts-modal').click(function() { @@ -636,7 +580,6 @@ $(document).on('change', '.interface_domain', function() { ); interface_domain_selected(this); reload_host_params(); - reload_puppetclass_params(); }); function clearIpField(parent, childclass) { diff --git a/app/controllers/concerns/foreman/controller/puppet/hosts_controller_extensions.rb b/app/controllers/concerns/foreman/controller/puppet/hosts_controller_extensions.rb index 0e885c98195a..6b83785d98fb 100644 --- a/app/controllers/concerns/foreman/controller/puppet/hosts_controller_extensions.rb +++ b/app/controllers/concerns/foreman/controller/puppet/hosts_controller_extensions.rb @@ -2,7 +2,6 @@ module Foreman::Controller::Puppet::HostsControllerExtensions extend ActiveSupport::Concern PUPPETMASTER_ACTIONS = [:externalNodes, :lookup] - PUPPET_AJAX_REQUESTS = %w{hostgroup_or_environment_selected puppetclass_parameters} MULTIPLE_EDIT_ACTIONS = %w(select_multiple_environment update_multiple_environment select_multiple_puppet_proxy update_multiple_puppet_proxy @@ -10,10 +9,7 @@ module Foreman::Controller::Puppet::HostsControllerExtensions included do add_smart_proxy_filters PUPPETMASTER_ACTIONS, :features => ['Puppet'] - alias_method :ajax_request_for_puppet_host_extensions, :ajax_request - before_action :ajax_request_for_puppet_host_extensions, :only => PUPPET_AJAX_REQUESTS - before_action :taxonomy_scope_for_puppet_host_extensions, :only => PUPPET_AJAX_REQUESTS before_action :find_multiple_for_puppet_host_extensions, :only => MULTIPLE_EDIT_ACTIONS before_action :validate_multiple_puppet_proxy, :only => :update_multiple_puppet_proxy before_action :validate_multiple_puppet_ca_proxy, :only => :update_multiple_puppet_ca_proxy @@ -23,24 +19,6 @@ module Foreman::Controller::Puppet::HostsControllerExtensions set_callback :set_class_variables, :after, :set_puppet_class_variables end - def hostgroup_or_environment_selected - refresh_host - set_class_variables(@host) - Taxonomy.as_taxonomy @organization, @location do - if @environment || @hostgroup - render :partial => 'puppetclasses/class_selection', :locals => {:obj => @host} - else - logger.info "environment_id or hostgroup_id is required to render puppetclasses" - end - end - end - - def puppetclass_parameters - Taxonomy.as_taxonomy @organization, @location do - render :partial => "puppetclasses/classes_parameters", :locals => { :obj => refresh_host} - end - end - def select_multiple_environment end @@ -174,10 +152,6 @@ def set_puppet_class_variables @environment = @host.environment end - def taxonomy_scope_for_puppet_host_extensions - taxonomy_scope - end - def find_multiple_for_puppet_host_extensions find_multiple end diff --git a/app/controllers/hostgroups_controller.rb b/app/controllers/hostgroups_controller.rb index a3b810c70d69..a9b222f3cf0a 100644 --- a/app/controllers/hostgroups_controller.rb +++ b/app/controllers/hostgroups_controller.rb @@ -6,7 +6,7 @@ class HostgroupsController < ApplicationController include Foreman::Controller::SetRedirectionPath before_action :find_resource, :only => [:nest, :clone, :edit, :update, :destroy] - before_action :ajax_request, :only => [:process_hostgroup, :puppetclass_parameters] + before_action :ajax_request, :only => [:process_hostgroup] before_action :taxonomy_scope, :only => [:new, :edit, :process_hostgroup] def index @@ -83,25 +83,6 @@ def destroy process_error(:error_msg => _("Cannot delete group %{current} because it has nested groups.") % { :current => @hostgroup.title }) end - def puppetclass_parameters - Taxonomy.as_taxonomy @organization, @location do - render :partial => "puppetclasses/classes_parameters", - :locals => { :obj => refresh_hostgroup } - end - end - - def environment_selected - env_id = params[:environment_id] || params[:hostgroup][:environment_id] - return not_found if env_id.to_i > 0 && !(@environment = Environment.find(env_id)) - - refresh_hostgroup - @hostgroup.environment = @environment if @environment - - @hostgroup.puppetclasses = Puppetclass.where(:id => params[:hostgroup][:puppetclass_ids]) - @hostgroup.config_groups = ConfigGroup.where(:id => params[:hostgroup][:config_group_ids]) - render :partial => 'puppetclasses/class_selection', :locals => {:obj => @hostgroup, :type => 'hostgroup'} - end - def process_hostgroup define_parent refresh_hostgroup diff --git a/app/helpers/puppet_related_helper.rb b/app/helpers/puppet_related_helper.rb index e85c543eeafd..303fe434379d 100644 --- a/app/helpers/puppet_related_helper.rb +++ b/app/helpers/puppet_related_helper.rb @@ -5,68 +5,6 @@ module PuppetRelatedHelper overview_buttons_provider :puppet_host_overview_buttons end - def host_puppet_environment_field(form, select_options = {}, html_options = {}) - select_options = { - :include_blank => true, - :disable_button => _(HostsAndHostgroupsHelper::INHERIT_TEXT), - :disable_button_enabled => inherited_by_default?(:environment_id, @host), - :user_set => user_set?(:environment_id)}.deep_merge(select_options) - - html_options = { - :data => { - :url => hostgroup_or_environment_selected_hosts_path, - :host => { - :id => @host.id, - }, - }}.deep_merge(html_options) - - puppet_environment_field( - form, - accessible_resource(@host, :environment), - select_options, - html_options) - end - - def hostgroup_puppet_environment_field(form, select_options = {}, html_options = {}) - select_options = { - :include_blank => blank_or_inherit_f(form, :environment), - }.deep_merge(select_options) - - html_options = { - :data => { - :url => environment_selected_hostgroups_path, - }}.deep_merge(html_options) - - puppet_environment_field( - form, - accessible_resource(@hostgroup, :environment), - select_options, - html_options) - end - - def puppet_environment_field(form, environments_choice, select_options = {}, html_options = {}) - html_options = { - :onchange => "update_puppetclasses(this)", - :help_inline => :indicator}.deep_merge(html_options) - - select_f( - form, - :environment_id, - environments_choice, - :id, - :to_label, - select_options, - html_options) - end - - def interesting_puppetclasses(obj) - classes = obj.all_puppetclasses - classes_ids = classes.reorder(nil).pluck("puppetclasses.id") - class_vars = PuppetclassLookupKey.reorder(nil).joins(:environment_classes).where(:environment_classes => { :puppetclass_id => classes_ids }).distinct.pluck("environment_classes.puppetclass_id") - - classes.where(:id => class_vars) - end - def puppet_actions actions = [] if authorized_for(:controller => :hosts, :action => :edit) diff --git a/app/views/hostgroups/_form.html.erb b/app/views/hostgroups/_form.html.erb index bff7eed54a2d..9a67ed72d513 100644 --- a/app/views/hostgroups/_form.html.erb +++ b/app/views/hostgroups/_form.html.erb @@ -1,5 +1,5 @@ <%= javascript 'host_edit', 'host_edit_interfaces' %> -<%= form_for @hostgroup, :html => {:class => 'hostresource-form form-horizontal well', :data => {:id => @hostgroup.try(:id)}} do |f| %> +<%= form_for @hostgroup, :html => {:class => 'hostresource-form hostgroup-form form-horizontal well', :data => {:id => @hostgroup.try(:id)}} do |f| %> <%= base_errors_for @hostgroup %>