Created
October 20, 2015 15:07
-
-
Save cvd/8b5e0147c30abb63a1ce to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/app/models/data_platform/filters/base.rb b/app/models/data_platform/filters/base.rb | |
index a2442a1..3b028b9 100644 | |
--- a/app/models/data_platform/filters/base.rb | |
+++ b/app/models/data_platform/filters/base.rb | |
@@ -2,8 +2,6 @@ class DataPlatform::Filters::Base | |
FILTER_TYPES = [:id, :date] | |
- class_attribute :token, :name, :opts | |
- | |
delegate :params, :query_args, to: :@query_obj | |
self.opts = {} | |
@@ -38,8 +36,15 @@ class DataPlatform::Filters::Base | |
self.opts = options | |
end | |
- def initialize(query) | |
+ def initialize(query, options) | |
+ @options = options | |
@query_obj = query | |
+ defaults = { | |
+ type: self.class.type, | |
+ token: self.class.token, | |
+ name: self.class.name | |
+ } | |
+ @options.reverse_merge!(defaults) | |
end | |
def apply | |
@@ -50,7 +55,7 @@ class DataPlatform::Filters::Base | |
Rails.logger.debug "No filter applied for #{name}" | |
filter_sql = '' | |
end | |
- @query_obj.sql.gsub!(token, filter_sql) unless token.nil? | |
+ @query_obj.sql.gsub!(@options.token, filter_sql) unless @options.token.nil? | |
end | |
def self.to_param | |
@@ -65,10 +70,10 @@ class DataPlatform::Filters::Base | |
def display | |
disp = {} | |
- disp[name] = [] | |
- return disp unless params[name].present? | |
+ disp[@options.name] = [] | |
+ return disp unless params[@options.name].present? | |
display_relation.map do |c| | |
- disp[name] << c.text | |
+ disp[@options.name] << c.text | |
end | |
disp | |
end | |
@@ -118,8 +123,8 @@ class DataPlatform::Filters::Base | |
end | |
def in_query_tokens | |
- Rails.logger.info "QUERY PARAMS: #{self.name}: #{params.inspect}" | |
- values = params[self.name].to_s.split(",").map(&:to_i) | |
+ Rails.logger.info "QUERY PARAMS: #{@options.name}: #{params.inspect}" | |
+ values = params[@options.name].to_s.split(",").map(&:to_i) | |
values.map do |val| | |
add_param(val) | |
"$#{param_count}" | |
diff --git a/app/models/data_platform/queries/base.rb b/app/models/data_platform/queries/base.rb | |
index cf4ae5a..0cf24a7 100644 | |
--- a/app/models/data_platform/queries/base.rb | |
+++ b/app/models/data_platform/queries/base.rb | |
@@ -5,8 +5,9 @@ class DataPlatform::Queries::Base | |
attr_accessor :params, :query_args, :sql, :result | |
def self.filters_on(*args) | |
+ filter_options = args.extract_options! | |
self.filters ||= [] | |
- self.filters << args.map {|filter_name| filter_locator(filter_name) } | |
+ self.filters << args.map {|filter_name| filter_locator(filter_name) }.map {|filter| filter.new(self, filter_options)} | |
self.filters.flatten!.compact! | |
end | |
@@ -105,4 +106,3 @@ class DataPlatform::Queries::Base | |
end | |
end | |
- | |
diff --git a/app/models/data_platform/queries/curriculum_requests.rb b/app/models/data_platform/queries/curriculum_requests.rb | |
index 1a72297..afb1266 100644 | |
--- a/app/models/data_platform/queries/curriculum_requests.rb | |
+++ b/app/models/data_platform/queries/curriculum_requests.rb | |
@@ -1,7 +1,8 @@ | |
class DataPlatform::Queries::CurriculumRequests < DataPlatform::Queries::Base | |
with_query_title "Curriculum Requests" | |
- filters_on :state, :curriculum, :account_manager, :since | |
+ filters_on :state, :curriculum, :account_manager | |
+ filters_on :since, table_name: :curriculum_requests | |
with_query_name "curriculum_requests" | |
@@ -32,8 +33,8 @@ class DataPlatform::Queries::CurriculumRequests < DataPlatform::Queries::Base | |
LEFT JOIN administrators AS account_manager ON account_manager.id = schools.account_manager_id | |
- LEFT JOIN master_schools ON master_schools.id = schools.master_school_id | |
- | |
+ LEFT JOIN master_schools ON master_schools.id = schools.master_school_id | |
+ | |
LEFT JOIN master_districts ON master_districts.id = master_schools.master_district_id | |
WHERE |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment