Create a gist now

Instantly share code, notes, and snippets.

Embed
What would you like to do?
class DistributionReport < BaseReport
attr_accessor :current_user
scope do
Distribution.includes(:owner => {}, :matching_profile => [])
end
filter(:partner_id, :integer) do |partner_id|
self.by_partner_ids(partner_id)
end
filter(:matching_profile_id, :enum, :select => [], :include_blank => false, :multiple => true) do |matching_profile_id|
matching_profile_id.reject!(&:blank?)
if matching_profile_id.empty?
self.scoped({})
else
self.conditions(:matching_profile_id => matching_profile_id)
end
end
filter(:exported, :eboolean) do |value|
self.scoped({})
end
date_range_filters(:created_at)
column(:first_name, :order => "users.first_name") do
self.owner.first_name
end
column(:last_name, :order => "users.last_name") do
self.owner.last_name
end
column(:location) do
self.owner.location_tags.first.try(:title)
end
column(:email, :order => "users.email") do
self.owner.email
end
column(:last_job_employer) do
self.owner.profile.last_job_employer
end
column(:last_job_title) do
self.owner.profile.last_job_title
end
column(:matching_profile) do
self.matching_profile.title
end
column(:delivered_at, :order => "distributions.created_at") do
self.created_at
end
column(:price)
column(:resume, :format => :url) do
self.resume && UrlService.download_blob_url(self.resume)
end
def partner
partner_id.blank? ? nil : Partner.find(self.partner_id)
end
def matching_profiles
MatchingProfile.within(self.matching_profile_id)
end
def distributions
assets
end
def to_param
:report
end # to_param
def to_csv(options = {})
self.assets.each do |distribution|
distribution.download!(self.current_user)
end
super(options)
end
def scope
result = super
unless self.exported.blank?
result = scope.downloaded_by(self.current_user, self.exported == "YES")
end
result
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment