Sha256: 0f22d8b9fa3674b3d1fa58e16f1a66b130f34eaf3052f4891450e06f12d80444

Contents?: true

Size: 1.91 KB

Versions: 5

Compression:

Stored size: 1.91 KB

Contents

require 'foreman/controller/smart_proxy_auth'

class ReportsController < ApplicationController
  include Foreman::Controller::AutoCompleteSearch
  include Foreman::Controller::SmartProxyAuth

  add_puppetmaster_filters :create
  before_filter :setup_search_options, :only => :index

  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

  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

  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

  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

end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
foreman_discovery-1.0.0 test/foreman_app/app/controllers/reports_controller.rb
foreman_discovery-1.0.0.rc4 test/foreman_app/app/controllers/reports_controller.rb
foreman_discovery-1.0.0.rc3 test/foreman_app/app/controllers/reports_controller.rb
foreman_discovery-1.0.0.rc2 test/foreman_app/app/controllers/reports_controller.rb
foreman_discovery-1.0.0.rc1 test/foreman_app/app/controllers/reports_controller.rb