← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 3063: Impl export to PDF, XLS, CSV for organisation unit search result through Grid results

 

------------------------------------------------------------
revno: 3063
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Thu 2011-03-17 23:55:56 +0100
message:
  Impl export to PDF, XLS, CSV for organisation unit search result through Grid results
modified:
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/organisationunit/DefaultOrganisationUnitService.java
  dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/commons.js
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-organisationunit/src/main/java/org/hisp/dhis/oum/action/search/SearchOrganisationUnitsAction.java
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-organisationunit/src/main/resources/org/hisp/dhis/oum/i18n_module.properties
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-organisationunit/src/main/resources/struts.xml
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-organisationunit/src/main/webapp/dhis-web-maintenance-organisationunit/index.vm
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-organisationunit/src/main/webapp/dhis-web-maintenance-organisationunit/javascript/organisationUnitSearch.js
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-organisationunit/src/main/webapp/dhis-web-maintenance-organisationunit/menu.vm
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-organisationunit/src/main/webapp/dhis-web-maintenance-organisationunit/organisationUnitSearch.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-services/dhis-service-core/src/main/java/org/hisp/dhis/organisationunit/DefaultOrganisationUnitService.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/organisationunit/DefaultOrganisationUnitService.java	2011-03-17 20:59:33 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/organisationunit/DefaultOrganisationUnitService.java	2011-03-17 22:55:56 +0000
@@ -413,7 +413,9 @@
     @SuppressWarnings("unchecked")    
     public Collection<OrganisationUnit> getOrganisationUnitsByNameAndGroups( String name, Collection<OrganisationUnitGroup> groups, OrganisationUnit parent, boolean limit )
     {
-        final Collection<OrganisationUnit> result = organisationUnitStore.getOrganisationUnitsByNameAndGroups( name, groups, limit );
+        boolean _limit = limit && parent == null; // Can only limit in query if parent is not set and we get all units
+        
+        final Collection<OrganisationUnit> result = organisationUnitStore.getOrganisationUnitsByNameAndGroups( name, groups, _limit );
         
         if ( parent == null )
         {
@@ -422,7 +424,9 @@
         
         final Collection<OrganisationUnit> subTree = getOrganisationUnitWithChildren( parent.getId() );
         
-        return CollectionUtils.intersection( subTree, result );
+        List<OrganisationUnit> intersection = new ArrayList<OrganisationUnit>( CollectionUtils.intersection( subTree, result ) );
+
+        return limit && intersection != null && intersection.size() > MAX_LIMIT ? intersection.subList( 0, MAX_LIMIT ) : intersection;   
     }
     
     // -------------------------------------------------------------------------

=== modified file 'dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/commons.js'
--- dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/commons.js	2011-03-16 09:23:45 +0000
+++ dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/commons.js	2011-03-17 22:55:56 +0000
@@ -486,7 +486,7 @@
  */
 function setWaitMessage( message )
 {
-	setMessage( message + "&nbsp;&nbsp;&nbsp;<img src='../images/ajax-loader-bar-small.gif'>" );
+	setMessage( message + "&nbsp;&nbsp;&nbsp;<img src='../../images/ajax-loader-bar-small.gif'>" );
 }
 
 /**
@@ -529,7 +529,7 @@
  */
 function setHeaderWaitMessage( message )
 {
-	$( 'div#headerMessage' ).html( message + "&nbsp;&nbsp;&nbsp;<img src='../images/ajax-loader-bar-small.gif'>" );
+	$( 'div#headerMessage' ).html( message + "&nbsp;&nbsp;&nbsp;<img src='../../images/ajax-loader-bar-small.gif'>" );
     $( 'div#headerMessage' ).slideDown( 'fast' );
 }
 
@@ -541,7 +541,7 @@
  */
 function updateHeaderWaitMessage( message )
 {
-	$( 'div#headerMessage' ).html( message + "&nbsp;&nbsp;&nbsp;<img src='../images/ajax-loader-bar-small.gif'>" );
+	$( 'div#headerMessage' ).html( message + "&nbsp;&nbsp;&nbsp;<img src='../../images/ajax-loader-bar-small.gif'>" );
 }
 
 /**
@@ -557,6 +557,18 @@
 }
 
 /**
+ * Sets the header wait message and hides it after 3 seconds.
+ */
+function setHeaderWaitDelayMessage( message )
+{
+	setHeaderWaitMessage( message );
+	
+	window.clearTimeout( headerMessageTimeout ); // Clear waiting invocations
+	
+	headerMessageTimeout = window.setTimeout( "hideHeaderMessage();", 3000 );
+}
+
+/**
  * Sets the header message and hides it after the given seconds, default as 3s.
  */
 function setHeaderTimeDelayMessage( message, timing )

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-organisationunit/src/main/java/org/hisp/dhis/oum/action/search/SearchOrganisationUnitsAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-organisationunit/src/main/java/org/hisp/dhis/oum/action/search/SearchOrganisationUnitsAction.java	2011-03-17 20:59:33 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-organisationunit/src/main/java/org/hisp/dhis/oum/action/search/SearchOrganisationUnitsAction.java	2011-03-17 22:55:56 +0000
@@ -34,6 +34,10 @@
 import java.util.List;
 
 import org.apache.commons.lang.StringUtils;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.hisp.dhis.common.Grid;
+import org.hisp.dhis.common.GridHeader;
 import org.hisp.dhis.organisationunit.OrganisationUnit;
 import org.hisp.dhis.organisationunit.OrganisationUnitGroup;
 import org.hisp.dhis.organisationunit.OrganisationUnitGroupService;
@@ -41,6 +45,7 @@
 import org.hisp.dhis.organisationunit.OrganisationUnitService;
 import org.hisp.dhis.organisationunit.comparator.OrganisationUnitGroupSetNameComparator;
 import org.hisp.dhis.ouwt.manager.OrganisationUnitSelectionManager;
+import org.hisp.dhis.system.grid.ListGrid;
 
 import com.opensymphony.xwork2.Action;
 
@@ -50,8 +55,11 @@
 public class SearchOrganisationUnitsAction
     implements Action
 {
+    private static final Log log = LogFactory.getLog( SearchOrganisationUnitsAction.class );
+    
     private static final int ANY = 0;
-
+    private static final String DEFAULT_TYPE = "html";
+    
     // -------------------------------------------------------------------------
     // Depdencies
     // -------------------------------------------------------------------------
@@ -81,11 +89,11 @@
     // Input and output
     // -------------------------------------------------------------------------
 
-    private boolean search;
+    private boolean skipSearch;
     
-    public void setSearch( boolean search )
+    public void setSkipSearch( boolean skipSearch )
     {
-        this.search = search;
+        this.skipSearch = skipSearch;
     }
 
     private String name;
@@ -143,6 +151,20 @@
     {
         return limited;
     }
+    
+    private String type;
+    
+    public void setType( String type )
+    {
+        this.type = type;
+    }
+
+    private Grid grid;
+
+    public Grid getGrid()
+    {
+        return grid;
+    }
 
     // -------------------------------------------------------------------------
     // Action implementation
@@ -151,15 +173,27 @@
     public String execute()
         throws Exception
     {
+        type = StringUtils.trimToNull( type );
+        
+        // ---------------------------------------------------------------------
+        // Get group sets
+        // ---------------------------------------------------------------------
+
+        groupSets = new ArrayList<OrganisationUnitGroupSet>( organisationUnitGroupService.getCompulsoryOrganisationUnitGroupSets() );
+        
+        Collections.sort( groupSets, new OrganisationUnitGroupSetNameComparator() );
+        
         // ---------------------------------------------------------------------
         // Assemble groups and get search result
         // ---------------------------------------------------------------------
 
-        if ( search )
+        if ( !skipSearch )
         {
             name = StringUtils.trimToNull( name );
             
             selectedOrganisationUnit = selectionManager.getSelectedOrganisationUnit();
+
+            log.debug( "Name: " + name + ", Orgunit: " + selectedOrganisationUnit + ", type: " + type );
             
             Collection<OrganisationUnitGroup> groups = new HashSet<OrganisationUnitGroup>();
             
@@ -171,20 +205,49 @@
                     groups.add( group );
                 }
             }
-        
-            organisationUnits = organisationUnitService.getOrganisationUnitsByNameAndGroups( name, groups, selectedOrganisationUnit, true );
+            
+            boolean limit = type == null; // Only limit for HTML view since browser is memory constrained
+            
+            organisationUnits = organisationUnitService.getOrganisationUnitsByNameAndGroups( name, groups, selectedOrganisationUnit, limit );
             
             limited = organisationUnits != null && organisationUnits.size() == OrganisationUnitService.MAX_LIMIT;
-        }
-        
-        // ---------------------------------------------------------------------
-        // Get group sets
-        // ---------------------------------------------------------------------
-
-        groupSets = new ArrayList<OrganisationUnitGroupSet>( organisationUnitGroupService.getCompulsoryOrganisationUnitGroupSets() );
-        
-        Collections.sort( groupSets, new OrganisationUnitGroupSetNameComparator() );
-        
-        return SUCCESS;
+            
+            if ( type != null && !type.equalsIgnoreCase( DEFAULT_TYPE ) )
+            {
+                grid = generateGrid();
+            }            
+        }
+        
+        return type != null ? type : SUCCESS;
+    }
+
+    // -------------------------------------------------------------------------
+    // Supportive methods
+    // -------------------------------------------------------------------------
+
+    private Grid generateGrid()
+    {
+        final Grid orgUnitGrid = new ListGrid().setTitle( "Organisation unit search result" );
+        
+        orgUnitGrid.addHeader( new GridHeader( "Organisation unit", false, true ) );
+        
+        for ( OrganisationUnitGroupSet groupSet : groupSets )
+        {
+            orgUnitGrid.addHeader( new GridHeader( groupSet.getName(), false, true ) );
+        }
+        
+        for ( OrganisationUnit unit : organisationUnits )
+        {
+            orgUnitGrid.addRow();
+            
+            orgUnitGrid.addValue( unit.getName() );
+            
+            for ( OrganisationUnitGroupSet groupSet : groupSets )
+            {
+                orgUnitGrid.addValue( unit.getGroupNameInGroupSet( groupSet ) );
+            }
+        }
+        
+        return orgUnitGrid;
     }
 }

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-organisationunit/src/main/resources/org/hisp/dhis/oum/i18n_module.properties'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-organisationunit/src/main/resources/org/hisp/dhis/oum/i18n_module.properties	2011-03-17 20:59:33 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-organisationunit/src/main/resources/org/hisp/dhis/oum/i18n_module.properties	2011-03-17 22:55:56 +0000
@@ -111,4 +111,9 @@
 feature_type										= Feature type
 available_data_sets									= Available data sets
 selected_data_sets									= Selected data sets
-limited												= Limited
\ No newline at end of file
+limited												= Limited
+get_report_as_xls 									= Download as Excel
+get_report_as_csv 									= Download as CSV
+get_report_as_pdf 									= Download as PDF
+please_wait_while_downloading						= Please wait while downloading report
+please_wait_while_searching							= Please wait while searching
\ No newline at end of file

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-organisationunit/src/main/resources/struts.xml'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-organisationunit/src/main/resources/struts.xml	2011-02-15 13:45:11 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-organisationunit/src/main/resources/struts.xml	2011-03-17 22:55:56 +0000
@@ -297,6 +297,9 @@
 			<param name="page">/dhis-web-maintenance-organisationunit/organisationUnitSearch.vm</param>
 			<param name="menu">/dhis-web-maintenance-organisationunit/menuWithTree.vm</param>
 			<param name="javascripts">../dhis-web-commons/ouwt/ouwt.js,javascript/organisationUnitSearch.js</param>
+			<result name="csv" type="gridCsvResult"/>
+			<result name="xls" type="gridXlsResult"/>
+			<result name="pdf" type="gridPdfResult"/>
 			<interceptor-ref name="organisationUnitTreeStack" />
 		</action>
 		

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-organisationunit/src/main/webapp/dhis-web-maintenance-organisationunit/index.vm'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-organisationunit/src/main/webapp/dhis-web-maintenance-organisationunit/index.vm	2011-01-11 16:52:46 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-organisationunit/src/main/webapp/dhis-web-maintenance-organisationunit/index.vm	2011-03-17 22:55:56 +0000
@@ -6,6 +6,6 @@
     #introListImgItem( "organisationUnitGroup.action" "org_unit_group" "organisationunit" )
     #introListImgItem( "organisationUnitGroupSet.action" "org_unit_group_set" "organisationunit" )
     #introListImgItem( "organisationUnitLevel.action" "org_unit_level" "organisationunit" )
-    #introListImgItem( "organisationUnitSearch.action" "org_unit_search" "search" )
+    #introListImgItem( "organisationUnitSearch.action?skipSearch=true" "org_unit_search" "search" )
     #introListImgItem( "hierarchyOperations.action" "hierarchy_operations_menu" "hierarchy" )
 </ul>

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-organisationunit/src/main/webapp/dhis-web-maintenance-organisationunit/javascript/organisationUnitSearch.js'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-organisationunit/src/main/webapp/dhis-web-maintenance-organisationunit/javascript/organisationUnitSearch.js	2010-12-13 17:03:08 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-organisationunit/src/main/webapp/dhis-web-maintenance-organisationunit/javascript/organisationUnitSearch.js	2011-03-17 22:55:56 +0000
@@ -21,6 +21,8 @@
 		width:600,
 		height:600
 	} );
+	
+	selection.setUnselectAllowed( true );
 }
 
 function showOrgUnitDetails( id )
@@ -29,3 +31,19 @@
 		$( "#organisationUnitDetails" ).dialog( "open" );
 	} );
 }
+
+function download( type )
+{
+	if ( type != null && type != "" )
+	{
+		setHeaderWaitDelayMessage( i18n_please_wait_while_downloading );
+	}
+	else
+	{
+		setWaitMessage( i18n_please_wait_while_searching );
+	}
+	
+	$( "#type" ).val( type );
+	
+	document.getElementById( "searchForm" ).submit();
+}
\ No newline at end of file

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-organisationunit/src/main/webapp/dhis-web-maintenance-organisationunit/menu.vm'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-organisationunit/src/main/webapp/dhis-web-maintenance-organisationunit/menu.vm	2010-12-12 17:09:27 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-organisationunit/src/main/webapp/dhis-web-maintenance-organisationunit/menu.vm	2011-03-17 22:55:56 +0000
@@ -6,6 +6,6 @@
 	<li><a href="organisationUnitGroup.action">$i18n.getString( "org_unit_group" )&nbsp;</a></li>
 	<li><a href="organisationUnitGroupSet.action">$i18n.getString( "org_unit_group_set" )&nbsp;</a></li>
     <li><a href="organisationUnitLevel.action">$i18n.getString( "org_unit_level" )&nbsp;</a></li>
-    <li><a href="organisationUnitSearch.action">$i18n.getString( "org_unit_search" )&nbsp;</a></li>
+    <li><a href="organisationUnitSearch.action?skipSearch=true">$i18n.getString( "org_unit_search" )&nbsp;</a></li>
 	<li><a href="hierarchyOperations.action">$i18n.getString( "hierarchy_operations_menu" )&nbsp;</a></li>
 </ul>

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-organisationunit/src/main/webapp/dhis-web-maintenance-organisationunit/organisationUnitSearch.vm'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-organisationunit/src/main/webapp/dhis-web-maintenance-organisationunit/organisationUnitSearch.vm	2011-03-17 20:59:33 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-organisationunit/src/main/webapp/dhis-web-maintenance-organisationunit/organisationUnitSearch.vm	2011-03-17 22:55:56 +0000
@@ -7,9 +7,9 @@
 
 <h3>$i18n.getString( "org_unit_search_management" )</h3>
 
-<form action="organisationUnitSearch.action" method="post">
+<form id="searchForm" action="organisationUnitSearch.action" method="post">
 
-<input type="hidden" name="search" value="true">
+<input type="hidden" id="type" name="type">
 
 <table>
 <tr>
@@ -19,19 +19,19 @@
 
 <tr>
 <td>$i18n.getString( "organisation_unit" )</td>
-<td><input type="text" id="selectedOrganisationUnit" style="width:325px" readonly="true" value="${orgUnitText}"></td>
+<td><input type="text" id="selectedOrganisationUnit" style="width:360px" readonly="true" value="${orgUnitText}"></td>
 </tr>
 
 <tr>
 <td>$i18n.getString( "name" )</th>
-<td><input type="text" name="name" style="width:325px" value="$!{name}"></td>
+<td><input type="text" name="name" style="width:360px" value="$!{name}"></td>
 </tr>
 
 #foreach( $groupSet in $groupSets )
 <tr>
 <td>$encoder.htmlEncode( $groupSet.name )</td>
 <td>
-  <select name="groupId" style="width:325px">
+  <select name="groupId" style="width:360px">
   <option value="0">[ $i18n.getString( "all" ) $encoder.htmlEncode( $groupSet.name ) ]</option>
     #foreach( $group in $groupSet.organisationUnitGroups )
     <option value="$group.id"
@@ -46,22 +46,34 @@
 <tr>
 <td style="height:10px" colspan="2"></td>
 </tr>
-<tr>
-
-<td></td>
-<td><input type="submit" value="$i18n.getString( 'search' )" style="width:100px">
-<input type="button" onclick="window.location.href='organisationUnitSearch.action'" value="$i18n.getString( 'clear' )" style="width:100px"></td>
+
+<tr>
+<td></td>
+<td><input type="button" value="$i18n.getString( 'search' )" style="width:120px" onclick="download( '' )"><input 
+type="button" onclick="window.location.href='organisationUnitSearch.action?skipSearch=true'" value="$i18n.getString( 'clear' )" style="width:120px"></td>
+</tr>
+
+<tr>
+<td style="height:2px" colspan="2"></td>
+</tr>
+
+<tr>
+<td></td>
+<td><input type="button" value="$i18n.getString( 'get_report_as_pdf' )" style="width:120px" onclick="download( 'pdf' )"><input 
+type="button" value="$i18n.getString( 'get_report_as_xls' )" style="width:120px" onclick="download( 'xls' )"><input 
+type="button" value="$i18n.getString( 'get_report_as_csv' )" style="width:120px" onclick="download( 'csv' )"></td>
+</tr>
 
 <tr>
 <td style="height:15px" colspan="2"></td>
 </tr>
 <tr>
 
-</tr>
-
 </table>
 </form>
 
+<span id="message"></span>
+
 #if ( $organisationUnits )
 
 <h4>$i18n.getString( "found" ) $organisationUnits.size() $i18n.getString( "organisation_units" ) #if( $limited )($i18n.getString( "limited" ))#end</h4>
@@ -103,5 +115,7 @@
 } );
 
 var i18n_all = '$encoder.jsEscape( $i18n.getString( "all" ) , "'" )';
+var i18n_please_wait_while_downloading = '$encoder.jsEscape( $i18n.getString( "please_wait_while_downloading" ) , "'" )';
+var i18n_please_wait_while_searching = '$encoder.jsEscape( $i18n.getString( "please_wait_while_searching" ) , "'" )';
 
 </script>