From 39eb3fab3989e1097ce3aa98b14689130c9bf1d0 Mon Sep 17 00:00:00 2001 From: Coleman Watts Date: Fri, 8 Apr 2022 21:49:50 -0400 Subject: [PATCH] API4 Explorer - Remove confusing "Save" button This button was added as a prototype for saving a smart group from the Explorer. But since that time SearchKit has evolved with the same functionality. Since the presence of the button in the Explorer is confusing and redundant with SearchKit, I think it's best to remove it. --- CRM/Api4/Page/Api4Explorer.php | 2 - ang/api4Explorer.ang.php | 2 +- ang/api4Explorer/Explorer.html | 1 - ang/api4Explorer/Explorer.js | 96 +------------------------------- ang/api4Explorer/SaveSearch.html | 26 --------- 5 files changed, 2 insertions(+), 125 deletions(-) delete mode 100644 ang/api4Explorer/SaveSearch.html diff --git a/CRM/Api4/Page/Api4Explorer.php b/CRM/Api4/Page/Api4Explorer.php index 249991cfee..b27a565a80 100644 --- a/CRM/Api4/Page/Api4Explorer.php +++ b/CRM/Api4/Page/Api4Explorer.php @@ -21,7 +21,6 @@ class CRM_Api4_Page_Api4Explorer extends CRM_Core_Page { public function run() { $apiDoc = new ReflectionFunction('civicrm_api4'); - $groupOptions = civicrm_api4('Group', 'getFields', ['loadOptions' => TRUE, 'select' => ['options', 'name'], 'where' => [['name', 'IN', ['visibility', 'group_type']]]]); $extensions = \CRM_Extension_System::singleton()->getMapper(); $vars = [ @@ -30,7 +29,6 @@ class CRM_Api4_Page_Api4Explorer extends CRM_Core_Page { 'schema' => (array) \Civi\Api4\Entity::get()->setChain(['fields' => ['$name', 'getFields']])->execute(), 'docs' => \Civi\Api4\Utils\ReflectionUtils::parseDocBlock($apiDoc->getDocComment()), 'functions' => self::getSqlFunctions(), - 'groupOptions' => array_column((array) $groupOptions, 'options', 'name'), 'authxEnabled' => $extensions->isActiveModule('authx'), 'restUrl' => rtrim(CRM_Utils_System::url('civicrm/ajax/api4/CRMAPI4ENTITY/CRMAPI4ACTION', NULL, TRUE, NULL, FALSE), '/'), ]; diff --git a/ang/api4Explorer.ang.php b/ang/api4Explorer.ang.php index d0ac2be6ec..e539892ca5 100644 --- a/ang/api4Explorer.ang.php +++ b/ang/api4Explorer.ang.php @@ -15,5 +15,5 @@ return [ 'basePages' => [], 'bundles' => ['bootstrap3'], 'permissions' => ['access debug output', 'edit groups', 'administer reserved groups'], - 'requires' => ['crmUi', 'crmUtil', 'ngRoute', 'crmRouteBinder', 'ui.sortable', 'api4', 'ngSanitize', 'dialogService', 'checklist-model'], + 'requires' => ['crmUi', 'crmUtil', 'ngRoute', 'crmRouteBinder', 'ui.sortable', 'api4', 'ngSanitize'], ]; diff --git a/ang/api4Explorer/Explorer.html b/ang/api4Explorer/Explorer.html index d78bd81451..e6d1e4a0f7 100644 --- a/ang/api4Explorer/Explorer.html +++ b/ang/api4Explorer/Explorer.html @@ -16,7 +16,6 @@ -
diff --git a/ang/api4Explorer/Explorer.js b/ang/api4Explorer/Explorer.js index ee6e9864ea..4d299cf9ec 100644 --- a/ang/api4Explorer/Explorer.js +++ b/ang/api4Explorer/Explorer.js @@ -19,7 +19,7 @@ }); }); - angular.module('api4Explorer').controller('Api4Explorer', function($scope, $routeParams, $location, $timeout, $http, crmUiHelp, crmApi4, dialogService) { + angular.module('api4Explorer').controller('Api4Explorer', function($scope, $routeParams, $location, $timeout, $http, crmUiHelp, crmApi4) { var ts = $scope.ts = CRM.ts(), ctrl = $scope.$ctrl = this; $scope.entities = entities; @@ -37,7 +37,6 @@ $scope.crmUrl = CRM.url; $scope.perm = { accessDebugOutput: CRM.checkPerm('access debug output'), - editGroups: CRM.checkPerm('edit groups') }; marked.setOptions({highlight: prettyPrintOne}); var getMetaParams = {}, @@ -1122,102 +1121,9 @@ return doc; }; - $scope.saveDoc = function() { - return { - description: ts('Save API call as a smart group.'), - comment: ts('Create a SavedSearch using these API params to populate a smart group.') + - '\n\n' + ts('NOTE: you must select contact id as the only field.') - }; - }; - $scope.$watch('params', writeCode, true); $scope.$watch('index', writeCode); writeCode(); - - $scope.save = function() { - $scope.params.limit = $scope.params.offset = 0; - if ($scope.params.chain.length) { - CRM.alert(ts('Smart groups are not compatible with API chaining.'), ts('Error'), 'error', {expires: 5000}); - return; - } - if ($scope.params.select.length !== 1 || !_.includes($scope.params.select[0], 'id')) { - CRM.alert(ts('To create a smart group, the API must select contact id and no other fields.'), ts('Error'), 'error', {expires: 5000}); - return; - } - var model = { - title: '', - description: '', - visibility: 'User and User Admin Only', - group_type: [], - id: null, - entity: $scope.entity, - params: JSON.parse(angular.toJson($scope.params)) - }; - model.params.version = 4; - delete model.params.chain; - delete model.params.debug; - delete model.params.limit; - delete model.params.offset; - delete model.params.orderBy; - delete model.params.checkPermissions; - var options = CRM.utils.adjustDialogDefaults({ - width: '500px', - autoOpen: false, - title: ts('Save smart group') - }); - dialogService.open('saveSearchDialog', '~/api4Explorer/SaveSearch.html', model, options); - }; - }); - - angular.module('api4Explorer').controller('SaveSearchCtrl', function($scope, crmApi4, dialogService) { - var ts = $scope.ts = CRM.ts(), - model = $scope.model; - $scope.groupEntityRefParams = { - entity: 'Group', - api: { - params: {is_hidden: 0, is_active: 1, 'saved_search_id.api_entity': model.entity}, - extra: ['saved_search_id', 'description', 'visibility', 'group_type'] - }, - select: { - allowClear: true, - minimumInputLength: 0, - placeholder: ts('Select existing group') - } - }; - if (!CRM.checkPerm('administer reserved groups')) { - $scope.groupEntityRefParams.api.params.is_reserved = 0; - } - $scope.perm = { - administerReservedGroups: CRM.checkPerm('administer reserved groups') - }; - $scope.options = CRM.vars.api4.groupOptions; - $scope.$watch('model.id', function(id) { - if (id) { - _.assign(model, $('#api-save-search-select-group').select2('data').extra); - } - }); - $scope.cancel = function() { - dialogService.cancel('saveSearchDialog'); - }; - $scope.save = function() { - $('.ui-dialog:visible').block(); - var group = model.id ? {id: model.id} : {title: model.title}; - group.description = model.description; - group.visibility = model.visibility; - group.group_type = model.group_type; - group.saved_search_id = '$id'; - var savedSearch = { - api_entity: model.entity, - api_params: model.params - }; - if (group.id) { - savedSearch.id = model.saved_search_id; - } - crmApi4('SavedSearch', 'save', {records: [savedSearch], chain: {group: ['Group', 'save', {'records': [group]}]}}) - .then(function(result) { - dialogService.close('saveSearchDialog', result[0]); - }); - }; }); angular.module('api4Explorer').component('crmApi4Clause', { diff --git a/ang/api4Explorer/SaveSearch.html b/ang/api4Explorer/SaveSearch.html deleted file mode 100644 index a59d01de9c..0000000000 --- a/ang/api4Explorer/SaveSearch.html +++ /dev/null @@ -1,26 +0,0 @@ -
-
- - - -
- - - -
-
- -
-
- - -
-
- - -
-
-
-- 2.25.1