← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 4338: added roots to orgunittreeaction

 

------------------------------------------------------------
revno: 4338
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Wed 2011-08-17 17:46:00 +0200
message:
  added roots to orgunittreeaction
modified:
  dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/ajax/jsonOrganisationUnitTree.vm
  dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/commons/action/GetOrganisationUnitTreeAction.java


--
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/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-17 15:16:43 +0000
+++ dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/ajax/jsonOrganisationUnitTree.vm	2011-08-17 15:46:00 +0000
@@ -2,6 +2,7 @@
 "version":"$!encoder.jsonEncode( $version )"
 #if( ! $versionOnly )
 ,"organisationUnits": {
+"roots": [ #foreach( $root in $rootOrganisationUnits )$root.id#if( $velocityCount < $rootOrganisationUnits.size() ),#end#end ], 
 #foreach( $unit in $organisationUnits )
 "${unit.id}":{"id":${unit.id},"n":"${unit.name}",#if( $unit.parent )"pid":${unit.parent.id},#end"c":[#foreach( $child in $unit.sortedChildren )${child.id}#if( $velocityCount < $unit.children.size() ),#end#end]}
 #if( $velocityCount < $organisationUnits.size() ),#end#end

=== 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-17 14:51:49 +0000
+++ dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/commons/action/GetOrganisationUnitTreeAction.java	2011-08-17 15:46:00 +0000
@@ -84,6 +84,13 @@
         return organisationUnits;
     }
 
+    private List<OrganisationUnit> rootOrganisationUnits = new ArrayList<OrganisationUnit>();
+
+    public List<OrganisationUnit> getRootOrganisationUnits()
+    {
+        return rootOrganisationUnits;
+    }
+
     private String version;
 
     public String getVersion()
@@ -109,16 +116,17 @@
 
     public String execute()
         throws Exception
-    {   
+    {
         if ( !versionOnly )
         {
             Collection<OrganisationUnit> userOrganisationUnits = new HashSet<OrganisationUnit>();
-            
+
             User user = currentUserService.getCurrentUser();
 
             if ( user.getOrganisationUnits() != null && user.getOrganisationUnits().size() > 0 )
             {
                 userOrganisationUnits = new ArrayList<OrganisationUnit>( user.getOrganisationUnits() );
+                rootOrganisationUnits = new ArrayList<OrganisationUnit>( user.getOrganisationUnits() );
             }
             else
             {
@@ -126,17 +134,20 @@
                 {
                     userOrganisationUnits = new ArrayList<OrganisationUnit>(
                         organisationUnitService.getRootOrganisationUnits() );
+                    rootOrganisationUnits = new ArrayList<OrganisationUnit>(
+                        organisationUnitService.getRootOrganisationUnits() );
                 }
                 else
                 {
                     userOrganisationUnits = new ArrayList<OrganisationUnit>();
+                    rootOrganisationUnits = new ArrayList<OrganisationUnit>();
                 }
             }
 
             for ( OrganisationUnit unit : userOrganisationUnits )
             {
                 organisationUnits.addAll( organisationUnitService.getOrganisationUnitWithChildren( unit.getId() ) );
-            }            
+            }
         }
 
         version = getVersionString();