diff --git a/app/controllers/concerns/resource_methods.rb b/app/controllers/concerns/resource_methods.rb index a76502fd1..840981ee6 100644 --- a/app/controllers/concerns/resource_methods.rb +++ b/app/controllers/concerns/resource_methods.rb @@ -296,14 +296,14 @@ def query_part(filter:) # change to allowd limiting to named cols?, pass in list of cols to include based in what is displayed ... model_class.columns.each do |col| next unless [:text, :string].include?(col.type) - query_part = get_query_part(table: col_table, column: col.name, operation: 'like', value: value) + query_part = get_query_part(table: col_table, column: col.name, operation: 'like', value: value, key: key) part = part ? part.or(query_part) : query_part end # This for survey submissions .... if model_class == Survey::Submission Survey::Response.columns.each do |col| next unless [:text, :string].include?(col.type) - query_part = get_query_part(table: Arel::Table.new('survey_responses'), column: col.name, operation: 'like', value: value) + query_part = get_query_part(table: Arel::Table.new('survey_responses'), column: col.name, operation: 'like', value: value, key: key) part = part ? part.or(query_part) : query_part end end @@ -320,7 +320,7 @@ def query_part(filter:) if array_col?(col_name: col) col_table = array_table(col_name: col) end - part = get_query_part(table: col_table, column: col, operation: operation, value: value, top: true) + part = get_query_part(table: col_table, column: col, operation: operation, value: value, top: true, key: key) if (key.include?('responses.')) key.slice! "responses." @@ -365,7 +365,7 @@ def get_column(column:) return col end - def get_query_part(table:, column:, operation:, value:, top: false) + def get_query_part(table:, column:, operation:, value:, top: false, key: nil) op = translate_operator(operation: operation) return nil if value.kind_of?(String) && value.blank? diff --git a/app/controllers/people_controller.rb b/app/controllers/people_controller.rb index dd7560806..2e141c88b 100644 --- a/app/controllers/people_controller.rb +++ b/app/controllers/people_controller.rb @@ -375,7 +375,8 @@ def includes def references [ :email_addresses, - :convention_roles + :convention_roles, + {person_schedule_approvals: {schedule_workflow: :schedule_snapshot}} ] end @@ -405,6 +406,28 @@ def get_table(column:) return super(column: column) end + def get_query_part(table:, column:, operation:, value:, top: false, key: nil) + if key.include?('draft_person_schedule_approvals') + return approval_query(table: table, column: column, operation: operation, value: value, label: 'draft') + end + if key.include?('firm_person_schedule_approvals') + return approval_query(table: table, column: column, operation: operation, value: value, label: 'firm') + end + + return super(table: table, column: column, operation: operation, value: value, top: top, key: key) + end + + def approval_query(table:, column:, operation:, value:, label:) + op = translate_operator(operation: operation) + schedule_snapshots = ScheduleSnapshot.arel_table + part = table[column.to_sym].send(op, value).and(schedule_snapshots[:label].eq(label)) + if value == 'not_set' + part = part.or(table[column.to_sym].eq(nil)) + end + + return part + end + # TODO: on create must have at least one email_addresses_attributes # def join_tables