Skip to content

Commit

Permalink
APIv4 - Basic support for joins in api4 Explorer
Browse files Browse the repository at this point in the history
  • Loading branch information
colemanw committed May 15, 2020
1 parent b854ff5 commit 192b622
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
15 changes: 15 additions & 0 deletions ang/api4Explorer/Explorer.html
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,21 @@ <h1 crm-page-title>
<input class="collapsible-optgroups form-control huge" ng-model="controls.select" crm-ui-select="{data: fieldsAndJoinsAndFunctionsAndWildcards}" placeholder="Add select" />
</div>
</fieldset>
<fieldset class="api4-input form-inline" ng-mouseenter="help('join', availableParams.join)" ng-mouseleave="help()" ng-if="::availableParams.join">
<legend>join<span class="crm-marker" ng-if="::availableParams.join.required"> *</span></legend>
<div ng-model="params.join" ui-sortable="{axis: 'y'}">
<div class="api4-input form-inline" ng-repeat="item in params.join track by $index">
<i class="crm-i fa-arrows"></i>
<input class="form-control twenty" type="text" ng-model="params.join[$index][0]" />
<select class="form-control" ng-model="params.join[$index][1]" ng-options="o.k as o.v for o in ::[{k: false, v: ts('Optional')}, {k: true, v: ts('Required')}]" ></select>
<input class="form-control twenty" type="text" ng-model="params.join[$index][2]" />
<a href class="crm-hover-button" title="Clear" ng-click="clearParam('join', $index)"><i class="crm-i fa-times"></i></a>
</div>
</div>
<div class="api4-input form-inline">
<input class="collapsible-optgroups form-control huge" ng-model="controls.join" crm-ui-select="{data: entities}" placeholder="Add join" />
</div>
</fieldset>
<div class="api4-input form-inline" ng-mouseenter="help('fields', availableParams.fields)" ng-mouseleave="help()" ng-if="::availableParams.fields">
<label for="api4-param-fields">fields<span class="crm-marker" ng-if="::availableParams.fields.required"> *</span></label>
<input class="form-control" ng-list crm-ui-select="::{data: fields, multiple: true}" id="api4-param-fields" ng-model="params.fields" style="width: 85%;"/>
Expand Down
11 changes: 7 additions & 4 deletions ang/api4Explorer/Explorer.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@
}
fields.push({
text: link.alias,
description: 'Join to ' + link.entity,
description: 'Implicit join to ' + link.entity,
children: wildCard.concat(formatForSelect2(linkFields, [], 'name', ['description'], link.alias + '.'))
});
}
Expand Down Expand Up @@ -253,7 +253,7 @@
if (_.isEmpty($scope.availableParams)) {
return;
}
var specialParams = ['select', 'fields', 'action', 'where', 'values', 'defaults', 'orderBy', 'chain', 'groupBy', 'having'];
var specialParams = ['select', 'fields', 'action', 'where', 'values', 'defaults', 'orderBy', 'chain', 'groupBy', 'having', 'join'];
if ($scope.availableParams.limit && $scope.availableParams.offset) {
specialParams.push('limit', 'offset');
}
Expand Down Expand Up @@ -454,12 +454,15 @@
});
});
}
if (typeof objectParams[name] !== 'undefined' || name === 'groupBy' || name === 'select') {
if (typeof objectParams[name] !== 'undefined' || name === 'groupBy' || name === 'select' || name === 'join') {
$scope.$watch('controls.' + name, function(value) {
var field = value;
$timeout(function() {
if (field) {
if (typeof objectParams[name] === 'undefined') {
if (name === 'join') {
$scope.params[name].push([field + ' AS ' + _.snakeCase(field), false, '[]']);
}
else if (typeof objectParams[name] === 'undefined') {
$scope.params[name].push(field);
} else {
var defaultOp = _.cloneDeep(objectParams[name]);
Expand Down

0 comments on commit 192b622

Please sign in to comment.