← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 4282: made orgunit tree only update when there are changes, or the client side tree is empty

 

------------------------------------------------------------
revno: 4282
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Fri 2011-08-12 15:23:47 +0200
message:
  made orgunit tree only update when there are changes, or the client side tree is empty
modified:
  dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/cacheManifest.vm
  dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/ajax/jsonOrganisationUnitTree.vm
  dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/ouwt/ouwt.js
  dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/commons/action/GetOrganisationUnitTreeAction.java
  dhis-2/dhis-web/dhis-web-commons/src/main/resources/META-INF/dhis/beans.xml


--
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-commons-resources/src/main/webapp/cacheManifest.vm'
--- dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/cacheManifest.vm	2011-08-10 10:56:58 +0000
+++ dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/cacheManifest.vm	2011-08-12 13:23:47 +0000
@@ -1,5 +1,5 @@
 CACHE MANIFEST
-# 2.4-SNAPSHOT Version 10
+# 2.4-SNAPSHOT Version 11
 NETWORK:
 *
 CACHE:

=== modified file 'dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/ajax/jsonOrganisationUnitTree.vm'
--- dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/ajax/jsonOrganisationUnitTree.vm	2011-08-08 15:09:46 +0000
+++ dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/ajax/jsonOrganisationUnitTree.vm	2011-08-12 13:23:47 +0000
@@ -11,9 +11,12 @@
 	}
 #end
 
-{ "organisationUnits": [
+{ "version": "$!encoder.jsonEncode( $version )"
+  #if( ! $versionOnly )
+  ,"organisationUnits": [
 	#foreach ( $organisationUnit in $organisationUnits )
 		#expandOrganisationUnit( $organisationUnit )#if( $velocityCount < $organisationUnits.size() ),#end
 	#end
 	]
+ #end
 }

=== modified file 'dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/ouwt/ouwt.js'
--- dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/ouwt/ouwt.js	2011-08-11 11:31:42 +0000
+++ dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/ouwt/ouwt.js	2011-08-12 13:23:47 +0000
@@ -61,19 +61,7 @@
 
     this.load = function()
     {
-        $.get( '../dhis-web-commons-ajax-json/getOrganisationUnitTree.action', function( data, textStatus, jqXHR )
-        {
-            var roots = [];
-
-            for ( var i in data.organisationUnits )
-            {
-                var ou = data.organisationUnits[i];
-                roots.push( ou.id );
-                store_ou( ou );
-            }
-
-            localStorage[getTagId( "Roots" )] = JSON.stringify( roots );
-        } ).complete( function()
+        function sync_and_reload()
         {
             var roots = JSON.parse( localStorage[getTagId( "Roots" )] );
 
@@ -93,7 +81,46 @@
             subtree.reloadTree();
 
             $( "#ouwt_loader" ).hide();
-        } );
+        }
+
+        var version = localStorage[getTagId( "Version" )];
+        var should_update = false;
+
+        $.get( '../dhis-web-commons-ajax-json/getOrganisationUnitTree.action', {
+            "versionOnly" : true
+        }, function( data, textStatus, jqXHR )
+        {
+            if ( version != data.version )
+            {
+                should_update = true;
+            }
+        } ).complete(
+                function()
+                {
+                    if ( should_update )
+                    {
+                        $.get( '../dhis-web-commons-ajax-json/getOrganisationUnitTree.action',
+                                function( data, textStatus, jqXHR )
+                                {
+                                    var roots = [];
+
+                                    for ( var i in data.organisationUnits )
+                                    {
+                                        var ou = data.organisationUnits[i];
+                                        roots.push( ou.id );
+                                        store_ou( ou );
+                                    }
+
+                                    localStorage[getTagId( "Roots" )] = JSON.stringify( roots );
+                                    localStorage[getTagId( "Version" )] = data.version;
+
+                                } ).complete( sync_and_reload );
+                    }
+                    else
+                    {
+                        sync_and_reload();
+                    }
+                } );
     };
 
     // server = true : sync from server
@@ -505,8 +532,10 @@
         }
     };
 
+    // force reload
     this.refreshTree = function()
     {
+        localStorage.removeItem( getTagId( "Version" ) );
         selection.load();
     };
 

=== modified file 'dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/commons/action/GetOrganisationUnitTreeAction.java'
--- dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/commons/action/GetOrganisationUnitTreeAction.java	2011-08-08 15:09:46 +0000
+++ dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/commons/action/GetOrganisationUnitTreeAction.java	2011-08-12 13:23:47 +0000
@@ -31,10 +31,13 @@
 import java.util.Collections;
 import java.util.Comparator;
 import java.util.List;
+import java.util.UUID;
 
 import org.hisp.dhis.organisationunit.OrganisationUnit;
 import org.hisp.dhis.user.CurrentUserService;
 import org.hisp.dhis.user.User;
+import org.hisp.dhis.version.Version;
+import org.hisp.dhis.version.VersionService;
 
 import com.opensymphony.xwork2.Action;
 
@@ -55,6 +58,13 @@
         this.currentUserService = currentUserService;
     }
 
+    private VersionService versionService;
+
+    public void setVersionService( VersionService versionService )
+    {
+        this.versionService = versionService;
+    }
+
     // -------------------------------------------------------------------------
     // Comparator
     // -------------------------------------------------------------------------
@@ -77,6 +87,25 @@
         return organisationUnits;
     }
 
+    private String version;
+
+    public String getVersion()
+    {
+        return version;
+    }
+
+    private Boolean versionOnly = false;
+
+    public void setVersionOnly( Boolean versionOnly )
+    {
+        this.versionOnly = versionOnly;
+    }
+
+    public Boolean getVersionOnly()
+    {
+        return versionOnly;
+    }
+
     // -------------------------------------------------------------------------
     // Action implementation
     // -------------------------------------------------------------------------
@@ -84,19 +113,40 @@
     public String execute()
         throws Exception
     {
-        User user = currentUserService.getCurrentUser();
-
-        if ( user.getOrganisationUnits() != null )
-        {
-            organisationUnits = new ArrayList<OrganisationUnit>( user.getOrganisationUnits() );
-        }
-        else
-        {
-            organisationUnits = new ArrayList<OrganisationUnit>();
-        }
-
-        Collections.sort( organisationUnits, organisationUnitComparator );
+        if ( !versionOnly )
+        {
+            User user = currentUserService.getCurrentUser();
+
+            if ( user.getOrganisationUnits() != null )
+            {
+                organisationUnits = new ArrayList<OrganisationUnit>( user.getOrganisationUnits() );
+            }
+            else
+            {
+                organisationUnits = new ArrayList<OrganisationUnit>();
+            }
+
+            Collections.sort( organisationUnits, organisationUnitComparator );
+        }
+
+        version = getVersionString();
 
         return SUCCESS;
     }
+
+    private String getVersionString()
+    {
+        Version orgUnitVersion = versionService.getVersionByKey( VersionService.ORGANISATIONUNIT_VERSION );
+
+        if ( orgUnitVersion == null )
+        {
+            String uuid = UUID.randomUUID().toString();
+            orgUnitVersion = new Version();
+            orgUnitVersion.setKey( VersionService.ORGANISATIONUNIT_VERSION );
+            orgUnitVersion.setValue( uuid );
+            versionService.addVersion( orgUnitVersion );
+        }
+
+        return orgUnitVersion.getValue();
+    }
 }

=== modified file 'dhis-2/dhis-web/dhis-web-commons/src/main/resources/META-INF/dhis/beans.xml'
--- dhis-2/dhis-web/dhis-web-commons/src/main/resources/META-INF/dhis/beans.xml	2011-08-08 17:57:47 +0000
+++ dhis-2/dhis-web/dhis-web-commons/src/main/resources/META-INF/dhis/beans.xml	2011-08-12 13:23:47 +0000
@@ -46,7 +46,7 @@
         <value>page</value>
         <value>menu</value>
         <value>menuTreeHeight</value>
-		<value>offline</value>
+        <value>offline</value>
       </set>
     </property>
     <property name="commaSeparatedParams">
@@ -525,6 +525,7 @@
   <bean id="org.hisp.dhis.commons.action.GetOrganisationUnitTreeAction" class="org.hisp.dhis.commons.action.GetOrganisationUnitTreeAction"
     scope="prototype">
     <property name="currentUserService" ref="org.hisp.dhis.user.CurrentUserService" />
+    <property name="versionService" ref="org.hisp.dhis.version.VersionService" />
   </bean>
 
   <bean id="org.hisp.dhis.commons.action.GetPeriodAction" class="org.hisp.dhis.commons.action.GetPeriodAction"