kanbanworkflowstimelinescrumrubyroadmapproject-planningproject-managementopenprojectangularissue-trackerifcgantt-chartganttbug-trackerboardsbcf
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
47 lines
1.3 KiB
47 lines
1.3 KiB
15 years ago
|
# encoding: UTF-8
|
||
14 years ago
|
class Report::Transformer
|
||
15 years ago
|
attr_reader :query
|
||
|
|
||
15 years ago
|
def initialize(query)
|
||
15 years ago
|
@query = query
|
||
15 years ago
|
end
|
||
15 years ago
|
|
||
15 years ago
|
##
|
||
14 years ago
|
# @return [Report::Result::Base] Result tree with row group bys at the top
|
||
|
# @see Report::Chainable#result
|
||
15 years ago
|
def row_first
|
||
|
@row_first ||= query.result
|
||
|
end
|
||
|
|
||
15 years ago
|
##
|
||
14 years ago
|
# @return [Report::Result::Base] Result tree with column group bys at the top
|
||
|
# @see Report::Walker#row_first
|
||
15 years ago
|
def column_first
|
||
|
@column_first ||= begin
|
||
15 years ago
|
# reverse since we fake recursion ↓↓↓
|
||
15 years ago
|
list, all_fields = restructured.reverse, @all_fields.dup
|
||
15 years ago
|
result = list.inject(@ungrouped) do |aggregate, (current_fields, type)|
|
||
15 years ago
|
fields, all_fields = all_fields, all_fields - current_fields
|
||
15 years ago
|
aggregate.grouped_by fields, type, current_fields
|
||
15 years ago
|
end
|
||
15 years ago
|
result or query.result
|
||
15 years ago
|
end
|
||
|
end
|
||
|
|
||
15 years ago
|
##
|
||
15 years ago
|
# Important side effect: it sets @ungrouped, @all_fields.
|
||
15 years ago
|
# @return [Array<Array<Array<String,Symbol>, Symbol>>] Group by fields + types (:row or :column)
|
||
15 years ago
|
def restructured
|
||
15 years ago
|
rows, columns, current = [], [], query.chain
|
||
15 years ago
|
@all_fields = []
|
||
15 years ago
|
until current.filter?
|
||
15 years ago
|
@ungrouped = current.result if current.responsible_for_sql?
|
||
|
list = current.row? ? rows : columns
|
||
|
list << [current.group_fields, current.type]
|
||
|
@all_fields.push(*current.group_fields)
|
||
15 years ago
|
current = current.child
|
||
|
end
|
||
|
columns + rows
|
||
|
end
|
||
15 years ago
|
end
|