← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 22297: tracker-capture: moved rule effect processing function of attributes to service

 

------------------------------------------------------------
revno: 22297
committer: Abyot Asalefew Gizaw <abyot@xxxxxxxxx>
branch nick: dhis2
timestamp: Mon 2016-03-14 15:00:44 +0100
message:
  tracker-capture: moved rule effect processing function of attributes to service
modified:
  dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/registration/registration-controller.js
  dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/dhis2/dhis2.angular.services.js


--
lp:dhis2
https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk

Your team DHIS 2 developers is subscribed to branch lp:dhis2.
To unsubscribe from this branch go to https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk/+edit-subscription
=== modified file 'dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/registration/registration-controller.js'
--- dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/registration/registration-controller.js	2016-02-19 16:53:52 +0000
+++ dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/registration/registration-controller.js	2016-03-14 14:00:44 +0000
@@ -268,63 +268,6 @@
         performRegistration(destination);
     }; 
     
-    var processRuleEffect = function(){        
-        $scope.warningMessages = [];        
-        angular.forEach($rootScope.ruleeffects['registration'], function (effect) {
-            if (effect.trackedEntityAttribute) {
-                //in the data entry controller we only care about the "hidefield", showerror and showwarning actions
-                if (effect.action === "HIDEFIELD") {
-                    if (effect.trackedEntityAttribute) {
-                        if (effect.ineffect && $scope.selectedTei[effect.trackedEntityAttribute.id]) {
-                            //If a field is going to be hidden, but contains a value, we need to take action;
-                            if (effect.content) {
-                                //TODO: Alerts is going to be replaced with a proper display mecanism.
-                                alert(effect.content);
-                            }
-                            else {
-                                //TODO: Alerts is going to be replaced with a proper display mecanism.
-                                alert($scope.attributesById[effect.trackedEntityAttribute.id].displayName + "Was blanked out and hidden by your last action");
-                            }
-
-                            //Blank out the value:
-                            $scope.selectedTei[effect.trackedEntityAttribute.id] = "";
-                        }
-
-                        $scope.hiddenFields[effect.trackedEntityAttribute.id] = effect.ineffect;
-                    }
-                    else {
-                        $log.warn("ProgramRuleAction " + effect.id + " is of type HIDEFIELD, bot does not have an attribute defined");
-                    }
-                } else if (effect.action === "SHOWERROR") {
-                    if (effect.trackedEntityAttribute) {                        
-                        if(effect.ineffect) {
-                            var dialogOptions = {
-                                headerText: 'validation_error',
-                                bodyText: effect.content + (effect.data ? effect.data : "")
-                            };
-                            DialogService.showDialog({}, dialogOptions);
-                            $scope.selectedTei[effect.trackedEntityAttribute.id] = $scope.tei[effect.trackedEntityAttribute.id];
-                        }
-                    }
-                    else {
-                        $log.warn("ProgramRuleAction " + effect.id + " is of type HIDEFIELD, bot does not have an attribute defined");
-                    }
-                } else if (effect.action === "SHOWWARNING") {
-                    if (effect.trackedEntityAttribute) {
-                        if(effect.ineffect) {
-                            var message = effect.content + (angular.isDefined(effect.data) ? effect.data : "");
-                            $scope.warningMessages.push(message);
-                            $scope.warningMessages[effect.trackedEntityAttribute.id] = message;
-                        }
-                    }
-                    else {
-                        $log.warn("ProgramRuleAction " + effect.id + " is of type HIDEFIELD, bot does not have an attribute defined");
-                    }
-                }
-            }
-        });
-    };
-    
     $scope.executeRules = function () {
         var flag = {debug: true, verbose: false};
         
@@ -361,8 +304,12 @@
     };
     
     //listen for rule effect changes
-    $scope.$on('ruleeffectsupdated', function (event, args) {
-        processRuleEffect(args.event);
+    $scope.$on('ruleeffectsupdated', function(){
+        $scope.warningMessages = [];
+        var effectResult = TrackerRulesExecutionService.processRuleEffectAttribute('registration', $scope.selectedTei, $scope.tei, $scope.attributesById, $scope.hiddenFields, $scope.warningMessages);
+        $scope.selectedTei = effectResult.selectedTei;
+        $scope.hiddenFields = effectResult.hiddenFields;
+        $scope.warningMessages = effectResult.warningMessages;
     });
 
 

=== modified file 'dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/dhis2/dhis2.angular.services.js'
--- dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/dhis2/dhis2.angular.services.js	2016-03-08 16:27:49 +0000
+++ dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/dhis2/dhis2.angular.services.js	2016-03-14 14:00:44 +0000
@@ -1174,7 +1174,7 @@
     })
 
     /* service for executing tracker rules and broadcasting results */
-    .service('TrackerRulesExecutionService', function(VariableService, DateUtils, DHIS2EventFactory, CalendarService, $rootScope, $log, $filter, orderByFilter){
+    .service('TrackerRulesExecutionService', function(VariableService, DateUtils, DialogService, DHIS2EventFactory, CalendarService, $rootScope, $log, $filter, orderByFilter){
 
         var replaceVariables = function(expression, variablesHash){
             //replaces the variables in an expression with actual variable values.
@@ -1957,6 +1957,63 @@
 
                     return true;
                 }
+            },
+            processRuleEffectAttribute: function(context, selectedTei, tei, attributesById, hiddenFields, warningMessages){
+                angular.forEach($rootScope.ruleeffects[context], function (effect) {
+                    if (effect.trackedEntityAttribute) {
+                        //in the data entry controller we only care about the "hidefield", showerror and showwarning actions
+                        if (effect.action === "HIDEFIELD") {
+                            if (effect.trackedEntityAttribute) {
+                                if (effect.ineffect && selectedTei[effect.trackedEntityAttribute.id]) {
+                                    //If a field is going to be hidden, but contains a value, we need to take action;
+                                    if (effect.content) {
+                                        //TODO: Alerts is going to be replaced with a proper display mecanism.
+                                        alert(effect.content);
+                                    }
+                                    else {
+                                        //TODO: Alerts is going to be replaced with a proper display mecanism.
+                                        alert(attributesById[effect.trackedEntityAttribute.id].displayName + "Was blanked out and hidden by your last action");
+                                    }
+
+                                    //Blank out the value:
+                                    selectedTei[effect.trackedEntityAttribute.id] = "";
+                                }
+
+                                hiddenFields[effect.trackedEntityAttribute.id] = effect.ineffect;
+                            }
+                            else {
+                                $log.warn("ProgramRuleAction " + effect.id + " is of type HIDEFIELD, bot does not have an attribute defined");
+                            }
+                        } else if (effect.action === "SHOWERROR") {
+                            if (effect.trackedEntityAttribute) {                        
+                                if(effect.ineffect) {
+                                    var dialogOptions = {
+                                        headerText: 'validation_error',
+                                        bodyText: effect.content + (effect.data ? effect.data : "")
+                                    };
+                                    DialogService.showDialog({}, dialogOptions);
+                                    selectedTei[effect.trackedEntityAttribute.id] = tei[effect.trackedEntityAttribute.id];
+                                }
+                            }
+                            else {
+                                $log.warn("ProgramRuleAction " + effect.id + " is of type HIDEFIELD, bot does not have an attribute defined");
+                            }
+                        } else if (effect.action === "SHOWWARNING") {
+                            if (effect.trackedEntityAttribute) {
+                                if(effect.ineffect) {
+                                    var message = effect.content + (angular.isDefined(effect.data) ? effect.data : "");
+                                    warningMessages.push(message);
+                                    warningMessages[effect.trackedEntityAttribute.id] = message;
+                                }
+                            }
+                            else {
+                                $log.warn("ProgramRuleAction " + effect.id + " is of type HIDEFIELD, bot does not have an attribute defined");
+                            }
+                        }
+                    }
+                });
+                
+                return {selectedTei: selectedTei, hiddenFields: hiddenFields, warningMessages: warningMessages};
             }
         };
     })