← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 21275: tracker-capture: upcoming/overdue event report generation now does not restrict if a given orguni...

 

------------------------------------------------------------
revno: 21275
committer: Abyot Asalefew Gizaw <abyota@xxxxxxxxx>
branch nick: dhis2
timestamp: Wed 2015-12-02 21:59:00 +0100
message:
  tracker-capture: upcoming/overdue event report generation now does not restrict if a given orgunit has program assigned or not. This makes it easy to generate reports from a higher level while programs are assigned at lower level. The only requirement is user need to have access to program.
modified:
  dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/report/overdue-events-controller.js
  dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/report/upcoming-events-controller.js
  dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/scripts/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/report/overdue-events-controller.js'
--- dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/report/overdue-events-controller.js	2015-12-02 12:35:44 +0000
+++ dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/report/overdue-events-controller.js	2015-12-02 20:59:00 +0000
@@ -51,18 +51,16 @@
     //watch for selection of org unit from tree
     $scope.$watch('selectedOrgUnit', function() {
         $scope.reportFinished = false;
-        $scope.reportStarted = false;
-        $scope.selectedProgram = null;
-        if( angular.isObject($scope.selectedOrgUnit)){            
-            $scope.loadPrograms($scope.selectedOrgUnit);
+        $scope.reportStarted = false;        
+        if( angular.isObject($scope.selectedOrgUnit)){
+            $scope.loadPrograms();
         }
     });
     
     //load programs associated with the selected org unit.
-    $scope.loadPrograms = function(orgUnit) {        
-        $scope.selectedOrgUnit = orgUnit;        
+    $scope.loadPrograms = function() {
         if (angular.isObject($scope.selectedOrgUnit)){
-            ProgramFactory.getProgramsByOu($scope.selectedOrgUnit, $scope.selectedProgram).then(function(response){
+            ProgramFactory.getAllForUser($scope.selectedProgram).then(function(response){
                 $scope.programs = response.programs;
                 $scope.selectedProgram = response.selectedProgram;
             });

=== modified file 'dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/report/upcoming-events-controller.js'
--- dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/report/upcoming-events-controller.js	2015-12-02 12:35:44 +0000
+++ dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/report/upcoming-events-controller.js	2015-12-02 20:59:00 +0000
@@ -47,18 +47,16 @@
     $scope.pager = {pageSize: 50, page: 1, toolBarDisplay: 5};
     
     //watch for selection of org unit from tree
-    $scope.$watch('selectedOrgUnit', function() {      
-        $scope.selectedProgram = null;
+    $scope.$watch('selectedOrgUnit', function() {
         if( angular.isObject($scope.selectedOrgUnit)){            
-            $scope.loadPrograms($scope.selectedOrgUnit);
+            $scope.loadPrograms();
         }
     });
     
     //load programs associated with the selected org unit.
-    $scope.loadPrograms = function(orgUnit) {        
-        $scope.selectedOrgUnit = orgUnit;        
+    $scope.loadPrograms = function() {
         if (angular.isObject($scope.selectedOrgUnit)){
-            ProgramFactory.getProgramsByOu($scope.selectedOrgUnit, $scope.selectedProgram).then(function(response){
+            ProgramFactory.getAllForUser($scope.selectedProgram).then(function(response){
                 $scope.programs = response.programs;
                 $scope.selectedProgram = response.selectedProgram;
             });

=== modified file 'dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/scripts/services.js'
--- dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/scripts/services.js	2015-12-02 12:35:44 +0000
+++ dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/scripts/services.js	2015-12-02 20:59:00 +0000
@@ -290,6 +290,49 @@
             
             return def.promise;            
         },
+        getAllForUser: function(selectedProgram){
+            var roles = SessionStorageService.get('USER_ROLES');
+            var userRoles = roles && roles.userCredentials && roles.userCredentials.userRoles ? roles.userCredentials.userRoles : [];
+            var def = $q.defer();
+            
+            TCStorageService.currentStore.open().done(function(){
+                TCStorageService.currentStore.getAll('programs').done(function(prs){
+                    var programs = [];
+                    angular.forEach(prs, function(pr){                            
+                        if(userHasValidRole(pr, userRoles)){
+                            programs.push(pr);
+                        }
+                    });
+                    
+                    if(programs.length === 0){
+                        selectedProgram = null;
+                    }
+                    else if(programs.length === 1){
+                        selectedProgram = programs[0];
+                    } 
+                    else{
+                        if(selectedProgram){
+                            var continueLoop = true;
+                            for(var i=0; i<programs.length && continueLoop; i++){
+                                if(programs[i].id === selectedProgram.id){                                
+                                    selectedProgram = programs[i];
+                                    continueLoop = false;
+                                }
+                            }
+                            if(continueLoop){
+                                selectedProgram = null;
+                            }
+                        }
+                    }
+                    
+                    $rootScope.$apply(function(){
+                        def.resolve({programs: programs, selectedProgram: selectedProgram});
+                    });                      
+                });
+            });
+            
+            return def.promise;
+        },
         get: function(uid){
             
             var def = $q.defer();
@@ -345,7 +388,7 @@
             });
             
             return def.promise;
-        }          
+        }
     };
 })