Class: ReportsController

Inherits:
ApplicationController show all
Includes:
Foreman::Controller::AutoCompleteSearch, Foreman::Controller::SmartProxyAuth
Defined in:
app/controllers/reports_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


36
37
38
39
40
41
42
43
44
45
46
# File 'app/controllers/reports_controller.rb', line 36

def create
  Taxonomy.no_taxonomy_scope do
    if Report.import params.delete("report") || request.body
      render :text => _("Imported report"), :status => 200 and return
    else
      render :text => _("Failed to import report"), :status => 500
    end
  end
rescue => e
  render :text => e.to_s, :status => 500
end

#destroyObject


48
49
50
51
52
53
54
55
56
# File 'app/controllers/reports_controller.rb', line 48

def destroy
  @report = Report.find(params[:id])
  if @report.destroy
    notice _("Successfully destroyed report.")
  else
    error @report.errors.full_messages.join("<br/>")
  end
  redirect_to reports_url
end

#indexObject


8
9
10
11
12
13
14
15
16
17
18
# File 'app/controllers/reports_controller.rb', line 8

def index
  values = Report.my_reports.search_for(params[:search], :order => params[:order])
  pagination_opts = { :page => params[:page], :per_page => params[:per_page] }
  respond_to do |format|
    format.html { @reports =      values.paginate(pagination_opts).includes(:host) }
    format.json { render :json => values.paginate(pagination_opts).includes(:host, :logs)}
  end
rescue => e
  error e.to_s
  @reports = Report.my_reports.search_for("").paginate :page => params[:page]
end

#showObject


20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'app/controllers/reports_controller.rb', line 20

def show  # are we searching for the last report?

  if params[:id] == "last"
    conditions = { :host_id => Host.find_by_name(params[:host_id]).try(:id) } unless params[:host_id].blank?
    params[:id] = Report.my_reports.maximum(:id, :conditions => conditions)
  end

  return not_found if params[:id].blank?

  @report = Report.my_reports.find(params[:id], :include => { :logs => [:message, :source] })
  respond_to do |format|
    format.html { @offset = @report.reported_at - @report.created_at }
    format.json { render :json => @report }
  end
end