← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 7633: (DV) 'Rewind one period' option when selecting relative periods. Work in progress.

 

Merge authors:
  Jan Henrik Øverland (janhenrik-overland)
------------------------------------------------------------
revno: 7633 [merge]
committer: Jan Henrik Overland <janhenrik.overland@xxxxxxxxx>
branch nick: dhis2
timestamp: Wed 2012-07-18 16:31:40 +0200
message:
  (DV) 'Rewind one period' option when selecting relative periods. Work in progress.
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/RelativePeriods.java
  dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/ChartPluginController.java
  dhis-2/dhis-web/dhis-web-visualizer/src/main/resources/org/hisp/dhis/visualizer/i18n_module.properties
  dhis-2/dhis-web/dhis-web-visualizer/src/main/webapp/dhis-web-visualizer/app/css/style.css
  dhis-2/dhis-web/dhis-web-visualizer/src/main/webapp/dhis-web-visualizer/app/scripts/app.js


--
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-api/src/main/java/org/hisp/dhis/period/RelativePeriods.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/RelativePeriods.java	2012-05-08 18:53:35 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/RelativePeriods.java	2012-07-18 14:27:53 +0000
@@ -471,6 +471,144 @@
         
         return periods;
     }
+
+    /**
+     * Gets a list of Periods based on the given input and the state of this
+     * RelativePeriods.
+     *
+     * @param date the date representing now. If null the current date will be
+     *        used and an interval based on the period type will be subtracted 
+     *        from the date.
+     * @param format the i18n format.
+     * @return a list of relative Periods.
+     */
+    public List<Period> getRelativePeriods( I18nFormat format, boolean dynamicNames, Integer rewindedPeriods )
+    {
+        rewindedPeriods = rewindedPeriods == null ? 0 : rewindedPeriods;
+    
+        Date date = subtractMonth( 1, new Date() );
+        
+        List<Period> periods = new ArrayList<Period>();
+        
+        boolean rewind = true;
+
+        if ( isReportingMonth() )
+        {
+            periods.add( getRelativePeriod( new MonthlyPeriodType(), REPORTING_MONTH, rewind ? subtractMonth( rewindedPeriods, date ) : date, dynamicNames, format ) );
+            
+            rewind = false;
+        }
+
+        if ( isReportingBimonth() )
+        {
+            periods.add( getRelativePeriod( new BiMonthlyPeriodType(), REPORTING_BIMONTH, date, dynamicNames, format ) );
+        }
+
+        if ( isReportingQuarter() )
+        {
+            periods.add( getRelativePeriod( new QuarterlyPeriodType(), REPORTING_QUARTER, rewind ? subtractQuarters( rewindedPeriods, date ) : date, dynamicNames, format ) );
+            
+            rewind = false;
+        }
+
+        if ( isLastSixMonth() )
+        {
+            periods.add( getRelativePeriod( new SixMonthlyPeriodType(), LAST_SIXMONTH, rewind ? subtractSixmonths( rewindedPeriods, date ) : date, dynamicNames, format ) );
+            
+            rewind = false;
+        }
+
+        if ( isMonthsThisYear() )
+        {
+            periods.addAll( getRelativePeriodList( new MonthlyPeriodType(), MONTHS_THIS_YEAR, date, dynamicNames, format ) );
+        }
+
+        if ( isQuartersThisYear() )
+        {
+            periods.addAll( getRelativePeriodList( new QuarterlyPeriodType(), QUARTERS_THIS_YEAR, date, dynamicNames, format ) );
+        }
+
+        if ( isThisYear() )
+        {
+            periods.add( getRelativePeriod( new YearlyPeriodType(), THIS_YEAR, rewind ? subtractYears( rewindedPeriods, date ) : date, dynamicNames, format ) );
+            
+            rewind = false;
+        }
+
+        if ( isLast5Years() )
+        {
+            periods.addAll( getRollingRelativePeriodList( new YearlyPeriodType(), LAST_5_YEARS, rewind ? subtractYears( rewindedPeriods, date ) : date, dynamicNames, format ) );
+            
+            rewind = false;
+        }
+
+        if ( isLast12Months() )
+        {
+            periods.addAll( getRollingRelativePeriodList( new MonthlyPeriodType(), MONTHS_LAST_12, rewind ? subtractMonth( rewindedPeriods, date ) : date, dynamicNames, format ) );
+            
+            rewind = false;
+        }
+
+        if ( isLast6BiMonths() )
+        {
+            periods.addAll( getRollingRelativePeriodList( new BiMonthlyPeriodType(), BIMONTHS_LAST_6, date, dynamicNames, format ) );
+        }
+
+        if ( isLast4Quarters() )
+        {
+            periods.addAll( getRollingRelativePeriodList( new QuarterlyPeriodType(), QUARTERS_THIS_YEAR, rewind ? subtractQuarters( rewindedPeriods, date ) : date, dynamicNames, format ) );
+            
+            rewind = false;
+        }
+
+        if ( isLast2SixMonths() )
+        {
+            periods.addAll( getRollingRelativePeriodList( new SixMonthlyPeriodType(), SIXMONHTS_LAST_2, rewind ? subtractSixmonths( rewindedPeriods, date ) : date, dynamicNames, format ) );
+            
+            rewind = false;
+        }
+
+        if ( isThisFinancialYear() )
+        {
+            periods.add( getRelativePeriod( new FinancialJulyPeriodType(), THIS_FINANCIAL_YEAR, date, dynamicNames, format ) );
+        }
+
+        if ( isLast5FinancialYears() )
+        {
+            periods.addAll( getRollingRelativePeriodList( new FinancialJulyPeriodType(), LAST_5_FINANCIAL_YEARS, date, dynamicNames, format ) );
+        }
+
+        if ( isLast52Weeks() )
+        {
+            periods.addAll( getRollingRelativePeriodList( new WeeklyPeriodType(), WEEKS_LAST_52, date, dynamicNames, format ) );
+        }
+        
+        date = subtractMonth( MONTHS_IN_YEAR, date );
+
+        if ( isMonthsLastYear() )
+        {
+            periods.addAll( getRelativePeriodList( new MonthlyPeriodType(), MONTHS_LAST_YEAR, date, dynamicNames, format ) );
+        }
+
+        if ( isQuartersLastYear() )
+        {
+            periods.addAll( getRelativePeriodList( new QuarterlyPeriodType(), QUARTERS_LAST_YEAR, date, dynamicNames, format ) );
+        }
+
+        if ( isLastYear() )
+        {
+            periods.add( getRelativePeriod( new YearlyPeriodType(), LAST_YEAR, rewind ? subtractYears( rewindedPeriods, date ) : date, dynamicNames, format ) );
+            
+            rewind = false;
+        }
+        
+        if ( isLastFinancialYear() )
+        {
+            periods.add( getRelativePeriod( new FinancialJulyPeriodType(), LAST_FINANCIAL_YEAR, date, dynamicNames, format ) );
+        }
+        
+        return periods;
+    }
     
     /**
      * Returns periods for the last 6 months based on the given period types.
@@ -638,6 +776,51 @@
         return cal.getTime();
     }
 
+    /**
+     * Returns a date.
+     *
+     * @param months the number of months to subtract from the current date.
+     * @param date the date representing now, ignored if null.
+     * @return a date.
+     */
+    private Date subtractQuarters( int quarters, Date date )
+    {
+        Calendar cal = PeriodType.createCalendarInstance( date );
+        cal.add( Calendar.MONTH, (quarters * 3 * -1) );
+
+        return cal.getTime();
+    }
+
+    /**
+     * Returns a date.
+     *
+     * @param months the number of months to subtract from the current date.
+     * @param date the date representing now, ignored if null.
+     * @return a date.
+     */
+    private Date subtractSixmonths( int sixmonths, Date date )
+    {
+        Calendar cal = PeriodType.createCalendarInstance( date );
+        cal.add( Calendar.MONTH, (sixmonths * 6 * -1) );
+
+        return cal.getTime();
+    }
+
+    /**
+     * Returns a date.
+     *
+     * @param months the number of months to subtract from the current date.
+     * @param date the date representing now, ignored if null.
+     * @return a date.
+     */
+    private Date subtractYears( int years, Date date )
+    {
+        Calendar cal = PeriodType.createCalendarInstance( date );
+        cal.add( Calendar.YEAR, (years * -1) );
+
+        return cal.getTime();
+    }
+
     // -------------------------------------------------------------------------
     // Getters & setters
     // -------------------------------------------------------------------------

=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/ChartPluginController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/ChartPluginController.java	2012-07-10 11:50:19 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/ChartPluginController.java	2012-07-18 14:27:53 +0000
@@ -122,6 +122,7 @@
         @RequestParam( required = false ) boolean userOrganisationUnit,
         @RequestParam( required = false ) boolean userOrganisationUnitChildren,
         @RequestParam( required = false ) boolean periodIsFilter,
+        @RequestParam( required = false ) boolean rewind,
         RelativePeriods relativePeriods, Model model, HttpServletResponse response ) throws Exception
     {
         ChartPluginValue chartValue = new ChartPluginValue();
@@ -132,7 +133,7 @@
         // Periods
         // ---------------------------------------------------------------------
         
-        List<Period> periods = relativePeriods.getRelativePeriods();
+        List<Period> periods = relativePeriods.getRelativePeriods( null, false, rewind ? 1 : 0 );
 
         if ( p != null && p.size() > 0 )
         {

=== modified file 'dhis-2/dhis-web/dhis-web-visualizer/src/main/resources/org/hisp/dhis/visualizer/i18n_module.properties'
--- dhis-2/dhis-web/dhis-web-visualizer/src/main/resources/org/hisp/dhis/visualizer/i18n_module.properties	2012-07-10 17:15:05 +0000
+++ dhis-2/dhis-web/dhis-web-visualizer/src/main/resources/org/hisp/dhis/visualizer/i18n_module.properties	2012-07-18 14:27:53 +0000
@@ -38,8 +38,8 @@
 chart_options=Chart options
 png_only=For the PNG version only
 trend_line=Show trend line
-hide_subtitle=Hide subtitle
-hide_legend=Hide legend
+hide_subtitle=Hide chart subtitle
+hide_legend=Hide chart legend
 user_orgunit=User organisation unit
 domain_axis_label=Domain axis (X) label
 range_axis_label=Range axis (Y) label

=== modified file 'dhis-2/dhis-web/dhis-web-visualizer/src/main/webapp/dhis-web-visualizer/app/css/style.css'
--- dhis-2/dhis-web/dhis-web-visualizer/src/main/webapp/dhis-web-visualizer/app/css/style.css	2012-07-02 14:01:54 +0000
+++ dhis-2/dhis-web/dhis-web-visualizer/src/main/webapp/dhis-web-visualizer/app/css/style.css	2012-07-18 14:27:53 +0000
@@ -537,7 +537,7 @@
 .dv-label-period-heading {
     font-size: 11px;
     font-weight: bold;
-    color: #444;
+    color: #333;
     line-height: 20px;
 }
 

=== modified file 'dhis-2/dhis-web/dhis-web-visualizer/src/main/webapp/dhis-web-visualizer/app/scripts/app.js'
--- dhis-2/dhis-web/dhis-web-visualizer/src/main/webapp/dhis-web-visualizer/app/scripts/app.js	2012-07-17 10:28:16 +0000
+++ dhis-2/dhis-web/dhis-web-visualizer/src/main/webapp/dhis-web-visualizer/app/scripts/app.js	2012-07-18 14:27:53 +0000
@@ -1604,7 +1604,6 @@
 						if (f.periods) {
 							for (var i = 0; i < f.periods.length; i++) {
 								DV.c.fixedperiod.records.push({id: f.periods[i].id, name: DV.conf.util.jsonEncodeString(f.periods[i].name)});
-								//DV.c.fixedperiod.records.push({id: f.periods[i], name: f.periods[i]});
 							}
 						}							
 						
@@ -1697,6 +1696,7 @@
             }
         },
         setOptions: function() {
+			DV.c.relativeperiod.rewind = DV.cmp.dimension.relativeperiod.rewind.getValue();
             DV.c.hidesubtitle = DV.cmp.favorite.hidesubtitle.getValue();
             DV.c.hidelegend = DV.cmp.favorite.hidelegend.getValue();
             DV.c.trendline = DV.cmp.favorite.trendline.getValue();
@@ -2033,7 +2033,8 @@
             params = {
 				periodIsFilter: (DV.c.dimension.filter === DV.conf.finals.dimension.period.value),
 				userOrganisationUnit: DV.c.userorganisationunit,
-				userOrganisationUnitChildren: DV.c.userorganisationunitchildren
+				userOrganisationUnitChildren: DV.c.userorganisationunitchildren,
+				rewind: DV.c.relativeperiod.rewind
 			};
 			if (DV.c.organisationunit.groupsetid) {
 				params.organisationUnitGroupSetId = DV.c.organisationunit.groupsetid;
@@ -2088,6 +2089,7 @@
 			dataelement: {},
 			dataset: {},
 			relativeperiod: {},
+			rewind: false,
 			fixedperiod: {},
 			organisationunit: {},
 			hidesubtitle: false,
@@ -3285,6 +3287,32 @@
 																boxLabel: DV.i18n.last_5_years
 															}
 														]
+													},
+													{
+														xtype: 'panel',
+														layout: 'anchor',
+														bodyStyle: 'border-style:none; padding:5px 0 0 46px',
+														defaults: {
+															labelSeparator: ''
+														},
+														items: [
+															{
+																xtype: 'label',
+																text: 'Options',
+																cls: 'dv-label-period-heading',
+																style: 'color:#666'
+															},
+															{
+																xtype: 'checkbox',
+																paramName: 'rewind',
+																boxLabel: 'Rewind one period',
+																listeners: {
+																	added: function() {
+																		DV.cmp.dimension.relativeperiod.rewind = this;
+																	}
+																}
+															}
+														]
 													}
 												]
 											}