Skip to content

Commit

Permalink
APIv4 Explorer - performance boost with less intensive loops
Browse files Browse the repository at this point in the history
  • Loading branch information
colemanw committed Apr 13, 2020
1 parent e74c275 commit b2e544a
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 7 deletions.
8 changes: 4 additions & 4 deletions ang/api4Explorer/Explorer.html
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ <h1 crm-page-title>
</div>
<div class="panel-body">
<div class="api4-input form-inline">
<label class="form-control" ng-mouseenter="help(name, param)" ng-mouseleave="help()" ng-class="{'api4-option-selected': params[name]}" ng-repeat="(name, param) in availableParams" ng-if="::!isSpecial(name) && param.type[0] === 'bool' && param.default !== null">
<label class="form-control" ng-mouseenter="help(name, param)" ng-mouseleave="help()" ng-class="{'api4-option-selected': params[name]}" ng-repeat="(name, param) in ::getGenericParams(['bool'], false)">
<input type="checkbox" id="api4-param-{{:: name }}" ng-model="params[name]"/>
{{:: name }}<span class="crm-marker" ng-if="::param.required"> *</span>
</label>
Expand All @@ -40,7 +40,7 @@ <h1 crm-page-title>
SelectRowCount
</label>
</div>
<div class="api4-input form-inline" ng-mouseenter="help(name, param)" ng-mouseleave="help()" ng-repeat="(name, param) in availableParams" ng-if="::!isSpecial(name) && param.type[0] === 'bool' && param.default === null">
<div class="api4-input form-inline" ng-mouseenter="help(name, param)" ng-mouseleave="help()" ng-repeat="(name, param) in ::getGenericParams(['bool'], true)">
<label>{{ name }}<span class="crm-marker" ng-if="::param.required"> *</span></label>
<label class="radio-inline">
<input type="radio" ng-model="params[name]" ng-value="true" />true
Expand Down Expand Up @@ -71,13 +71,13 @@ <h1 crm-page-title>
<label for="api4-param-action">action<span class="crm-marker" ng-if="::availableParams.action.required"> *</span></label>
<input class="form-control" crm-ui-select="{data: actions, allowClear: true, placeholder: 'None'}" id="api4-param-action" ng-model="params.action"/>
</div>
<div class="api4-input form-inline" ng-mouseenter="help(name, param)" ng-mouseleave="help()" ng-repeat="(name, param) in availableParams" ng-if="::!isSpecial(name) && (param.type[0] === 'string' || param.type[0] === 'int')">
<div class="api4-input form-inline" ng-mouseenter="help(name, param)" ng-mouseleave="help()" ng-repeat="(name, param) in ::getGenericParams(['string', 'int'])">
<label for="api4-param-{{:: name }}">{{:: name }}<span class="crm-marker" ng-if="::param.required"> *</span></label>
<input class="form-control" ng-if="::!param.options" type="{{ param.type[0] === 'int' && param.type.length === 1 ? 'number' : 'text' }}" id="api4-param-{{:: name }}" ng-model="params[name]"/>
<select class="form-control" ng-if="::param.options" ng-options="o for o in param.options" id="api4-param-{{:: name }}" ng-model="params[name]"></select>
<a href class="crm-hover-button" title="Clear" ng-click="clearParam(name)" ng-show="!!params[name]"><i class="crm-i fa-times"></i></a>
</div>
<div class="api4-input" ng-mouseenter="help(name, param)" ng-mouseleave="help()" ng-repeat="(name, param) in availableParams" ng-if="::!isSpecial(name) && (param.type[0] === 'array' || param.type[0] === 'mixed')">
<div class="api4-input" ng-mouseenter="help(name, param)" ng-mouseleave="help()" ng-repeat="(name, param) in ::getGenericParams(['array', 'mixed'])">
<label for="api4-param-{{:: name }}">{{:: name }}<span class="crm-marker" ng-if="::param.required"> *</span></label>
<textarea class="form-control" type="{{:: param.type[0] === 'int' && param.type.length === 1 ? 'number' : 'text' }}" id="api4-param-{{:: name }}" ng-model="params[name]">
</textarea>
Expand Down
24 changes: 21 additions & 3 deletions ang/api4Explorer/Explorer.js
Original file line number Diff line number Diff line change
Expand Up @@ -222,12 +222,30 @@
}
};

$scope.isSpecial = function(name) {
var specialParams = ['select', 'fields', 'action', 'where', 'values', 'defaults', 'orderBy', 'chain', 'groupBy', 'having'];
// Gets generic params for use in one-time binding loops
$scope.getGenericParams = function(paramType, defaultNull) {
// Returns undefined if params are not yet set; one-time bindings will stabilize when this function returns a value
if (_.isEmpty($scope.availableParams)) {
return;
}
var genericParams = {},
specialParams = ['select', 'fields', 'action', 'where', 'values', 'defaults', 'orderBy', 'chain', 'groupBy', 'having'];
if ($scope.availableParams.limit && $scope.availableParams.offset) {
specialParams.push('limit', 'offset');
}
return _.contains(specialParams, name);
_.each($scope.availableParams, function(param, name) {
if (_.contains(specialParams, name)) {
return;
}
if (typeof paramType !== 'undefined' && !_.contains(paramType, param.type[0])) {
return;
}
if (typeof defaultNull !== 'undefined' && ((param.default === null) !== defaultNull)) {
return;
}
genericParams[name] = param;
});
return genericParams;
};

$scope.selectRowCount = function() {
Expand Down

0 comments on commit b2e544a

Please sign in to comment.