← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 21648: Now showing error message if TEI loading fails in TEI dashboard

 

------------------------------------------------------------
revno: 21648
committer: Markus Bekken <markus.bekken@xxxxxxxxx>
branch nick: dhis2
timestamp: Thu 2016-01-07 18:56:29 +0100
message:
  Now showing error message if TEI loading fails in TEI dashboard
modified:
  dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/dashboard/dashboard-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/dashboard/dashboard-controller.js'
--- dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/dashboard/dashboard-controller.js	2015-12-16 09:43:38 +0000
+++ dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/dashboard/dashboard-controller.js	2016-01-07 17:56:29 +0000
@@ -167,74 +167,76 @@
             
                 //Fetch the selected entity
                 TEIService.get($scope.selectedTeiId, $scope.optionSets, $scope.attributesById).then(function(response){
-                    $scope.selectedTei = response;
-                    
-                    setInactiveMessage();                   
-
-                    //get the entity type
-                    TEService.get($scope.selectedTei.trackedEntity).then(function(te){                    
-                        $scope.trackedEntity = te;
-
-                        //get enrollments for the selected tei
-                        EnrollmentService.getByEntity($scope.selectedTeiId).then(function(response){                    
-                            var enrollments = angular.isObject(response) && response.enrollments ? response.enrollments : [];
-                            var selectedEnrollment = null, backupSelectedEnrollment = null;                            
-                            if(enrollments.length === 1 ){
-                                selectedEnrollment = enrollments[0];                               
-                            }
-                            else{
-                                if( $scope.selectedProgramId ){
-                                    angular.forEach(enrollments, function(en){
-                                        if( en.program === $scope.selectedProgramId ){
-                                            if( en.status === 'ACTIVE'){
-                                                selectedEnrollment = en;
-                                            }
-                                            else{
-                                                backupSelectedEnrollment = en;
-                                            }
-                                        }
-                                    });
-                                }                                
-                            }                            
-                            selectedEnrollment = selectedEnrollment ? selectedEnrollment : backupSelectedEnrollment;
-                            
-                            ProgramFactory.getAll().then(function(programs){
-                                $scope.programs = [];
-                                $scope.programNames = [];  
-                                $scope.programStageNames = [];        
-
-                                //get programs valid for the selected ou and tei
-                                angular.forEach(programs, function(program){                                    
-                                    if( program.trackedEntity.id === $scope.selectedTei.trackedEntity ){
-                                        $scope.programs.push(program);
-                                        $scope.programNames[program.id] = {id: program.id, name: program.name};
-                                        angular.forEach(program.programStages, function(stage){                
-                                                $scope.programStageNames[stage.id] = {id: stage.id, name: stage.name};
+                    if(response) {
+                        $scope.selectedTei = response;
+
+                        setInactiveMessage();                   
+
+                        //get the entity type
+                        TEService.get($scope.selectedTei.trackedEntity).then(function(te){                    
+                            $scope.trackedEntity = te;
+
+                            //get enrollments for the selected tei
+                            EnrollmentService.getByEntity($scope.selectedTeiId).then(function(response){                    
+                                var enrollments = angular.isObject(response) && response.enrollments ? response.enrollments : [];
+                                var selectedEnrollment = null, backupSelectedEnrollment = null;                            
+                                if(enrollments.length === 1 ){
+                                    selectedEnrollment = enrollments[0];                               
+                                }
+                                else{
+                                    if( $scope.selectedProgramId ){
+                                        angular.forEach(enrollments, function(en){
+                                            if( en.program === $scope.selectedProgramId ){
+                                                if( en.status === 'ACTIVE'){
+                                                    selectedEnrollment = en;
+                                                }
+                                                else{
+                                                    backupSelectedEnrollment = en;
+                                                }
+                                            }
                                         });
-
-                                        if($scope.selectedProgramId && program.id === $scope.selectedProgramId || selectedEnrollment && selectedEnrollment.program === program.id){
-                                            $scope.selectedProgram = program;
-                                        }
                                     }                                
+                                }                            
+                                selectedEnrollment = selectedEnrollment ? selectedEnrollment : backupSelectedEnrollment;
+
+                                ProgramFactory.getAll().then(function(programs){
+                                    $scope.programs = [];
+                                    $scope.programNames = [];  
+                                    $scope.programStageNames = [];        
+
+                                    //get programs valid for the selected ou and tei
+                                    angular.forEach(programs, function(program){                                    
+                                        if( program.trackedEntity.id === $scope.selectedTei.trackedEntity ){
+                                            $scope.programs.push(program);
+                                            $scope.programNames[program.id] = {id: program.id, name: program.name};
+                                            angular.forEach(program.programStages, function(stage){                
+                                                    $scope.programStageNames[stage.id] = {id: stage.id, name: stage.name};
+                                            });
+
+                                            if($scope.selectedProgramId && program.id === $scope.selectedProgramId || selectedEnrollment && selectedEnrollment.program === program.id){
+                                                $scope.selectedProgram = program;
+                                            }
+                                        }                                
+                                    });
+
+                                    //filter those enrollments that belong to available programs
+                                    var len = enrollments.length;
+                                    while(len--){
+                                        if(enrollments[len].program && !$scope.programNames[enrollments[len].program]){
+                                            enrollments.splice(len,1);
+                                        }
+                                    }
+
+                                    DHIS2EventFactory.getEventsByProgram($scope.selectedTeiId, null).then(function(events){                                        
+                                        //prepare selected items for broadcast
+                                        CurrentSelection.setSelectedTeiEvents(events);                                        
+                                        CurrentSelection.set({tei: $scope.selectedTei, te: $scope.trackedEntity, prs: $scope.programs, pr: $scope.selectedProgram, prNames: $scope.programNames, prStNames: $scope.programStageNames, enrollments: enrollments, selectedEnrollment: selectedEnrollment, optionSets: $scope.optionSets});                            
+                                        getDashboardLayout(); 
+                                    });                    
                                 });
-                                
-                                //filter those enrollments that belong to available programs
-                                var len = enrollments.length;
-                                while(len--){
-                                    if(enrollments[len].program && !$scope.programNames[enrollments[len].program]){
-                                        enrollments.splice(len,1);
-                                    }
-                                }
-                                
-                                DHIS2EventFactory.getEventsByProgram($scope.selectedTeiId, null).then(function(events){                                        
-                                    //prepare selected items for broadcast
-                                    CurrentSelection.setSelectedTeiEvents(events);                                        
-                                    CurrentSelection.set({tei: $scope.selectedTei, te: $scope.trackedEntity, prs: $scope.programs, pr: $scope.selectedProgram, prNames: $scope.programNames, prStNames: $scope.programStageNames, enrollments: enrollments, selectedEnrollment: selectedEnrollment, optionSets: $scope.optionSets});                            
-                                    getDashboardLayout(); 
-                                });                    
                             });
-                        });
-                    });            
+                        }); 
+                    }
                 });  
             });
         });

=== 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	2016-01-07 10:29:04 +0000
+++ dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/scripts/services.js	2016-01-07 17:56:29 +0000
@@ -693,6 +693,21 @@
                     att.value = AttributesFactory.formatAttributeValue(att, attributesById, optionSets, 'USER');
                 });
                 return tei;
+            }, function(error){
+                if(error){
+                    var dialogOptions = {
+                        headerText: 'error',
+                        bodyText: 'access_denied'
+                    };
+                    if(error.statusText) {
+                        dialogOptions.headerText = error.statusText;
+                    }
+                    if(error.data && error.data.message) {
+                        dialogOptions.bodyText = error.data.message;
+                    }
+                    
+                    DialogService.showDialog({}, dialogOptions);
+                }
             });
             
             return promise;