foreman/app/controllers/reports_controller.rb @ 459e0feb
eafaf5f1 | Ohad Levy | class ReportsController < ApplicationController
|
|
1ba05a93 | Ohad Levy | before_filter :require_login, :except => :create
|
|
6c6713de | Ohad Levy | before_filter :require_ssl, :except => :create
|
|
966a4556 | Ohad Levy | before_filter :verify_authenticity_token, :except => :create
|
|
767bbf03 | Ohad Levy | helper :reports
|
|
07a1c800 | Ohad Levy | # avoids storing the report data in the log files
|
|
filter_parameter_logging :report
|
|||
459e0feb | Paul Kelly | def index
|
|
search_cmd = "Report"
|
|||
for condition in Report::METRIC
|
|||
search_cmd += ".with('#{condition.to_s}', #{params[condition]})" if params.has_key? condition
|
|||
end
|
|||
search_cmd += ".search(params[:search])"
|
|||
# set defaults search order - cant use default scope due to bug in AR
|
|||
# http://github.com/binarylogic/searchlogic/issues#issue/17
|
|||
params[:search] ||= {}
|
|||
params[:search][:order] ||= "ascend_by_reported_at"
|
|||
@search = eval search_cmd
|
|||
@reports = @search.paginate :page => params[:page], :include => [{:host => :domain}]
|
|||
end
|
|||
def show
|
|||
@report = Report.find(params[:id])
|
|||
eafaf5f1 | Ohad Levy | end
|
|
def create
|
|||
respond_to do |format|
|
|||
format.yml {
|
|||
if Report.import params.delete("report")
|
|||
render :text => "Imported report", :status => 200 and return
|
|||
else
|
|||
render :text => "Failed to import report", :status => 500
|
|||
end
|
|||
}
|
|||
end
|
|||
end
|
|||
9f9a8052 | Ohad Levy | ||
459e0feb | Paul Kelly | def destroy
|
|
767bbf03 | Ohad Levy | @report = Report.find(params[:id])
|
|
459e0feb | Paul Kelly | if @report.destroy
|
|
flash[:foreman_notice] = "Successfully destroyed report."
|
|||
else
|
|||
flash[:foreman_error] = @report.errors.full_messages.join("<br>")
|
|||
end
|
|||
redirect_to reports_url
|
|||
767bbf03 | Ohad Levy | end
|
|
eafaf5f1 | Ohad Levy | end
|