Sha256: 5b5dabef81bbebf3877bfca7537c5a14bbb40b1c15f3c427ad673f98a3229034

Contents?: true

Size: 1.32 KB

Versions: 6

Compression:

Stored size: 1.32 KB

Contents

module ForemanSalt
  module Concerns
    module HostgroupsControllerExtensions
      extend ActiveSupport::Concern

      included do
        alias_method_chain :load_vars_for_ajax, :salt_modules
      end

      def salt_environment_selected
        @hostgroup = Hostgroup.authorized(:view_hostgroups, Hostgroup).find_by_id(params[:hostgroup_id]) || Hostgroup.new(params[:hostgroup])

        if params[:hostgroup][:salt_environment_id].present?
          @salt_environment = ::ForemanSalt::SaltEnvironment.find(params[:hostgroup][:salt_environment_id])
          load_vars_for_ajax
          render :partial => 'foreman_salt/salt_modules/host_tab_pane'
        else
          logger.info 'environment_id is required to render states'
        end
      end

      private

      def load_vars_for_ajax_with_salt_modules
        load_vars_for_ajax_without_salt_modules
        @obj = @hostgroup
        @salt_environment ||= @hostgroup.salt_environment

        if @salt_environment
          @inherited_salt_modules = @salt_environment.salt_modules.where(:id => @hostgroup.inherited_salt_modules)
          @salt_modules           = @salt_environment.salt_modules - @inherited_salt_modules
        else
          @inherited_salt_modules = @salt_modules = []
        end

        @selected = @hostgroup.salt_modules || []
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
foreman_salt-4.0.1 app/controllers/foreman_salt/concerns/hostgroups_controller_extensions.rb
foreman_salt-4.0.0 app/controllers/foreman_salt/concerns/hostgroups_controller_extensions.rb
foreman_salt-3.0.2 app/controllers/foreman_salt/concerns/hostgroups_controller_extensions.rb
foreman_salt-3.0.1 app/controllers/foreman_salt/concerns/hostgroups_controller_extensions.rb
foreman_salt-3.0.0 app/controllers/foreman_salt/concerns/hostgroups_controller_extensions.rb
foreman_salt-2.1.0 app/controllers/foreman_salt/concerns/hostgroups_controller_extensions.rb