From 4eb8402594b9a3043217586ef285834a6f798110 Mon Sep 17 00:00:00 2001 From: Stefan Frank Date: Tue, 1 Oct 2013 15:00:24 +0200 Subject: [PATCH] replaced compare_date with at_time --- app/controllers/api/v2/planning_elements_controller.rb | 6 +++--- app/services/planning_comparison_service.rb | 8 ++++---- features/planning_elements/filter.feature | 2 +- features/step_definitions/api_steps.rb | 6 +++--- 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/app/controllers/api/v2/planning_elements_controller.rb b/app/controllers/api/v2/planning_elements_controller.rb index e279db75c0..a4e10beb5e 100644 --- a/app/controllers/api/v2/planning_elements_controller.rb +++ b/app/controllers/api/v2/planning_elements_controller.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 diff --git a/app/services/planning_comparison_service.rb b/app/services/planning_comparison_service.rb index 1f5e07f5b3..b1a5bad3f8 100644 --- a/app/services/planning_comparison_service.rb +++ b/app/services/planning_comparison_service.rb @@ -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 \ No newline at end of file diff --git a/features/planning_elements/filter.feature b/features/planning_elements/filter.feature index 44702e90b3..cf078760d7 100644 --- a/features/planning_elements/filter.feature +++ b/features/planning_elements/filter.feature @@ -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" diff --git a/features/step_definitions/api_steps.rb b/features/step_definitions/api_steps.rb index ab3a417c86..8de3c801a7 100644 --- a/features/step_definitions/api_steps.rb +++ b/features/step_definitions/api_steps.rb @@ -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