------------------------------------------------------------
revno: 1694
committer: Tran Thanh Tri <Tran Thanh t...@compaq>
branch nick: trunk
timestamp: Thu 2010-03-25 12:32:49 +0100
message:
  GIS - export map to excel function
added:
  
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
modified:
  dhis-2/dhis-web/dhis-web-mapping/pom.xml
  
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/resources/META-INF/dhis/beans.xml
  dhis-2/dhis-web/dhis-web-mapping/src/main/resources/struts.xml
  
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/pom.xml'
--- dhis-2/dhis-web/dhis-web-mapping/pom.xml	2010-03-25 08:25:46 +0000
+++ dhis-2/dhis-web/dhis-web-mapping/pom.xml	2010-03-25 11:32:49 +0000
@@ -77,6 +77,15 @@
       </exclusions>
     </dependency>
 	
+	<!-- JSON -->
+
+	<dependency>
+		<groupId>net.sf.json-lib</groupId>
+		<artifactId>json-lib</artifactId>
+		<version>2.2.3</version>
+		<classifier>jdk15</classifier>
+	</dependency>
+	
 	
 	<!-- Batik -->
 

=== added 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	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-web/dhis-web-mapping/src/main/java/org/hisp/dhis/mapping/action/ExportExcelAction.java	2010-03-25 11:32:49 +0000
@@ -0,0 +1,359 @@
+package org.hisp.dhis.mapping.action;
+
+/*
+ * Copyright (c) 2004-2007, University of Oslo
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * * Redistributions of source code must retain the above copyright notice, this
+ *   list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright notice,
+ *   this list of conditions and the following disclaimer in the documentation
+ *   and/or other materials provided with the distribution.
+ * * Neither the name of the HISP project nor the names of its contributors may
+ *   be used to endorse or promote products derived from this software without
+ *   specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+import java.io.File;
+
+import jxl.Workbook;
+import jxl.format.Alignment;
+import jxl.format.Border;
+import jxl.format.BorderLineStyle;
+import jxl.format.Colour;
+import jxl.write.Label;
+import jxl.write.Number;
+import jxl.write.WritableCellFormat;
+import jxl.write.WritableImage;
+import jxl.write.WritableSheet;
+import jxl.write.WritableWorkbook;
+
+import net.sf.json.JSONArray;
+import net.sf.json.JSONObject;
+import net.sf.json.JSONSerializer;
+
+import org.hisp.dhis.external.location.LocationManager;
+import org.hisp.dhis.i18n.I18n;
+import org.hisp.dhis.i18n.I18nFormat;
+import org.hisp.dhis.indicator.Indicator;
+import org.hisp.dhis.indicator.IndicatorService;
+import org.hisp.dhis.mapping.MappingService;
+import org.hisp.dhis.mapping.export.SVGDocument;
+import org.hisp.dhis.mapping.export.SVGUtils;
+import org.hisp.dhis.organisationunit.OrganisationUnit;
+import org.hisp.dhis.organisationunit.OrganisationUnitService;
+import org.hisp.dhis.period.Period;
+import org.hisp.dhis.period.PeriodService;
+import org.hisp.dhis.system.util.StreamUtils;
+
+import com.opensymphony.xwork2.Action;
+
+/**
+ * @author Tran Thanh Tri
+ * @version $Id$
+ */
+
+public class ExportExcelAction
+    implements Action
+{
+    // -------------------------------------------------------------------------
+    // Map position in excel
+    // -------------------------------------------------------------------------
+
+    int titlePositionCol = 1;
+
+    int titlePositionRow = 1;
+
+    int mapPositionCol = 1;
+
+    int mapPositionCRow = 5;
+
+    int legendPositionCol = 9;
+
+    int legendPositionRow = 5;
+
+    int orgunitPositionCol = 13;
+
+    int orgunitPositionRow = 5;
+
+    // -------------------------------------------------------------------------
+    // Dependencies
+    // -------------------------------------------------------------------------
+
+    private LocationManager locationManager;
+
+    public void setLocationManager( LocationManager locationManager )
+    {
+        this.locationManager = locationManager;
+    }
+
+    private OrganisationUnitService organisationUnitService;
+
+    public void setOrganisationUnitService( OrganisationUnitService organisationUnitService )
+    {
+        this.organisationUnitService = organisationUnitService;
+    }
+
+    private PeriodService periodService;
+
+    public void setPeriodService( PeriodService periodService )
+    {
+        this.periodService = periodService;
+    }
+
+    private IndicatorService indicatorService;
+
+    public void setIndicatorService( IndicatorService indicatorService )
+    {
+        this.indicatorService = indicatorService;
+    }
+
+    protected I18nFormat format;
+
+    public void setFormat( I18nFormat format )
+    {
+        this.format = format;
+    }
+
+    private I18n i18n;
+
+    public void setI18n( I18n i18n )
+    {
+        this.i18n = i18n;
+    }
+
+    // -------------------------------------------
+    // Output & Input
+    // -------------------------------------------
+
+    private String svg;
+
+    public void setSvg( String svg )
+    {
+        this.svg = svg;
+    }
+
+    private String title;
+
+    public void setTitle( String title )
+    {
+        this.title = title;
+    }
+
+    private Integer indicator;
+
+    public void setIndicator( Integer indicator )
+    {
+        this.indicator = indicator;
+    }
+
+    private Integer period;
+
+    public void setPeriod( Integer period )
+    {
+        this.period = period;
+    }
+
+    private String outputFile;
+
+    public String getOutputFile()
+    {
+        return outputFile;
+    }
+
+    private Integer width;
+
+    public void setWidth( Integer width )
+    {
+        this.width = width;
+    }
+
+    private Integer height;
+
+    public void setHeight( Integer height )
+    {
+        this.height = height;
+    }
+
+    private String datavalues;
+
+    public void setDatavalues( String datavalues )
+    {
+        this.datavalues = datavalues;
+    }
+
+    private boolean includeValues;
+
+    public void setIncludeValues( boolean includeValues )
+    {
+        this.includeValues = includeValues;
+    }
+
+    private boolean includeLegend;
+
+    public void setIncludeLegend( boolean includeLegend )
+    {
+        this.includeLegend = includeLegend;
+    }
+
+    @Override
+    public String execute()
+        throws Exception
+    {
+
+        Period p = periodService.getPeriod( period );
+
+        p.setName( format.formatPeriod( p ) );
+
+        Indicator i = indicatorService.getIndicator( indicator );
+
+        /* TODO write map to file */
+
+        SVGDocument svgDocument = new SVGDocument();
+
+        svgDocument.setTitle( this.title );
+
+        svgDocument.setSvg( this.svg );
+
+        svgDocument.setPeriod( p );
+
+        svgDocument.setIndicator( i );
+
+        int random = (int) (Math.random() * 1000);
+
+        File temporaryDir = locationManager.getFileForWriting( MappingService.MAP_TEMPL_DIR );
+
+        File svgTemporary = new File( temporaryDir, "svg_" + random + ".svg" );
+
+        StreamUtils.writeContent( svgTemporary, svgDocument.getSVGForExcel() );
+
+        File image = new File( temporaryDir, "svg_" + random + ".png" );
+
+        SVGUtils.convertSVG2PNG( svgTemporary, image, width, height );
+
+        /* TODO write excel to file */
+
+        File output = new File( temporaryDir, "excel_" + random + ".xls" );
+
+        WritableWorkbook outputReportWorkbook = Workbook.createWorkbook( output );
+
+        WritableSheet sheet = outputReportWorkbook.createSheet( i.getName(), 1 );
+
+        /* TODO add map to excel */
+
+        sheet.mergeCells( mapPositionCol, mapPositionCRow, mapPositionCol + 6, mapPositionCRow + 25 );
+
+        WritableImage map = new WritableImage( mapPositionCol, mapPositionCRow, 7, 26, image );
+
+        sheet.addImage( map );
+
+        WritableCellFormat map_format = new WritableCellFormat();
+        map_format.setBorder( Border.ALL, BorderLineStyle.THIN );
+        map_format.setAlignment( Alignment.CENTRE );
+
+        sheet.addCell( new Label( mapPositionCol, mapPositionCRow, "", map_format ) );
+
+        /* TODO add title */
+
+        WritableCellFormat header = new WritableCellFormat();
+        header.setBackground( Colour.ICE_BLUE );
+        header.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 ) );
+
+        if ( includeLegend )
+        {
+
+            WritableCellFormat legendHeader = new WritableCellFormat();
+            legendHeader.setBorder( Border.ALL, BorderLineStyle.THIN );
+            legendHeader.setAlignment( Alignment.CENTRE );
+            legendHeader.setBackground( Colour.ICE_BLUE );
+
+            sheet.mergeCells( legendPositionCol, legendPositionRow, legendPositionCol + 2, legendPositionRow );
+            sheet.addCell( new Label( legendPositionCol, legendPositionRow, i18n.getString( "legend" ), legendHeader ) );
+            sheet.addCell( new Label( legendPositionCol, legendPositionRow + 1, i18n.getString( "color" ), legendHeader ) );
+            sheet.addCell( new Label( legendPositionCol + 1, legendPositionRow + 1, i18n.getString( "min" ), legendHeader ) );
+            sheet.addCell( new Label( legendPositionCol + 2, legendPositionRow + 1, i18n.getString( "max" ), legendHeader ) );
+
+        }
+
+        if ( includeValues )
+        {
+            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 ) );
+            
+            
+            WritableCellFormat valCellFormat = new WritableCellFormat();
+            valCellFormat.setAlignment( Alignment.LEFT );
+            valCellFormat.setBorder( Border.ALL, BorderLineStyle.THIN );      
+            
+            int rowValue = orgunitPositionRow + 1;            
+            
+            JSONObject datavalue;
+
+            OrganisationUnit organisationUnit;         
+           
+
+            JSONObject json = (JSONObject) JSONSerializer.toJSON( datavalues );
+
+            JSONArray jsonDataValues = json.getJSONArray( "datavalues" );
+
+            for ( int index = 0; index < jsonDataValues.size(); index++ )
+            {
+
+                datavalue = jsonDataValues.getJSONObject( index );
+
+                organisationUnit = organisationUnitService.getOrganisationUnit( datavalue.getInt( "organisation" ) );
+
+                double value = datavalue.getDouble( "value" );   
+                         
+                sheet.addCell( new Label( orgunitPositionCol, rowValue, organisationUnit.getName(), valCellFormat ) );
+                
+                sheet.addCell( new Number( orgunitPositionCol + 1, rowValue, value , valCellFormat ) );     
+
+                rowValue++;
+
+            }
+
+        }
+
+        outputReportWorkbook.write();
+
+        outputReportWorkbook.close();
+
+        outputFile = output.getAbsolutePath();
+
+        return SUCCESS;
+    }
+}

=== added 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	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-web/dhis-web-mapping/src/main/java/org/hisp/dhis/mapping/action/ExportImageAction.java	2010-03-25 11:32:49 +0000
@@ -0,0 +1,174 @@
+package org.hisp.dhis.mapping.action;
+/*
+ * Copyright (c) 2004-2007, University of Oslo
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * * Redistributions of source code must retain the above copyright notice, this
+ *   list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright notice,
+ *   this list of conditions and the following disclaimer in the documentation
+ *   and/or other materials provided with the distribution.
+ * * Neither the name of the HISP project nor the names of its contributors may
+ *   be used to endorse or promote products derived from this software without
+ *   specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+import java.io.File;
+
+import org.hisp.dhis.external.location.LocationManager;
+import org.hisp.dhis.i18n.I18nFormat;
+import org.hisp.dhis.indicator.Indicator;
+import org.hisp.dhis.indicator.IndicatorService;
+import org.hisp.dhis.mapping.MappingService;
+import org.hisp.dhis.mapping.export.SVGDocument;
+import org.hisp.dhis.mapping.export.SVGUtils;
+import org.hisp.dhis.period.Period;
+import org.hisp.dhis.period.PeriodService;
+import org.hisp.dhis.system.util.StreamUtils;
+
+import com.opensymphony.xwork2.Action;
+
+/**
+ * @author Tran Thanh Tri
+ * @version $Id$
+ */
+public class ExportImageAction
+    implements Action
+{
+
+    // -------------------------------------------------------------------------
+    // Dependencies
+    // -------------------------------------------------------------------------
+
+    private LocationManager locationManager;
+
+    public void setLocationManager( LocationManager locationManager )
+    {
+        this.locationManager = locationManager;
+    }
+
+    private PeriodService periodService;
+
+    public void setPeriodService( PeriodService periodService )
+    {
+        this.periodService = periodService;
+    }
+
+    private IndicatorService indicatorService;
+
+    public void setIndicatorService( IndicatorService indicatorService )
+    {
+        this.indicatorService = indicatorService;
+    }
+
+    protected I18nFormat format;
+
+    public void setFormat( I18nFormat format )
+    {
+        this.format = format;
+    }
+
+    // -------------------------------------------
+    // Output & Input
+    // -------------------------------------------
+
+    private String svg;
+
+    public void setSvg( String svg )
+    {
+        this.svg = svg;
+    }
+
+    private String title;
+
+    public void setTitle( String title )
+    {
+        this.title = title;
+    }
+
+    private Integer indicator;
+
+    public void setIndicator( Integer indicator )
+    {
+        this.indicator = indicator;
+    }
+
+    private Integer period;
+
+    public void setPeriod( Integer period )
+    {
+        this.period = period;
+    }
+
+    private String outputFile;
+
+    public String getOutputFile()
+    {
+        return outputFile;
+    }
+
+    private Integer width;
+
+    public void setWidth( Integer width )
+    {
+        this.width = width;
+    }
+
+    private Integer height;
+
+    public void setHeight( Integer height )
+    {
+        this.height = height;
+    }
+
+    @Override
+    public String execute()
+        throws Exception
+    {
+
+        Period p = periodService.getPeriod( period );
+        
+        p.setName( format.formatPeriod( p ) );
+        
+        Indicator i = indicatorService.getIndicator( indicator );
+        
+        int random = (int) (Math.random() * 100);
+
+        File temporaryDir = locationManager.getFileForWriting( MappingService.MAP_TEMPL_DIR );
+
+        File svgTemporary = new File( temporaryDir, "svg_" + random + ".svg" );
+
+        SVGDocument svgDocument = new SVGDocument(); 
+        
+        svgDocument.setTitle( this.title );
+
+        svgDocument.setSvg( this.svg );
+        
+        svgDocument.setPeriod( p );
+        
+        svgDocument.setIndicator( i );        
+
+        StreamUtils.writeContent( svgTemporary, svgDocument.getSVGForImage() );
+
+        File output = new File( temporaryDir, "svg_" + random + ".png" );
+
+        SVGUtils.convertSVG2PNG( svgTemporary, output, width, height );
+
+        outputFile = output.getAbsolutePath();
+
+        return SUCCESS;
+    }
+
+}

=== 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-03-24 10:56:30 +0000
+++ dhis-2/dhis-web/dhis-web-mapping/src/main/java/org/hisp/dhis/mapping/export/SVGDocument.java	2010-03-25 11:32:49 +0000
@@ -1,5 +1,8 @@
 package org.hisp.dhis.mapping.export;
 
+import org.hisp.dhis.indicator.Indicator;
+import org.hisp.dhis.period.Period;
+
 public class SVGDocument
 {
 
@@ -8,8 +11,6 @@
         + "<!ATTLIST svg   xmlns:attrib CDATA #IMPLIED> <!ATTLIST path attrib:divname CDATA #IMPLIED>]>";
 
     static final String namespace = "xmlns=\"http://www.w3.org/2000/svg\"; xmlns:xlink=\"http://www.w3.org/1999/xlink\"; xmlns:attrib=\"http://www.carto.net/attrib/\";  ";
-    
-    
 
     private String title;
 
@@ -17,27 +18,42 @@
 
     private String legend;
 
+    private Period period;
+
+    private Indicator indicator;
+
     public SVGDocument()
     {
-        
-
-    }
-   
-    
-    public void repairForImage(){
-        
-        this.title = "<g id=\"title\" style=\"display: block; visibility: visible;\"><text id=\"title\" x=\"30\" y=\"15\" font-size=\"14\" font-weight=\"bold\"><tspan>" + title + "</tspan></text></g>";
-        
-        this.svg = doctype + this.svg;
-
-        this.svg = this.svg.replaceFirst( "<svg", "<svg " + namespace );
-        
-        this.svg = this.svg.replaceFirst( "</svg>", this.title + "</svg>" );
-    }
-    
-    public StringBuffer getSVGscript()
-    {
-        return new StringBuffer( this.svg );
+
+    }
+
+    public StringBuffer getSVGForImage()
+    {
+        String title_ = "<g id=\"title\" style=\"display: block; visibility: visible;\"><text id=\"title\" x=\"30\" y=\"15\" font-size=\"14\" font-weight=\"bold\"><tspan>"
+            + this.title + "</tspan></text></g>";
+
+        String period_ = "<g id=\"period\" style=\"display: block; visibility: visible;\"><text id=\"period\" x=\"30\" y=\"30\" font-size=\"12\"><tspan>"
+            + this.period.getName() + "</tspan></text></g>";
+
+        String indicator_ = "<g id=\"indicator\" style=\"display: block; visibility: visible;\"><text id=\"indicator\" x=\"30\" y=\"45\" font-size=\"12\"><tspan>"
+            + this.indicator.getName() + "</tspan></text></g>";
+
+        String svg_ = doctype + this.svg;
+
+        svg_ = svg_.replaceFirst( "<svg", "<svg " + namespace );
+
+        svg_ = svg_.replaceFirst( "</svg>", title_ + period_ + indicator_ + "</svg>" );
+
+        return new StringBuffer( svg_ );
+    }
+
+    public StringBuffer getSVGForExcel()
+    {
+        String svg_ = doctype + this.svg;
+
+        svg_ = svg_.replaceFirst( "<svg", "<svg " + namespace );       
+
+        return new StringBuffer( svg_ );
     }
 
     public String getTitle()
@@ -46,11 +62,9 @@
     }
 
     public void setTitle( String title )
-    {        
+    {
         this.title = title;
     }
-    
-    
 
     public String getSvg()
     {
@@ -59,8 +73,8 @@
 
     public void setSvg( String svg )
     {
-        this.svg = svg;       
-        
+        this.svg = svg;
+
     }
 
     public String getLegend()
@@ -73,6 +87,26 @@
         this.legend = legend;
     }
 
+    public Period getPeriod()
+    {
+        return period;
+    }
+
+    public void setPeriod( Period period )
+    {
+        this.period = period;
+    }
+
+    public Indicator getIndicator()
+    {
+        return indicator;
+    }
+
+    public void setIndicator( Indicator indicator )
+    {
+        this.indicator = indicator;
+    }
+
     @Override
     public String toString()
     {

=== 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-03-24 10:56:30 +0000
+++ dhis-2/dhis-web/dhis-web-mapping/src/main/resources/META-INF/dhis/beans.xml	2010-03-25 11:32:49 +0000
@@ -287,11 +287,23 @@
 	</bean>
 
 	<!-- Export Map -->
-	
-	<bean id="org.hisp.dhis.mapping.action.ConvertSVGToImageAction"
-		class="org.hisp.dhis.mapping.action.ConvertSVGToImageAction" scope="prototype">
-		<property name="locationManager"
-			ref="org.hisp.dhis.external.location.LocationManager" />
+
+	<bean id="org.hisp.dhis.mapping.action.ExportImageAction" class="org.hisp.dhis.mapping.action.ExportImageAction"
+		scope="prototype">
+		<property name="locationManager"
+			ref="org.hisp.dhis.external.location.LocationManager" />
+		<property name="periodService" ref="org.hisp.dhis.period.PeriodService" />
+		<property name="indicatorService" ref="org.hisp.dhis.indicator.IndicatorService" />
+	</bean>
+
+	<bean id="org.hisp.dhis.mapping.action.ExportExcelAction" class="org.hisp.dhis.mapping.action.ExportExcelAction"
+		scope="prototype">
+		<property name="locationManager"
+			ref="org.hisp.dhis.external.location.LocationManager" />
+		<property name="periodService" ref="org.hisp.dhis.period.PeriodService" />
+		<property name="indicatorService" ref="org.hisp.dhis.indicator.IndicatorService" />
+		<property name="organisationUnitService"
+			ref="org.hisp.dhis.organisationunit.OrganisationUnitService" />
 	</bean>
 
 

=== 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-03-24 10:56:30 +0000
+++ dhis-2/dhis-web/dhis-web-mapping/src/main/resources/struts.xml	2010-03-25 11:32:49 +0000
@@ -313,9 +313,14 @@
 
 		<!-- Export Map -->
 
-		<action name="convertSVGToImage"
-			class="org.hisp.dhis.mapping.action.ConvertSVGToImageAction">
-			<result name="success" type="velocity-json">/dhis-web-mapping/jsonOutputFile.vm</result>
+		<action name="exportImage" class="org.hisp.dhis.mapping.action.ExportImageAction">
+			<result name="success" type="velocity-json">
+				/dhis-web-mapping/jsonOutputFile.vm</result>
+		</action>
+
+		<action name="exportExcel" class="org.hisp.dhis.mapping.action.ExportExcelAction">
+			<result name="success" type="velocity-json">
+				/dhis-web-mapping/jsonOutputFile.vm</result>
 		</action>
 
 		<action name="download" class="org.hisp.dhis.mapping.action.DownloadFileAction">

=== 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-03-24 10:56:30 +0000
+++ dhis-2/dhis-web/dhis-web-mapping/src/main/webapp/dhis-web-mapping/mapping/script/index.js	2010-03-25 11:32:49 +0000
@@ -11,6 +11,7 @@
 var ACTIVEPANEL;
 var MASK;
 var LABELS;
+var EXPORTVALUES;
 
 function getUrlParam(strParamName) {
     var output = '';
@@ -647,13 +648,14 @@
 				xtype: 'checkbox',
 				id: 'export_image_include_legend',
 				fieldLabel: 'Include legend',
-				labelSeparator: labelseparator,				
+				labelSeparator: '',				
 				isFormField: true		
 			},
 			{
 				xtype: 'button',
                 id: 'export_image_button',
 				isFormField: true,
+				labelSeparator: labelseparator,
 				hideLabel: false,
 				cls: 'window-button',
 				text: 'Export Image',
@@ -665,15 +667,19 @@
 					var w = Ext.getCmp('export_image_width').getValue();
 					var h = Ext.getCmp('export_image_height').getValue();
 					var includeLegend = Ext.getCmp('export_image_include_legend').getValue();
+					var period = Ext.getCmp('period_cb').getValue();
+					var indicator = Ext.getCmp('indicator_cb').getValue();
 					Ext.Ajax.request({
-						url: path + 'convertSVGToImage' + type,
+						url: path + 'exportImage' + type,
 						method: 'POST',
 						params: { 
 								title: title,
 								svg: svg,
-								width:w,
-								height:h,
-								includeLegend: includeLegend
+								width: w,
+								height: h,
+								includeLegend: includeLegend,
+								period: period,
+								indicator: indicator
 						},
 						success: function( responseObject ) {
 							MASK.hide();
@@ -716,46 +722,44 @@
 				xtype: 'checkbox',
 				id: 'export_excel_include_value',
 				fieldLabel: 'Include values',
-				labelSeparator: labelseparator,
-				editable: true,
-				valueField: 'id',
-				displayField: 'text',
-				isFormField: true,
-				width: combo_width_fieldset,
-				minListWidth: combo_list_width_fieldset,
-				mode: 'local',
-				triggerAction: 'all',
-				value: true						
+				labelSeparator: '',				
+				isFormField: true								
 			},
 			{
 				xtype: 'button',
                 id: 'export_excel_button',
 				isFormField: true,
+				labelSeparator: labelseparator,
 				hideLabel: false,
 				cls: 'window-button',
 				text: 'Export Excel',
 				handler: function() {					
 					MASK.msg = 'Exporting excel...';
 					MASK.show();
-					var svg = document.getElementById('OpenLayers.Layer.Vector_17').innerHTML;
-					var title = Ext.getCmp('export_image_title').getValue();
-					var w = Ext.getCmp('export_image_width').getValue();
-					var h = Ext.getCmp('export_image_height').getValue();
+					var title = Ext.getCmp('export_excel_title').getValue();
+					var svg = document.getElementById('OpenLayers.Layer.Vector_17').innerHTML;					
 					var includeLegend = Ext.getCmp('export_image_include_legend').getValue();
+					var includeValues = Ext.getCmp('export_excel_include_value').getValue();
+					var period = Ext.getCmp('period_cb').getValue();
+					var indicator = Ext.getCmp('indicator_cb').getValue();					
 					Ext.Ajax.request({
-						url: path + 'convertSVGToImage' + type,
+						url: path + 'exportExcel' + type,
 						method: 'POST',
-						params: { 
+						params: { 	
 								title: title,
-								svg: svg,
-								width:w,
-								height:h,
-								includeLegend: includeLegend
+								width:500,
+								height:500,
+								svg: svg,							
+								includeLegend: includeLegend,
+								includeValues: includeValues,
+								period: period,
+								indicator: indicator,
+								datavalues: EXPORTVALUES								
 						},
 						success: function( responseObject ) {
 							MASK.hide();
 							var file =  Ext.util.JSON.decode(responseObject.responseText).file;
-							window.open(path + "download" + type + "?path=" + file + "&outputFormat=application/image" );
+							window.open(path + "download" + type + "?path=" + file + "&outputFormat=application/ms-excel" );
 						}
 					});						
 						
@@ -3094,18 +3098,26 @@
 		}
 	});
 	
-	function showExportMap(){			
-		
-		var x = Ext.getCmp('center').x + 15;
-		var y = Ext.getCmp('center').y + 41;   
-		
-		exportMapWindow.setPosition(x,y);
+	function showExportMap(){		
+		
+		if(ACTIVEPANEL == thematicMap
+			&& Ext.getCmp('period_cb').getValue()!='' 
+			&& Ext.getCmp('indicator_cb').getValue()!=''
+			&& Ext.getCmp('map_cb').getValue()!=''){
+		
+			var x = Ext.getCmp('center').x + 15;
+			var y = Ext.getCmp('center').y + 41;   
+			
+			exportMapWindow.setPosition(x,y);
 
-		if (exportMapWindow.visible) {
-			exportMapWindow.hide();
-		}
-		else {
-			exportMapWindow.show();
+			if (exportMapWindow.visible) {
+				exportMapWindow.hide();
+			}
+			else {
+				exportMapWindow.show();
+			}
+		}else{
+			Ext.messageRed.msg('Please render the map fist!','Form does not completed');
 		}
 		
 	}
@@ -3522,6 +3534,27 @@
     });
 }
 
+function getExportDataValueJSON( mapvalues ){
+	var json = '{';
+	json += '"datavalues":';
+	json += '[';	
+	for (var i = 0; i < mapvalues.length; i++) {		
+		json += '{';
+		json += '"organisation": "' + mapvalues[i].orgUnitId + '",';
+		json += '"value": "' + mapvalues[i].value + '" ';
+		if(i < mapvalues.length-1){
+			json += '},';
+		}else{
+			json += '}';
+		}
+	}
+	json += ']';
+	json += '}';
+	
+	return json;
+	
+}
+
 /*CHOROPLETH*/
 function getChoroplethData() {
 	MASK.msg = 'Creating choropleth...';
@@ -3542,6 +3575,9 @@
 			var layers = MAP.getLayersByName('Thematic map');
 			var features = layers[0].features;
 			var mapvalues = Ext.util.JSON.decode(r.responseText).mapvalues;
+			
+			EXPORTVALUES = getExportDataValueJSON( mapvalues );	
+			
 			var mv = new Array();
 			var nameColumn = MAPDATA.nameColumn;
 			var options = {};

_______________________________________________
Mailing list: https://launchpad.net/~dhis2-devs
Post to     : dhis2-devs@lists.launchpad.net
Unsubscribe : https://launchpad.net/~dhis2-devs
More help   : https://help.launchpad.net/ListHelp

Reply via email to