replaced compare_date with at_time

pull/1215/head
Stefan Frank 11 years ago
parent e3ff807796
commit 4eb8402594
  1. 6
      app/controllers/api/v2/planning_elements_controller.rb
  2. 8
      app/services/planning_comparison_service.rb
  3. 2
      features/planning_elements/filter.feature
  4. 6
      features/step_definitions/api_steps.rb

@ -170,7 +170,7 @@ module Api
# is called as a before filter and as a method
def assign_planning_elements(projects = (@projects || [@project]))
@planning_elements = if params[:compare_date]
@planning_elements = if params[:at_time]
historical_work_packages
else
current_work_packages
@ -190,9 +190,9 @@ module Api
end
def historical_work_packages
compare_date = Date.parse(params[:compare_date])
at_time = Date.parse(params[:at_time])
filter = {f: params[:f], op: params[:op], v: params[:v]}
historical = PlanningComparisonService.compare(@project, compare_date, filter)
historical = PlanningComparisonService.compare(@project, at_time, filter)
end
# remove this and replace by calls it with calls

@ -4,7 +4,7 @@ class PlanningComparisonService
from journals
inner join (select journable_id, max(created_at) as latest_date
from #{Journal.table_name}
where #{Journal.table_name}.created_at <= '#compare_date'
where #{Journal.table_name}.created_at <= '#at_time'
group by #{Journal.table_name}.journable_id) as latest
on #{Journal.table_name}.journable_id=latest.journable_id
and #{Journal.table_name}.created_at=latest.latest_date
@ -27,7 +27,7 @@ SQL
# the comparison always works on the current date, filters the current workpackages
# 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
def self.compare(project, compare_date, filter={})
def self.compare(project, at_time, filter={})
# The query uses three steps to find the journalized entries for the filtered workpackages
# at the given point in time:
@ -56,7 +56,7 @@ SQL
# 2 fetch latest journal-entries for the given time
sql = @@journal_sql.gsub("#work_package_ids", work_package_ids.join(','))
.gsub("#compare_date", compare_date.strftime("%Y-%m-%d"))
.gsub("#at_time", at_time.strftime("%Y-%m-%d"))
journal_ids = ActiveRecord::Base.connection.execute(sql)
.map{|result| result["id"]}
@ -64,7 +64,7 @@ SQL
# use the journaled attributes to make the journal-entry appear like a real(tm) WorkPackage
attributes = Journal::WorkPackageJournal::journaled_attributes_keys.map{|attribute| "#{Journal::WorkPackageJournal.table_name}.#{attribute}"}.join ','
# 3 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.gsub('#journal_ids',journal_ids.join(',')))
end
end

@ -227,7 +227,7 @@ Feature: Filtering work packages via the api
| type | Story |
| responsible | bob |
Given the date is "2010/03/01"
And I call the work_package-api on project "sample_project" with compare-date "2010/01/03" and filter for types "Story"
And I call the work_package-api on project "sample_project" at time "2010/01/03" and filter for types "Story"
Then the json-response should include 1 work package
And the json-response for work_package "work_package#3" should have the type "Task"
And the json-response for work_package "work_package#3" should have the responsible "Pamela Anderson"

@ -112,7 +112,7 @@ When(/^I call the work_package\-api on project "(.*?)" requesting format "(.*?)"
end
And(/^I call the work_package\-api on project "(.*?)" with compare\-date "(.*?)" and filter for types "(.*?)"$/) do |project_name, compare_date, type_names|
And(/^I call the work_package\-api on project "(.*?)" at time "(.*?)" and filter for types "(.*?)"$/) do |project_name, at_time, type_names|
types = Project.find_by_identifier(project_name).types.where(name: type_names.split(','))
get_filtered_json(project_name: project_name,
@ -120,7 +120,7 @@ And(/^I call the work_package\-api on project "(.*?)" with compare\-date "(.*?)"
filters: [:type_id],
operators: {type_id: '='},
values: {type_id: types.map(&:id)},
compare_date: compare_date)
at_time: at_time)
end
@ -177,7 +177,7 @@ def get_filtered_json(params)
f: params[:filters],
op: params[:operators],
v: params[:values],
compare_date: params[:compare_date])
at_time: params[:at_time])
end
end

Loading…
Cancel
Save