← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 18536: tracker-capture: bug fix when downloading attributes in no program

 

------------------------------------------------------------
revno: 18536
committer: Abyot Asalefew Gizaw <abyota@xxxxxxxxx>
branch nick: dhis2
timestamp: Mon 2015-03-09 13:29:40 +0100
message:
  tracker-capture: bug fix when downloading attributes in no program
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-apps/src/main/webapp/dhis-web-tracker-capture/scripts/tracker-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-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	2015-03-06 14:43:54 +0000
+++ dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/registration/registration-controller.js	2015-03-09 12:29:40 +0000
@@ -24,6 +24,7 @@
     
     $scope.attributesById = CurrentSelection.getAttributesById();
     if(!$scope.attributesById){
+        $scope.attributesById = [];
         AttributesFactory.getAll().then(function(atts){
             angular.forEach(atts, function(att){
                 $scope.attributesById[att.id] = att;

=== modified file 'dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/scripts/tracker-capture.js'
--- dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/scripts/tracker-capture.js	2015-03-06 16:52:13 +0000
+++ dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/scripts/tracker-capture.js	2015-03-09 12:29:40 +0000
@@ -133,6 +133,7 @@
     promise = promise.then( getPrograms );     
     promise = promise.then( getProgramStages );    
     promise = promise.then( getOptionSetsForDataElements );
+    promise = promise.then( getMetaTrackeEntityAttributes );
     promise = promise.then( getTrackedEntityAttributes );
     promise = promise.then( getOptionSetsForAttributes );
     promise = promise.then( getMetaProgramValidations );
@@ -152,7 +153,6 @@
     
 }
 
-
 function getCalendarSetting()
 {
     if(localStorage['CALENDAR_SETTING']){
@@ -325,124 +325,6 @@
     };
 }
 
-function getTrackedEntityAttributes( 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.programTrackedEntityAttributes){
-            _.each(_.values(program.programTrackedEntityAttributes), function(teAttribute){
-                build = build.then(function() {
-                    var d = $.Deferred();
-                    var p = d.promise();
-                    dhis2.tc.store.get('attributes', teAttribute.trackedEntityAttribute.id).done(function(obj) {
-                        if(!obj || obj.version !== teAttribute.trackedEntityAttribute.version) {
-                            promise = promise.then( getAttribute( teAttribute.trackedEntityAttribute.id ) );
-                        }
-                        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 getAttribute( id )
-{
-    return function() {
-        return $.ajax( {
-            url: '../api/trackedEntityAttributes.json',
-            type: 'GET',
-            data: 'filter=id:eq:' + id +'&fields=id,name,code,version,description,valueType,confidential,inherit,sortOrderInVisitSchedule,sortOrderInListNoProgram,displayOnVisitSchedule,displayInListNoProgram,unique,optionSet[id,version]'
-        }).done( function( response ){            
-            _.each( _.values( response.trackedEntityAttributes ), function( teAttribute ) {
-                dhis2.tc.store.set( 'attributes', teAttribute );
-            });
-        });
-    };
-}
-
-
-function getOptionSetsForAttributes( 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.programTrackedEntityAttributes){
-            _.each(_.values( program.programTrackedEntityAttributes), function( teAttribute) {           
-                if( teAttribute.trackedEntityAttribute.optionSet && teAttribute.trackedEntityAttribute.optionSet.id ){
-                    build = build.then(function() {
-                        var d = $.Deferred();
-                        var p = d.promise();
-                        dhis2.tc.store.get('optionSets', teAttribute.trackedEntityAttribute.optionSet.id).done(function(obj) {                            
-                            if((!obj || obj.version !== teAttribute.trackedEntityAttribute.optionSet.version) && !optionSetsInPromise[teAttribute.trackedEntityAttribute.optionSet.id]) {                                
-                                optionSetsInPromise[teAttribute.trackedEntityAttribute.optionSet.id] = teAttribute.trackedEntityAttribute.optionSet.id;                                
-                                promise = promise.then( getOptionSet( teAttribute.trackedEntityAttribute.optionSet.id ) );
-                            }
-                            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 getProgramStages( programs )
 {
     if( !programs ){
@@ -682,8 +564,6 @@
                     programValidation.id &&
                     programValidation.program &&
                     programValidation.program.id ) {
-                    
-                    //
                     dhis2.tc.store.set( 'programValidations', programValidation );
                 }
             });
@@ -691,6 +571,147 @@
     };
 }
 
+function getMetaTrackeEntityAttributes( programs ){
+    
+    var def = $.Deferred();
+    
+    $.ajax({
+        url: '../api/trackedEntityAttributes.json',
+        type: 'GET',
+        data:'paging=false&filter=displayInListNoProgram:eq:true&fields=id,optionSet[id,version]'
+    }).done( function(response) {          
+        var trackedEntityAttributes = [];
+        _.each( _.values( response.trackedEntityAttributes ), function ( trackedEntityAttribute ) {             
+            if( trackedEntityAttribute && trackedEntityAttribute.id ) {            
+                trackedEntityAttributes.push( trackedEntityAttribute );
+            }            
+        });
+        
+        _.each( _.values( programs ), function ( program ) {        
+            if(program.programTrackedEntityAttributes){
+                _.each(_.values(program.programTrackedEntityAttributes), function(teAttribute){                    
+                    trackedEntityAttributes.push(teAttribute.trackedEntityAttribute);
+                });
+            }
+        });
+        
+        def.resolve( {trackedEntityAttributes: trackedEntityAttributes, programs: programs} );
+        
+    }).fail(function(){
+        def.resolve( null );
+    });
+    
+    return def.promise();
+}
+
+function getTrackedEntityAttributes( data )
+{
+    if( !data.trackedEntityAttributes ){
+        return;
+    }
+    
+    var mainDef = $.Deferred();
+    var mainPromise = mainDef.promise();
+
+    var def = $.Deferred();
+    var promise = def.promise();
+
+    var builder = $.Deferred();
+    var build = builder.promise();        
+
+    _.each(_.values(data.trackedEntityAttributes), function(teAttribute){        
+        build = build.then(function() {
+            var d = $.Deferred();
+            var p = d.promise();
+            dhis2.tc.store.get('attributes', teAttribute.id).done(function(obj) {
+                if(!obj || obj.version !== teAttribute.version) {
+                    promise = promise.then( getAttribute( teAttribute.id ) );
+                }
+                d.resolve();
+            });
+            return p;
+        });            
+    });
+
+    build.done(function() {
+        def.resolve();
+
+        promise = promise.done( function () {
+            mainDef.resolve( {trackedEntityAttributes: data.trackedEntityAttributes, programs: data.programs} );
+        } );
+    }).fail(function(){
+        mainDef.resolve( null );
+    });
+
+    builder.resolve();
+
+    return mainPromise;    
+}
+
+function getAttribute( id )
+{
+    return function() {
+        return $.ajax( {
+            url: '../api/trackedEntityAttributes.json',
+            type: 'GET',
+            data: 'filter=id:eq:' + id +'&fields=id,name,code,version,description,valueType,confidential,inherit,sortOrderInVisitSchedule,sortOrderInListNoProgram,displayOnVisitSchedule,displayInListNoProgram,unique,optionSet[id,version]'
+        }).done( function( response ){            
+            _.each( _.values( response.trackedEntityAttributes ), function( teAttribute ) {
+                dhis2.tc.store.set( 'attributes', teAttribute );
+            });
+        });
+    };
+}
+
+
+function getOptionSetsForAttributes( data )
+{
+    if( !data.trackedEntityAttributes ){
+        return;
+    }
+    
+    var mainDef = $.Deferred();
+    var mainPromise = mainDef.promise();
+
+    var def = $.Deferred();
+    var promise = def.promise();
+
+    var builder = $.Deferred();
+    var build = builder.promise();
+
+    _.each(_.values( data.trackedEntityAttributes), function( teAttribute) {           
+        if( teAttribute.optionSet && teAttribute.optionSet.id ){
+            build = build.then(function() {
+                var d = $.Deferred();
+                var p = d.promise();
+                dhis2.tc.store.get('optionSets', teAttribute.optionSet.id).done(function(obj) {                            
+                    if((!obj || obj.version !== teAttribute.optionSet.version) && !optionSetsInPromise[teAttribute.optionSet.id]) {                                
+                        optionSetsInPromise[teAttribute.optionSet.id] = teAttribute.optionSet.id;                                
+                        promise = promise.then( getOptionSet( teAttribute.optionSet.id ) );
+                    }
+                    d.resolve();
+                });
+
+                return p;
+            });
+        }            
+    });
+
+    build.done(function() {
+        def.resolve();
+
+        promise = promise.done( function () {
+            mainDef.resolve( data.programs );
+        } );
+    }).fail(function(){
+        mainDef.resolve( null );
+    });
+
+    builder.resolve();
+
+    return mainPromise;    
+}
+
 function getTrackedEntityForms( )
 {
     dhis2.tc.store.getKeys( 'trackedEntityForms').done(function(res){