Class: Spree::Report
- Inherits:
-
Object
show all
- Defined in:
- app/reports/spree/report.rb,
app/reports/spree/report/chart.rb,
app/reports/spree/report/result.rb,
app/reports/spree/report/timed_result.rb
Direct Known Subclasses
BestSellingProductsReport, CartAdditionsReport, CartRemovalsReport, CartUpdationsReport, PaymentMethodTransactionsConversionRateReport, PaymentMethodTransactionsReport, ProductViewsReport, ProductViewsToCartAdditionsReport, ProductViewsToPurchasesReport, PromotionalCostReport, ReturnedProductsReport, SalesPerformanceReport, SalesTaxReport, ShippingCostReport, TrendingSearchReport, UniquePurchasesReport, UserPoolReport, UsersNotConvertedReport, UsersWhoRecentlyPurchasedReport
Defined Under Namespace
Modules: Chart, DateSlicer, QueryFragments, QueryTimeScale
Classes: Configuration, Observation, Result, TimedObservation, TimedResult
Constant Summary
collapse
- TIME_SCALES =
[:hourly, :daily, :monthly, :yearly]
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(options) ⇒ Report
Returns a new instance of Report.
42
43
44
45
46
47
48
49
50
51
52
|
# File 'app/reports/spree/report.rb', line 42
def initialize(options)
self.search = options.fetch(:search, {})
self.records_per_page = options[:records_per_page]
self.current_page = options[:offset]
self.paginate = options[:paginate]
determine_report_time_scale
if self.class::SORTABLE_ATTRIBUTES.present?
set_sortable_attributes(options, self.class::DEFAULT_SORTABLE_ATTRIBUTE)
end
end
|
Instance Attribute Details
#current_page ⇒ Object
Returns the value of attribute current_page.
4
5
6
|
# File 'app/reports/spree/report.rb', line 4
def current_page
@current_page
end
|
#paginate ⇒ Object
Also known as:
paginate?
Returns the value of attribute paginate.
4
5
6
|
# File 'app/reports/spree/report.rb', line 4
def paginate
@paginate
end
|
#records_per_page ⇒ Object
Returns the value of attribute records_per_page.
4
5
6
|
# File 'app/reports/spree/report.rb', line 4
def records_per_page
@records_per_page
end
|
#reporting_period ⇒ Object
Returns the value of attribute reporting_period.
4
5
6
|
# File 'app/reports/spree/report.rb', line 4
def reporting_period
@reporting_period
end
|
#search ⇒ Object
Returns the value of attribute search.
4
5
6
|
# File 'app/reports/spree/report.rb', line 4
def search
@search
end
|
#sortable_attribute ⇒ Object
Returns the value of attribute sortable_attribute.
4
5
6
|
# File 'app/reports/spree/report.rb', line 4
def sortable_attribute
@sortable_attribute
end
|
#sortable_type ⇒ Object
Also known as:
sort_direction
Returns the value of attribute sortable_type.
4
5
6
|
# File 'app/reports/spree/report.rb', line 4
def sortable_type
@sortable_type
end
|
#total_records ⇒ Object
Returns the value of attribute total_records.
4
5
6
|
# File 'app/reports/spree/report.rb', line 4
def total_records
@total_records
end
|
Class Method Details
.deeplink(template_for_headers = {}) ⇒ Object
26
27
28
29
30
|
# File 'app/reports/spree/report.rb', line 26
def self.deeplink( = {})
define_method :deeplink_properties do
{ deeplinked: true }.merge()
end
end
|
Instance Method Details
#active_record_sort ⇒ Object
76
77
78
|
# File 'app/reports/spree/report.rb', line 76
def active_record_sort
"#{ sortable_attribute } #{ sortable_type }"
end
|
#deeplink_properties ⇒ Object
20
21
22
23
24
|
# File 'app/reports/spree/report.rb', line 20
def deeplink_properties
{
deeplinked: false
}
end
|
#generate(options = {}) ⇒ Object
32
33
34
35
36
37
38
39
|
# File 'app/reports/spree/report.rb', line 32
def generate(options = {})
self.class::Result.new do |report|
report.start_date = @start_date
report.end_date = @end_date
report.time_scale = @time_scale
report.report = self
end
end
|
#get_results ⇒ Object
58
59
60
61
62
63
64
65
66
67
68
69
|
# File 'app/reports/spree/report.rb', line 58
def get_results
query =
if
paginated_report_query
else
report_query
end
query = query.order(active_record_sort) if sortable_attribute.present?
query_sql = query.to_sql
r = ActiveRecord::Base.connection.exec_query(query_sql)
end
|
54
55
56
|
# File 'app/reports/spree/report.rb', line 54
def ()
sortable_attribute.present? && sortable_attribute.eql?()
end
|
#name ⇒ Object
104
105
106
|
# File 'app/reports/spree/report.rb', line 104
def name
@_report_name ||= self.class.to_s.demodulize.underscore.gsub("_report", "")
end
|
#paginated? ⇒ Boolean
12
13
14
|
# File 'app/reports/spree/report.rb', line 12
def paginated?
false
end
|
16
17
18
|
# File 'app/reports/spree/report.rb', line 16
def
paginated? && paginate?
end
|
#set_sortable_attributes(options, default_sortable_attribute) ⇒ Object
71
72
73
74
|
# File 'app/reports/spree/report.rb', line 71
def set_sortable_attributes(options, default_sortable_attribute)
self.sortable_type ||= (options[:sort] && options[:sort][:type].eql?('desc')) ? :desc : :asc
self.sortable_attribute = options[:sort] ? options[:sort][:attribute].to_sym : default_sortable_attribute
end
|
#time_scale_columns ⇒ Object
#time_scale_columns_to_s ⇒ Object
100
101
102
|
# File 'app/reports/spree/report.rb', line 100
def time_scale_columns_to_s
@_time_scale_columns_to_s ||= time_scale_columns.collect(&:to_s)
end
|
#time_scale_selects(time_scale_on = nil) ⇒ Object
92
93
94
|
# File 'app/reports/spree/report.rb', line 92
def time_scale_selects(time_scale_on = nil)
QueryTimeScale.select(@time_scale, time_scale_on)
end
|
#total_pages ⇒ Object
84
85
86
87
88
89
90
|
# File 'app/reports/spree/report.rb', line 84
def total_pages
if
total_pages = total_records / records_per_page
total_pages -= 1 if total_records % records_per_page == 0
total_pages
end
end
|