From d7507e8975c5847818de4eb58a1f3f986b7294a2 Mon Sep 17 00:00:00 2001 From: Coleman Watts Date: Tue, 17 Mar 2020 16:28:14 -0400 Subject: [PATCH] APIv4 - Improve saveSearch popup in Explorer --- CRM/Api4/Page/Api4Explorer.php | 4 +++- ang/api4Explorer.ang.php | 2 +- ang/api4Explorer/Explorer.html | 2 +- ang/api4Explorer/Explorer.js | 31 ++++++++++++++++++++++++++++--- ang/api4Explorer/SaveSearch.html | 18 +++++++++++++++--- css/api4-explorer.css | 8 ++++++++ 6 files changed, 56 insertions(+), 9 deletions(-) diff --git a/CRM/Api4/Page/Api4Explorer.php b/CRM/Api4/Page/Api4Explorer.php index adc1d74326dd..77eb0d1e5337 100644 --- a/CRM/Api4/Page/Api4Explorer.php +++ b/CRM/Api4/Page/Api4Explorer.php @@ -21,16 +21,18 @@ 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']]]]); $vars = [ 'operators' => \CRM_Core_DAO::acceptedSQLOperators(), 'basePath' => Civi::resources()->getUrl('civicrm'), 'schema' => (array) \Civi\Api4\Entity::get()->setChain(['fields' => ['$name', 'getFields']])->execute(), 'links' => (array) \Civi\Api4\Entity::getLinks()->execute(), 'docs' => \Civi\Api4\Utils\ReflectionUtils::parseDocBlock($apiDoc->getDocComment()), + 'groupOptions' => array_column((array) $groupOptions, 'options', 'name'), ]; Civi::resources() ->addVars('api4', $vars) - ->addPermissions(['access debug output']) + ->addPermissions(['access debug output', 'edit groups', 'administer reserved groups']) ->addScriptFile('civicrm', 'js/load-bootstrap.js') ->addScriptFile('civicrm', 'bower_components/js-yaml/dist/js-yaml.min.js') ->addScriptFile('civicrm', 'bower_components/marked/marked.min.js') diff --git a/ang/api4Explorer.ang.php b/ang/api4Explorer.ang.php index 816856b86df8..2eec108aaf14 100644 --- a/ang/api4Explorer.ang.php +++ b/ang/api4Explorer.ang.php @@ -13,5 +13,5 @@ 'ang/api4Explorer', ], 'basePages' => [], - 'requires' => ['crmUi', 'crmUtil', 'ngRoute', 'crmRouteBinder', 'ui.sortable', 'api4', 'ngSanitize', 'dialogService'], + 'requires' => ['crmUi', 'crmUtil', 'ngRoute', 'crmRouteBinder', 'ui.sortable', 'api4', 'ngSanitize', 'dialogService', 'checklist-model'], ]; diff --git a/ang/api4Explorer/Explorer.html b/ang/api4Explorer/Explorer.html index 90d3287deb4b..659917ecb2fe 100644 --- a/ang/api4Explorer/Explorer.html +++ b/ang/api4Explorer/Explorer.html @@ -26,7 +26,7 @@

- +
diff --git a/ang/api4Explorer/Explorer.js b/ang/api4Explorer/Explorer.js index b589bdaaf3e4..09db7d1d02a2 100644 --- a/ang/api4Explorer/Explorer.js +++ b/ang/api4Explorer/Explorer.js @@ -32,7 +32,8 @@ $scope.index = ''; $scope.selectedTab = {result: 'result', code: 'php'}; $scope.perm = { - accessDebugOutput: CRM.checkPerm('access debug output') + accessDebugOutput: CRM.checkPerm('access debug output'), + editGroups: CRM.checkPerm('edit groups') }; marked.setOptions({highlight: prettyPrintOne}); var getMetaParams = {}, @@ -709,6 +710,9 @@ $scope.save = function() { var model = { title: '', + description: '', + visibility: 'User and User Admin Only', + group_type: [], id: null, entity: $scope.entity, params: JSON.parse(angular.toJson($scope.params)) @@ -731,9 +735,28 @@ 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) { - model.description = $('#api-save-search-select-group').select2('data').extra.description; + _.assign(model, $('#api-save-search-select-group').select2('data').extra); } }); $scope.cancel = function() { @@ -743,13 +766,15 @@ $('.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 = $('#api-save-search-select-group').select2('data').extra.saved_search_id; + savedSearch.id = model.saved_search_id; } crmApi4('SavedSearch', 'save', {records: [savedSearch], chain: {group: ['Group', 'save', {'records': [group]}]}}) .then(function(result) { diff --git a/ang/api4Explorer/SaveSearch.html b/ang/api4Explorer/SaveSearch.html index 2935d325fec6..72ffecfeaf88 100644 --- a/ang/api4Explorer/SaveSearch.html +++ b/ang/api4Explorer/SaveSearch.html @@ -1,13 +1,25 @@
- + +
- + + +
+
+ +
+
+ +
- +
diff --git a/css/api4-explorer.css b/css/api4-explorer.css index ae419a5086cb..077f95b7bef4 100644 --- a/css/api4-explorer.css +++ b/css/api4-explorer.css @@ -199,6 +199,14 @@ div.select2-drop.collapsible-optgroups-enabled .select2-result-with-children.opt content: "\f0d7"; } +/* Another weird shoreditch fix */ +#bootstrap-theme .form-inline div.checkbox { + margin-right: 1em; +} +#bootstrap-theme .form-inline div.checkbox label input[type=checkbox] { + margin: 0; +} + /** * Shims so the UI isn't completely broken when a Bootstrap theme is not installed */