From: Coleman Watts Date: Wed, 29 Jan 2020 00:56:33 +0000 (-0500) Subject: Api4 Explorer - Add code styles and display in tabs X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=19d01932ef66c1fff9a53c24c121a47060bf9934;p=civicrm-core.git Api4 Explorer - Add code styles and display in tabs --- diff --git a/ang/api4Explorer/Explorer.html b/ang/api4Explorer/Explorer.html index 4a3da7b4d6..f1a43e0017 100644 --- a/ang/api4Explorer/Explorer.html +++ b/ang/api4Explorer/Explorer.html @@ -137,22 +137,26 @@
-
-

{{ ts('Code') }}

-
+
- - - - +
{{ codeLabel[type] }}
+ + +
{{ style.label }}
-
+

           
-
+

             

{{ ts('To view debugging output, enable the debug param before executing.') }} @@ -183,6 +187,4 @@

- -
diff --git a/ang/api4Explorer/Explorer.js b/ang/api4Explorer/Explorer.js index 3c5c5ca0b9..1023b73914 100644 --- a/ang/api4Explorer/Explorer.js +++ b/ang/api4Explorer/Explorer.js @@ -30,7 +30,7 @@ $scope.availableParams = {}; $scope.params = {}; $scope.index = ''; - $scope.resultTab = {selected: 'result'}; + $scope.selectedTab = {result: 'result', code: 'php'}; $scope.perm = { accessDebugOutput: CRM.checkPerm('access debug output') }; @@ -47,19 +47,35 @@ $scope.status = 'default'; $scope.loading = false; $scope.controls = {}; - $scope.codeLabel = { - oop: ts('PHP (oop style)'), - php: ts('PHP (traditional)'), - js: ts('Javascript'), - cli: ts('Command Line') - }; - $scope.code = codeDefaults(); - - function codeDefaults() { - return _.mapValues($scope.codeLabel, function(val, key) { - return key === 'oop' ? ts('Select an entity and action') : ''; - }); - } + $scope.code = [ + { + lang: 'php', + style: [ + {name: 'oop', label: ts('OOP Style'), code: ''}, + {name: 'php', label: ts('Traditional'), code: ''} + ] + }, + { + lang: 'js', + style: [ + {name: 'js', label: ts('Single Call'), code: ''}, + {name: 'js2', label: ts('Batch Calls'), code: ''} + ] + }, + { + lang: 'ang', + style: [ + {name: 'ang', label: ts('Single Call'), code: ''}, + {name: 'ang2', label: ts('Batch Calls'), code: ''} + ] + }, + { + lang: 'cli', + style: [ + {name: 'cv', label: ts('CV'), code: ''} + ] + }, + ]; if (!entities.length) { formatForSelect2(schema, entities, 'name', ['description']); @@ -380,7 +396,7 @@ } function writeCode() { - var code = codeDefaults(), + var code = {}, entity = $scope.entity, action = $scope.action, params = getParams(), @@ -401,19 +417,22 @@ } // Write javascript - code.js = "CRM.api4('" + entity + "', '" + action + "', {"; + var js = "'" + entity + "', '" + action + "', {"; _.each(params, function(param, key) { - code.js += "\n " + key + ': ' + stringify(param) + + js += "\n " + key + ': ' + stringify(param) + (++i < paramCount ? ',' : ''); if (key === 'checkPermissions') { - code.js += ' // IGNORED: permissions are always enforced from client-side requests'; + js += ' // IGNORED: permissions are always enforced from client-side requests'; } }); - code.js += "\n}"; + js += "\n}"; if (index || index === 0) { - code.js += ', ' + JSON.stringify(index); + js += ', ' + JSON.stringify(index); } - code.js += ").then(function(" + results + ") {\n // do something with " + results + " array\n}, function(failure) {\n // handle failure\n});"; + code.js = "CRM.api4(" + js + ").then(function(" + results + ") {\n // do something with " + results + " array\n}, function(failure) {\n // handle failure\n});"; + code.js2 = "CRM.api4({" + results + ': [' + js + "]}).then(function(batch) {\n // do something with batch." + results + " array\n}, function(failure) {\n // handle failure\n});"; + code.ang = "crmApi4(" + js + ").then(function(" + results + ") {\n // do something with " + results + " array\n}, function(failure) {\n // handle failure\n});"; + code.ang2 = "crmApi4({" + results + ': [' + js + "]}).then(function(batch) {\n // do something with batch." + results + " array\n}, function(failure) {\n // handle failure\n});"; // Write php code code.php = '$' + results + " = civicrm_api4('" + entity + "', '" + action + "', ["; @@ -472,10 +491,12 @@ } // Write cli code - code.cli = 'cv api4 ' + entity + '.' + action + " '" + stringify(params) + "'"; + code.cv = 'cv api4 ' + entity + '.' + action + " '" + stringify(params) + "'"; } - _.each(code, function(val, type) { - $scope.code[type] = prettyPrintOne(_.escape(val)); + _.each($scope.code, function(vals) { + _.each(vals.style, function(style) { + style.code = code[style.name] ? prettyPrintOne(code[style.name]) : ''; + }); }); } diff --git a/css/api4-explorer.css b/css/api4-explorer.css index 8041edda26..b549bbb9a3 100644 --- a/css/api4-explorer.css +++ b/css/api4-explorer.css @@ -40,7 +40,14 @@ background-color: #f1f1f18c } #bootstrap-theme.api4-explorer-page .explorer-code-panel table td:first-child { - width: 5em; + width: 6em; + word-break: break-word; +} +#bootstrap-theme.api4-explorer-page .explorer-code-panel table td pre { + min-height: 3.3em; +} +#bootstrap-theme.api4-explorer-page .explorer-code-panel .panel-heading.nav li a { + text-transform: uppercase; } #bootstrap-theme.api4-explorer-page .explorer-params-panel > .panel-body > div.api4-input {