------------------------------------------------------------ revno: 2715 committer: Lars Helge Overland <larshe...@gmail.com> branch nick: dhis2 timestamp: Fri 2011-01-21 19:49:34 +0100 message: Added proper json encoding for web pivot table added: dhis-2/dhis-web/dhis-web-reporting/src/main/java/org/hisp/dhis/reporting/pivottable/action/GetPivotTableOptionsAction.java modified: dhis-2/dhis-web/dhis-web-reporting/src/main/resources/META-INF/dhis/beans.xml dhis-2/dhis-web/dhis-web-reporting/src/main/resources/struts.xml dhis-2/dhis-web/dhis-web-reporting/src/main/webapp/dhis-web-reporting/javascript/criteria.js dhis-2/dhis-web/dhis-web-reporting/src/main/webapp/dhis-web-reporting/javascript/pivot.js dhis-2/dhis-web/dhis-web-reporting/src/main/webapp/dhis-web-reporting/responsePivotTable.vm dhis-2/dhis-web/dhis-web-reporting/src/main/webapp/dhis-web-reporting/viewPivotTableForm.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
=== added file 'dhis-2/dhis-web/dhis-web-reporting/src/main/java/org/hisp/dhis/reporting/pivottable/action/GetPivotTableOptionsAction.java' --- dhis-2/dhis-web/dhis-web-reporting/src/main/java/org/hisp/dhis/reporting/pivottable/action/GetPivotTableOptionsAction.java 1970-01-01 00:00:00 +0000 +++ dhis-2/dhis-web/dhis-web-reporting/src/main/java/org/hisp/dhis/reporting/pivottable/action/GetPivotTableOptionsAction.java 2011-01-21 18:49:34 +0000 @@ -0,0 +1,78 @@ +package org.hisp.dhis.reporting.pivottable.action; + +/* + * Copyright (c) 2004-2010, 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.util.ArrayList; +import java.util.Collections; +import java.util.List; + +import org.hisp.dhis.indicator.IndicatorGroup; +import org.hisp.dhis.indicator.IndicatorService; +import org.hisp.dhis.indicator.comparator.IndicatorGroupNameComparator; +import org.hisp.dhis.period.PeriodType; + +import com.opensymphony.xwork2.Action; + +/** + * @author Lars Helge Overland + */ +public class GetPivotTableOptionsAction + implements Action +{ + private IndicatorService indicatorService; + + public void setIndicatorService( IndicatorService indicatorService ) + { + this.indicatorService = indicatorService; + } + + private List<PeriodType> periodTypes = PeriodType.getAvailablePeriodTypes(); + + public List<PeriodType> getPeriodTypes() + { + return periodTypes; + } + + private List<IndicatorGroup> indicatorGroups = new ArrayList<IndicatorGroup>(); + + public List<IndicatorGroup> getIndicatorGroups() + { + return indicatorGroups; + } + + @Override + public String execute() + throws Exception + { + indicatorGroups = new ArrayList<IndicatorGroup>( indicatorService.getAllIndicatorGroups() ); + + Collections.sort( indicatorGroups, new IndicatorGroupNameComparator() ); + + return SUCCESS; + } +} === modified file 'dhis-2/dhis-web/dhis-web-reporting/src/main/resources/META-INF/dhis/beans.xml' --- dhis-2/dhis-web/dhis-web-reporting/src/main/resources/META-INF/dhis/beans.xml 2011-01-18 12:44:08 +0000 +++ dhis-2/dhis-web/dhis-web-reporting/src/main/resources/META-INF/dhis/beans.xml 2011-01-21 18:49:34 +0000 @@ -353,6 +353,13 @@ <!-- PivotTable --> + <bean id="org.hisp.dhis.reporting.pivottable.action.GetPivotTableOptionsAction" + class="org.hisp.dhis.reporting.pivottable.action.GetPivotTableOptionsAction" + scope="prototype"> + <property name="indicatorService" + ref="org.hisp.dhis.indicator.IndicatorService"/> + </bean> + <bean id="org.hisp.dhis.reporting.pivottable.action.GetPivotTableAction" class="org.hisp.dhis.reporting.pivottable.action.GetPivotTableAction" scope="prototype"> === modified file 'dhis-2/dhis-web/dhis-web-reporting/src/main/resources/struts.xml' --- dhis-2/dhis-web/dhis-web-reporting/src/main/resources/struts.xml 2011-01-21 16:22:50 +0000 +++ dhis-2/dhis-web/dhis-web-reporting/src/main/resources/struts.xml 2011-01-21 18:49:34 +0000 @@ -260,7 +260,7 @@ <!-- PivotTable --> - <action name="displayPivotTableForm" class="org.hisp.dhis.reporting.action.NoAction"> + <action name="displayPivotTableForm" class="org.hisp.dhis.reporting.pivottable.action.GetPivotTableOptionsAction"> <result name="success" type="velocity">/main.vm</result> <param name="page">/dhis-web-reporting/viewPivotTableForm.vm</param> <param name="menu">/dhis-web-reporting/menu.vm</param> === modified file 'dhis-2/dhis-web/dhis-web-reporting/src/main/webapp/dhis-web-reporting/javascript/criteria.js' --- dhis-2/dhis-web/dhis-web-reporting/src/main/webapp/dhis-web-reporting/javascript/criteria.js 2011-01-21 13:39:40 +0000 +++ dhis-2/dhis-web/dhis-web-reporting/src/main/webapp/dhis-web-reporting/javascript/criteria.js 2011-01-21 18:49:34 +0000 @@ -3,53 +3,6 @@ // Public methods // ------------------------------------------------------------------------- -function addOption( list, value, text ) -{ - var option = document.createElement( "option" ); - option.value = value; - option.text = text; - list.add( option, null ); -} - -function loadIndicatorGroups() -{ - var list = byId( "indicatorGroup" ); - - $.getJSON( - "getIndicatorGroups.action", - function( json ) - { - for ( var i=0; i<json.indicatorGroups.length; i++ ) - { - var id = json.indicatorGroups[i].id; - var name = json.indicatorGroups[i].name; - - addOption( list, id, name ); - } - } - ); -} - -function loadPeriodTypes() -{ - var list = byId( "periodType" ); - - $.getJSON( - "getPeriodTypes.action", - function( json ) - { - for ( var i=0; i<json.periodTypes.length; i++ ) - { - var name = json.periodTypes[i].name; - - addOption( list, name, name ); - } - - $( "#periodType option[value=Monthly]" ).attr( "selected", "selected" ); - } - ); -} - function showCriteria() { $( "div#criteria" ).show( "fast" ); === modified file 'dhis-2/dhis-web/dhis-web-reporting/src/main/webapp/dhis-web-reporting/javascript/pivot.js' --- dhis-2/dhis-web/dhis-web-reporting/src/main/webapp/dhis-web-reporting/javascript/pivot.js 2011-01-06 22:22:18 +0000 +++ dhis-2/dhis-web/dhis-web-reporting/src/main/webapp/dhis-web-reporting/javascript/pivot.js 2011-01-21 18:49:34 +0000 @@ -41,16 +41,12 @@ clearGlobalVariables(); var indicatorGroupId = $( "#indicatorGroup" ).val(); - var indicatorGroupName = $( "#indicatorGroup" ).text(); var startDate = $( "#startDate" ).val(); var endDate = $( "#endDate" ).val(); var periodTypeName = $( "#periodType" ).val(); - document.getElementById( "dataLabel" ).innerHTML = - i18n_indicator_group + ": " + indicatorGroupName + - ", " + i18n_start_date + ": " + startDate + - ", " + i18n_end_date + ": " + endDate + - ", " + i18n_period_type + ": " + periodTypeName; + document.getElementById( "dataLabel" ).innerHTML = i18n_start_date + ": " + startDate + + ", " + i18n_end_date + ": " + endDate + ", " + i18n_period_type + ": " + periodTypeName; var url = "getPivotTable.action"; === modified file 'dhis-2/dhis-web/dhis-web-reporting/src/main/webapp/dhis-web-reporting/responsePivotTable.vm' --- dhis-2/dhis-web/dhis-web-reporting/src/main/webapp/dhis-web-reporting/responsePivotTable.vm 2009-03-03 16:46:36 +0000 +++ dhis-2/dhis-web/dhis-web-reporting/src/main/webapp/dhis-web-reporting/responsePivotTable.vm 2011-01-21 18:49:34 +0000 @@ -6,27 +6,31 @@ "sizeOrganisationUnits": "$pivotTable.organisationUnits.size()", "indicators": [ + #set( $size = $pivotTable.indicators.size() ) #foreach( $indicator in $pivotTable.indicators ) - { "id": "${indicator.id}", "name": "${indicator.shortName}" }, + { "id": "${indicator.id}", "name": "$!encoder.jsonEncode( ${indicator.shortName} )" }#if( $velocityCount < $size ),#end #end ], "periods": [ + #set( $size = $pivotTable.periods.size() ) #foreach( $period in $pivotTable.periods ) - { "id": "${period.id}", "name": "${period.name}" }, + { "id": "${period.id}", "name": "$!encoder.jsonEncode( ${period.name} )" }#if( $velocityCount < $size ),#end #end ], "organisationUnits": [ + #set( $size = $pivotTable.organisationUnits.size() ) #foreach( $organisationUnit in $pivotTable.organisationUnits ) - { "id": "${organisationUnit.id}", "name": "${organisationUnit.shortName}" }, + { "id": "${organisationUnit.id}", "name": "$!encoder.jsonEncode( ${organisationUnit.shortName} )" }#if( $velocityCount < $size ),#end #end ], "indicatorValues": [ { + #set( $size = $pivotTable.indicatorValues.size() ) #foreach( $value in $pivotTable.indicatorValues ) - "${value.indicatorId}-${value.periodId}-${value.organisationUnitId}": "${value.value}", + "${value.indicatorId}-${value.periodId}-${value.organisationUnitId}": "${value.value}"#if( $velocityCount < $size ),#end #end } ] === modified file 'dhis-2/dhis-web/dhis-web-reporting/src/main/webapp/dhis-web-reporting/viewPivotTableForm.vm' --- dhis-2/dhis-web/dhis-web-reporting/src/main/webapp/dhis-web-reporting/viewPivotTableForm.vm 2011-01-06 22:22:18 +0000 +++ dhis-2/dhis-web/dhis-web-reporting/src/main/webapp/dhis-web-reporting/viewPivotTableForm.vm 2011-01-21 18:49:34 +0000 @@ -76,6 +76,9 @@ <label>$i18n.getString( "indicator_group" )</label> <select id="indicatorGroup" style="width:250px"> <option value="-1">[ All ]</option> + #foreach( $group in $indicatorGroups ) + <option value="${group.id}">$encoder.htmlEncode( $group.name )</option> + #end </select> </p> @@ -91,7 +94,11 @@ <p> <label>$i18n.getString( "period_type" )</label> -<select id="periodType" style="width:250px"></select> +<select id="periodType" style="width:250px"> + #foreach( $type in $periodTypes ) + <option value="${type.name}" #if( $type.name == "Monthly" )selected="selected"#end>$encoder.htmlEncode( $type.name )</option> + #end +</select> </p> <p> @@ -167,8 +174,6 @@ <!-- Init page --> <script type="text/javascript"> - loadIndicatorGroups(); - loadPeriodTypes(); loadListeners(); selectionTreeSelection.setMultipleSelectionAllowed( false );
_______________________________________________ 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