← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 2086: Impl action for rendering of orgunit tree widget in mapping module

 

------------------------------------------------------------
revno: 2086
committer: Lars <larshelg@larshelg-laptop>
branch nick: trunk
timestamp: Mon 2010-07-05 16:09:20 +0200
message:
  Impl action for rendering of orgunit tree widget in mapping module
added:
  dhis-2/dhis-web/dhis-web-mapping/src/main/java/org/hisp/dhis/mapping/action/GetOrganisationUnitChildrenAction.java
  dhis-2/dhis-web/dhis-web-mapping/src/main/webapp/dhis-web-mapping/jsonOrganisationUnitChildren.vm
modified:
  dhis-2/dhis-web/dhis-web-mapping/src/main/resources/META-INF/dhis/beans.xml
  dhis-2/dhis-web/dhis-web-mapping/src/main/resources/struts.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
=== added file 'dhis-2/dhis-web/dhis-web-mapping/src/main/java/org/hisp/dhis/mapping/action/GetOrganisationUnitChildrenAction.java'
--- dhis-2/dhis-web/dhis-web-mapping/src/main/java/org/hisp/dhis/mapping/action/GetOrganisationUnitChildrenAction.java	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-web/dhis-web-mapping/src/main/java/org/hisp/dhis/mapping/action/GetOrganisationUnitChildrenAction.java	2010-07-05 14:09:20 +0000
@@ -0,0 +1,48 @@
+package org.hisp.dhis.mapping.action;
+
+import java.util.Collection;
+import java.util.HashSet;
+
+import org.hisp.dhis.organisationunit.OrganisationUnit;
+import org.hisp.dhis.organisationunit.OrganisationUnitService;
+
+import com.opensymphony.xwork2.Action;
+
+public class GetOrganisationUnitChildrenAction
+    implements Action
+{
+    private OrganisationUnitService organisationUnitService;
+
+    public void setOrganisationUnitService( OrganisationUnitService organisationUnitService )
+    {
+        this.organisationUnitService = organisationUnitService;
+    }
+
+    private Integer node;
+    
+    public void setNode( Integer node )
+    {
+        this.node = node;
+    }
+
+    private Collection<OrganisationUnit> units = new HashSet<OrganisationUnit>();
+    
+    public Collection<OrganisationUnit> getUnits()
+    {
+        return units;
+    }
+
+    @Override
+    public String execute()
+        throws Exception
+    {
+        OrganisationUnit unit = organisationUnitService.getOrganisationUnit( node );
+        
+        if ( unit != null )
+        {
+            units = unit.getChildren();
+        }
+        
+        return SUCCESS;
+    }
+}

=== modified file 'dhis-2/dhis-web/dhis-web-mapping/src/main/resources/META-INF/dhis/beans.xml'
--- dhis-2/dhis-web/dhis-web-mapping/src/main/resources/META-INF/dhis/beans.xml	2010-05-30 21:24:18 +0000
+++ dhis-2/dhis-web/dhis-web-mapping/src/main/resources/META-INF/dhis/beans.xml	2010-07-05 14:09:20 +0000
@@ -25,6 +25,13 @@
 			ref="org.hisp.dhis.organisationunit.OrganisationUnitService" />
 	</bean>
 
+	<bean id="org.hisp.dhis.mapping.action.GetOrganisationUnitChildrenAction"
+		class="org.hisp.dhis.mapping.action.GetOrganisationUnitChildrenAction"
+		scope="prototype">
+		<property name="organisationUnitService"
+			ref="org.hisp.dhis.organisationunit.OrganisationUnitService" />
+	</bean>
+
 	<!-- Map -->
 
 	<bean id="org.hisp.dhis.mapping.action.AddOrUpdateMapAction"

=== modified file 'dhis-2/dhis-web/dhis-web-mapping/src/main/resources/struts.xml'
--- dhis-2/dhis-web/dhis-web-mapping/src/main/resources/struts.xml	2010-05-30 21:24:18 +0000
+++ dhis-2/dhis-web/dhis-web-mapping/src/main/resources/struts.xml	2010-07-05 14:09:20 +0000
@@ -38,6 +38,12 @@
 				/dhis-web-mapping/jsonminOrganisationUnits.vm</result>
 		</action>
 
+		<action name="getOrganisationUnitChildren"
+			class="org.hisp.dhis.mapping.action.GetOrganisationUnitChildrenAction">
+			<result name="success" type="velocity-json">
+				/dhis-web-mapping/jsonOrganisationUnitChildren.vm</result>
+		</action>
+
 		<!-- Map -->
 
 		<action name="addOrUpdateMap"

=== added file 'dhis-2/dhis-web/dhis-web-mapping/src/main/webapp/dhis-web-mapping/jsonOrganisationUnitChildren.vm'
--- dhis-2/dhis-web/dhis-web-mapping/src/main/webapp/dhis-web-mapping/jsonOrganisationUnitChildren.vm	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-web/dhis-web-mapping/src/main/webapp/dhis-web-mapping/jsonOrganisationUnitChildren.vm	2010-07-05 14:09:20 +0000
@@ -0,0 +1,22 @@
+[
+#set( $size = $units.size() )
+#foreach( $unit in $units )
+{ 
+  "id": ${unit.id}, 
+  "text": "${unit.name}",
+  #if( $unit.hasChild() )
+  "children": [
+  #set( $innerSize = $unit.children.size() )
+  #foreach( $child in $unit.children )
+  {
+    "id": ${child.id},
+    "text": "${child.name}"
+  }#if( $velocityCount < $innerSize ),#end
+  #end
+  ]
+  #else
+  "leaf": "true"
+  #end
+}#if( $velocityCount < $size ),#end
+#end
+]
\ No newline at end of file