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.
110 lines
2.7 KiB
110 lines
2.7 KiB
11 years ago
|
#-- copyright
|
||
|
# ReportingEngine
|
||
|
#
|
||
|
# Copyright (C) 2010 - 2014 the OpenProject Foundation (OPF)
|
||
|
#
|
||
|
# This program is free software; you can redistribute it and/or
|
||
|
# modify it under the terms of the GNU General Public License
|
||
|
# version 3.
|
||
|
#
|
||
|
# This program is distributed in the hope that it will be useful,
|
||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
|
# GNU General Public License for more details.
|
||
|
#
|
||
|
# You should have received a copy of the GNU General Public License
|
||
|
# along with this program; if not, write to the Free Software
|
||
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||
|
#++
|
||
|
|
||
15 years ago
|
# encoding: UTF-8
|
||
15 years ago
|
require 'enumerator'
|
||
15 years ago
|
|
||
14 years ago
|
class Report::Table
|
||
15 years ago
|
attr_accessor :query
|
||
14 years ago
|
include Report::QueryUtils
|
||
15 years ago
|
|
||
15 years ago
|
def initialize(query)
|
||
|
@query = query
|
||
15 years ago
|
end
|
||
|
|
||
15 years ago
|
def row_index
|
||
|
get_index :row
|
||
15 years ago
|
end
|
||
|
|
||
15 years ago
|
def column_index
|
||
|
get_index :column
|
||
|
end
|
||
|
|
||
|
def row_fields
|
||
|
fields_for :row
|
||
|
end
|
||
|
|
||
|
def column_fields
|
||
|
fields_for :column
|
||
|
end
|
||
|
|
||
12 years ago
|
def rows_for(result)
|
||
|
fields_for result, :row
|
||
|
end
|
||
|
|
||
|
def columns_for(result)
|
||
|
fields_for result, :column
|
||
|
end
|
||
15 years ago
|
|
||
|
def fields_from(result, type)
|
||
15 years ago
|
fields_for(type).map { |k| map_field k, result.fields[k] }
|
||
15 years ago
|
end
|
||
|
|
||
|
##
|
||
|
# @param [Array] expected Fields expected
|
||
14 years ago
|
# @param [Array,Hash,Result] given Fields/result to be tested
|
||
15 years ago
|
# @return [TrueClass,FalseClass]
|
||
|
def satisfies?(type, expected, given)
|
||
15 years ago
|
given = fields_from(given, type) if given.respond_to? :to_hash
|
||
15 years ago
|
zipped = expected.zip given
|
||
10 years ago
|
zipped.all? { |a, b| a == b or b.nil? }
|
||
15 years ago
|
end
|
||
|
|
||
|
def fields_for(type)
|
||
|
@fields_for ||= begin
|
||
10 years ago
|
child, fields = query.chain, Hash.new { |h, k| h[k] = [] }
|
||
15 years ago
|
until child.filter?
|
||
|
fields[child.type].push(*child.group_fields)
|
||
|
child = child.child
|
||
|
end
|
||
|
fields
|
||
15 years ago
|
end
|
||
|
@fields_for[type]
|
||
|
end
|
||
|
|
||
|
def get_row(*args)
|
||
|
@query.each_row { |result| return with_gaps_for(type, result) if satisfies? :row, args, result }
|
||
|
[]
|
||
|
end
|
||
|
|
||
|
def with_gaps_for(type, result)
|
||
|
return enum_for(:with_gaps_for, type, result) unless block_given?
|
||
|
stack = get_index(type).dup
|
||
15 years ago
|
result.each_direct_result do |subresult|
|
||
|
yield nil until stack.empty? or satisfies? type, stack.shift, subresult
|
||
15 years ago
|
yield subresult
|
||
|
end
|
||
15 years ago
|
stack.size.times { yield nil }
|
||
15 years ago
|
end
|
||
|
|
||
10 years ago
|
def [](x, y)
|
||
15 years ago
|
get_row(row_index[y]).first(x).last
|
||
|
end
|
||
|
|
||
|
def get_index(type)
|
||
|
@indexes ||= begin
|
||
10 years ago
|
indexes = Hash.new { |h, k| h[k] = Set.new }
|
||
15 years ago
|
query.each_direct_result { |result| [:row, :column].each { |t| indexes[t] << fields_from(result, t) } }
|
||
14 years ago
|
indexes.keys.each { |k| indexes[k] = indexes[k].sort { |x, y| compare x, y } }
|
||
15 years ago
|
indexes
|
||
15 years ago
|
end
|
||
|
@indexes[type]
|
||
|
end
|
||
15 years ago
|
end
|