feat: Add date custom filter (#3892)
This commit is contained in:
@@ -31,6 +31,8 @@ class Contacts::FilterService < FilterService
|
||||
case current_filter['attribute_type']
|
||||
when 'additional_attributes'
|
||||
" LOWER(contacts.additional_attributes ->> '#{attribute_key}') #{filter_operator_value} #{query_operator} "
|
||||
when 'date_attributes'
|
||||
" (contacts.#{attribute_key})::#{current_filter['data_type']} #{filter_operator_value}#{current_filter['data_type']} #{query_operator} "
|
||||
when 'standard'
|
||||
if attribute_key == 'labels'
|
||||
" tags.id #{filter_operator_value} #{query_operator} "
|
||||
|
||||
@@ -37,6 +37,8 @@ class Conversations::FilterService < FilterService
|
||||
case current_filter['attribute_type']
|
||||
when 'additional_attributes'
|
||||
" conversations.additional_attributes ->> '#{attribute_key}' #{filter_operator_value} #{query_operator} "
|
||||
when 'date_attributes'
|
||||
" (conversations.#{attribute_key})::#{current_filter['data_type']} #{filter_operator_value}#{current_filter['data_type']} #{query_operator} "
|
||||
when 'standard'
|
||||
if attribute_key == 'labels'
|
||||
" tags.name #{filter_operator_value} #{query_operator} "
|
||||
|
||||
@@ -36,6 +36,8 @@ class FilterService
|
||||
@filter_values["value_#{current_index}"] = 'IS NULL'
|
||||
when 'is_greater_than', 'is_less_than'
|
||||
@filter_values["value_#{current_index}"] = lt_gt_filter_values(query_hash)
|
||||
when 'days_before'
|
||||
@filter_values["value_#{current_index}"] = days_before_filter_values(query_hash)
|
||||
else
|
||||
@filter_values["value_#{current_index}"] = filter_values(query_hash).to_s
|
||||
"= :value_#{current_index}"
|
||||
@@ -64,6 +66,13 @@ class FilterService
|
||||
"#{operator} '#{value}'::#{attribute_data_type}"
|
||||
end
|
||||
|
||||
def days_before_filter_values(query_hash)
|
||||
date = Time.zone.today - query_hash['values'][0].to_i.days
|
||||
query_hash['values'] = [date.strftime]
|
||||
query_hash['filter_operator'] = 'is_less_than'
|
||||
lt_gt_filter_values(query_hash)
|
||||
end
|
||||
|
||||
def set_count_for_all_conversations
|
||||
[
|
||||
@conversations.assigned_to(@user).count,
|
||||
|
||||
Reference in New Issue
Block a user