dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #22103
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 10607: (GIS) PDF download option implemented.
Merge authors:
Jan Henrik Øverland (janhenrik-overland)
------------------------------------------------------------
revno: 10607 [merge]
committer: Jan Henrik Overland <janhenrik.overland@xxxxxxxxx>
branch nick: dhis2
timestamp: Wed 2013-04-17 18:03:07 +0200
message:
(GIS) PDF download option implemented.
modified:
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/webapp/dhis-web-mapping/app/index.html
dhis-2/dhis-web/dhis-web-mapping/src/main/webapp/dhis-web-mapping/app/scripts/app.js
dhis-2/dhis-web/dhis-web-mapping/src/main/webapp/dhis-web-mapping/app/scripts/core.js
dhis-2/dhis-web/dhis-web-mapping/src/main/webapp/dhis-web-mapping/app/styles/style.css
dhis-2/dhis-web/dhis-web-visualizer/src/main/java/org/hisp/dhis/visualizer/action/ExportImageAction.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-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 2013-04-04 18:06:19 +0000
+++ dhis-2/dhis-web/dhis-web-mapping/src/main/java/org/hisp/dhis/mapping/action/ExportImageAction.java 2013-04-17 16:01:35 +0000
@@ -40,6 +40,7 @@
import org.apache.batik.transcoder.image.PNGTranscoder;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.apache.fop.svg.PDFTranscoder;
import org.hisp.dhis.system.util.CodecUtils;
import org.hisp.dhis.util.ContextUtils;
import org.hisp.dhis.util.StreamActionSupport;
@@ -54,34 +55,56 @@
{
private static final Log log = LogFactory.getLog( ExportImageAction.class );
+ private static final String TYPE_PNG = "png";
+
+ private static final String TYPE_PDF = "pdf";
+
// -------------------------------------------------------------------------
// Input & Output
// -------------------------------------------------------------------------
+ private String title;
+
+ public void setTitle( String title )
+ {
+ this.title = title;
+ }
+
private String svg;
public void setSvg( String svg )
{
this.svg = svg;
}
-
- private String title;
-
- public void setTitle( String title )
+
+ private String type;
+
+ public void setType( String type )
{
- this.title = title;
+ this.type = type;
}
@Override
protected String execute( HttpServletResponse response, OutputStream out )
throws Exception
{
- if ( svg == null )
+ if ( svg != null )
{
- log.info( "Error: SVG is empty" );
+ if ( type == null || TYPE_PNG.equals( type ) )
+ {
+ convertToPNG( new StringBuffer( this.svg ), out );
+ }
+ else if ( TYPE_PDF.equals( type ) )
+ {
+ convertToPDF( new StringBuffer( this.svg ), out );
+ }
}
+ else
+ {
+ log.info( "svg = " + svg + ", type = " + type );
- convertToPNG( new StringBuffer( this.svg ), out );
+ return NONE;
+ }
return SUCCESS;
}
@@ -95,7 +118,7 @@
@Override
protected String getFilename()
{
- return "dhis2-gis_" + CodecUtils.filenameEncode( this.title ) + ".png";
+ return "dhis2_map_" + CodecUtils.filenameEncode( this.title ) + "." + CodecUtils.filenameEncode( type );
}
public void convertToPNG( StringBuffer buffer, OutputStream out )
@@ -112,6 +135,18 @@
t.transcode( input, output );
}
+ public void convertToPDF( StringBuffer buffer, OutputStream out )
+ throws TranscoderException
+ {
+ PDFTranscoder t = new PDFTranscoder();
+
+ TranscoderInput input = new TranscoderInput( new StringReader( buffer.toString() ) );
+
+ TranscoderOutput output = new TranscoderOutput( out );
+
+ t.transcode( input, output );
+ }
+
@Override
protected boolean disallowCache()
{
=== modified file 'dhis-2/dhis-web/dhis-web-mapping/src/main/webapp/dhis-web-mapping/app/index.html'
--- dhis-2/dhis-web/dhis-web-mapping/src/main/webapp/dhis-web-mapping/app/index.html 2013-04-16 17:47:28 +0000
+++ dhis-2/dhis-web/dhis-web-mapping/src/main/webapp/dhis-web-mapping/app/index.html 2013-04-17 16:01:35 +0000
@@ -14,8 +14,9 @@
<div id="layerItems"></div>
<form id="exportForm" method="post">
+ <input type="hidden" id="typeField" name="type"/>
+ <input type="hidden" id="titleField" name="title"/>
<input type="hidden" id="svgField" name="svg"/>
- <input type="hidden" id="titleField" name="title"/>
</form>
<script type="text/javascript">
=== modified file 'dhis-2/dhis-web/dhis-web-mapping/src/main/webapp/dhis-web-mapping/app/scripts/app.js'
--- dhis-2/dhis-web/dhis-web-mapping/src/main/webapp/dhis-web-mapping/app/scripts/app.js 2013-04-17 10:38:34 +0000
+++ dhis-2/dhis-web/dhis-web-mapping/src/main/webapp/dhis-web-mapping/app/scripts/app.js 2013-04-17 16:01:35 +0000
@@ -148,9 +148,11 @@
namespace,
titleSVG,
legendSVG = '',
+ scalelineSVG,
x = 20,
y = 35,
- center = gis.viewport.centerRegion;
+ center = gis.viewport.centerRegion,
+ scalelineEl = Ext.get(Ext.query('.olControlScaleLineTop')[0]);
if (!layers.length) {
return false;
@@ -228,11 +230,22 @@
}
}
+ // Scale line
+ scalelineSVG = '<text x="' + (x + 3) + '" y="' + y + '" fill="#000">' + scalelineEl.dom.innerHTML + '</text>';
+
+ y += 3;
+ scalelineSVG += '<line x1="' + x + '" y1="' + y + '" x2="' + x + '" y2="' + (y + 3) + '" style="stroke:#000;stroke-width:1" />';
+ scalelineSVG += '<line x1="' + (x + scalelineEl.getWidth()) + '" y1="' + y + '" x2="' + (x + scalelineEl.getWidth()) + '" y2="' + (y + 3) + '" style="stroke:#000;stroke-width:1" />';
+
+ y += 3;
+ scalelineSVG += '<line x1="' + x + '" y1="' + y + '" x2="' + (x + scalelineEl.getWidth()) + '" y2="' + y + '" style="stroke:#000;stroke-width:1" />';
+
+ // Map
if (svgArray.length) {
svg = util.svg.merge(svg, svgArray);
}
- svg = svg.replace('</svg>', (titleSVG + legendSVG) + '</svg>');
+ svg = svg.replace('</svg>', (titleSVG + legendSVG + scalelineSVG) + '</svg>');
return svg;
};
@@ -3003,21 +3016,43 @@
GIS.app.DownloadWindow = function() {
var window,
- textfield,
+ format,
+ name,
button;
- textfield = Ext.create('Ext.form.field.Text', {
+ format = Ext.create('Ext.form.field.ComboBox', {
+ cls: 'gis-combo',
+ width: 60,
+ style: 'margin-bottom:0; margin-left:2px',
+ valueField: 'id',
+ displayField: 'text',
+ editable: false,
+ queryMode: 'local',
+ forceSelection: true,
+ value: 'png',
+ store: Ext.create('Ext.data.ArrayStore', {
+ fields: ['id', 'text'],
+ data: [
+ ['png', 'PNG'],
+ ['pdf', 'PDF']
+ ]
+ })
+ });
+
+ name = Ext.create('Ext.form.field.Text', {
cls: 'gis-textfield',
- height: 26,
+ //height: 23,
width: 230,
- fieldStyle: 'padding-left: 5px',
+ fieldStyle: 'padding-left:4px',
+ style: 'margin-bottom:0',
emptyText: GIS.i18n.please_enter_map_title
});
button = Ext.create('Ext.button.Button', {
text: GIS.i18n.download,
handler: function() {
- var title = Ext.htmlEncode(textfield.getValue()),
+ var type = format.getValue(),
+ title = Ext.htmlEncode(name.getValue()),
svg = gis.util.svg.getString(title, gis.util.map.getVisibleVectorLayers()),
exportForm = document.getElementById('exportForm');
@@ -3026,8 +3061,9 @@
return;
}
+ document.getElementById('typeField').value = type;
+ document.getElementById('titleField').value = title;
document.getElementById('svgField').value = svg;
- document.getElementById('titleField').value = title;
exportForm.action = '../exportImage.action';
exportForm.method = 'post';
exportForm.submit();
@@ -3038,13 +3074,16 @@
window = Ext.create('Ext.window.Window', {
title: GIS.i18n.download_map_as_png,
- layout: 'fit',
+ layout: 'column',
iconCls: 'gis-window-title-icon-download',
cls: 'gis-container-default',
bodyStyle: 'padding:2px',
resizable: true,
modal: true,
- items: textfield,
+ items: [
+ name,
+ format
+ ],
bbar: [
'->',
button
=== modified file 'dhis-2/dhis-web/dhis-web-mapping/src/main/webapp/dhis-web-mapping/app/scripts/core.js'
--- dhis-2/dhis-web/dhis-web-mapping/src/main/webapp/dhis-web-mapping/app/scripts/core.js 2013-04-17 10:38:34 +0000
+++ dhis-2/dhis-web/dhis-web-mapping/src/main/webapp/dhis-web-mapping/app/scripts/core.js 2013-04-17 14:53:47 +0000
@@ -232,7 +232,7 @@
new OpenLayers.Control.Permalink(),
new OpenLayers.Control.ScaleLine({
geodesic: true,
- maxWidth: 200,
+ maxWidth: 170,
minWidth: 100
})
],
=== modified file 'dhis-2/dhis-web/dhis-web-mapping/src/main/webapp/dhis-web-mapping/app/styles/style.css'
--- dhis-2/dhis-web/dhis-web-mapping/src/main/webapp/dhis-web-mapping/app/styles/style.css 2013-04-16 14:28:29 +0000
+++ dhis-2/dhis-web/dhis-web-mapping/src/main/webapp/dhis-web-mapping/app/styles/style.css 2013-04-17 16:01:35 +0000
@@ -211,7 +211,6 @@
color: #111;
}
-
/*----------------------------------------------------------------------------
* GIS Combobox
*--------------------------------------------------------------------------*/
@@ -226,7 +225,7 @@
/* Combobox border-radius */
.gis-combo input {
- border-radius: 2px 0px 0px 0px;
+ border-radius: 1px 0px 0px 0px;
font-size: 10px !important;
}
=== modified file 'dhis-2/dhis-web/dhis-web-visualizer/src/main/java/org/hisp/dhis/visualizer/action/ExportImageAction.java'
--- dhis-2/dhis-web/dhis-web-visualizer/src/main/java/org/hisp/dhis/visualizer/action/ExportImageAction.java 2013-04-04 18:06:19 +0000
+++ dhis-2/dhis-web/dhis-web-visualizer/src/main/java/org/hisp/dhis/visualizer/action/ExportImageAction.java 2013-04-17 16:01:35 +0000
@@ -92,27 +92,25 @@
protected String execute( HttpServletResponse response, OutputStream out )
throws Exception
{
- if ( svg != null && type != null )
+ if ( svg != null )
{
- if ( type.equals( TYPE_PNG ) )
+ if ( type == null || TYPE_PNG.equals( type ) )
{
convertToPNG( new StringBuffer( doctype + svg ), out );
}
-
- else if ( type.equals( TYPE_PDF ) )
+ else if ( TYPE_PDF.equals( type ) )
{
convertToPDF( new StringBuffer( doctype + svg ), out );
}
-
- return SUCCESS;
}
-
else
{
log.info( "svg = " + svg + ", type = " + type );
return NONE;
}
+
+ return SUCCESS;
}
public void convertToPNG( StringBuffer buffer, OutputStream out )
@@ -152,7 +150,7 @@
{
String t = title != null ? CodecUtils.filenameEncode( title ) : "";
- return "dhis2_dv_" + t + "." + CodecUtils.filenameEncode( type );
+ return "dhis2_chart_" + t + "." + CodecUtils.filenameEncode( type );
}
@Override