=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/caseaggregation/LoadPeriodsAction.java' --- dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/caseaggregation/LoadPeriodsAction.java 2010-12-03 06:08:58 +0000 +++ dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/caseaggregation/LoadPeriodsAction.java 2011-01-05 01:13:23 +0000 @@ -7,6 +7,7 @@ import java.util.Iterator; import java.util.List; +import org.hisp.dhis.caseentry.state.PeriodGenericManager; import org.hisp.dhis.dataelement.DataElement; import org.hisp.dhis.dataset.DataSet; import org.hisp.dhis.dataset.DataSetService; @@ -29,6 +30,13 @@ this.dataSetService = dataSetService; } + private PeriodGenericManager periodGenericManager; + + public void setPeriodGenericManager( PeriodGenericManager periodGenericManager ) + { + this.periodGenericManager = periodGenericManager; + } + // ------------------------------------------------------------------------- // Input // ------------------------------------------------------------------------- @@ -73,6 +81,11 @@ { DataSet selectedDataSet = dataSetService.getDataSet( dataSetId ); + periodGenericManager.clearSelectedPeriod(); + periodGenericManager.clearBasePeriod(); + + periodGenericManager.setPeriodType( selectedDataSet.getPeriodType().getName() ); + if ( selectedDataSet != null ) { periods = getPeriodList( (CalendarPeriodType) selectedDataSet.getPeriodType() ); === added file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/state/DefaultPeriodGenericManager.java' --- dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/state/DefaultPeriodGenericManager.java 1970-01-01 00:00:00 +0000 +++ dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/state/DefaultPeriodGenericManager.java 2011-01-05 01:13:23 +0000 @@ -0,0 +1,205 @@ +package org.hisp.dhis.caseentry.state; + +/* + * 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.Date; +import java.util.Iterator; +import java.util.List; +import java.util.Map; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.hisp.dhis.period.CalendarPeriodType; +import org.hisp.dhis.period.Period; +import org.hisp.dhis.period.PeriodService; +import org.hisp.dhis.period.PeriodType; + +import com.opensymphony.xwork2.ActionContext; + +/** + * @author Chau Thu Tran + * @version $Id$ + */ +public class DefaultPeriodGenericManager + implements PeriodGenericManager +{ + + private static final Log log = LogFactory.getLog( DefaultPeriodGenericManager.class ); + + + public static final String SESSION_KEY_SELECTED_PERIOD_TYPE = "SESSION_KEY_SELECTED_PERIOD_TYPE"; + + // ------------------------------------------------------------------------- + // Dependencies + // ------------------------------------------------------------------------- + + private PeriodService periodService; + + public void setPeriodService( PeriodService periodService ) + { + this.periodService = periodService; + } + + + // ------------------------------------------------------------------------- + // Period + // ------------------------------------------------------------------------- + + public void setSelectedPeriodIndex( String key, Integer index ) + { + getSession().put( key, index ); + } + + public Integer getSelectedPeriodIndex( String key ) + { + return (Integer) getSession().get( key ); + } + + public Period getSelectedPeriod( String key, String baseKey ) + { + Integer index = getSelectedPeriodIndex( key ); + + if ( index == null ) + { + return null; + } + + List periods = getPeriodList( key, baseKey ); + + if ( index >= 0 && index < periods.size() ) + { + return periods.get( index ); + } + + return null; + } + + public void clearSelectedPeriod() + { + getSession().remove( SESSION_KEY_SELECTED_PERIOD_INDEX_START ); + getSession().remove( SESSION_KEY_SELECTED_PERIOD_INDEX_END ); + } + + public List getPeriodList( String key, String baseKey ) + { + Period basePeriod = getBasePeriod( baseKey ); + + CalendarPeriodType periodType = (CalendarPeriodType) getPeriodType(); + + List periods = periodType.generatePeriods( basePeriod ); + + Date now = new Date(); + + Iterator iterator = periods.iterator(); + + while ( iterator.hasNext() ) + { + if ( iterator.next().getStartDate().after( now ) ) + { + iterator.remove(); + } + } + + return periods; + } + + public void nextPeriodSpan( String key, String baseKey ) + { + List periods = getPeriodList( key, baseKey ); + CalendarPeriodType periodType = (CalendarPeriodType) getPeriodType(); + + Period basePeriod = periods.get( periods.size() - 1 ); + Period newBasePeriod = periodType.getNextPeriod( basePeriod ); + + if ( newBasePeriod.getStartDate().before( new Date() ) ) // Future periods not allowed + { + getSession().put( baseKey, newBasePeriod ); + } + } + + public void previousPeriodSpan( String key, String baseKey ) + { + List periods = getPeriodList(key, baseKey); + CalendarPeriodType periodType = (CalendarPeriodType) getPeriodType(); + + Period basePeriod = periods.get( 0 ); + Period newBasePeriod = periodType.getPreviousPeriod( basePeriod ); + + getSession().put( baseKey, newBasePeriod ); + } + + // ------------------------------------------------------------------------- + // Support methods + // ------------------------------------------------------------------------- + + private PeriodType getPeriodType() + { + return (PeriodType) getSession().get( SESSION_KEY_SELECTED_PERIOD_TYPE ); + } + + private Period getBasePeriod( String baseKey ) + { + Period basePeriod = (Period) getSession().get( baseKey ); + + PeriodType periodType = getPeriodType(); + + if ( basePeriod == null ) + { + log.debug( "Base period is null, creating new" ); + + basePeriod = periodType.createPeriod(); + getSession().put( baseKey, basePeriod ); + } + else if ( !basePeriod.getPeriodType().equals( periodType ) ) + { + log.debug( "Wrong type of base period, transforming" ); + + basePeriod = periodType.createPeriod( basePeriod.getStartDate() ); + getSession().put( baseKey, basePeriod ); + } + + return basePeriod; + } + + private static final Map getSession() + { + return ActionContext.getContext().getSession(); + } + + @Override + public void setPeriodType( String periodTypeName ) + { + getSession().put( SESSION_KEY_SELECTED_PERIOD_TYPE, periodService.getPeriodTypeByName( periodTypeName ) ); + } + + public void clearBasePeriod( ) + { + getSession().remove( SESSION_KEY_BASE_PERIOD_START ); + getSession().remove( SESSION_KEY_BASE_PERIOD_END ); + } +} === added file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/state/NextPeriodsAction.java' --- dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/state/NextPeriodsAction.java 1970-01-01 00:00:00 +0000 +++ dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/state/NextPeriodsAction.java 2011-01-05 01:13:23 +0000 @@ -0,0 +1,109 @@ +package org.hisp.dhis.caseentry.state; + +/* + * 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.List; + +import org.hisp.dhis.period.Period; + +import com.opensymphony.xwork2.Action; + +/** + * @author Torgeir Lorange Ostby + * @version $Id: NextPeriodsAction.java 2966 2007-03-03 14:38:20Z torgeilo $ * + * @modifier Dang Duy Hieu + * @since 2009-10-14 + */ +public class NextPeriodsAction + implements Action +{ + // ------------------------------------------------------------------------- + // Dependencies + // ------------------------------------------------------------------------- + + private PeriodGenericManager periodGenericManager; + + public void setPeriodGenericManager( PeriodGenericManager periodGenericManager ) + { + this.periodGenericManager = periodGenericManager; + } + + // ------------------------------------------------------------------------- + // Input && Output + // ------------------------------------------------------------------------- + + private boolean startField; + + public void setStartField( boolean startField ) + { + this.startField = startField; + } + + private List periods; + + public List getPeriods() + { + return periods; + } + + private Integer index; + + public void setIndex( Integer index ) + { + this.index = index; + } + + // ------------------------------------------------------------------------- + // Action implementation + // ------------------------------------------------------------------------- + + public String execute() + throws Exception + { + String selectedPeriodKey = ""; + String basePeriodKey = ""; + + if ( startField ) + { + selectedPeriodKey = PeriodGenericManager.SESSION_KEY_SELECTED_PERIOD_INDEX_START; + basePeriodKey = PeriodGenericManager.SESSION_KEY_BASE_PERIOD_START; + } + else + { + selectedPeriodKey = PeriodGenericManager.SESSION_KEY_SELECTED_PERIOD_INDEX_END; + basePeriodKey = PeriodGenericManager.SESSION_KEY_BASE_PERIOD_END; + } + + periodGenericManager.setSelectedPeriodIndex( selectedPeriodKey, index ); + periodGenericManager.nextPeriodSpan(selectedPeriodKey, basePeriodKey); + + periods = periodGenericManager.getPeriodList(selectedPeriodKey, basePeriodKey); + + return SUCCESS; + } +} === added file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/state/PeriodGenericManager.java' --- dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/state/PeriodGenericManager.java 1970-01-01 00:00:00 +0000 +++ dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/state/PeriodGenericManager.java 2011-01-05 01:13:23 +0000 @@ -0,0 +1,66 @@ +package org.hisp.dhis.caseentry.state; + +/* + * 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.List; + +import org.hisp.dhis.period.Period; + +/** + * @author Chau Thu Tran + * @version $Id$ + */ +public interface PeriodGenericManager +{ + + public static final String SESSION_KEY_BASE_PERIOD_START = "SESSION_KEY_BASE_PERIOD_START"; + public static final String SESSION_KEY_BASE_PERIOD_END = "SESSION_KEY_BASE_PERIOD_END"; + + public static final String SESSION_KEY_SELECTED_PERIOD_INDEX_START = "SESSION_KEY_SELECTED_PERIOD_INDEX_START"; + public static final String SESSION_KEY_SELECTED_PERIOD_INDEX_END = "SESSION_KEY_SELECTED_PERIOD_INDEX_END"; + + + public void setSelectedPeriodIndex( String key, Integer index ); + + public Integer getSelectedPeriodIndex( String key ); + + public Period getSelectedPeriod( String key, String baseKey ); + + public void setPeriodType( String periodTypeName ); + + public void clearSelectedPeriod( ); + + public void clearBasePeriod( ); + + public List getPeriodList( String key, String baseKey ); + + public void nextPeriodSpan( String key, String baseKey ); + + public void previousPeriodSpan( String key, String baseKey ); + +} === added file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/state/PreviousPeriodsAction.java' --- dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/state/PreviousPeriodsAction.java 1970-01-01 00:00:00 +0000 +++ dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/state/PreviousPeriodsAction.java 2011-01-05 01:13:23 +0000 @@ -0,0 +1,111 @@ +package org.hisp.dhis.caseentry.state; + +/* + * 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.List; + +import org.hisp.dhis.period.Period; + +import com.opensymphony.xwork2.Action; + +/** + * @author Torgeir Lorange Ostby + * @version $Id: PreviousPeriodsAction.java 2966 2007-03-03 14:38:20Z torgeilo $ + * * + * @modifier Dang Duy Hieu + * @since 2009-10-14 + */ +public class PreviousPeriodsAction + implements Action +{ + // ------------------------------------------------------------------------- + // Dependencies + // ------------------------------------------------------------------------- + + private PeriodGenericManager periodGenericManager; + + public void setPeriodGenericManager( PeriodGenericManager periodGenericManager ) + { + this.periodGenericManager = periodGenericManager; + } + + // ------------------------------------------------------------------------- + // Output + // ------------------------------------------------------------------------- + + private boolean startField; + + public void setStartField( boolean startField ) + { + this.startField = startField; + } + + private List periods; + + public List getPeriods() + { + return periods; + } + + private Integer index; + + public void setIndex( Integer index ) + { + this.index = index; + } + + // ------------------------------------------------------------------------- + // Action implementation + // ------------------------------------------------------------------------- + + public String execute() + throws Exception + { + String selectedPeriodKey = ""; + String basePeriodKey = ""; + + if ( startField ) + { + selectedPeriodKey = PeriodGenericManager.SESSION_KEY_SELECTED_PERIOD_INDEX_START; + basePeriodKey = PeriodGenericManager.SESSION_KEY_BASE_PERIOD_START; + } + else + { + selectedPeriodKey = PeriodGenericManager.SESSION_KEY_SELECTED_PERIOD_INDEX_END; + basePeriodKey = PeriodGenericManager.SESSION_KEY_BASE_PERIOD_END; + } + + periodGenericManager.setSelectedPeriodIndex( selectedPeriodKey, index ); + periodGenericManager.previousPeriodSpan( selectedPeriodKey, basePeriodKey ); + + periods = periodGenericManager.getPeriodList( selectedPeriodKey, basePeriodKey ); + + return SUCCESS; + } + +} === modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/resources/META-INF/dhis/beans.xml' --- dhis-2/dhis-web/dhis-web-caseentry/src/main/resources/META-INF/dhis/beans.xml 2010-12-04 00:17:59 +0000 +++ dhis-2/dhis-web/dhis-web-caseentry/src/main/resources/META-INF/dhis/beans.xml 2011-01-05 01:13:23 +0000 @@ -349,6 +349,7 @@ class="org.hisp.dhis.caseentry.action.caseaggregation.LoadPeriodsAction" scope="prototype"> + + + + + + + + + + + + + + === modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/resources/struts.xml' --- dhis-2/dhis-web/dhis-web-caseentry/src/main/resources/struts.xml 2010-12-09 03:09:38 +0000 +++ dhis-2/dhis-web/dhis-web-caseentry/src/main/resources/struts.xml 2011-01-05 01:13:23 +0000 @@ -237,6 +237,18 @@ /dhis-web-caseentry/caseAggregationResult.vm /dhis-web-caseentry/menu.vm + + + + /dhis-web-commons/ajax/jsonPeriods.vm + + + + + /dhis-web-commons/ajax/jsonPeriods.vm + === modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/caseAggregationForm.vm' --- dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/caseAggregationForm.vm 2010-12-03 06:08:58 +0000 +++ dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/caseAggregationForm.vm 2011-01-05 01:13:23 +0000 @@ -37,13 +37,15 @@ - + $i18n.getString( "from" ) - + + + @@ -52,7 +54,9 @@ $i18n.getString( "to" ) - + + + @@ -61,7 +65,7 @@ $i18n.getString( "ga_facilityby" ) - + "; + html = ""; }else { id = dataEntryId; - html = "" ; + html = "" ; } if( checkExisted( id ) )