← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 1752: (GIS) Exported Excel spreadsheet layout improved and mapvalues sorted desc by value as default.

 

Merge authors:
  Jan Henrik Øverland (janhenrik-overland)
------------------------------------------------------------
revno: 1752 [merge]
committer: Jan Henrik Overland <janhenrik.overland@xxxxxxxxx>
branch nick: trunk
timestamp: Thu 2010-04-08 18:02:07 +0200
message:
  (GIS) Exported Excel spreadsheet layout improved and mapvalues sorted desc by value as default.
modified:
  dhis-2/dhis-web/dhis-web-mapping/src/main/java/org/hisp/dhis/mapping/action/ExportExcelAction.java
  dhis-2/dhis-web/dhis-web-mapping/src/main/java/org/hisp/dhis/mapping/action/ExportImageAction.java
  dhis-2/dhis-web/dhis-web-mapping/src/main/java/org/hisp/dhis/mapping/export/SVGDocument.java
  dhis-2/dhis-web/dhis-web-mapping/src/main/webapp/dhis-web-mapping/mapping/script/index.js


--
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-mapping/src/main/java/org/hisp/dhis/mapping/action/ExportExcelAction.java'
--- dhis-2/dhis-web/dhis-web-mapping/src/main/java/org/hisp/dhis/mapping/action/ExportExcelAction.java	2010-04-08 11:37:23 +0000
+++ dhis-2/dhis-web/dhis-web-mapping/src/main/java/org/hisp/dhis/mapping/action/ExportExcelAction.java	2010-04-08 15:59:17 +0000
@@ -31,6 +31,7 @@
 
 import javax.servlet.http.HttpServletResponse;
 
+import jxl.CellView;
 import jxl.Workbook;
 import jxl.format.Alignment;
 import jxl.format.Border;
@@ -87,7 +88,7 @@
 
     int legendPositionRow = 5;
 
-    int orgunitPositionCol = 13;
+    int orgunitPositionCol = 9;
 
     int orgunitPositionRow = 5;
 
@@ -250,7 +251,7 @@
         // ---------------------------------------------------------------------
 
         sheet.mergeCells( mapPositionCol, mapPositionCRow, mapPositionCol + 6, mapPositionCRow + 25 );
-
+        
         WritableImage map = new WritableImage( mapPositionCol, mapPositionCRow, 7, 26, image.toByteArray() );
 
         sheet.addImage( map );
@@ -266,22 +267,25 @@
         // ---------------------------------------------------------------------
 
         WritableCellFormat header = new WritableCellFormat();
-        header.setBackground( Colour.ICE_BLUE );
+        header.setBackground( Colour.GREY_25_PERCENT );
         header.setBorder( Border.ALL, BorderLineStyle.THIN );
-
+        
+        WritableCellFormat headerContent = new WritableCellFormat();
+        headerContent.setBorder( Border.ALL, BorderLineStyle.THIN );
+        
         sheet.mergeCells( titlePositionCol, titlePositionRow, titlePositionCol + 1, titlePositionRow );
         sheet.mergeCells( titlePositionCol + 2, titlePositionRow, titlePositionCol + 6, titlePositionRow );
         sheet.mergeCells( titlePositionCol, titlePositionRow + 1, titlePositionCol + 1, titlePositionRow + 1 );
         sheet.mergeCells( titlePositionCol + 2, titlePositionRow + 1, titlePositionCol + 6, titlePositionRow + 1 );
         sheet.mergeCells( titlePositionCol, titlePositionRow + 2, titlePositionCol + 1, titlePositionRow + 2 );
         sheet.mergeCells( titlePositionCol + 2, titlePositionRow + 2, titlePositionCol + 6, titlePositionRow + 2 );
-
-        sheet.addCell( new Label( titlePositionCol, titlePositionRow, i18n.getString( "title" ), header ) );
-        sheet.addCell( new Label( titlePositionCol + 2, titlePositionRow, this.title, header ) );
-        sheet.addCell( new Label( titlePositionCol, titlePositionRow + 1, i18n.getString( "indicator" ), header ) );
-        sheet.addCell( new Label( titlePositionCol + 2, titlePositionRow + 1, i.getName(), header ) );
-        sheet.addCell( new Label( titlePositionCol, titlePositionRow + 2, i18n.getString( "period" ), header ) );
-        sheet.addCell( new Label( titlePositionCol + 2, titlePositionRow + 2, p.getName(), header ) );
+        
+        sheet.addCell( new Label( titlePositionCol, titlePositionRow, i18n.getString( "Title" ), header ) );
+        sheet.addCell( new Label( titlePositionCol + 2, titlePositionRow, this.title, headerContent ) );
+        sheet.addCell( new Label( titlePositionCol, titlePositionRow + 1, i18n.getString( "Indicator" ), header ) );
+        sheet.addCell( new Label( titlePositionCol + 2, titlePositionRow + 1, i.getName(), headerContent ) );
+        sheet.addCell( new Label( titlePositionCol, titlePositionRow + 2, i18n.getString( "Period" ), header ) );
+        sheet.addCell( new Label( titlePositionCol + 2, titlePositionRow + 2, p.getName(), headerContent ) );
 
         // ---------------------------------------------------------------------
         // Write data values to workbook
@@ -292,11 +296,11 @@
             WritableCellFormat datavalueHeader = new WritableCellFormat();
             datavalueHeader.setBorder( Border.ALL, BorderLineStyle.THIN );
             datavalueHeader.setAlignment( Alignment.CENTRE );
-            datavalueHeader.setBackground( Colour.ICE_BLUE );
-
-            sheet.addCell( new Label( orgunitPositionCol, orgunitPositionRow, i18n.getString( "name" ), datavalueHeader ) );
-
-            sheet.addCell( new Label( orgunitPositionCol + 1, orgunitPositionRow, i18n.getString( "value" ), datavalueHeader ) );
+            datavalueHeader.setBackground( Colour.GREY_25_PERCENT );
+
+            sheet.addCell( new Label( orgunitPositionCol, orgunitPositionRow, i18n.getString( "Name" ), datavalueHeader ) );
+
+            sheet.addCell( new Label( orgunitPositionCol + 1, orgunitPositionRow, i18n.getString( "Value" ), datavalueHeader ) );
 
             WritableCellFormat valCellFormat = new WritableCellFormat();
             valCellFormat.setAlignment( Alignment.LEFT );
@@ -311,6 +315,10 @@
             JSONObject json = (JSONObject) JSONSerializer.toJSON( datavalues );
 
             JSONArray jsonDataValues = json.getJSONArray( "datavalues" );
+            
+            CellView cellView = new CellView();
+            
+            cellView.setSize( 7000 );
 
             for ( int index = 0; index < jsonDataValues.size(); index++ )
             {
@@ -321,6 +329,8 @@
                 double value = datavalue.getDouble( "value" );
 
                 sheet.addCell( new Label( orgunitPositionCol, rowValue, organisationUnit.getName(), valCellFormat ) );
+                
+                sheet.setColumnView( orgunitPositionCol, cellView ); 
 
                 sheet.addCell( new Number( orgunitPositionCol + 1, rowValue, value, valCellFormat ) );
 

=== modified file 'dhis-2/dhis-web/dhis-web-mapping/src/main/java/org/hisp/dhis/mapping/action/ExportImageAction.java'
--- dhis-2/dhis-web/dhis-web-mapping/src/main/java/org/hisp/dhis/mapping/action/ExportImageAction.java	2010-04-08 11:37:23 +0000
+++ dhis-2/dhis-web/dhis-web-mapping/src/main/java/org/hisp/dhis/mapping/action/ExportImageAction.java	2010-04-08 15:59:17 +0000
@@ -170,8 +170,8 @@
 
         svgDocument.setTitle( this.title );
         svgDocument.setSvg( this.svg );
+        svgDocument.setIndicator( i );
         svgDocument.setPeriod( p );
-        svgDocument.setIndicator( i );
         svgDocument.setLegends( legends );
         svgDocument.setIncludeLegends( includeLegends );
 

=== modified file 'dhis-2/dhis-web/dhis-web-mapping/src/main/java/org/hisp/dhis/mapping/export/SVGDocument.java'
--- dhis-2/dhis-web/dhis-web-mapping/src/main/java/org/hisp/dhis/mapping/export/SVGDocument.java	2010-04-07 11:02:26 +0000
+++ dhis-2/dhis-web/dhis-web-mapping/src/main/java/org/hisp/dhis/mapping/export/SVGDocument.java	2010-04-08 16:02:07 +0000
@@ -120,10 +120,9 @@
 
         int y = 0;
 
-        for ( int index = 0; index < jsonLegends.size(); index++ )
+        for ( int i = 0; i < jsonLegends.size(); i++ )
         {
-
-            legend = jsonLegends.getJSONObject( index );
+            legend = jsonLegends.getJSONObject( i );
 
             String label = legend.getString( "label" );
 
@@ -155,9 +154,9 @@
 
         JSONArray jsonLegends = json.getJSONArray( "legends" );
 
-        for ( int index = 0; index < jsonLegends.size(); index++ )
+        for ( int i = 0; i < jsonLegends.size(); i++ )
         {
-            legend = jsonLegends.getJSONObject( index );
+            legend = jsonLegends.getJSONObject( i );
 
             String label = legend.getString( "label" );
 

=== modified file 'dhis-2/dhis-web/dhis-web-mapping/src/main/webapp/dhis-web-mapping/mapping/script/index.js'
--- dhis-2/dhis-web/dhis-web-mapping/src/main/webapp/dhis-web-mapping/mapping/script/index.js	2010-04-07 15:47:50 +0000
+++ dhis-2/dhis-web/dhis-web-mapping/src/main/webapp/dhis-web-mapping/mapping/script/index.js	2010-04-08 16:02:07 +0000
@@ -3921,11 +3921,16 @@
     });
 }
 
+function sortByValue(a, b) {
+	return b.value - a.value;
+}
+
 function getExportDataValueJSON( mapvalues ){
 	var json = '{';
 	json += '"datavalues":';
-	json += '[';	
-	
+	json += '[';
+	mapvalues.sort(sortByValue);
+
 	for (var i = 0; i < mapvalues.length; i++) {		
 		json += '{';
 		json += '"organisation": "' + mapvalues[i].orgUnitId + '",';
@@ -3938,17 +3943,17 @@
 	return json;
 }
 
-function getLegendsJSON(){
+function getLegendsJSON() {
 	var legends = choropleth.imageLegend;
 	var json = '{';
 	json += '"legends":';
 	json += '[';
 	
-	for ( var i=0; i<legends.length; i++ ) {
+	for (var i = 0; i < choropleth.imageLegend.length; i++) {
 		json += '{';
-		json += '"label": "' + legends[i].label + '",';
-		json += '"color": "' + legends[i].color + '" ';
-		json += i < legends.length-1 ? '},' : '}';
+		json += '"label": "' + choropleth.imageLegend[i].label + '",';
+		json += '"color": "' + choropleth.imageLegend[i].color + '" ';
+		json += i < choropleth.imageLegend.length-1 ? '},' : '}';
 	}	
 	json += ']';
 	json += '}';