]> err.no Git - scalable-opengroupware.org/commitdiff
git-svn-id: http://svn.opengroupware.org/SOGo/trunk@258 d1b88da0-ebda-0310-925b-ed51d...
authorhelge <helge@d1b88da0-ebda-0310-925b-ed51d893ca5b>
Mon, 16 Aug 2004 12:56:48 +0000 (12:56 +0000)
committerhelge <helge@d1b88da0-ebda-0310-925b-ed51d893ca5b>
Mon, 16 Aug 2004 12:56:48 +0000 (12:56 +0000)
SOGo/UI/Scheduler/ChangeLog
SOGo/UI/Scheduler/UIxAppointmentProposal.m
SOGo/UI/Scheduler/Version

index 17d412298c8bacc1ab2d80f30cde1ddcaa80bbda..8de44a1b03df54147eae94e3c699295acec720c2 100644 (file)
@@ -1,5 +1,7 @@
 2004-08-16  Helge Hess  <helge.hess@skyrix.com>
 
+       * UIxAppointmentProposal.m: first working version of proposal (v0.9.62)
+
        * UIxAppointmentProposal: proper vertical/horizontal row generation
          (v0.9.61)
 
index 4ea4faef9f8ce1ff6dae0ab198c33216032380b1..85e15b5b2ec81cc57f70262098ea5a4e01f89e84 100644 (file)
   NSArray        *participants; /* array of iCalPerson's */
   NSArray        *resources;    /* array of iCalPerson's */
   id             duration;
+  
+  NSArray *blockedRanges;
 }
 
 @end
 
+#include <SoObjects/Appointments/SOGoAppointmentFolder.h>
+#include <NGExtensions/NGCalendarDateRange.h>
 #include "common.h"
 
 @implementation UIxAppointmentProposal
 
 - (void)dealloc {
+  [self->blockedRanges   release];
+
   [self->startDateHour   release];
   [self->startDateMinute release];
   [self->startDateDay    release];
 
 /* slots */
 
+- (BOOL)isRangeGreen:(NGCalendarDateRange *)_range {
+  unsigned idx;
+
+  idx = [self->blockedRanges indexOfFirstIntersectingDateRange:_range];
+  if (idx != NSNotFound)
+    return NO;
+  
+  return YES;
+}
+
+- (BOOL)isSlotRangeGreen:(NGCalendarDateRange *)_slotRange {
+  NGCalendarDateRange *aptRange;
+  NSCalendarDate *aptStartDate, *aptEndDate;
+
+  if (_slotRange == nil)
+    return NO;
+  
+  /* calculate the interval requested by the user (can be larger) */
+  
+  aptStartDate = [_slotRange startDate];
+  aptEndDate   = [[NSCalendarDate alloc] initWithTimeIntervalSince1970:
+                                          [aptStartDate timeIntervalSince1970]
+                                        + [self durationAsTimeInterval]];
+  [aptStartDate setTimeZone:[self viewTimeZone]];
+  [aptEndDate   setTimeZone:[self viewTimeZone]];
+  aptRange = [NGCalendarDateRange calendarDateRangeWithStartDate:aptStartDate
+                                 endDate:aptEndDate];
+  [aptEndDate release]; aptEndDate = nil;
+  
+  return [self isRangeGreen:aptRange];
+}
+
 - (BOOL)isFirstHalfGreen {
-  [self logWithFormat:@"is first green: %@ %@", self->currentDay, self->item];
-  return NO;
+  /* currentday is the date, self->item the hour */
+  NSCalendarDate *from, *to;
+  NGCalendarDateRange *range;
+
+  from  = [self->currentDay hour:[[self item] intValue] minute:0];
+  to    = [self->currentDay hour:[[self item] intValue] minute:30];
+  range = [NGCalendarDateRange calendarDateRangeWithStartDate:from endDate:to];
+  return [self isSlotRangeGreen:range];
 }
 - (BOOL)isSecondHalfGreen {
-  [self logWithFormat:@"is second green: %@ %@", self->currentDay, self->item];
-  return YES;
+  /* currentday is the date, self->item the hour */
+  NSCalendarDate *from, *to;
+  NGCalendarDateRange *range;
+
+  from  = [self->currentDay hour:[[self item] intValue] minute:30];
+  to    = [self->currentDay hour:[[self item] intValue] minute:59];
+  range = [NGCalendarDateRange calendarDateRangeWithStartDate:from endDate:to];
+  return [self isSlotRangeGreen:range];
 }
 
 - (BOOL)isFirstHalfBlocked {
 }
 
 - (id)proposalSearchAction {
+  NSArray               *attendees, *uids;
+  SOGoAppointmentFolder *groupCalendar;
+  NSArray *coreInfos;
+  NSArray *ranges;
+  
   [self logWithFormat:@"search from %@ to %@", 
          [self startDate], [self endDate]];
-  [self logWithFormat:@"  participants: %@", [self participants]];
-  [self logWithFormat:@"  resources:    %@", [self resources]];
+  
+  attendees = [self attendees];
+  uids      = [[self clientObject] uidsFromICalPersons:attendees];
+  if ([uids count] == 0) {
+    [self logWithFormat:@"Note: no UIDs selected."];
+    return self;
+  }
+  
+  groupCalendar = [[self clientObject] lookupGroupCalendarFolderForUIDs:uids
+                                      inContext:[self context]];
+  [self debugWithFormat:@"group calendar: %@", groupCalendar];
+  
+  if (![groupCalendar respondsToSelector:@selector(fetchCoreInfosFrom:to:)]) {
+    return [NSException exceptionWithHTTPStatus:500 /* Internal Error */
+                       reason:@"invalid folder to run proposal query on!"];
+  }
+  
+  // TODO: just query startdate and enddate ... (freebusy)
+  coreInfos = [groupCalendar fetchCoreInfosFrom:[self startDate]
+                            to:[self endDate]];
+  [self debugWithFormat:@"  process: %d events", [coreInfos count]];
+
+  ranges = [coreInfos arrayByCreatingDateRangesFromObjectsWithStartDateKey:
+                       @"startDate"
+                     andEndDateKey:@"endDate"];
+  ranges = [ranges arrayByCompactingContainedDateRanges];
+  [self debugWithFormat:@"  ranges: %@", ranges];
+  
+  ASSIGNCOPY(self->blockedRanges, ranges);
+  
   return self;
 }
 
index 491c78134c924d6fbc6df1f9b9fe717a75d4c763..4b7ecabdc84fd1ba02979e70096e325fe896db26 100644 (file)
@@ -1,7 +1,8 @@
 # $Id$
 
-SUBMINOR_VERSION:=60
+SUBMINOR_VERSION:=61
 
+# v0.9.61 requires libNGExtensions v4.2.102
 # v0.9.41 requires libNGObjWeb     v4.2.431
 # v0.9.31 requires libWEExtensions v4.2.52
 # v0.9.29 requires libWEExtensions v4.2.51