← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 11581: in anonymous entry, only load optionsets into browser-store if optionset isnt already loaded, or ...

 

------------------------------------------------------------
revno: 11581
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Tue 2013-08-06 13:39:28 +0700
message:
  in anonymous entry, only load optionsets into browser-store if optionset isnt already loaded, or optionset.version !== stored.version
modified:
  dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/GetOptionSetAction.java
  dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/GetProgramMetaDataAction.java
  dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/javascript/anonymousRegistration.js
  dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/jsonOptionSet.vm
  dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/jsonProgramMetaData.vm


--
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-caseentry/src/main/java/org/hisp/dhis/caseentry/action/GetOptionSetAction.java'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/GetOptionSetAction.java	2013-04-24 06:11:42 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/GetOptionSetAction.java	2013-08-06 06:39:28 +0000
@@ -30,6 +30,7 @@
 import com.opensymphony.xwork2.Action;
 import org.hisp.dhis.dataelement.DataElement;
 import org.hisp.dhis.dataelement.DataElementService;
+import org.hisp.dhis.option.OptionService;
 import org.hisp.dhis.option.OptionSet;
 import org.springframework.beans.factory.annotation.Autowired;
 
@@ -45,6 +46,9 @@
     @Autowired
     private DataElementService dataElementService;
 
+    @Autowired
+    private OptionService optionService;
+
     // -------------------------------------------------------------------------
     // Input & Output
     // -------------------------------------------------------------------------
@@ -56,6 +60,13 @@
         this.dataElementUid = dataElementUid;
     }
 
+    private String id;
+
+    public void setId( String id )
+    {
+        this.id = id;
+    }
+
     private OptionSet optionSet;
 
     public OptionSet getOptionSet()
@@ -70,19 +81,31 @@
     @Override
     public String execute() throws Exception
     {
-        if ( dataElementUid == null )
+        if ( id == null && dataElementUid == null )
         {
             return INPUT;
         }
 
-        DataElement dataElement = dataElementService.getDataElement( dataElementUid );
-
-        if ( dataElement == null || dataElement.getOptionSet() == null )
-        {
-            return ERROR;
-        }
-
-        optionSet = dataElement.getOptionSet();
+        if ( id != null )
+        {
+            optionSet = optionService.getOptionSet( id );
+
+            if ( optionSet == null )
+            {
+                return ERROR;
+            }
+        }
+        else
+        {
+            DataElement dataElement = dataElementService.getDataElement( dataElementUid );
+
+            if ( dataElement == null || dataElement.getOptionSet() == null )
+            {
+                return ERROR;
+            }
+
+            optionSet = dataElement.getOptionSet();
+        }
 
         return SUCCESS;
     }

=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/GetProgramMetaDataAction.java'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/GetProgramMetaDataAction.java	2013-04-24 08:54:41 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/GetProgramMetaDataAction.java	2013-08-06 06:39:28 +0000
@@ -29,6 +29,7 @@
 
 import com.opensymphony.xwork2.Action;
 import org.hisp.dhis.dataelement.DataElement;
+import org.hisp.dhis.option.OptionSet;
 import org.hisp.dhis.organisationunit.OrganisationUnit;
 import org.hisp.dhis.program.Program;
 import org.hisp.dhis.program.ProgramService;
@@ -88,9 +89,9 @@
         return programAssociations;
     }
 
-    private Set<String> optionSets = new HashSet<String>();
+    private Set<OptionSet> optionSets = new HashSet<OptionSet>();
 
-    public Set<String> getOptionSets()
+    public Set<OptionSet> getOptionSets()
     {
         return optionSets;
     }
@@ -137,7 +138,7 @@
             {
                 if ( programStageDataElement.getDataElement().getOptionSet() != null )
                 {
-                    optionSets.add( programStageDataElement.getDataElement().getUid() );
+                    optionSets.add( programStageDataElement.getDataElement().getOptionSet() );
                 }
 
                 if ( programStageDataElement.getDataElement().getType().equals( DataElement.VALUE_TYPE_USER_NAME ) )

=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/javascript/anonymousRegistration.js'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/javascript/anonymousRegistration.js	2013-08-05 07:09:17 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/javascript/anonymousRegistration.js	2013-08-06 06:39:28 +0000
@@ -75,18 +75,31 @@
     var promise = deferred2.promise();
 
     _.each( metaData.optionSets, function ( item, idx ) {
-        promise = promise.then( function () {
-            return $.ajax( {
-                url: 'getOptionSet.action?dataElementUid=' + item,
-                dataType: 'json',
-                cache: false
-            } ).done( function ( data ) {
-                var obj = {};
-                obj.id = item;
-                obj.optionSet = data.optionSet;
-                DAO.store.set( 'optionSets', obj );
-            } );
-        } );
+        DAO.store.get('optionSets', item.uid).done(function(obj) {
+            console.log('obj: ', obj);
+            console.log('item: ', item);
+
+            if(typeof obj === 'undefined' || obj.optionSet.version !== item.v) {
+                console.log('loading ', item);
+                promise = promise.then(function() {
+                    return $.ajax({
+                        url: 'getOptionSet.action',
+                        data: {
+                            id: item.uid
+                        },
+                        dataType: 'json',
+                        cache: false
+                    }).done(function(data) {
+                        var obj = {};
+                        obj.id = item.uid;
+                        obj.optionSet = data.optionSet;
+                        DAO.store.set('optionSets', obj);
+                    });
+                });
+            } else {
+                console.log('skipping ', item);
+            }
+        });
     } );
 
     if ( metaData.usernames ) {

=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/jsonOptionSet.vm'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/jsonOptionSet.vm	2013-04-18 06:05:48 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/jsonOptionSet.vm	2013-08-06 06:39:28 +0000
@@ -1,6 +1,7 @@
 { "optionSet": {
     "uid": "$encoder.jsonEncode( $optionSet.uid )",
     "name": "$encoder.jsonEncode( $optionSet.displayName )",
+    "version": $optionSet.version,
     "options": [#foreach( $option in $optionSet.options )"$encoder.jsonEncode( $option )"#if( $velocityCount < $optionSet.options.size() ),#end #end]
    }
 }

=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/jsonProgramMetaData.vm'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/jsonProgramMetaData.vm	2013-06-06 15:17:26 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/jsonProgramMetaData.vm	2013-08-06 06:39:28 +0000
@@ -1,5 +1,5 @@
 { "metaData": {
-"optionSets": [#foreach( $os in $optionSets )"$encoder.jsonEncode( $os )"#if( $velocityCount < $optionSets.size() ),#end#end],
+"optionSets": [#foreach( $os in $optionSets ) {"uid":"$encoder.jsonEncode( $os.uid )", "v": $os.version}#if( $velocityCount < $optionSets.size() ),#end#end],
 "usernames": $usernames,
 "programs": {
 #set( $psize = $programs.size() )