|
|
@ -41,7 +41,7 @@ class PlanningComparisonService |
|
|
|
where #{Journal.table_name}.created_at=latest.latest_date |
|
|
|
where #{Journal.table_name}.created_at=latest.latest_date |
|
|
|
and #{Journal.table_name}.id=latest.latest_id; |
|
|
|
and #{Journal.table_name}.id=latest.latest_id; |
|
|
|
SQL |
|
|
|
SQL |
|
|
|
@@mapped_attributes = Journal::WorkPackageJournal.journaled_attributes.map{|attribute| "#{Journal::WorkPackageJournal.table_name}.#{attribute}"}.join ',' |
|
|
|
@@mapped_attributes = Journal::WorkPackageJournal.journaled_attributes.map { |attribute| "#{Journal::WorkPackageJournal.table_name}.#{attribute}" }.join ',' |
|
|
|
|
|
|
|
|
|
|
|
@@work_package_select = <<SQL |
|
|
|
@@work_package_select = <<SQL |
|
|
|
Select #{Journal.table_name}.journable_id as id, |
|
|
|
Select #{Journal.table_name}.journable_id as id, |
|
|
@ -58,8 +58,7 @@ SQL |
|
|
|
# the comparison always works on the current date, filters the current workpackages |
|
|
|
# the comparison always works on the current date, filters the current workpackages |
|
|
|
# and returns the state of these work_packages at the given time |
|
|
|
# and returns the state of these work_packages at the given time |
|
|
|
# filters are given in the format expected by Query and are just passed through to query |
|
|
|
# filters are given in the format expected by Query and are just passed through to query |
|
|
|
def self.compare(projects, at_time, filter={}) |
|
|
|
def self.compare(projects, at_time, filter = {}) |
|
|
|
|
|
|
|
|
|
|
|
# The query uses three steps to find the journalized entries for the filtered workpackages |
|
|
|
# The query uses three steps to find the journalized entries for the filtered workpackages |
|
|
|
# at the given point in time: |
|
|
|
# at the given point in time: |
|
|
|
# 1 filter the ids using query |
|
|
|
# 1 filter the ids using query |
|
|
@ -79,7 +78,7 @@ SQL |
|
|
|
.map(&:id) |
|
|
|
.map(&:id) |
|
|
|
|
|
|
|
|
|
|
|
# 3&4 fetch the journaled data and make rails think it is actually a work_package |
|
|
|
# 3&4 fetch the journaled data and make rails think it is actually a work_package |
|
|
|
work_packages = WorkPackage.find_by_sql([@@work_package_select,journal_ids]) |
|
|
|
work_packages = WorkPackage.find_by_sql([@@work_package_select, journal_ids]) |
|
|
|
|
|
|
|
|
|
|
|
restore_references(work_packages) |
|
|
|
restore_references(work_packages) |
|
|
|
end |
|
|
|
end |
|
|
@ -107,7 +106,6 @@ SQL |
|
|
|
# introduced by the json/xml-rendering |
|
|
|
# introduced by the json/xml-rendering |
|
|
|
# the simple .includes does not work the work due to the find_by_sql |
|
|
|
# the simple .includes does not work the work due to the find_by_sql |
|
|
|
def self.restore_references(work_packages) |
|
|
|
def self.restore_references(work_packages) |
|
|
|
|
|
|
|
|
|
|
|
projects = resolve_projects(work_packages) |
|
|
|
projects = resolve_projects(work_packages) |
|
|
|
types = resolve_types(work_packages) |
|
|
|
types = resolve_types(work_packages) |
|
|
|
statuses = resolve_statuses(work_packages) |
|
|
|
statuses = resolve_statuses(work_packages) |
|
|
@ -119,22 +117,20 @@ SQL |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
work_packages |
|
|
|
work_packages |
|
|
|
|
|
|
|
|
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
def self.resolve_projects(work_packages) |
|
|
|
def self.resolve_projects(work_packages) |
|
|
|
project_ids = work_packages.map(&:project_id).uniq.compact |
|
|
|
project_ids = work_packages.map(&:project_id).uniq.compact |
|
|
|
projects = Hash[Project.find(project_ids).map {|wp| [wp.id,wp]}] |
|
|
|
projects = Hash[Project.find(project_ids).map { |wp| [wp.id, wp] }] |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
def self.resolve_types(work_packages) |
|
|
|
def self.resolve_types(work_packages) |
|
|
|
type_ids = work_packages.map(&:type_id).uniq.compact |
|
|
|
type_ids = work_packages.map(&:type_id).uniq.compact |
|
|
|
types = Hash[Type.find(type_ids).map{|type| [type.id,type]}] |
|
|
|
types = Hash[Type.find(type_ids).map { |type| [type.id, type] }] |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
def self.resolve_statuses(work_packages) |
|
|
|
def self.resolve_statuses(work_packages) |
|
|
|
status_ids = work_packages.map(&:status_id).uniq.compact |
|
|
|
status_ids = work_packages.map(&:status_id).uniq.compact |
|
|
|
statuses = Hash[Status.find(status_ids).map{|status| [status.id,status]}] |
|
|
|
statuses = Hash[Status.find(status_ids).map { |status| [status.id, status] }] |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
end |
|
|
|
end |
|
|
|