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.
92 lines
2.4 KiB
92 lines
2.4 KiB
14 years ago
|
class Report::GroupBy
|
||
14 years ago
|
class Base < Report::Chainable
|
||
14 years ago
|
include Report::QueryUtils
|
||
|
|
||
14 years ago
|
inherited_attributes :group_fields, :list => true, :merge => false
|
||
15 years ago
|
|
||
|
def self.inherited(klass)
|
||
|
klass.group_fields klass.field
|
||
|
super
|
||
|
end
|
||
|
|
||
15 years ago
|
def correct_position?
|
||
14 years ago
|
type == :row or !child.is_a?(engine::GroupBy::Base) or child.type == :column
|
||
15 years ago
|
end
|
||
|
|
||
15 years ago
|
def filter?
|
||
|
false
|
||
|
end
|
||
|
|
||
|
def sql_aggregation?
|
||
|
child.filter?
|
||
|
end
|
||
15 years ago
|
|
||
15 years ago
|
##
|
||
|
# @param [FalseClass, TrueClass] prefix Whether or not add a table prefix the field names
|
||
|
# @return [Array<String,Symbol>] List of group by fields corresponding to self and all parents'
|
||
|
def all_group_fields(prefix = true)
|
||
15 years ago
|
@all_group_fields ||= []
|
||
|
@all_group_fields[prefix ? 0 : 1] ||= begin
|
||
14 years ago
|
fields = group_fields.reject { |c| c.blank? or c == 'base' }
|
||
14 years ago
|
(parent ? parent.all_group_fields(prefix) : []) + (prefix ? with_table(fields) : fields)
|
||
15 years ago
|
end.uniq
|
||
|
end
|
||
|
|
||
14 years ago
|
def self.select_fields(*fields)
|
||
|
unless fields.empty?
|
||
|
@select_fields ||= []
|
||
|
@select_fields += fields
|
||
|
end
|
||
|
@select_fields
|
||
|
end
|
||
|
|
||
|
def select_fields
|
||
|
if self.class.select_fields
|
||
|
(parent ? parent.select_fields : []) + self.class.select_fields
|
||
|
else
|
||
|
group_fields
|
||
|
end
|
||
|
end
|
||
|
|
||
|
##
|
||
|
# @param [FalseClass, TrueClass] prefix Whether or not add a table prefix the field names
|
||
|
# @return [Array<String,Symbol>] List of select fields corresponding to self and all parents'
|
||
|
def all_select_fields(prefix = true)
|
||
|
@all_select_fields ||= []
|
||
|
@all_select_fields[prefix ? 0 : 1] ||= begin
|
||
|
fields = select_fields.reject { |c| c.blank? or c == 'base' }
|
||
|
(parent ? parent.all_select_fields(prefix) : []) + (prefix ? with_table(fields) : fields)
|
||
|
end.uniq
|
||
|
end
|
||
|
|
||
15 years ago
|
def clear
|
||
14 years ago
|
@all_group_fields = @all_select_fields = nil
|
||
15 years ago
|
super
|
||
15 years ago
|
end
|
||
|
|
||
|
def aggregation_mixin
|
||
14 years ago
|
sql_aggregation? ? engine::GroupBy::SqlAggregation : engine::GroupBy::RubyAggregation
|
||
14 years ago
|
end
|
||
15 years ago
|
|
||
|
def initialize(child = nil, optios = {})
|
||
|
super
|
||
|
extend aggregation_mixin
|
||
|
end
|
||
|
|
||
15 years ago
|
def result
|
||
|
super
|
||
|
end
|
||
|
|
||
|
def compute_result
|
||
|
super.tap do |r|
|
||
|
r.type = type
|
||
|
r.important_fields = group_fields
|
||
|
end
|
||
|
end
|
||
|
|
||
15 years ago
|
def define_group(sql)
|
||
14 years ago
|
sql.select all_select_fields
|
||
|
sql.group_by all_group_fields
|
||
15 years ago
|
end
|
||
|
end
|
||
|
end
|