Commit 972c44b2 authored by jaapjansma's avatar jaapjansma
Browse files

Improvement for performance #22

parent 59b85e9e
......@@ -6,10 +6,15 @@
angular.module('form_processor').factory('formProcessorFactory', ["crmApi", "$q", function(crmApi, $q) {
var actionTypes = {};
var retrieveAction = function(name, context) {
// Initialize the context.
var setContext = function(context) {
if (!(context in actionTypes)) {
actionTypes[context] = {};
}
}
var retrieveAction = function(name, context) {
setContext(context);
if (!(name in actionTypes[context])) {
return crmApi('ActionProvider', 'getaction', {name: name, context:context});
}
......@@ -22,11 +27,15 @@
},
getFieldList: function (inputs, actions, selectedAction, context) {
setContext(context);
var defer = $q.defer();
var fields = [];
var promises = [];
angular.forEach(inputs, function(input, key) {
var field = {
'id': 'input.'+input.name,
'text': 'Input::'+input.name,
'name': 'input.'+input.name,
'label': 'Input::'+input.name
};
......@@ -34,26 +43,52 @@
});
var skipAfter = false;
var actionApiCalls = {};
angular.forEach(actions, function(action, key) {
if (selectedAction && selectedAction.name == action.name) {
skipAfter = true;
}
if (!skipAfter && !action.delay) {
promises.push(
retrieveAction(action.type, context)
.then(function (actionType) {
angular.forEach(actionType.output_spec, function(output_field, output_field_key) {
var field = {
'name': 'action.'+action.name+'.'+output_field.name,
'label': 'Action::'+action.title+'::'+output_field.title
};
fields.push(field);
});
return $q.resolve();
})
);
if (!(action.name in actionTypes[context])) {
actionApiCalls[key] = [
'ActionProvider',
'getaction',
{"name": action.type, "context":context}
];
} else {
angular.forEach(actionTypes[context][action.name].output_spec, function(output_field, output_field_key) {
var field = {
'id': 'action.'+action.name+'.'+output_field.name,
'text': 'Action::'+action.title+'::'+output_field.title,
'name': 'action.'+action.name+'.'+output_field.name,
'label': 'Action::'+action.title+'::'+output_field.title
};
fields.push(field);
});
}
}
});
if (Object.keys(actionApiCalls).length) {
promises.push(
CRM.api3(actionApiCalls)
.then(function(results) {
angular.forEach(results, function(actionType, key) {
var action = actions[key];
actionTypes[context][action.name] = actionType;
angular.forEach(actionType.output_spec, function(output_field, output_field_key) {
var field = {
'id': 'action.' + action.name + '.' + output_field.name,
'text': 'Action::' + action.title + '::' + output_field.title,
'name': 'action.' + action.name + '.' + output_field.name,
'label': 'Action::' + action.title + '::' + output_field.title
};
fields.push(field);
});
});
return $q.resolve();
})
);
}
$q.all(promises).then(function() {
defer.resolve(fields);
......
......@@ -53,7 +53,7 @@
$scope.deletedActions = [];
$scope.deletedDefaultDataInputs = [];
$scope.deletedDefaultDataActions = [];
$scope.default_data_fields = {};
$scope.default_data_fields = { results: []}
$scope.permissions = CRM.form_processor.permissions;
$scope.actionTitles = CRM.form_processor.actionTitles;
$scope.defaultDataActionTitles = CRM.form_processor.defaultDataActionTitles;
......@@ -94,12 +94,11 @@
$scope.$watchCollection('formProcessor.default_data_actions', function (newActions, oldActions) {
formProcessorFactory.getFieldList([], $scope.formProcessor.default_data_actions, false, "form_processor_default_data")
.then(function(fields) {
var originalDefaultDataOutputConfiguration = $scope.formProcessor.default_data_output_configuration;
$scope.default_data_fields = fields;
$scope.formProcessor.default_data_output_configuration = originalDefaultDataOutputConfiguration;
$timeout(function() {
$("select.defaultDataOutputSelect2").trigger('change.select2');
});
//var originalDefaultDataOutputConfiguration = $scope.formProcessor.default_data_output_configuration;
$scope.default_data_fields.results = fields;
$("input.defaultDataOutputSelect2").trigger('change.select2');
//$scope.formProcessor.default_data_output_configuration = originalDefaultDataOutputConfiguration;
console.log('loaded');
});
});
......
<div class="crm-block" ng-form="defaultDataOutput" crm-ui-id-scope>
<h3 class="widget-header">{{ts('Set defaults')}}</h3>
<table>
<thead>
<th>{{ts('Field')}}</th>
<th>{{ts('Value')}}</th>
</thead>
<tbody>
<tr ng-repeat="input in formProcessor.inputs | orderBy:'name'" ng-class-even="'crm-entity even-row even'" ng-class-odd="'crm-entity odd-row odd'">
<td>{{input.name}}</td>
<td>
<select class="huge40 defaultDataOutputSelect2"
name="{{input.name}}"
crm-ui-id="defaultData.{{input.name}}"
ui-jq="select2"
ui-options="{dropdownAutoWidth : true, allowClear: true}"
ng-model="formProcessor.default_data_output_configuration[input.name]"
ng-required="false"
>
<option value="">{{ts('- Select field to add to the output -')}}</option>
<option ng-repeat="field in default_data_fields track by field.name" value="{{field.name}}">{{field.label}}</option>
</select>
</td>
</tr>
</table>
<h3 class="widget-header">{{ts('Set defaults')}}</h3>
<table>
<thead>
<th>{{ts('Field')}}</th>
<th>{{ts('Value')}}</th>
</thead>
<tbody>
<tr ng-repeat="input in formProcessor.inputs | orderBy:'name'" ng-class-even="'crm-entity even-row even'" ng-class-odd="'crm-entity odd-row odd'">
<td>{{input.name}}</td>
<td>
<input
type="text"
class="huge40 defaultDataOutputSelect2"
name="{{input.name}}"
ui-jq="select2"
crm-ui-id="defaultData.{{input.name}}"
ui-options="{dropdownAutoWidth : true, allowClear: true, data: default_data_fields}"
ng-model="formProcessor.default_data_output_configuration[input.name]"
ng-required="false"
placeholder="{{ts('- Select field to add to the output -')}}"
/>
</td>
</tr>
</table>
</div>
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment