← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 15095: add system DateFormat on the velocity stack, use in main.vm to set current date format in system ...

 

------------------------------------------------------------
revno: 15095
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Tue 2014-04-29 16:12:58 +0545
message:
  add system DateFormat on the velocity stack, use in main.vm to set current date format in system calendar
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/calendar/CalendarService.java
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/calendar/DefaultCalendarService.java
  dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/main.vm
  dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/interceptor/SystemSettingInterceptor.java


--
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/calendar/CalendarService.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/calendar/CalendarService.java	2014-04-29 10:10:17 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/calendar/CalendarService.java	2014-04-29 10:27:58 +0000
@@ -54,4 +54,11 @@
      * @return System calendar
      */
     Calendar getSystemCalendar();
+
+    /**
+     * Gets the currently selected date format.
+     * @return Date format
+     * @see DateFormat
+     */
+    DateFormat getSystemDateFormat();
 }

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/calendar/DefaultCalendarService.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/calendar/DefaultCalendarService.java	2014-04-29 10:10:17 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/calendar/DefaultCalendarService.java	2014-04-29 10:27:58 +0000
@@ -103,4 +103,20 @@
 
         return calendar;
     }
+
+    @Override
+    public DateFormat getSystemDateFormat()
+    {
+        String dateFormatKey = (String) settingManager.getSystemSetting( SystemSettingManager.KEY_DATE_FORMAT, SystemSettingManager.DEFAULT_DATE_FORMAT );
+
+        for ( DateFormat dateFormat : dateFormats )
+        {
+            if ( dateFormat.name().equals( dateFormatKey ) )
+            {
+                return dateFormat;
+            }
+        }
+
+        return dateFormats.get( 0 );
+    }
 }

=== modified file 'dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/main.vm'
--- dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/main.vm	2014-04-29 07:50:35 +0000
+++ dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/main.vm	2014-04-29 10:27:58 +0000
@@ -95,7 +95,7 @@
       #else
       dhis2.period.calendar = $.calendars.instance('$keyCalendar');
       #end
-      dhis2.period.generator = new dhis2.period.PeriodGenerator( dhis2.period.calendar, '$keyDateFormat' );
+      dhis2.period.generator = new dhis2.period.PeriodGenerator( dhis2.period.calendar, '$dateFormat.js' );
     </script>
   </head>
 

=== modified file 'dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/interceptor/SystemSettingInterceptor.java'
--- dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/interceptor/SystemSettingInterceptor.java	2014-04-29 07:50:35 +0000
+++ dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/interceptor/SystemSettingInterceptor.java	2014-04-29 10:27:58 +0000
@@ -30,8 +30,10 @@
 
 import com.opensymphony.xwork2.ActionInvocation;
 import com.opensymphony.xwork2.interceptor.Interceptor;
+import org.hisp.dhis.calendar.CalendarService;
 import org.hisp.dhis.configuration.ConfigurationService;
 import org.hisp.dhis.setting.SystemSettingManager;
+import org.springframework.beans.factory.annotation.Autowired;
 
 import java.util.HashMap;
 import java.util.Map;
@@ -64,6 +66,9 @@
         this.configurationService = configurationService;
     }
 
+    @Autowired
+    private CalendarService calendarService;
+
     // -------------------------------------------------------------------------
     // AroundInterceptor implementation
     // -------------------------------------------------------------------------
@@ -83,6 +88,7 @@
 
         map.put( KEY_CALENDAR, systemSettingManager.getSystemSetting( KEY_CALENDAR, DEFAULT_CALENDAR ) );
         map.put( KEY_DATE_FORMAT, systemSettingManager.getSystemSetting( KEY_DATE_FORMAT, DEFAULT_DATE_FORMAT ) );
+        map.put( "dateFormat", calendarService.getSystemDateFormat() );
         map.put( KEY_CACHE_STRATEGY, systemSettingManager.getSystemSetting( KEY_CACHE_STRATEGY, DEFAULT_CACHE_STRATEGY ) );
         map.put( KEY_APPLICATION_TITLE, systemSettingManager.getSystemSetting( KEY_APPLICATION_TITLE, DEFAULT_APPLICATION_TITLE ) );
         map.put( KEY_APPLICATION_INTRO, systemSettingManager.getSystemSetting( KEY_APPLICATION_INTRO ) );