From: Coleman Watts Date: Thu, 24 Sep 2020 14:31:09 +0000 (-0400) Subject: Search ext: Expose DISTINCT modifier X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=f99d41d2797a664d5db7dc99821d7d8ed05b96f2;p=civicrm-core.git Search ext: Expose DISTINCT modifier --- diff --git a/ext/search/ang/search.module.js b/ext/search/ang/search.module.js index ed60680e00..cec26c5d6e 100644 --- a/ext/search/ang/search.module.js +++ b/ext/search/ang/search.module.js @@ -100,12 +100,14 @@ getEntity: getEntity, getField: getField, parseExpr: function(expr) { - var result = {}, + var result = {fn: null, modifier: ''}, fieldName = expr, bracketPos = expr.indexOf('('); if (bracketPos >= 0) { - fieldName = expr.match(/[A-Z( _]*([\w.:]+)/)[1]; + var parsed = expr.substr(bracketPos).match(/[ ]?([A-Z]+[ ]+)?([\w.:]+)/); + fieldName = parsed[2]; result.fn = _.find(CRM.vars.search.functions, {name: expr.substring(0, bracketPos)}); + result.modifier = _.trim(parsed[1]); } result.field = getField(fieldName); var split = fieldName.split(':'), diff --git a/ext/search/ang/search/crmSearchFunction.component.js b/ext/search/ang/search/crmSearchFunction.component.js index 7a46aff431..9b7efce4b8 100644 --- a/ext/search/ang/search/crmSearchFunction.component.js +++ b/ext/search/ang/search/crmSearchFunction.component.js @@ -17,10 +17,28 @@ ctrl.path = fieldInfo.path + fieldInfo.suffix; ctrl.field = fieldInfo.field; ctrl.fn = !fieldInfo.fn ? '' : fieldInfo.fn.name; + ctrl.modifier = fieldInfo.modifier || null; + initFunction(); }; + function initFunction() { + ctrl.fnInfo = _.find(CRM.vars.search.functions, {name: ctrl.fn}); + if (ctrl.fnInfo && _.includes(ctrl.fnInfo.params[0].prefix, 'DISTINCT')) { + ctrl.modifierAllowed = true; + } + else { + ctrl.modifierAllowed = false; + ctrl.modifier = null; + } + } + this.selectFunction = function() { - ctrl.expr = ctrl.fn ? (ctrl.fn + '(' + ctrl.path + ')') : ctrl.path; + initFunction(); + ctrl.writeExpr(); + }; + + this.writeExpr = function() { + ctrl.expr = ctrl.fn ? (ctrl.fn + '(' + (ctrl.modifier ? ctrl.modifier + ' ' : '') + ctrl.path + ')') : ctrl.path; }; } }); diff --git a/ext/search/ang/search/crmSearchFunction.html b/ext/search/ang/search/crmSearchFunction.html index e0692e33d3..03238b825c 100644 --- a/ext/search/ang/search/crmSearchFunction.html +++ b/ext/search/ang/search/crmSearchFunction.html @@ -1,4 +1,8 @@
+