From 2e37273ff3a571975f950a63dece7c712f7e2bce Mon Sep 17 00:00:00 2001 From: Wolfgang Sourdeau Date: Mon, 17 May 2010 14:48:17 +0000 Subject: [PATCH] Monotone-Parent: 40b752e32c5a135beca554a131f9301c3e3afd72 Monotone-Revision: 19b0008e26816c6e8c6ccdb5329120a04a33f229 Monotone-Author: wsourdeau@inverse.ca Monotone-Date: 2010-05-17T14:48:17 Monotone-Branch: ca.inverse.sogo --- ChangeLog | 3 + UI/MainUI/SOGoUserHomePage.m | 103 +++++++++++++++++------------------ 2 files changed, 54 insertions(+), 52 deletions(-) diff --git a/ChangeLog b/ChangeLog index 53141f1fb..2e65fec35 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,8 @@ 2010-05-17 Wolfgang Sourdeau + * UI/MainUI/SOGoUserHomePage.m (-readFreeBusyAction): simplified + method by using -[self responseWithStatus:andString:]. + * UI/WebServerResources/generic.js (log): improved the method's performance by making use of DOM methods on the "logConsole" object. diff --git a/UI/MainUI/SOGoUserHomePage.m b/UI/MainUI/SOGoUserHomePage.m index ed0c5e649..d8b3c9ba4 100644 --- a/UI/MainUI/SOGoUserHomePage.m +++ b/UI/MainUI/SOGoUserHomePage.m @@ -152,79 +152,78 @@ } } -- (NSString *) _freeBusyAsTextFromStartDate: (NSCalendarDate *) startDate - toEndDate: (NSCalendarDate *) endDate - forFreeBusy: (SOGoFreeBusyObject *) fb +- (NSString *) _freeBusyFromStartDate: (NSCalendarDate *) startDate + toEndDate: (NSCalendarDate *) endDate + forFreeBusy: (SOGoFreeBusyObject *) fb { - NSMutableString *response; + NSMutableArray *freeBusy; unsigned int *freeBusyItems; NSTimeInterval interval; unsigned int count, intervals; interval = [endDate timeIntervalSinceDate: startDate] + 60; intervals = interval / intervalSeconds; /* slices of 15 minutes */ + freeBusyItems = NSZoneCalloc (NULL, intervals, sizeof (int)); [self _fillFreeBusyItems: freeBusyItems count: intervals withRecords: [fb fetchFreeBusyInfosFrom: startDate to: endDate] fromStartDate: startDate toEndDate: endDate]; - response = [NSMutableString string]; + freeBusy = [NSMutableArray arrayWithCapacity: intervals]; for (count = 0; count < intervals; count++) - [response appendFormat: @"%d,", *(freeBusyItems + count)]; - [response deleteCharactersInRange: NSMakeRange (intervals * 2 - 1, 1)]; + [freeBusy + addObject: [NSString stringWithFormat: @"%d", *(freeBusyItems + count)]]; NSZoneFree (NULL, freeBusyItems); - return response; -} - -- (NSString *) _freeBusyAsText -{ - SOGoFreeBusyObject *co; - NSCalendarDate *startDate, *endDate; - NSString *queryDay, *additionalDays; - NSTimeZone *uTZ; - SOGoUser *user; - - co = [self clientObject]; - user = [context activeUser]; - uTZ = [[user userDefaults] timeZone]; - - queryDay = [self queryParameterForKey: @"sday"]; - if ([queryDay length]) - startDate = [NSCalendarDate dateFromShortDateString: queryDay - andShortTimeString: @"0000" - inTimeZone: uTZ]; - else - { - startDate = [NSCalendarDate calendarDate]; - [startDate setTimeZone: uTZ]; - startDate = [startDate hour: 0 minute: 0]; - } - - queryDay = [self queryParameterForKey: @"eday"]; - if ([queryDay length]) - endDate = [NSCalendarDate dateFromShortDateString: queryDay - andShortTimeString: @"2359" - inTimeZone: uTZ]; - else - endDate = [startDate hour: 23 minute: 59]; - - additionalDays = [self queryParameterForKey: @"additional"]; - if ([additionalDays length] > 0) - endDate = [endDate dateByAddingYears: 0 months: 0 - days: [additionalDays intValue] - hours: 0 minutes: 0 seconds: 0]; - - return [self _freeBusyAsTextFromStartDate: startDate toEndDate: endDate - forFreeBusy: co]; + return [freeBusy componentsJoinedByString: @","]; } - (id ) readFreeBusyAction { WOResponse *response; + SOGoFreeBusyObject *co; + NSCalendarDate *startDate, *endDate; + NSString *queryDay; + NSTimeZone *uTZ; + SOGoUser *user; - response = [self responseWithStatus: 200]; - [response appendContentString: [self _freeBusyAsText]]; + user = [context activeUser]; + uTZ = [[user userDefaults] timeZone]; + + queryDay = [self queryParameterForKey: @"sday"]; + if ([queryDay length] == 8) + { + startDate = [NSCalendarDate dateFromShortDateString: queryDay + andShortTimeString: @"0000" + inTimeZone: uTZ]; + queryDay = [self queryParameterForKey: @"eday"]; + if ([queryDay length] == 8) + { + endDate = [NSCalendarDate dateFromShortDateString: queryDay + andShortTimeString: @"2359" + inTimeZone: uTZ]; + + if ([startDate earlierDate: endDate] == endDate) + response = [self responseWithStatus: 403 + andString: @"Start date is later than end date."]; + else + { + co = [self clientObject]; + response + = [self responseWithStatus: 200 + andString: [self + _freeBusyFromStartDate: startDate + toEndDate: endDate + forFreeBusy: co]]; + } + } + else + response = [self responseWithStatus: 403 + andString: @"Invalid end date."]; + } + else + response = [self responseWithStatus: 403 + andString: @"Invalid start date."]; return response; }