From d3803c8aed8de35d318ba794ca7205c55b9a0056 Mon Sep 17 00:00:00 2001 From: dleadbetter Date: Wed, 11 Sep 2024 13:39:29 -0400 Subject: [PATCH] UDF #35 - Adding "FuzzyDate" data type to user-defined fields --- app/controllers/concerns/user_defined_fields/queryable.rb | 2 ++ app/models/user_defined_fields/user_defined_field.rb | 1 + 2 files changed, 3 insertions(+) diff --git a/app/controllers/concerns/user_defined_fields/queryable.rb b/app/controllers/concerns/user_defined_fields/queryable.rb index 51ea240..11f699a 100644 --- a/app/controllers/concerns/user_defined_fields/queryable.rb +++ b/app/controllers/concerns/user_defined_fields/queryable.rb @@ -31,6 +31,8 @@ def apply_user_defined_sort(query) case user_defined_field.data_type when UserDefinedField::DATA_TYPES[:date] query.order(Arel.sql("(#{table_alias}.user_defined->>'#{uuid}')::TIMESTAMPTZ #{sort_direction}")) + when UserDefinedField::DATA_TYPES[:fuzzy_date] + query.order(Arel.sql("(#{table_alias}.user_defined->'#{uuid}'->>'start_date')::TIMESTAMPTZ #{sort_direction}")) when UserDefinedField::DATA_TYPES[:number] query.order(Arel.sql("(#{table_alias}.user_defined->>'#{uuid}')::DECIMAL #{sort_direction}")) else diff --git a/app/models/user_defined_fields/user_defined_field.rb b/app/models/user_defined_fields/user_defined_field.rb index e31c6cb..6911a9b 100644 --- a/app/models/user_defined_fields/user_defined_field.rb +++ b/app/models/user_defined_fields/user_defined_field.rb @@ -13,6 +13,7 @@ class UserDefinedField < ApplicationRecord DATA_TYPES = { boolean: 'Boolean', date: 'Date', + fuzzy_date: 'FuzzyDate', number: 'Number', richText: 'RichText', select: 'Select',