← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 21549: Reintroduced toggling between table and normal view + WIP functions for ID control digits

 

------------------------------------------------------------
revno: 21549
committer: Markus Bekken <markus.bekken@xxxxxxxxx>
branch nick: dhis2
timestamp: Wed 2015-12-30 03:55:18 +0100
message:
  Reintroduced toggling between table and normal view + WIP functions for ID control digits
modified:
  dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/dataentry/dataentry-controller.js
  dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/dataentry/dataentry.html
  dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/dataentry/modal-default-form-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/dataentry/dataentry-controller.js'
--- dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/dataentry/dataentry-controller.js	2015-12-28 14:53:48 +0000
+++ dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/dataentry/dataentry-controller.js	2015-12-30 02:55:18 +0000
@@ -42,7 +42,7 @@
     $scope.eventPeriods = [];
     $scope.currentPeriod = [];
     $scope.filterEvents = true;
-    $scope.showEventsAsTables = true;
+    $scope.showEventsAsTables = false;
     //variable is set while looping through the program stages later.
     $scope.stagesCanBeShownAsTable = false;
     $scope.showHelpText = {};
@@ -51,7 +51,7 @@
     $scope.errorMessages = {};
     $scope.warningMessages = {};
     $scope.hiddenSections = {};
-    $scope.tableMaxNumberOfDataElements = 10;
+    $scope.tableMaxNumberOfDataElements = 7;
     $scope.xVisitScheduleDataElement = false;
 
     
@@ -338,7 +338,7 @@
                     $scope.eventsByStage[stage.id] = [];
 
                     //If one of the stages has less than $scope.tableMaxNumberOfDataElements data elements, allow sorting as table:
-                    if (stage.programStageDataElements.length < $scope.tableMaxNumberOfDataElements) {
+                    if ($scope.stageCanBeShownAsTable(stage)) {
                         $scope.stagesCanBeShownAsTable = true;
                     }
                 });
@@ -434,24 +434,29 @@
     };
 
     $scope.stageCanBeShownAsTable = function (stage) {
-        if (stage.programStageDataElements && stage.programStageDataElements.length < $scope.tableMaxNumberOfDataElements) {
+        if (stage.programStageDataElements 
+                && stage.programStageDataElements.length < $scope.tableMaxNumberOfDataElements
+                && !stage.repeatable) {
             return true;
         }
         return false;
     };
 
-    $scope.toggleEventsTableDisplay = function () {        
-        
+    $scope.toggleEventsTableDisplay = function () {       
         $scope.showEventsAsTables = !$scope.showEventsAsTables;                
+
+        $scope.setDisplayTypeForStages();
+
         
-        angular.forEach($scope.programStages, function (stage) {
-            if (stage.programStageDataElements.length < $scope.tableMaxNumberOfDataElements) {
-                stage.displayEventsInTable = $scope.showEventsAsTables;
-                if ($scope.currentStage === stage) {
-                    $scope.getDataEntryForm();
-                }
+        if ($scope.currentStage && $scope.stageCanBeShownAsTable($scope.currentStage)) {
+            //If the current event was deselected, select the first event in the current Stage before showing data entry:
+            if(!$scope.currentEvent.event 
+                    && $scope.eventsByStage[$scope.currentStage.id]) {
+                $scope.currentEvent = $scope.eventsByStage[$scope.currentStage.id][0];
             }
-        });
+            
+            $scope.getDataEntryForm();
+        } 
     };
     
     $scope.setDisplayTypeForStages = function(){
@@ -461,7 +466,7 @@
     };
     
     $scope.setDisplayTypeForStage = function(stage){
-        if (stage.programStageDataElements.length < $scope.tableMaxNumberOfDataElements) {
+        if ($scope.stageCanBeShownAsTable(stage)) {
             stage.displayEventsInTable = $scope.showEventsAsTables;
         }
     };
@@ -597,15 +602,15 @@
                 $scope.addNewEvent(newEvent);
 
                 $scope.currentEvent = null;
-                $scope.showDataEntry(newEvent, false);
+                $scope.showDataEntry(newEvent, true);
             }
         }, function () {
         });
     };
 
-    $scope.showDataEntry = function (event, rightAfterEnrollment) {
+    $scope.showDataEntry = function (event, suppressToggling) {
         if (event) {
-            if ($scope.currentEvent && !rightAfterEnrollment && $scope.currentEvent.event === event.event) {
+            if ($scope.currentEvent && !suppressToggling && $scope.currentEvent.event === event.event) {
                 //clicked on the same stage, do toggling
                 $scope.currentStage = null;
                 $scope.currentEvent = null;
@@ -713,14 +718,14 @@
     
     $scope.switchToEventRowDeselected = function(event){
         if($scope.currentEvent !== event) {
-            $scope.showDataEntry(event,false);
+            $scope.showDataEntry(event,true);
         }
         $scope.currentEvent = {};
     };
     
     $scope.switchToEventRow = function (event) {
         if($scope.currentEvent !== event) {
-            $scope.showDataEntry(event,false);
+            $scope.showDataEntry(event,true);
         }
     };
 

=== modified file 'dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/dataentry/dataentry.html'
--- dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/dataentry/dataentry.html	2015-12-28 14:53:48 +0000
+++ dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/dataentry/dataentry.html	2015-12-30 02:55:18 +0000
@@ -8,6 +8,7 @@
         </span>
         <span class="pull-right widget-link">            
             <a href ng-click="toggleLegend()" title="{{'event_color_legend'| translate}}" class="small-horizonal-spacing"><i class="fa fa-info-circle vertical-center"></i></a>
+            <a href ng-click="toggleEventsTableDisplay()" title="{{showEventsAsTables ? 'toggle_table_view_off' : 'toggle_table_view_on'| translate}}" ng-show="stagesCanBeShownAsTable"><span ng-if="!showEventsAsTables"><i class="fa fa-bars vertical-center"></i></span><span ng-if="showEventsAsTables"><i class="fa fa-square vertical-center"></i></span></a>
             <a class="small-horizonal-spacing" href ng-click="expandCollapse(dataentryWidget)">
                 <span ng-show="dataentryWidget.expand"><i class="fa fa-chevron-up vertical-center" title="{{collapseLabel}}"></i></span>
                 <span ng-show="!dataentryWidget.expand"><i class="fa fa-chevron-down vertical-center" title="{{expandLabel}}"></i></span>
@@ -40,7 +41,7 @@
             <div ng-if="!selectedEnrollment || !selectedEnrollment.enrollment" class="alert alert-danger">{{notEnrolledLabel}}</div>
 
             <div ng-include="'components/dataentry/main-dataentry-form.html'"></div>
-
+            
             <div ng-if="displayCustomForm !== 'TABLE'">
                 <div ng-include="'components/dataentry/dataentry-notes.html'"></div>
             </div>

=== modified file 'dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/dataentry/modal-default-form-controller.js'
--- dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/dataentry/modal-default-form-controller.js	2015-12-21 13:28:07 +0000
+++ dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/dataentry/modal-default-form-controller.js	2015-12-30 02:55:18 +0000
@@ -5,7 +5,6 @@
     $scope.completeIncompleteEventModal = function(){  
            
         $scope.requestError = "";
-        debugger;
         if ($scope.currentEvent.status === 'COMPLETED'){
             var dhis2Event = $scope.makeDhis2EventToUpdate();
             dhis2Event.status = 'ACTIVE';

=== 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	2015-12-28 14:53:48 +0000
+++ dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/dhis2/dhis2.angular.services.js	2015-12-30 02:55:18 +0000
@@ -1196,7 +1196,9 @@
                                 {name:"d2:ceil",parameters:1},
                                 {name:"d2:round",parameters:1},
                                 {name:"d2:hasValue",parameters:1},
-                                {name:"d2:lastEventDate",parameters:1}];
+                                {name:"d2:lastEventDate",parameters:1},
+                                {name:"d2:addControlDigits",parameters:1},
+                                {name:"d2:checkControlDigits",parameters:1}];
             var continueLooping = true;
             //Safety harness on 10 loops, in case of unanticipated syntax causing unintencontinued looping
             for(var i = 0; i < 10 && continueLooping; i++ ) { 
@@ -1468,6 +1470,70 @@
                             expression = expression.replace(callToThisFunction, valueFound);
                             successfulExecution = true;
                         }
+                        else if(dhisFunction.name === "d2:addControlDigits") {
+                            
+                            var baseNumber = parameters[0];
+                            var baseDigits = baseNumber.split('');
+                            var error = false;
+                            
+                            
+                            var firstDigit = 0;
+                            var secondDigit = 0;
+                            
+                            if(baseDigits && baseDigits.length < 10 ) {
+                                var firstSum = 0;
+                                var baseNumberLength = baseDigits.length;
+                                //weights support up to 9 base digits:
+                                var firstWeights = [3,7,6,1,8,9,4,5,2];
+                                for(var i = 0; i < baseNumberLength && !error; i++) {
+                                    firstSum += parseInt(baseDigits[i]) * firstWeights[i];
+                                }
+                                firstDigit = firstSum % 11;
+                                
+                                //Push the first digit to the array before continuing, as the second digit is a result of the 
+                                //base digits and the first control digit.
+                                baseDigits.push(firstDigit);
+                                //Weights support up to 9 base digits plus first control digit:
+                                var secondWeights = [5,4,3,2,7,6,5,4,3,2];
+                                var secondSum = 0;
+                                for(var i = 0; i < baseNumberLength + 1 && !error; i++) {
+                                    secondSum += parseInt(baseDigits[i]) * secondWeights[i]; 
+                                }
+                                secondDigit = secondSum % 11;
+                                
+                                if(firstDigit === 10) {
+                                    $log.warn("First control digit became 10, replacing with 0");
+                                    firstDigit = 0;
+                                }
+                                if(secondDigit === 10) {
+                                    $log.warn("Second control digit became 10, replacing with 0");
+                                    secondDigit = 0;
+                                }
+                            }
+                            else
+                            {
+                                $log.warn("Base nuber not well formed(" + baseNumberLength + " digits): " + baseNumber);
+                            }
+                            
+                            if(!error) {
+                                //Replace the end evaluation of the dhis function:
+                                expression = expression.replace(callToThisFunction, baseNumber + firstDigit + secondDigit);
+                                successfulExecution = true;
+                            }
+                            else
+                            {
+                                //Replace the end evaluation of the dhis function:
+                                expression = expression.replace(callToThisFunction, baseNumber);
+                                successfulExecution = false;
+                            }
+                        }
+                        else if(dhisFunction.name === "d2:checkControlDigits") {
+                            $log.warn("checkControlDigits not implemented yet");
+                            
+                            //Replace the end evaluation of the dhis function:
+                            expression = expression.replace(callToThisFunction, parameters[0]);
+                            successfulExecution = false;
+                        }
                     });
                 });