Class: FactValuesController

Inherits:
ApplicationController show all
Includes:
Foreman::Controller::AutoCompleteSearch, Foreman::Controller::SmartProxyAuth
Defined in:
app/controllers/fact_values_controller.rb

Instance Method Summary collapse

Methods included from Foreman::Controller::SmartProxyAuth

#auth_smart_proxy, #require_puppetmaster_or_login

Methods included from Foreman::Controller::AutoCompleteSearch

#auto_complete_search, #invalid_search_query

Methods inherited from ApplicationController

#api_request?, #welcome

Methods included from Foreman::ThreadSession::Cleaner

#clear_thread, included

Instance Method Details

#createObject


26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'app/controllers/fact_values_controller.rb', line 26

def create
  Taxonomy.no_taxonomy_scope do
    imported = detect_host_type.importHostAndFacts params.delete("facts")
    respond_to do |format|
      format.yml {
        if imported
          render :text => _("Imported facts"), :status => 200 and return
        else
          render :text => _("Failed to import facts"), :status => 400
        end
      }
    end
  end
rescue Exception => e
  logger.warn "Failed to import facts: #{e}"
  render :text => _("Failed to import facts: %s") % (e), :status => 400
end

#indexObject


8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'app/controllers/fact_values_controller.rb', line 8

def index
  begin
    values = FactValue.my_facts.no_timestamp_facts.search_for(params[:search],:order => params[:order])
  rescue => e
    error e.to_s
    values = FactValue.no_timestamp_facts.search_for ""
  end

  respond_to do |format|
    format.html do
      @fact_values = values.required_fields.paginate :page => params[:page]
    end
    format.json do
      render :json => FactValue.build_facts_hash(values.all(:include => [:fact_name, :host]))
    end
  end
end