From 4a7a369458a6e4ef324d3dd5551b0f586c401436 Mon Sep 17 00:00:00 2001 From: Coleman Watts Date: Thu, 5 May 2022 14:28:02 -0400 Subject: [PATCH] SearchKit - Add date pseudo-fields --- .../SearchDisplay/AbstractRunAction.php | 22 ++++++++++++++++++- ext/search_kit/ang/crmSearchAdmin.module.js | 2 +- .../crmSearchAdmin.component.js | 5 +++-- 3 files changed, 25 insertions(+), 4 deletions(-) diff --git a/ext/search_kit/Civi/Api4/Action/SearchDisplay/AbstractRunAction.php b/ext/search_kit/Civi/Api4/Action/SearchDisplay/AbstractRunAction.php index 63a59d9da4..5928ffc190 100644 --- a/ext/search_kit/Civi/Api4/Action/SearchDisplay/AbstractRunAction.php +++ b/ext/search_kit/Civi/Api4/Action/SearchDisplay/AbstractRunAction.php @@ -1084,7 +1084,7 @@ abstract class AbstractRunAction extends \Civi\Api4\Generic\AbstractAction { ], [ 'name' => 'user_contact_id', - 'fieldName' => 'result_row_num', + 'fieldName' => 'user_contact_id', 'title' => ts('Current User ID'), 'label' => ts('Current User ID'), 'description' => ts('Contact ID of the current user if logged in'), @@ -1092,6 +1092,26 @@ abstract class AbstractRunAction extends \Civi\Api4\Generic\AbstractAction { 'data_type' => 'Integer', 'readonly' => TRUE, ], + [ + 'name' => 'CURDATE()', + 'fieldName' => 'CURDATE()', + 'title' => ts('Current Date'), + 'label' => ts('Current Date'), + 'description' => ts('System date at the moment the search is run'), + 'type' => 'Pseudo', + 'data_type' => 'Date', + 'readonly' => TRUE, + ], + [ + 'name' => 'NOW()', + 'fieldName' => 'NOW()', + 'title' => ts('Current Date + Time'), + 'label' => ts('Current Date + Time'), + 'description' => ts('System date and time at the moment the search is run'), + 'type' => 'Pseudo', + 'data_type' => 'Timestamp', + 'readonly' => TRUE, + ], ]; } diff --git a/ext/search_kit/ang/crmSearchAdmin.module.js b/ext/search_kit/ang/crmSearchAdmin.module.js index 82c4e60b38..a74b1f89be 100644 --- a/ext/search_kit/ang/crmSearchAdmin.module.js +++ b/ext/search_kit/ang/crmSearchAdmin.module.js @@ -276,7 +276,7 @@ var splitAs = expr.split(' AS '), info = {fn: null, args: [], alias: _.last(splitAs)}, bracketPos = expr.indexOf('('); - if (bracketPos >= 0) { + if (bracketPos >= 0 && !_.findWhere(CRM.crmSearchAdmin.pseudoFields, {name: expr})) { parseFnArgs(info, splitAs[0]); } else { var arg = parseArg(splitAs[0]); diff --git a/ext/search_kit/ang/crmSearchAdmin/crmSearchAdmin.component.js b/ext/search_kit/ang/crmSearchAdmin/crmSearchAdmin.component.js index f8643d7a95..9c8d80cc4b 100644 --- a/ext/search_kit/ang/crmSearchAdmin/crmSearchAdmin.component.js +++ b/ext/search_kit/ang/crmSearchAdmin/crmSearchAdmin.component.js @@ -488,6 +488,7 @@ this.getAllFields = function(suffix, allowedTypes, disabledIf, topJoin) { disabledIf = disabledIf || _.noop; + allowedTypes = allowedTypes || ['Field', 'Custom', 'Extra', 'Filter']; function formatEntityFields(entityName, join) { var prefix = join ? join.alias + '.' : '', @@ -515,7 +516,7 @@ if (disabledIf(item.id)) { item.disabled = true; } - if (!allowedTypes || _.includes(allowedTypes, field.type)) { + if (_.includes(allowedTypes, field.type)) { result.push(item); } }); @@ -550,7 +551,7 @@ }); // Include SearchKit's pseudo-fields if specifically requested - if (allowedTypes && _.includes(allowedTypes, 'Pseudo')) { + if (_.includes(allowedTypes, 'Pseudo')) { result.push({ text: ts('Extra'), icon: 'fa-gear', -- 2.25.1