← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 16286: Allow to select any time period in the past for lock exceptions.

 

------------------------------------------------------------
revno: 16286
committer: Tran Chau<tran.hispvietnam@xxxxxxxxx>
branch nick: dhis2
timestamp: Thu 2014-07-31 21:17:58 +0700
message:
  Allow to select any time period in the past for lock exceptions.
removed:
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/java/org/hisp/dhis/dataadmin/action/lockexception/GetPeriodsAction.java
modified:
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/resources/META-INF/dhis/beans.xml
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/resources/org/hisp/dhis/dataadmin/i18n_module.properties
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/resources/struts.xml
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/webapp/dhis-web-maintenance-dataadmin/addLockExceptionForm.vm
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/webapp/dhis-web-maintenance-dataadmin/javascript/lockException.js
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/webapp/dhis-web-maintenance-dataadmin/jsonDataSets.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
=== removed file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/java/org/hisp/dhis/dataadmin/action/lockexception/GetPeriodsAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/java/org/hisp/dhis/dataadmin/action/lockexception/GetPeriodsAction.java	2014-03-18 08:10:10 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/java/org/hisp/dhis/dataadmin/action/lockexception/GetPeriodsAction.java	1970-01-01 00:00:00 +0000
@@ -1,123 +0,0 @@
-package org.hisp.dhis.dataadmin.action.lockexception;
-
-/*
- * Copyright (c) 2004-2014, 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.Date;
-import java.util.List;
-
-import org.hisp.dhis.dataset.DataSet;
-import org.hisp.dhis.dataset.DataSetService;
-import org.hisp.dhis.i18n.I18nFormat;
-import org.hisp.dhis.period.CalendarPeriodType;
-import org.hisp.dhis.period.Period;
-import org.hisp.dhis.period.PeriodType;
-import org.hisp.dhis.system.filter.PastAndCurrentPeriodFilter;
-import org.hisp.dhis.system.util.FilterUtils;
-
-import com.opensymphony.xwork2.Action;
-
-/**
- * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
- */
-public class GetPeriodsAction
-    implements Action
-{
-    // -------------------------------------------------------------------------
-    // Dependencies
-    // -------------------------------------------------------------------------
-
-    private DataSetService dataSetService;
-
-    public void setDataSetService( DataSetService dataSetService )
-    {
-        this.dataSetService = dataSetService;
-    }
-
-    private I18nFormat format;
-
-    public void setFormat( I18nFormat format )
-    {
-        this.format = format;
-    }
-
-    // -------------------------------------------------------------------------
-    // Input & Output
-    // -------------------------------------------------------------------------
-
-    private int id;
-
-    public void setId( int id )
-    {
-        this.id = id;
-    }
-
-    private List<Period> periods;
-
-    public List<Period> getPeriods()
-    {
-        return periods;
-    }
-
-    // -------------------------------------------------------------------------
-    // Action Implementation
-    // -------------------------------------------------------------------------
-
-    @Override
-    public String execute() throws Exception
-    {
-        periods = getPeriodsForDataSet( id );
-
-        for ( Period period : periods )
-        {
-            period.setName( format.formatPeriod( period ) );
-        }
-
-        return SUCCESS;
-    }
-
-    private List<Period> getPeriodsForDataSet( int id )
-    {
-        DataSet dataSet = dataSetService.getDataSet( id );
-
-        if ( dataSet == null || dataSet.getPeriodType() == null )
-        {
-            return new ArrayList<Period>();
-        }
-
-        CalendarPeriodType periodType = (CalendarPeriodType) PeriodType.getPeriodTypeByName( dataSet.getPeriodType().getName() );
-
-        List<Period> periods = periodType.generateLast5Years( new Date() );
-        FilterUtils.filter( periods, new PastAndCurrentPeriodFilter() );
-        Collections.reverse( periods );
-
-        return periods;
-    }
-}

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/resources/META-INF/dhis/beans.xml'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/resources/META-INF/dhis/beans.xml	2014-07-29 07:52:47 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/resources/META-INF/dhis/beans.xml	2014-07-31 14:17:58 +0000
@@ -272,12 +272,6 @@
     <property name="organisationUnitService" ref="org.hisp.dhis.organisationunit.OrganisationUnitService" />
   </bean>
 
-  <bean id="org.hisp.dhis.dataadmin.action.lockexception.GetPeriodsAction"
-    class="org.hisp.dhis.dataadmin.action.lockexception.GetPeriodsAction"
-    scope="prototype">
-    <property name="dataSetService" ref="org.hisp.dhis.dataset.DataSetService" />
-  </bean>
-
   <bean id="org.hisp.dhis.dataadmin.action.lockexception.PrepareBatchRemovalAction"
     class="org.hisp.dhis.dataadmin.action.lockexception.PrepareBatchRemovalAction"
     scope="prototype">

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/resources/org/hisp/dhis/dataadmin/i18n_module.properties'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/resources/org/hisp/dhis/dataadmin/i18n_module.properties	2014-07-29 07:52:47 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/resources/org/hisp/dhis/dataadmin/i18n_module.properties	2014-07-31 14:17:58 +0000
@@ -359,4 +359,6 @@
 add_option = Add option
 edit_option = Edit option
 sort_options = Sort options
-available_options = Available options
\ No newline at end of file
+available_options = Available options
+please_select_a_dataset = Please select a dataset
+please_select_an_organisation_unit = Please select an organisation unit
\ No newline at end of file

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/resources/struts.xml'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/resources/struts.xml	2014-07-29 07:52:47 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/resources/struts.xml	2014-07-31 14:17:58 +0000
@@ -460,7 +460,8 @@
     <action name="showAddLockExceptionForm" class="org.hisp.dhis.dataadmin.action.NoAction">
       <result name="success" type="velocity">/main.vm</result>
       <param name="menu">/dhis-web-maintenance-dataadmin/menu.vm</param>
-      <param name="page">/dhis-web-maintenance-dataadmin/addLockExceptionForm.vm</param>
+      <param name="page">/dhis-web-maintenance-dataadmin/addLockExceptionForm.vm</param>      
+      <param name="javascripts">javascript/dataArchive.js</param>
       <param name="anyAuthorities">F_DATASET_PUBLIC_ADD, F_DATASET_PRIVATE_ADD</param>
     </action>
 
@@ -475,11 +476,6 @@
       <param name="onExceptionReturn">plainTextError</param>
     </action>
 
-    <action name="getPeriods" class="org.hisp.dhis.dataadmin.action.lockexception.GetPeriodsAction">
-      <result name="success" type="velocity-json">jsonPeriods.vm</result>
-      <param name="onExceptionReturn">plainTextError</param>
-    </action>
-
     <action name="getLockException" class="org.hisp.dhis.dataadmin.action.lockexception.GetLockExceptionAction">
       <result name="success" type="velocity-json">jsonLockException.vm</result>
       <param name="onExceptionReturn">plainTextError</param>

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/webapp/dhis-web-maintenance-dataadmin/addLockExceptionForm.vm'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/webapp/dhis-web-maintenance-dataadmin/addLockExceptionForm.vm	2012-02-13 04:51:23 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/webapp/dhis-web-maintenance-dataadmin/addLockExceptionForm.vm	2014-07-31 14:17:58 +0000
@@ -16,16 +16,18 @@
     <tr>
         <td>
             <select id="dataSets" name="dataSetId" disabled="disabled" style="width: 100%;">
-                <option>-- Please select an organisation unit --</option>
+                <option>-- $i18n.getString("please_select_an_organisation_unit") --</option>
             </select>
         </td>
     </tr>
 
     <tr>
         <td>
-            <select id="periods" name="periodId" disabled="disabled" style="width: 100%;">
-                <option>-- Please select a dataset --</option>
+            <select id="periods" name="periodId" disabled="disabled" style="width:58%;">
+                <option>-- $i18n.getString("please_select_a_dataset") --</option>
             </select>
+			<input type='button' id='prevPeriod' disabled="disabled" value="$i18n.getString('prev_year')" onclick="previousPeriodsSelected();" style="width: 20%;"/>
+			<input type='button' id='nextPeriod' disabled="disabled" value="$i18n.getString('next_year')" onclick="nextPeriodsSelected();" style="width: 20%;" />
         </td>
     </tr>
 

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/webapp/dhis-web-maintenance-dataadmin/javascript/lockException.js'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/webapp/dhis-web-maintenance-dataadmin/javascript/lockException.js	2013-09-27 13:45:21 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/webapp/dhis-web-maintenance-dataadmin/javascript/lockException.js	2014-07-31 14:17:58 +0000
@@ -8,7 +8,7 @@
     // arguments is only "array-like", so it doesnt have splice
     var args = Array.prototype.slice.call(arguments);
     var selectedOus = args.splice(1, args.length);
-
+    
     jQuery("#organisationUnitId").val(selectedOus.join(','));
 
     jQuery.getJSON('getDataSets.action?id=' + selectedOus.join(','), function ( data ) {
@@ -18,8 +18,7 @@
             resetDataSets();
         } else {
             for ( var n in data.dataSets ) {
-                var option = jQuery("<option />").attr("value", data.dataSets[n].id).text(data.dataSets[n].name)
-                jQuery("#dataSets").append(option);
+				jQuery("#dataSets").append("<option value='" +  data.dataSets[n].id + "' periodType='" + data.dataSets[n].periodType + "' allowFuturePeriods='" + data.dataSets[n].allowFuturePeriods + "'>" + data.dataSets[n].name + "</option>");
             }
 
             jQuery("#dataSets").removeAttr("disabled");
@@ -32,22 +31,13 @@
 function dataSetChanged( e ) {
     var dataSetId = jQuery("#dataSets option:selected").val();
     jQuery("#periods").children().remove();
+	currentPeriodOffset = 0;
 
     if ( !isNaN(dataSetId) ) {
-        jQuery.getJSON('getPeriods.action?id=' + dataSetId, function ( data ) {
-            if ( data.periods.length == 0 ) {
-                resetPeriods();
-            } else {
-                for ( var n in data.periods ) {
-                    var option = jQuery("<option />").attr("value", data.periods[n].id).text(data.periods[n].name);
-                    jQuery("#periods").append(option);
-                }
-
-                jQuery("#periods").removeAttr("disabled");
-            }
-
-            jQuery("#periods").trigger("change");
-        });
+       displayPeriods();
+	   enable('periods');
+	   enable('prevPeriod');
+	   enable('nextPeriod');
     } else {
         resetPeriods();
         jQuery("#periods").trigger("change");
@@ -64,8 +54,57 @@
 
 function resetDataSets() {
     jQuery("#dataSets").append("<option>-- Please select an organisation unit with a dataset --</option>").attr("disabled", true);
+	disable('prevPeriod');
+	disable('nextPeriod');
 }
 
 function resetPeriods() {
     jQuery("#periods").append("<option>-- Please select a dataset --</option>").attr("disabled", true);
+	disable('prevPeriod');
+	disable('nextPeriod');
+}
+
+/**
+ * Handles the onClick event for the next period button.
+ */
+var currentPeriodOffset = 0;
+
+function nextPeriodsSelected()
+{
+	if( currentPeriodOffset < 0 )
+	{
+		currentPeriodOffset++;
+		displayPeriods();
+	}
+}
+
+/**
+ * Handles the onClick event for the previous period button.
+ */
+function previousPeriodsSelected()
+{
+	currentPeriodOffset--;
+    displayPeriods();
+}
+
+/**
+ * Generates the period select list options.
+ */
+function displayPeriods()
+{
+    var periodType = $( '#dataSets option:selected' ).attr( "periodType" )
+    var allowFuturePeriods = $( '#dataSets option:selected' ).attr( "allowFuturePeriods" );
+    var periods = dhis2.period.generator.generateReversedPeriods(periodType,currentPeriodOffset);
+
+    if ( allowFuturePeriods == "false" )
+    {
+        periods = dhis2.period.generator.filterFuturePeriods( periods );
+    }
+
+    clearListById( 'periods' );
+
+    for( var i in periods )
+    {
+        jQuery("#periods").append("<option value='" + periods[i].iso + "' >" + periods[i].name  + "</option>" );
+    }
 }

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/webapp/dhis-web-maintenance-dataadmin/jsonDataSets.vm'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/webapp/dhis-web-maintenance-dataadmin/jsonDataSets.vm	2012-02-08 12:04:46 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/webapp/dhis-web-maintenance-dataadmin/jsonDataSets.vm	2014-07-31 14:17:58 +0000
@@ -3,7 +3,9 @@
 #foreach( $dataSet in $dataSets )
   {
     "id": $!{dataSet.id},
-    "name": "$!encoder.jsonEncode( ${dataSet.displayName} )"
+    "name": "$!encoder.jsonEncode( ${dataSet.displayName} )",
+	"periodType": "$!{dataSet.periodType.name}",
+	"allowFuturePeriods": "$!{dataSet.allowFuturePeriods}"
   }#if( $velocityCount < $size ),#end
 #end
 ] }