svn commit: r927783 - in /ofbiz/trunk/applications/workeffort: config/WorkEffortUiLabels.xml src/org/ofbiz/workeffort/workeffort/WorkEffortServices.java webapp/workeffort/calendar/month.ftl

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

svn commit: r927783 - in /ofbiz/trunk/applications/workeffort: config/WorkEffortUiLabels.xml src/org/ofbiz/workeffort/workeffort/WorkEffortServices.java webapp/workeffort/calendar/month.ftl

jacopoc
Author: jacopoc
Date: Fri Mar 26 11:57:41 2010
New Revision: 927783

URL: http://svn.apache.org/viewvc?rev=927783&view=rev
Log:
Implemented new method to group a set of events by date ranges:
if event #1 starts at date A and ends at date C and event #2 starts at date B and ends at date D then the metod will return the following maps:
A-B: event #1
B-C: events #1 and #2
C-D: event #2

This is useful for example to get statistics about calendar events, for example the max number of concurrent events or the max number of persons allocated in the same time; I have added the latter to the month view as an example of its usage.

Modified:
    ofbiz/trunk/applications/workeffort/config/WorkEffortUiLabels.xml
    ofbiz/trunk/applications/workeffort/src/org/ofbiz/workeffort/workeffort/WorkEffortServices.java
    ofbiz/trunk/applications/workeffort/webapp/workeffort/calendar/month.ftl

Modified: ofbiz/trunk/applications/workeffort/config/WorkEffortUiLabels.xml
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/workeffort/config/WorkEffortUiLabels.xml?rev=927783&r1=927782&r2=927783&view=diff
==============================================================================
--- ofbiz/trunk/applications/workeffort/config/WorkEffortUiLabels.xml (original)
+++ ofbiz/trunk/applications/workeffort/config/WorkEffortUiLabels.xml Fri Mar 26 11:57:41 2010
@@ -2192,6 +2192,10 @@
         <value xml:lang="th">จำนวนมาก</value>
         <value xml:lang="zh">最大金额</value>
     </property>
+    <property key="WorkEffortMaxNumberOfPersons">
+        <value xml:lang="en">Max # of Persons</value>
+        <value xml:lang="it">Max numero di persone</value>
+    </property>
     <property key="WorkEffortMonthView">
         <value xml:lang="en">Month View</value>
         <value xml:lang="es">Vista por meses</value>

Modified: ofbiz/trunk/applications/workeffort/src/org/ofbiz/workeffort/workeffort/WorkEffortServices.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/workeffort/src/org/ofbiz/workeffort/workeffort/WorkEffortServices.java?rev=927783&r1=927782&r2=927783&view=diff
==============================================================================
--- ofbiz/trunk/applications/workeffort/src/org/ofbiz/workeffort/workeffort/WorkEffortServices.java (original)
+++ ofbiz/trunk/applications/workeffort/src/org/ofbiz/workeffort/workeffort/WorkEffortServices.java Fri Mar 26 11:57:41 2010
@@ -28,6 +28,8 @@ import java.util.Locale;
 import java.util.Map;
 import java.util.Set;
 import java.util.TimeZone;
+import java.util.TreeMap;
+import java.util.TreeSet;
 
 import javolution.util.FastList;
 import javolution.util.FastMap;
@@ -349,6 +351,39 @@ public class WorkEffortServices {
         return resultMap;
     }
 
+    private static TreeMap<DateRange, List<Map<String, Object>>> groupCalendarEntriesByDateRange(DateRange inDateRange, List<Map<String, Object>> calendarEntries) {
+        TreeMap<DateRange, List<Map<String, Object>>> calendarEntriesByDateRange = new TreeMap();
+        TreeSet<Date> dateBoundaries = new TreeSet();
+        if (inDateRange != null) {
+            dateBoundaries.add(inDateRange.start());
+            dateBoundaries.add(inDateRange.end());
+        }
+        for (Map<String, Object>calendarEntry: calendarEntries) {
+            DateRange calEntryRange = (DateRange)calendarEntry.get("calEntryRange");
+            dateBoundaries.add(calEntryRange.start());
+            dateBoundaries.add(calEntryRange.end());
+        }
+        Date prevDateBoundary = null;
+        for (Date dateBoundary: dateBoundaries) {
+            if (prevDateBoundary != null) {
+                DateRange dateRange = new DateRange(prevDateBoundary, dateBoundary);
+                for (Map<String, Object>calendarEntry: calendarEntries) {
+                    DateRange calEntryRange = (DateRange)calendarEntry.get("calEntryRange");
+                    if (calEntryRange.intersectsRange(dateRange) && !(calEntryRange.end().equals(dateRange.start()) || calEntryRange.start().equals(dateRange.end()))) {
+                        List<Map<String, Object>> calendarEntryByDateRangeList = calendarEntriesByDateRange.get(dateRange);
+                        if (calendarEntryByDateRangeList == null) {
+                            calendarEntryByDateRangeList = FastList.newInstance();
+                        }
+                        calendarEntryByDateRangeList.add(calendarEntry);
+                        calendarEntriesByDateRange.put(dateRange, calendarEntryByDateRangeList);
+                    }
+                }
+            }
+            prevDateBoundary = dateBoundary;
+        }
+        return calendarEntriesByDateRange;
+    }
+
     private static List<EntityCondition> getDefaultWorkEffortExprList(String calendarType, Collection<String> partyIds, String workEffortTypeId, List<EntityCondition> cancelledCheckAndList) {
         List<EntityCondition> entityExprList = FastList.newInstance();
         if (cancelledCheckAndList != null) {
@@ -673,6 +708,8 @@ public class WorkEffortServices {
                         long length = ((weRange.end().after(endStamp) ? endStamp.getTime() : weRange.end().getTime()) - (weRange.start().before(startStamp) ? startStamp.getTime() : weRange.start().getTime()));
                         int periodSpan = (int) Math.ceil((double) length / periodLen);
                         calEntry.put("periodSpan", Integer.valueOf(periodSpan));
+                        DateRange calEntryRange = new DateRange((weRange.start().before(startStamp) ? startStamp : weRange.start()), (weRange.end().after(endStamp) ? endStamp : weRange.end()));
+                        calEntry.put("calEntryRange", calEntryRange);
                         if (firstEntry) {
                             // If this is the first period any valid entry is starting here
                             calEntry.put("startOfPeriod", Boolean.TRUE);
@@ -691,6 +728,7 @@ public class WorkEffortServices {
                 entry.put("start", periodRange.startStamp());
                 entry.put("end", periodRange.endStamp());
                 entry.put("calendarEntries", curWorkEfforts);
+                entry.put("calendarEntriesByDateRange", groupCalendarEntriesByDateRange(periodRange, curWorkEfforts));
                 periods.add(entry);
             }
         }

Modified: ofbiz/trunk/applications/workeffort/webapp/workeffort/calendar/month.ftl
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/workeffort/webapp/workeffort/calendar/month.ftl?rev=927783&r1=927782&r2=927783&view=diff
==============================================================================
--- ofbiz/trunk/applications/workeffort/webapp/workeffort/calendar/month.ftl (original)
+++ ofbiz/trunk/applications/workeffort/webapp/workeffort/calendar/month.ftl Fri Mar 26 11:57:41 2010
@@ -51,7 +51,27 @@ height: auto;
       <span class="h1"><a href='<@ofbizUrl>${parameters._LAST_VIEW_NAME_}?period=day&start=${period.start.time?string("#")}${urlParam?if_exists}${addlParam?if_exists}</@ofbizUrl>'>${period.start?date?string("d")?cap_first}</a></span>
       <a class="add-new" href='<@ofbizUrl>${parameters._LAST_VIEW_NAME_}?period=month&form=edit&start=${parameters.start?if_exists}&parentTypeId=${parentTypeId?if_exists}&currentStatusId=CAL_TENTATIVE&estimatedStartDate=${period.start?string("yyyy-MM-dd HH:mm:ss")}&estimatedCompletionDate=${period.end?string("yyyy-MM-dd HH:mm:ss")}${urlParam?if_exists}${addlParam?if_exists}</@ofbizUrl>'>${uiLabelMap.CommonAddNew}</a>
       <br class="clear"/>
-      
+
+      <#assign maxNumberOfPersons = 0/>
+      <#assign maxNumberOfEvents = 0/>
+      <#assign ranges = period.calendarEntriesByDateRange.keySet()/>
+      <#list ranges as range>
+          <#assign eventsInRange = period.calendarEntriesByDateRange.get(range)/>
+          <#assign numberOfPersons = 0/>
+          <#list eventsInRange as eventInRange>
+              <#assign numberOfPersons = numberOfPersons + eventInRange.workEffort.reservPersons?default(0)/>
+          </#list>
+          <#if (numberOfPersons > maxNumberOfPersons)>
+              <#assign maxNumberOfPersons = numberOfPersons/>
+          </#if>
+          <#if (eventsInRange.size() > maxNumberOfEvents)>
+              <#assign maxNumberOfEvents = eventsInRange.size()/>
+          </#if>
+      </#list>
+      <#if (maxNumberOfPersons > 0)>
+          ${uiLabelMap.WorkEffortMaxNumberOfPersons}: ${maxNumberOfPersons}<br/>
+      </#if>
+
       <#list period.calendarEntries as calEntry>
         <#if calEntry.workEffort.actualStartDate?exists>
             <#assign startDate = calEntry.workEffort.actualStartDate>