← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 21502: event-capture: improving meta-data loading - WIP

 

------------------------------------------------------------
revno: 21502
committer: Abyot Asalefew Gizaw <abyota@xxxxxxxxx>
branch nick: dhis2
timestamp: Mon 2015-12-21 17:42:10 +0100
message:
  event-capture: improving meta-data loading - WIP
modified:
  dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-event-capture/scripts/controllers.js
  dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-event-capture/scripts/event-capture.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-event-capture/scripts/controllers.js'
--- dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-event-capture/scripts/controllers.js	2015-12-03 10:14:07 +0000
+++ dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-event-capture/scripts/controllers.js	2015-12-21 16:42:10 +0000
@@ -179,9 +179,9 @@
                 $scope.selectedProgram.programStages[0].id){ 
                 
             //because this is single event, take the first program stage
-            MetaDataFactory.get('programStages', $scope.selectedProgram.programStages[0].id).then(function (programStage){
-
-                $scope.selectedProgramStage = programStage;   
+            
+            $scope.selectedProgramStage = $scope.selectedProgram.programStages[0];   
+            
 
                 angular.forEach($scope.selectedProgramStage.programStageSections, function(section){
                     section.open = true;
@@ -239,29 +239,22 @@
                 
                 $scope.newDhis2Event.eventDate = '';
                 
-                var categoryIds = [];
+                $scope.selectedCategories = [];
                 if($scope.selectedProgram.categoryCombo && 
                         !$scope.selectedProgram.categoryCombo.isDefault &&
                         $scope.selectedProgram.categoryCombo.categories){
-                    
-                    angular.forEach($scope.selectedProgram.categoryCombo.categories, function(cat){
-                        categoryIds.push(cat.id);
-                    });
+                    $scope.selectedCategories = $scope.selectedProgram.categoryCombo.categories;                    
                 }
                 else{
                     $scope.optionsReady = true;
                 }
                 
-                MetaDataFactory.getByIds('categories', categoryIds).then(function(categories){
-                    $scope.selectedCategories = categories;                    
-                    TrackerRulesFactory.getRules($scope.selectedProgram.id).then(function(rules){                    
-                        $scope.allProgramRules = rules;
-                        if($scope.selectedCategories.length === 0){
-                            $scope.loadEvents();
-                        }                        
-                    });
+                TrackerRulesFactory.getRules($scope.selectedProgram.id).then(function(rules){                    
+                    $scope.allProgramRules = rules;
+                    if($scope.selectedCategories.length === 0){
+                        $scope.loadEvents();
+                    }                        
                 });
-            });
         }
     };
     

=== modified file 'dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-event-capture/scripts/event-capture.js'
--- dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-event-capture/scripts/event-capture.js	2015-12-04 12:23:53 +0000
+++ dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-event-capture/scripts/event-capture.js	2015-12-21 16:42:10 +0000
@@ -154,8 +154,8 @@
     promise = promise.then( getOrgUnitLevels );    
     promise = promise.then( getMetaPrograms );     
     promise = promise.then( getPrograms );     
-    promise = promise.then( getProgramStages );
-    promise = promise.then( getCategories );
+    //promise = promise.then( getProgramStages );
+    //promise = promise.then( getCategories );
     promise = promise.then( getMetaProgramValidations );
     promise = promise.then( getProgramValidations );
     promise = promise.then( getMetaProgramIndicators );
@@ -224,7 +224,7 @@
         if(res.length > 0){
             return;
         }        
-        return getD2Objects('constants', 'constants', '../api/constants.json', 'paging=false&fields=id,name,displayName,value');        
+        return getD2Objects('constants', 'constants', '../api/constants.json', 'paging=false&fields=id,name,name,value');        
     });    
 }
 
@@ -245,7 +245,7 @@
     $.ajax({
         url: '../api/programs.json',
         type: 'GET',
-        data:'filter=programType:eq:WITHOUT_REGISTRATION&paging=false&fields=id,version,categoryCombo[id,isDefault,categories[id,categoryOptions[id]]],programStages[id,version,programStageSections[id],programStageDataElements[dataElement[id,optionSet[id,version]]]]'
+        data:'filter=programType:eq:WITHOUT_REGISTRATION&paging=false&fields=id,version,categoryCombo[id,isDefault,categories[id]],programStages[id,version,programStageSections[id],programStageDataElements[dataElement[id,optionSet[id,version]]]]'
     }).done( function(response) {        
         def.resolve( response.programs ? response.programs: [] );
     }).fail(function(){
@@ -270,6 +270,7 @@
     var builder = $.Deferred();
     var build = builder.promise();
 
+    var ids = [];
     _.each( _.values( programs ), function ( program ) {
         
         if(program.programStages && program.programStages[0].programStageDataElements){
@@ -278,7 +279,7 @@
                 var p = d.promise();
                 dhis2.ec.store.get('programs', program.id).done(function(obj) {
                     if(!obj || obj.version !== program.version) {
-                        promise = promise.then( getProgram( program.id ) );
+                        ids.push( program.id );
                     }
 
                     d.resolve();
@@ -290,11 +291,16 @@
     });
 
     build.done(function() {
-        def.resolve();
-
         promise = promise.done( function () {
-            mainDef.resolve( programs );
+            if( ids && ids.length > 0 ){
+                var _ids = ids.toString();
+                _ids = '[' + _ids + ']';
+                promise = promise.then( getAllPrograms( _ids ) );
+            }            
+            mainDef.resolve( programs, ids );
         } );
+        def.resolve();
+        
     }).fail(function(){
         mainDef.resolve( null );
     });
@@ -304,104 +310,36 @@
     return mainPromise;
 }
 
-function getProgram( id )
-{
+function getAllPrograms( ids )
+{    
     return function() {
         return $.ajax( {
-            url: '../api/programs/' + id + '.json',
+            url: '../api/programs.json',
             type: 'GET',
-            data: 'fields=id,name,programType,version,dataEntryMethod,skipOffline,enrollmentDateLabel,incidentDateLabel,displayIncidentDate,ignoreOverdueEvents,categoryCombo[id,isDefault,categories[id]],organisationUnits[id,name],programStages[id,name,version],userRoles[id,name]'
-        }).done( function( program ){            
-            var ou = {};
-            _.each(_.values( program.organisationUnits), function(o){
-                ou[o.id] = o.name;
-            });
-            program.organisationUnits = ou;
-
-            var ur = {};
-            _.each(_.values( program.userRoles), function(u){
-                ur[u.id] = u.name;
-            });
-            program.userRoles = ur;
-
-            dhis2.ec.store.set( 'programs', program );        
+            data: 'fields=id,name,programType,version,dataEntryMethod,enrollmentDateLabel,incidentDateLabel,displayIncidentDate,ignoreOverdueEvents,categoryCombo[id,name,isDefault,categories[id,name,categoryOptions[id,name]]],organisationUnits[id,name],programStages[id,name,version,description,excecutionDateLabel,captureCoordinates,dataEntryForm[id,name,style,htmlCode,format],minDaysFromStart,repeatable,preGenerateUID,programStageSections[id,name,programStageDataElements[dataElement[id]]],programStageDataElements[displayInReports,sortOrder,allowProvidedElsewhere,allowFutureDate,compulsory,dataElement[id,name,valueType,optionSetValue,formName,optionSet[id]]]],userRoles[id,name]&paging=false&filter=id:in:' + ids
+        }).done( function( response ){
+            
+            if(response.programs){
+                _.each(_.values( response.programs), function(program){
+                    var ou = {};
+                    _.each(_.values( program.organisationUnits), function(o){
+                        ou[o.id] = o.name;
+                    });
+                    program.organisationUnits = ou;
+
+                    var ur = {};
+                    _.each(_.values( program.userRoles), function(u){
+                        ur[u.id] = u.name;
+                    });
+                    program.userRoles = ur;
+
+                    dhis2.ec.store.set( 'programs', program );
+                });
+            }
         });
     };
 }
 
-function getProgramStages( programs )
-{
-    if( !programs ){
-        return;
-    }
-    
-    var mainDef = $.Deferred();
-    var mainPromise = mainDef.promise();
-
-    var def = $.Deferred();
-    var promise = def.promise();
-
-    var builder = $.Deferred();
-    var build = builder.promise();
-
-    _.each( _.values( programs ), function ( program ) {
-        
-        if(program.programStages){
-            build = build.then(function() {
-                var d = $.Deferred();
-                var p = d.promise();
-                dhis2.ec.store.get('programStages', program.programStages[0].id).done(function(obj) {
-                    if(!obj || obj.version !== program.programStages[0].version) {
-                        promise = promise.then( getD2Object( program.programStages[0].id, 'programStages', '../api/programStages', 'fields=id,name,version,description,excecutionDateLabel,captureCoordinates,dataEntryForm[id,name,style,htmlCode,format],minDaysFromStart,repeatable,preGenerateUID,programStageSections[id,name,programStageDataElements[dataElement[id]]],programStageDataElements[displayInReports,sortOrder,allowProvidedElsewhere,allowFutureDate,compulsory,dataElement[id,name,valueType,optionSetValue,formName,optionSet[id]]]', 'idb' ) );
-                    }
-
-                    d.resolve();
-                });
-
-                return p;
-            });
-        }              
-    });
-
-    build.done(function() {
-        def.resolve();
-
-        promise = promise.done( function () {
-            mainDef.resolve( programs );
-        } );
-    }).fail(function(){
-        mainDef.resolve( null );
-    });
-
-    builder.resolve();
-
-    return mainPromise;    
-}
-
-function getCategories( programs )
-{
-    if(!programs){
-        return;
-    }
-    
-    var catigories = [];
-    _.each( _.values( programs ), function ( program ) {
-        if( program && program.categoryCombo && !program.categoryCombo.isDefault && program.categoryCombo.categories ) {
-            _.each(_.values(program.categoryCombo.categories), function(cat){
-                catigories.push( cat );
-            });            
-        }
-    });
-    
-    if(catigories.length > 0 ){
-        return checkAndGetD2Objects( {programs: programs, self: catigories}, 'categories', '../api/categories', 'fields=id,name,categoryOptions[id,name]');
-    }
-    else
-    {
-        return programs;
-    }
-}
-
 function getOptionSets( programs )
 {
     if( !programs ){
@@ -462,7 +400,7 @@
 
 function getProgramValidations( programValidations )
 {
-    return checkAndGetD2Objects( programValidations, 'programValidations', '../api/programValidations', 'fields=id,name,displayName,operator,rightSide[expression,description],leftSide[expression,description],program[id]');
+    return checkAndGetD2Objects( programValidations, 'programValidations', '../api/programValidations', 'fields=id,name,name,operator,rightSide[expression,description],leftSide[expression,description],program[id]');
 }
 
 function getMetaProgramIndicators( programs )
@@ -472,7 +410,7 @@
 
 function getProgramIndicators( programIndicators )
 {
-    return checkAndGetD2Objects( programIndicators, 'programIndicators', '../api/programIndicators', 'fields=id,name,code,shortName,displayInForm,expression,displayDescription,rootDate,description,valueType,DisplayName,filter,program[id]');
+    return checkAndGetD2Objects( programIndicators, 'programIndicators', '../api/programIndicators', 'fields=id,name,code,shortName,displayInForm,expression,displayDescription,rootDate,description,valueType,name,filter,program[id]');
 }
 
 function getMetaProgramRules( programs )
@@ -492,7 +430,7 @@
 
 function getProgramRuleVariables( programRuleVariables )
 {
-    return checkAndGetD2Objects( programRuleVariables, 'programRuleVariables', '../api/programRuleVariables', 'fields=id,name,displayName,programRuleVariableSourceType,program[id],programStage[id],dataElement[id]');
+    return checkAndGetD2Objects( programRuleVariables, 'programRuleVariables', '../api/programRuleVariables', 'fields=id,name,name,programRuleVariableSourceType,program[id],programStage[id],dataElement[id]');
 }
 
 function getD2MetaObject( programs, objNames, url, filter )