From c419e6ed2a98daabcf67ac49cc5ebd4788aa6463 Mon Sep 17 00:00:00 2001 From: Coleman Watts Date: Fri, 9 Oct 2020 16:44:06 -0400 Subject: [PATCH] Search ext: misc cleanup & fixes - Fixes white on white button text by adding btn-default class - Fixes missing field names in the bulk-update action - Decouples searchActions from the main search controller - Misc cleanup --- ext/search/ang/search.module.js | 28 +++++++++---------- ext/search/ang/search/crmSearch.component.js | 13 +++------ ext/search/ang/search/crmSearch/controls.html | 4 +-- .../ang/search/crmSearchActions.component.js | 8 ++---- ext/search/ang/search/crmSearchActions.html | 2 +- .../crmSearchActionUpdate.ctrl.js | 2 +- 6 files changed, 25 insertions(+), 32 deletions(-) diff --git a/ext/search/ang/search.module.js b/ext/search/ang/search.module.js index 1927554dd8..291552c3db 100644 --- a/ext/search/ang/search.module.js +++ b/ext/search/ang/search.module.js @@ -81,23 +81,21 @@ .factory('searchMeta', function() { function getEntity(entityName) { if (entityName) { - entityName = entityName === true ? searchEntity : entityName; return _.find(CRM.vars.search.schema, {name: entityName}); } } - function getField(name) { - var dotSplit = name.split('.'), + function getField(fieldName, entityName) { + var dotSplit = fieldName.split('.'), joinEntity = dotSplit.length > 1 ? dotSplit[0] : null, - fieldName = _.last(dotSplit).split(':')[0], - entityName = searchEntity; + name = _.last(dotSplit).split(':')[0]; // Custom fields contain a dot in their fieldname // If 3 segments, the first is the joinEntity and the last 2 are the custom field if (dotSplit.length === 3) { - fieldName = dotSplit[1] + '.' + fieldName; + name = dotSplit[1] + '.' + name; } // If 2 segments, it's ambiguous whether this is a custom field or joined field. Search the main entity first. if (dotSplit.length === 2) { - var field = _.find(getEntity(true).fields, {name: dotSplit[0] + '.' + fieldName}); + var field = _.find(getEntity(entityName).fields, {name: dotSplit[0] + '.' + name}); if (field) { return field; } @@ -105,7 +103,7 @@ if (joinEntity) { entityName = _.find(CRM.vars.search.links[entityName], {alias: joinEntity}).entity; } - return _.find(getEntity(entityName).fields, {name: fieldName}); + return _.find(getEntity(entityName).fields, {name: name}); } return { getEntity: getEntity, @@ -120,12 +118,14 @@ 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(':'), - prefixPos = split[0].lastIndexOf(result.field.name); - result.path = split[0]; - result.prefix = prefixPos > 0 ? result.path.substring(0, prefixPos) : ''; - result.suffix = !split[1] ? '' : ':' + split[1]; + result.field = expr ? getField(fieldName, searchEntity) : undefined; + if (result.field) { + var split = fieldName.split(':'), + prefixPos = split[0].lastIndexOf(result.field.name); + result.path = split[0]; + result.prefix = prefixPos > 0 ? result.path.substring(0, prefixPos) : ''; + result.suffix = !split[1] ? '' : ':' + split[1]; + } return result; } }; diff --git a/ext/search/ang/search/crmSearch.component.js b/ext/search/ang/search/crmSearch.component.js index 9da0ffe8fa..49c9908172 100644 --- a/ext/search/ang/search/crmSearch.component.js +++ b/ext/search/ang/search/crmSearch.component.js @@ -18,7 +18,7 @@ this.page = 1; this.params = {}; // After a search this.results is an object of result arrays keyed by page, - // Prior to searching it's an empty string because 1: falsey and 2: doesn't throw an error if you try to access undefined properties + // Initially this.results is an empty string because 1: it's falsey (unlike an empty object) and 2: it doesn't throw an error if you try to access undefined properties (unlike null) this.results = ''; this.rowCount = false; // Have the filters (WHERE, HAVING, GROUP BY, JOIN) changed? @@ -381,13 +381,6 @@ return value; } - function getOption(field, value) { - return _.find(field.options, function(option) { - // Type coersion is intentional - return option.id == value; - }); - } - $scope.fieldsForGroupBy = function() { return {results: getAllFields('', function(key) { return _.contains(ctrl.params.groupBy, key); @@ -413,7 +406,9 @@ }; function getDefaultSelect() { - return _.filter(['id', 'display_name', 'label', 'title', 'location_type_id:label'], searchMeta.getField); + return _.filter(['id', 'display_name', 'label', 'title', 'location_type_id:label'], function(field) { + return !!searchMeta.getField(field, ctrl.entity); + }); } function getAllFields(suffix, disabledIf) { diff --git a/ext/search/ang/search/crmSearch/controls.html b/ext/search/ang/search/crmSearch/controls.html index c17724ba31..ce1f843e02 100644 --- a/ext/search/ang/search/crmSearch/controls.html +++ b/ext/search/ang/search/crmSearch/controls.html @@ -10,9 +10,9 @@ {{:: ts('Auto') }} - +
- diff --git a/ext/search/ang/search/crmSearchActions.component.js b/ext/search/ang/search/crmSearchActions.component.js index 73ed61a092..212b8d914f 100644 --- a/ext/search/ang/search/crmSearchActions.component.js +++ b/ext/search/ang/search/crmSearchActions.component.js @@ -4,11 +4,9 @@ angular.module('search').component('crmSearchActions', { bindings: { entity: '<', + refresh: '&', ids: '<' }, - require: { - search: '^crmSearch' - }, templateUrl: '~/search/crmSearchActions.html', controller: function($scope, crmApi4, dialogService, searchMeta) { var ts = $scope.ts = CRM.ts(), @@ -44,7 +42,7 @@ var path = $scope.$eval(action.crmPopup.path, data), query = action.crmPopup.query && $scope.$eval(action.crmPopup.query, data); CRM.loadForm(CRM.url(path, query)) - .on('crmFormSuccess', ctrl.search.refreshPage); + .on('crmFormSuccess', ctrl.refresh); } // If action uses dialogService else if (action.uiDialog) { @@ -53,7 +51,7 @@ title: action.title }); dialogService.open('crmSearchAction', action.uiDialog.templateUrl, data, options) - .then(ctrl.search.refreshPage); + .then(ctrl.refresh); } }; } diff --git a/ext/search/ang/search/crmSearchActions.html b/ext/search/ang/search/crmSearchActions.html index dbeae2c84c..7442efbe09 100644 --- a/ext/search/ang/search/crmSearchActions.html +++ b/ext/search/ang/search/crmSearchActions.html @@ -1,5 +1,5 @@
-