Commit 9757e942 authored by jaapjansma's avatar jaapjansma
Browse files

Improved performance (requires action provider version 1.61)

parent 34f3d62d
......@@ -11,14 +11,14 @@
if (!(context in actionTypes)) {
actionTypes[context] = {};
}
}
};
setAction = function(name, context, action) {
var setAction = function(name, context, action) {
setContext(context);
actionTypes[context][name] = action;
actionProviderFactory.setAction(name, context, action);
}
};
return {
getAction: function(name, context) {
return actionProviderFactory.getAction(name, context);
......@@ -39,7 +39,7 @@
};
fields.push(field);
});
var skipAfter = false;
var actionApiCalls = {};
angular.forEach(actions, function(action, key) {
......@@ -87,11 +87,11 @@
})
);
}
$q.all(promises).then(function() {
defer.resolve(fields);
});
return defer.promise;
}
};
......
......@@ -42,7 +42,7 @@
}
);
angular.module('form_processor').controller('FormProcessorEditCtrl', function($scope, formProcessorFactory, dialogService, crmApi, apiCalls, $location, $q, $timeout) {
angular.module('form_processor').controller('FormProcessorEditCtrl', function($scope, formProcessorFactory, dialogService, crmApi, apiCalls, $location, $window) {
var ts = $scope.ts = CRM.ts(null);
$scope.formProcessor = apiCalls.formProcessor;
......@@ -109,30 +109,97 @@
$scope.formProcessor.output_handler_configuration = output_handler.configuration;
var result = crmApi('FormProcessorInstance', 'create', $scope.formProcessor, true);
result.then(function(data) {
var apiCalls = {};
$scope.formProcessor.id = data.id;
$scope.formProcessor.output_handler = output_handler;
$scope.saveInputs($scope.formProcessor.inputs, $scope.deletedInputs, 'FormProcessorInput', $scope.formProcessor);
$scope.saveInputs($scope.formProcessor.default_data_inputs, $scope.deletedDefaultDataInputs, 'FormProcessorDefaultDataInput', $scope.formProcessor);
$scope.saveActions($scope.formProcessor.actions, $scope.deletedActions, 'FormProcessorAction', $scope.formProcessor);
$scope.saveActions($scope.formProcessor.default_data_actions, $scope.deletedDefaultDataActions, 'FormProcessorDefaultDataAction', $scope.formProcessor);
$scope.editFormProcessorForm.$setPristine();
apiCalls = $scope.createSaveInputApiCalls(apiCalls, $scope.formProcessor.inputs, $scope.deletedInputs, 'FormProcessorInput', $scope.formProcessor);
apiCalls = $scope.createSaveInputApiCalls(apiCalls, $scope.formProcessor.default_data_inputs, $scope.deletedDefaultDataInputs, 'FormProcessorDefaultDataInput', $scope.formProcessor);
apiCalls = $scope.createSaveActionApiCalls(apiCalls, $scope.formProcessor.actions, $scope.deletedActions, 'FormProcessorAction', $scope.formProcessor);
apiCalls = $scope.createSaveActionApiCalls(apiCalls, $scope.formProcessor.default_data_actions, $scope.deletedDefaultDataActions, 'FormProcessorDefaultDataAction', $scope.formProcessor);
CRM.api3(apiCalls)
.then(function(results) {
var apiCalls2 = {};
angular.forEach(results, function(result, key) {
var index;
if (key.startsWith('create_FormProcessorInput_')) {
index = key.substr(26);
$scope.formProcessor.inputs[index].id = result.id;
apiCalls2 = $scope.createSaveValidatorApiCalls(apiCalls2, $scope.formProcessor.inputs[index], 'FormProcessorInput');
}
if (key.startsWith('create_FormProcessorDefaultDataInput_')) {
index = key.substr(37);
$scope.formProcessor.default_data_inputs[index].id = result.id;
apiCalls2 = $scope.createSaveValidatorApiCalls(apiCalls2, $scope.formProcessor.inputs[index], 'FormProcessorDefaultDataInput');
}
if (key.startsWith('create_FormProcessorAction_')) {
index = key.substr(27);
$scope.formProcessor.actions[index].id = result.id;
}
if (key.startsWith('create_FormProcessorDefaultDataAction_')) {
index = key.substr(38);
$scope.formProcessor.default_data_actions[index].id = result.id;
}
});
if (goBack) {
$scope.goback();
}
CRM.api3(apiCalls2)
.then(function(results) {
if (goBack) {
$scope.goback();
} else {
$scope.editFormProcessorForm.$setPristine();
}
});
});
});
};
$scope.goback = function () {
$location.path('/formprocessors');
$location.path('/formprocessors');
$window.location.href = $location.absUrl();
};
/**
* Create a set of api calls to save the validators.
*
* @param apiCalls
* @param input
* @param api
* @returns {*}
*/
$scope.createSaveValidatorApiCalls = function(apiCalls, input, api) {
if (input.deletedValidators) {
angular.forEach(input.deletedValidators, function (deletedValidator, validator_index) {
if (deletedValidator.id) {
apiCalls['delete_FormProcessorValidation_'+deletedValidator.id] = ['FormProcessorValidation', 'delete', {'id': deletedValidator.id}];
}
});
}
angular.forEach(input.validators, function(validator, validator_index){
validator.entity = api;
validator.entity_id = input.id;
var validatorParams = angular.copy(validator);
validatorParams.validator = validator.validator.name;
apiCalls[api+'_FormProcessorValidation_'+input.id+'_'+validator_index] = ['FormProcessorValidation', 'create', validatorParams];
});
return apiCalls;
};
$scope.saveInputs = function(inputs, deletedInputs, api, formProcessor) {
/**
* Create a set of api calls to save all the inputs.
*
* @param apiCalls
* @param inputs
* @param deletedInputs
* @param api
* @param formProcessor
* @returns {*}
*/
$scope.createSaveInputApiCalls = function(apiCalls, inputs, deletedInputs, api, formProcessor) {
angular.forEach(deletedInputs, function(input, key) {
if (input.id) {
crmApi(api, 'delete', {'id': input.id}, true);
apiCalls['delete_'+api+'_'+key] = [api, 'delete', {'id': input.id}];
}
});
......@@ -140,38 +207,28 @@
if (input.id < 1) {
delete input.id;
}
var type = angular.copy(input.type);
input.form_processor_instance_id = formProcessor.id;
input.type = input.type.name;
crmApi(api, 'create', input, true).then(function (input_result){
input.id = input_result['id'];
input.type = type;
if (input.deletedValidators) {
angular.forEach(input.deletedValidators, function (deletedValidator, validator_index) {
if (deletedValidator.id) {
crmApi('FormProcessorValidation', 'delete', {'id': deletedValidator.id});
}
});
}
angular.forEach(input.validators, function(validator, validator_index){
validator.entity = api;
validator.entity_id = input.id;
var validator_type = angular.copy(validator.validator);
validator.validator = validator.validator.name;
crmApi('FormProcessorValidation', 'create', validator).then(function (validator_result) {
validator.validator = validator_type;
});
});
});
var inputParam = angular.copy(input);
inputParam.type = input.type.name;
apiCalls['create_'+api+'_'+key] = [api, 'create', inputParam];
});
return apiCalls;
};
$scope.saveActions = function(actions, deletedActions, api, formProcessor) {
/**
* Create a set of api Calls to save all the actions..
*
* @param apiCalls
* @param actions
* @param deletedActions
* @param api
* @param formProcessor
* @returns {*}
*/
$scope.createSaveActionApiCalls = function(apiCalls, actions, deletedActions, api, formProcessor) {
angular.forEach(deletedActions, function(action, key) {
if (action.id) {
crmApi(api, 'delete', {'id': action.id}, true);
apiCalls['delete_'+api+'_'+key] = [api, 'delete', {'id': action.id}];
}
});
......@@ -183,11 +240,10 @@
}
action.form_processor_instance_id = formProcessor.id;
action.weight = actionWeight;
crmApi(api, 'create', action, true).then(function(action_result) {
action.id = action_result.id;
});
apiCalls['create_'+api+'_'+key] = [api, 'create', action];
actionWeight++;
});
return apiCalls;
};
$scope.editOutputHandler = function editOutputHandler() {
......
(function(angular, $, _) {
angular.module('form_processor').controller('ConditionDialogCtrl', function ConditionDialogCtrl($scope, dialogService, crmApi) {
angular.module('form_processor').controller('ConditionDialogCtrl', function ConditionDialogCtrl($scope, dialogService) {
$scope.ts = CRM.ts(null);
$scope.action = $scope.model.action;
$scope.conditionTypes = CRM.form_processor.conditionTypes;
if (typeof $scope.action.condition_configuration !== 'object' || $scope.action.condition_configuration === null) {
$scope.action.condition_configuration = {};
}
$scope.saveClick = function() {
$scope.model.action = $scope.action;
dialogService.close('ConditionDialog', $scope.model);
};
$scope.cancelClick = function() {
dialogService.cancel('ConditionDialog');
};
});
})(angular, CRM.$, CRM._);
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