The aim of this gem is to standardise reporting. It also allow registration of reports and have them appear in the UI.
It will be used for reports which can not otherwise be produced with the data grid.
To register a report:
Reporting.register(name: 'BRU Recruitment Report',
report: Recruitment::Reports::BruRecruitment.new,
view: Recruitment::Engine.root.join('app/views/reports/bru_recruitment'))
Reports should follow provide this interface as a minimum:
class MyReport
def call
end
end
This report, since it has no user input will be have the create
view rendered.
Reports should be stateless so they same report can be called many times with different inputs.
Providing user input to the report:
class MyReport
class Form
include Reporting::Form
attribute :start_date, Date
validate :start_date, presence: true
end
end
class MyReport
def call(form)
end
end
Since the above report requires user input the new
view will be rendered first, if the form object is valid the report is generated and the create
action rendered.
Automatic CSV generation:
You can have your report automatically generate CSV if the dataset returns a Hash. The Hash keys will become the columns. To restrict the columns provide a method as such:
class MyReport
def csv_columns
%w(...)
end
end
Normally the create
view is used to render a report, if you wish to provide multiple ways of rendering the same report
add an attribute to the form to allow the user to select their view and render a different partial from the create
action based on this.