dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #35039
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 17994: Dashboard. Added get as image function, with download and web api link.
------------------------------------------------------------
revno: 17994
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Wed 2015-01-14 17:58:34 +0100
message:
Dashboard. Added get as image function, with download and web api link.
modified:
dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/ChartController.java
dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/mapping/MapController.java
dhis-2/dhis-web/dhis-web-dashboard-integration/src/main/resources/org/hisp/dhis/dashboard/i18n_module.properties
dhis-2/dhis-web/dhis-web-dashboard-integration/src/main/webapp/dhis-web-dashboard-integration/dashboard.vm
dhis-2/dhis-web/dhis-web-dashboard-integration/src/main/webapp/dhis-web-dashboard-integration/javascript/dashboard.js
dhis-2/dhis-web/dhis-web-dashboard-integration/src/main/webapp/dhis-web-dashboard-integration/style/dashboard.css
--
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-api/src/main/java/org/hisp/dhis/webapi/controller/ChartController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/ChartController.java 2015-01-12 17:23:39 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/ChartController.java 2015-01-14 16:58:34 +0000
@@ -169,6 +169,7 @@
@RequestParam( value = "ou", required = false ) String ou,
@RequestParam( value = "width", defaultValue = "800", required = false ) int width,
@RequestParam( value = "height", defaultValue = "500", required = false ) int height,
+ @RequestParam( value = "attachment", required = false ) boolean attachment,
HttpServletResponse response ) throws IOException
{
Chart chart = chartService.getChartNoAcl( uid );
@@ -185,7 +186,7 @@
String filename = CodecUtils.filenameEncode( chart.getName() ) + ".png";
- contextUtils.configureResponse( response, ContextUtils.CONTENT_TYPE_PNG, CacheStrategy.RESPECT_SYSTEM_SETTING, filename, false );
+ contextUtils.configureResponse( response, ContextUtils.CONTENT_TYPE_PNG, CacheStrategy.RESPECT_SYSTEM_SETTING, filename, attachment );
ChartUtilities.writeChartAsPNG( response.getOutputStream(), jFreeChart, width, height );
}
@@ -198,6 +199,7 @@
@RequestParam( value = "width", defaultValue = "800", required = false ) int width,
@RequestParam( value = "height", defaultValue = "500", required = false ) int height,
@RequestParam( value = "skipTitle", required = false ) boolean skipTitle,
+ @RequestParam( value = "attachment", required = false ) boolean attachment,
HttpServletResponse response ) throws IOException
{
Indicator indicator = indicatorService.getIndicator( indicatorUid );
@@ -214,7 +216,7 @@
chart = chartService.getJFreeOrganisationUnitChart( indicator, unit, !skipTitle, i18nManager.getI18nFormat() );
}
- contextUtils.configureResponse( response, ContextUtils.CONTENT_TYPE_PNG, CacheStrategy.RESPECT_SYSTEM_SETTING, "chart.png", false );
+ contextUtils.configureResponse( response, ContextUtils.CONTENT_TYPE_PNG, CacheStrategy.RESPECT_SYSTEM_SETTING, "chart.png", attachment );
ChartUtilities.writeChartAsPNG( response.getOutputStream(), chart, width, height );
}
=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/mapping/MapController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/mapping/MapController.java 2015-01-02 11:37:51 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/mapping/MapController.java 2015-01-14 16:58:34 +0000
@@ -195,6 +195,7 @@
@RequestParam( value = "ou", required = false ) String ou,
@RequestParam( required = false ) Integer width,
@RequestParam( required = false ) Integer height,
+ @RequestParam( value = "attachment", required = false ) boolean attachment,
HttpServletResponse response ) throws Exception
{
Map map = mappingService.getMapNoAcl( uid );
@@ -219,7 +220,7 @@
OrganisationUnit unit = ou != null ? organisationUnitService.getOrganisationUnit( ou ) : null;
- renderMapViewPng( map, date, unit, width, height, response );
+ renderMapViewPng( map, date, unit, width, height, attachment, response );
}
//--------------------------------------------------------------------------
@@ -283,14 +284,14 @@
}
}
- private void renderMapViewPng( Map map, Date date, OrganisationUnit unit, Integer width, Integer height, HttpServletResponse response )
+ private void renderMapViewPng( Map map, Date date, OrganisationUnit unit, Integer width, Integer height, boolean attachment, HttpServletResponse response )
throws Exception
{
BufferedImage image = mapGenerationService.generateMapImage( map, date, unit, width, height );
if ( image != null )
{
- contextUtils.configureResponse( response, ContextUtils.CONTENT_TYPE_PNG, CacheStrategy.RESPECT_SYSTEM_SETTING, "map.png", false );
+ contextUtils.configureResponse( response, ContextUtils.CONTENT_TYPE_PNG, CacheStrategy.RESPECT_SYSTEM_SETTING, "map.png", attachment );
ImageIO.write( image, "PNG", response.getOutputStream() );
}
=== modified file 'dhis-2/dhis-web/dhis-web-dashboard-integration/src/main/resources/org/hisp/dhis/dashboard/i18n_module.properties'
--- dhis-2/dhis-web/dhis-web-dashboard-integration/src/main/resources/org/hisp/dhis/dashboard/i18n_module.properties 2015-01-14 10:27:59 +0000
+++ dhis-2/dhis-web/dhis-web-dashboard-integration/src/main/resources/org/hisp/dhis/dashboard/i18n_module.properties 2015-01-14 16:58:34 +0000
@@ -121,3 +121,6 @@
could_not_delete_interpretation=Could not delete interpretation, please try again later
could_not_delete_interpretation_comment=Could not delete interpretation comment, please try again later
could_not_save_interpretation=Could not save interpretation, please try again later
+download=Download
+api_link=API link
+get_as_image=Get as image
\ No newline at end of file
=== modified file 'dhis-2/dhis-web/dhis-web-dashboard-integration/src/main/webapp/dhis-web-dashboard-integration/dashboard.vm'
--- dhis-2/dhis-web/dhis-web-dashboard-integration/src/main/webapp/dhis-web-dashboard-integration/dashboard.vm 2015-01-14 16:50:54 +0000
+++ dhis-2/dhis-web/dhis-web-dashboard-integration/src/main/webapp/dhis-web-dashboard-integration/dashboard.vm 2015-01-14 16:58:34 +0000
@@ -31,9 +31,10 @@
var i18n_see_fewer_hits = '$encoder.jsEscape( $i18n.getString( "see_fewer_hits" ), "'")';
var i18n_add = '$encoder.jsEscape( $i18n.getString( "add" ), "'")';
var i18n_click_and_drag_to_new_position = '$encoder.jsEscape( $i18n.getString( "click_and_drag_to_new_position" ), "'")';
+var i18n_get_as_image = '$encoder.jsEscape( $i18n.getString( "get_as_image" ), "'")';
jQuery( document ).ready( function() {
- dhis2.leftBar.resetPosition(); ## Force left bar initial position when displaying dashboard
+ dhis2.leftBar.resetPosition();
});
</script>
@@ -81,7 +82,11 @@
</div>
<div id="chartView" class="page">
- <img id="chartImage" src="" style="padding: 10px;">
+ <div id="chartViewHeader">
+ <span><a id="chartImageDownload" href="javascript:dhis2.db.downloadImage()">$i18n.getString( "download" )</a></span>
+ <span>$i18n.getString( "api_link" ): <a id="chartImageUrl" target="_blank"></a></span>
+ </div>
+ <div><img id="chartImage" src="" style="padding: 10px;"></div>
</div>
<div id="reportDialogView" class="page"></div>
=== modified file 'dhis-2/dhis-web/dhis-web-dashboard-integration/src/main/webapp/dhis-web-dashboard-integration/javascript/dashboard.js'
--- dhis-2/dhis-web/dhis-web-dashboard-integration/src/main/webapp/dhis-web-dashboard-integration/javascript/dashboard.js 2015-01-14 13:17:15 +0000
+++ dhis-2/dhis-web/dhis-web-dashboard-integration/src/main/webapp/dhis-web-dashboard-integration/javascript/dashboard.js 2015-01-14 16:58:34 +0000
@@ -25,6 +25,7 @@
dhis2.db.currentShareType;
dhis2.db.currentShareId;
dhis2.db.currentMaxType = [];
+dhis2.db.contextPath;
dhis2.db.maxItems = 40;
dhis2.db.shapeNormal = "normal";
dhis2.db.shapeDoubleWidth = "double_width";
@@ -60,6 +61,10 @@
dhis2.db.currentKey = "dhis2.dashboard.current." + json.username;
dhis2.db.renderDashboardListLoadFirst();
} );
+
+ $.getJSON( "../api/system/info.json", function( json ) {
+ dhis2.db.contextPath = json.contextPath;
+ } );
} );
//------------------------------------------------------------------------------
@@ -82,7 +87,7 @@
chartItem: "<li id='liDrop-${itemId}' class='liDropItem'><div class='dropItem' id='drop-${itemId}' data-item='${itemId}'></div></li>" +
"<li id='li-${itemId}' class='liItem'><div class='item' id='${itemId}' style='${style}'><div class='itemHeader'><a href='javascript:dhis2.db.removeItem( \"${itemId}\" )'>${i18n_remove}</a>" +
- "<a href='javascript:dhis2.db.viewImage( \"../api/charts/${id}/data?width=820&height=550\", \"${name}\" )'>${i18n_view}</a>" +
+ "<a href='javascript:dhis2.db.viewImage( \"../api/charts/${id}/data?width=820&height=550\", \"${name}\" )'>${i18n_get_as_image}</a>" +
"<a href='javascript:dhis2.db.viewShareForm( \"${id}\", \"chart\", \"${name}\" )'>${i18n_share}</a>" +
"<a href='javascript:dhis2.db.exploreChart( \"${id}\" )'>${i18n_explore}</a>" +
"<a href='javascript:dhis2.db.resizeItem( \"${itemId}\" )'>${i18n_resize}</a>" +
@@ -92,7 +97,7 @@
eventChartItem: "<li id='liDrop-${itemId}' class='liDropItem'><div class='dropItem' id='drop-${itemId}' data-item='${itemId}'></div></li>" +
"<li id='li-${itemId}' class='liItem'><div class='item' id='${itemId}' style='${style}'><div class='itemHeader'><a href='javascript:dhis2.db.removeItem( \"${itemId}\" )'>${i18n_remove}</a>" +
- "<a href='javascript:dhis2.db.viewImage( \"../api/eventCharts/${id}/data?width=820&height=550\", \"${name}\" )'>${i18n_view}</a>" +
+ "<a href='javascript:dhis2.db.viewImage( \"../api/eventCharts/${id}/data?width=820&height=550\", \"${name}\" )'>${i18n_get_as_image}</a>" +
"<a href='javascript:dhis2.db.exploreEventChart( \"${id}\" )'>${i18n_explore}</a>" +
"<a href='javascript:dhis2.db.resizeItem( \"${itemId}\" )'>${i18n_resize}</a>" +
"<i class=\"fa fa-arrows dragIcon\" title=\"${i18n_click_and_drag_to_new_position}\"></i></div>" +
@@ -101,7 +106,7 @@
mapItem: "<li id='liDrop-${itemId}' class='liDropItem'><div class='dropItem' id='drop-${itemId}' data-item='${itemId}'></div></li>" +
"<li id='li-${itemId}' class='liItem'><div class='item' id='${itemId}' style='${style}'><div class='itemHeader'><a href='javascript:dhis2.db.removeItem( \"${itemId}\" )'>${i18n_remove}</a>" +
- "<a href='javascript:dhis2.db.viewImage( \"../api/maps/${id}/data?width=820&height=550\", \"${name}\" )'>${i18n_view}</a>" +
+ "<a href='javascript:dhis2.db.viewImage( \"../api/maps/${id}/data?width=820&height=550\", \"${name}\" )'>${i18n_get_as_image}</a>" +
"<a href='javascript:dhis2.db.viewShareForm( \"${id}\", \"map\", \"${name}\" )'>${i18n_share}</a>" +
"<a href='javascript:dhis2.db.exploreMap( \"${id}\" )'>${i18n_explore}</a>" +
"<a href='javascript:dhis2.db.resizeItem( \"${itemId}\" )'>${i18n_resize}</a>" +
@@ -111,7 +116,6 @@
reportTableItem: "<li id='liDrop-${itemId}' class='liDropItem'><div class='dropItem' id='drop-${itemId}' data-item='${itemId}'></div></li>" +
"<li id='li-${itemId}' class='liItem'><div class='item' id='${itemId}' style='${style}'><div class='itemHeader'><a href='javascript:dhis2.db.removeItem( \"${itemId}\" )'>${i18n_remove}</a>" +
- "<a href='javascript:dhis2.db.viewReportDialog( \"../api/reportTables/${id}/data.html\", \"${name}\" )'>${i18n_view}</a>" +
"<a href='javascript:dhis2.db.viewShareForm( \"${id}\", \"reportTable\", \"${name}\" )'>${i18n_share}</a>" +
"<a href='javascript:dhis2.db.exploreReportTable( \"${id}\" )'>${i18n_explore}</a>" +
"<a href='javascript:dhis2.db.resizeItem( \"${itemId}\" )'>${i18n_resize}</a>" +
@@ -121,7 +125,6 @@
eventReportItem: "<li id='liDrop-${itemId}' class='liDropItem'><div class='dropItem' id='drop-${itemId}' data-item='${itemId}'></div></li>" +
"<li id='li-${itemId}' class='liItem'><div class='item' id='${itemId}' style='${style}'><div class='itemHeader'><a href='javascript:dhis2.db.removeItem( \"${itemId}\" )'>${i18n_remove}</a>" +
- "<a href='javascript:dhis2.db.viewReportDialog( \"../api/reportTables/${id}/data.html\", \"${name}\" )'>${i18n_view}</a>" +
"<a href='javascript:dhis2.db.viewShareForm( \"${id}\", \"reportTable\", \"${name}\" )'>${i18n_share}</a>" +
"<a href='javascript:dhis2.db.exploreEventReport( \"${id}\" )'>${i18n_explore}</a>" +
"<a href='javascript:dhis2.db.resizeItem( \"${itemId}\" )'>${i18n_resize}</a>" +
@@ -531,7 +534,7 @@
if ( "chart" == dashboardItem.type )
{
$d.append( $.tmpl( dhis2.db.tmpl.chartItem, { "itemId": dashboardItem.id, "id": dashboardItem.chart.id, "name": dashboardItem.chart.name, "style": style,
- "i18n_remove": i18n_remove, "i18n_view": i18n_view_full_size, "i18n_share": i18n_share_interpretation, "i18n_click_and_drag_to_new_position": i18n_click_and_drag_to_new_position } ) );
+ "i18n_remove": i18n_remove, "i18n_get_as_image": i18n_get_as_image, "i18n_share": i18n_share_interpretation, "i18n_click_and_drag_to_new_position": i18n_click_and_drag_to_new_position } ) );
DHIS.getChart({
url: '..',
@@ -566,7 +569,7 @@
else if ( "eventChart" == dashboardItem.type )
{
$d.append( $.tmpl( dhis2.db.tmpl.eventChartItem, { "itemId": dashboardItem.id, "id": dashboardItem.eventChart.id,
- "name": dashboardItem.eventChart.name, "style": style, "i18n_remove": i18n_remove, "i18n_view": i18n_view_full_size,
+ "name": dashboardItem.eventChart.name, "style": style, "i18n_remove": i18n_remove, "i18n_get_as_image": i18n_get_as_image,
"i18n_share": i18n_share_interpretation, "i18n_click_and_drag_to_new_position": i18n_click_and_drag_to_new_position, "i18n_explore": i18n_explore } ) );
DHIS.getEventChart({
@@ -602,7 +605,7 @@
else if ( "map" == dashboardItem.type )
{
$d.append( $.tmpl( dhis2.db.tmpl.mapItem, { "itemId": dashboardItem.id, "id": dashboardItem.map.id, "name": dashboardItem.map.name, "style": style,
- "i18n_remove": i18n_remove, "i18n_view": i18n_view_full_size, "i18n_share": i18n_share_interpretation, "i18n_click_and_drag_to_new_position": i18n_click_and_drag_to_new_position } ) );
+ "i18n_remove": i18n_remove, "i18n_get_as_image": i18n_get_as_image, "i18n_share": i18n_share_interpretation, "i18n_click_and_drag_to_new_position": i18n_click_and_drag_to_new_position } ) );
DHIS.getMap({
url: '..',
@@ -619,7 +622,7 @@
else if ( "reportTable" == dashboardItem.type )
{
$d.append( $.tmpl( dhis2.db.tmpl.reportTableItem, { "itemId": dashboardItem.id, "id": dashboardItem.reportTable.id, "name": dashboardItem.reportTable.name, "style": style,
- "i18n_remove": i18n_remove, "i18n_view": i18n_view_full_size, "i18n_share": i18n_share_interpretation, "i18n_click_and_drag_to_new_position": i18n_click_and_drag_to_new_position } ) );
+ "i18n_remove": i18n_remove, "i18n_share": i18n_share_interpretation, "i18n_click_and_drag_to_new_position": i18n_click_and_drag_to_new_position } ) );
DHIS.getTable({
url: '..',
@@ -637,7 +640,7 @@
else if ( "eventReport" == dashboardItem.type )
{
$d.append( $.tmpl( dhis2.db.tmpl.reportTableItem, { "itemId": dashboardItem.id, "id": dashboardItem.reportTable.id, "name": dashboardItem.reportTable.name, "style": style,
- "i18n_remove": i18n_remove, "i18n_view": i18n_view_full_size, "i18n_share": i18n_share_interpretation, "i18n_click_and_drag_to_new_position": i18n_click_and_drag_to_new_position } ) );
+ "i18n_remove": i18n_remove, "i18n_share": i18n_share_interpretation, "i18n_click_and_drag_to_new_position": i18n_click_and_drag_to_new_position } ) );
DHIS.getEventReport({
url: '..',
@@ -1083,11 +1086,16 @@
$( "#chartImage" ).attr( "src", url );
+ var link = dhis2.db.contextPath + url.substring( 2 );
+
+ $( "#chartImageUrl" ).html( link );
+ $( "#chartImageUrl" ).attr( "href", link );
+
$( "#chartView" ).dialog( {
autoOpen : true,
modal : true,
- height : height + 65,
- width : width + 25,
+ height : height + 110,
+ width : width + 40,
resizable : false,
title : title
} );
@@ -1112,3 +1120,13 @@
title : title
} );
}
+
+dhis2.db.downloadImage = function()
+{
+ var url = $( "#chartImage" ).attr( "src" );
+
+ if ( url ) {
+ url = url + "&attachment=true";
+ window.location.href = url;
+ }
+}
=== modified file 'dhis-2/dhis-web/dhis-web-dashboard-integration/src/main/webapp/dhis-web-dashboard-integration/style/dashboard.css'
--- dhis-2/dhis-web/dhis-web-dashboard-integration/src/main/webapp/dhis-web-dashboard-integration/style/dashboard.css 2015-01-14 14:29:24 +0000
+++ dhis-2/dhis-web/dhis-web-dashboard-integration/src/main/webapp/dhis-web-dashboard-integration/style/dashboard.css 2015-01-14 16:58:34 +0000
@@ -340,6 +340,19 @@
margin: 0;
}
+#chartViewHeader
+{
+ border-bottom: 1px solid #e0e0e0;
+ padding: 2px 5px 5px 3px;
+ margin: 6px 6px;
+}
+
+#chartViewHeader a
+{
+ color: #3162C5;
+ margin-right: 5px;
+}
+
.gridTable th
{
text-align: center;