Skip to content

Commit

Permalink
Add sort by start date for the tasks list
Browse files Browse the repository at this point in the history
Fixes #3840
  • Loading branch information
cgx committed Nov 30, 2016
1 parent a1746cd commit 52cdb71
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 21 deletions.
1 change: 1 addition & 0 deletions NEWS
Expand Up @@ -3,6 +3,7 @@

Enhancements
- [core] added handling of BYSETPOS for BYDAY in recurrence rules
- [web] added sort by start date for tasks (#3840)

Bug fixes
- [web] fixed JavaScript exception when SOGo is launched from an external link (#3900)
Expand Down
34 changes: 18 additions & 16 deletions UI/Scheduler/NSArray+Scheduler.h
Expand Up @@ -54,21 +54,22 @@
#define taskCalendarNameIndex 2
#define taskStatusIndex 3
#define taskTitleIndex 4
#define taskEndDateIndex 5
#define taskClassificationIndex 6
#define taskLocationIndex 7
#define taskCategoryIndex 8
#define taskViewableIndex 9
#define taskEditableIndex 10
#define taskErasableIndex 11
#define taskPriorityIndex 12
#define taskOwnerIndex 13
#define taskIsCycleIndex 14
#define taskNextAlarmIndex 15
#define taskRecurrenceIdIndex 16
#define taskIsExceptionIndex 17
#define taskDescriptionIndex 18
#define taskStatusFlagIndex 19
#define taskStartDateIndex 5
#define taskEndDateIndex 6
#define taskClassificationIndex 7
#define taskLocationIndex 8
#define taskCategoryIndex 9
#define taskViewableIndex 10
#define taskEditableIndex 11
#define taskErasableIndex 12
#define taskPriorityIndex 13
#define taskOwnerIndex 14
#define taskIsCycleIndex 15
#define taskNextAlarmIndex 16
#define taskRecurrenceIdIndex 17
#define taskIsExceptionIndex 18
#define taskDescriptionIndex 19
#define taskStatusFlagIndex 20

@interface NSArray (SOGoEventComparison)

Expand All @@ -80,7 +81,8 @@
- (NSComparisonResult) compareTasksAscending: (NSArray *) otherTask;
- (NSComparisonResult) compareTasksPriorityAscending: (NSArray *) otherTask;
- (NSComparisonResult) compareTasksTitleAscending: (NSArray *) otherTask;
- (NSComparisonResult) compareTasksEndAscending: (NSArray *) otherTask;
- (NSComparisonResult) compareTasksStartDateAscending: (NSArray *) otherTask;
- (NSComparisonResult) compareTasksEndDateAscending: (NSArray *) otherTask;
- (NSComparisonResult) compareTasksLocationAscending: (NSArray *) otherTask;
- (NSComparisonResult) compareTasksCategoryAscending: (NSArray *) otherTask;
- (NSComparisonResult) compareTasksCalendarNameAscending: (NSArray *) otherTask;
Expand Down
36 changes: 35 additions & 1 deletion UI/Scheduler/NSArray+Scheduler.m
Expand Up @@ -182,7 +182,41 @@ - (NSComparisonResult) compareTasksTitleAscending: (NSArray *) otherTask
return [selfTitle caseInsensitiveCompare: otherTitle];
}

- (NSComparisonResult) compareTasksEndAscending: (NSArray *) otherTask
- (NSComparisonResult) compareTasksStartDateAscending: (NSArray *) otherTask
{
NSComparisonResult result;
unsigned int selfTime, otherTime;

// Start date
selfTime = [[self objectAtIndex: taskStartDateIndex] intValue];
otherTime = [[otherTask objectAtIndex: taskStartDateIndex] intValue];
if (selfTime && !otherTime)
result = NSOrderedAscending;
else if (!selfTime && otherTime)
result = NSOrderedDescending;
else
{
if (selfTime > otherTime)
result = NSOrderedDescending;
else if (selfTime < otherTime)
result = NSOrderedAscending;
else
{
// Calendar ID
result = [[self objectAtIndex: taskFolderIndex]
compare: [otherTask objectAtIndex: taskFolderIndex]];
if (result == NSOrderedSame)
// Task name
result = [[self objectAtIndex: taskTitleIndex]
compare: [otherTask objectAtIndex: taskTitleIndex]
options: NSCaseInsensitiveSearch];
}
}

return result;
}

- (NSComparisonResult) compareTasksEndDateAscending: (NSArray *) otherTask
{
NSComparisonResult result;
unsigned int selfTime, otherTime;
Expand Down
7 changes: 4 additions & 3 deletions UI/Scheduler/UIxCalListingActions.m
Expand Up @@ -90,7 +90,7 @@ + (void) initialize
{
tasksFields = [NSArray arrayWithObjects: @"c_name", @"c_folder",
@"calendarName",
@"c_status", @"c_title", @"c_enddate",
@"c_status", @"c_title", @"c_startdate", @"c_enddate",
@"c_classification", @"c_location", @"c_category",
@"viewable", @"editable", @"erasable",
@"c_priority", @"c_owner",
Expand Down Expand Up @@ -1595,7 +1595,6 @@ - (WOResponse *) tasksListAction
forAllDay: NO]];
else
[filteredTask addObject: [NSNull null]];

if (([tasksView isEqualToString:@"view_today"] ||
[tasksView isEqualToString:@"view_next7"] ||
[tasksView isEqualToString:@"view_next14"] ||
Expand All @@ -1621,8 +1620,10 @@ - (WOResponse *) tasksListAction
[filteredTasks sortUsingSelector: @selector (compareTasksTitleAscending:)];
else if ([sort isEqualToString: @"priority"])
[filteredTasks sortUsingSelector: @selector (compareTasksPriorityAscending:)];
else if ([sort isEqualToString: @"start"])
[filteredTasks sortUsingSelector: @selector (compareTasksStartDateAscending:)];
else if ([sort isEqualToString: @"end"])
[filteredTasks sortUsingSelector: @selector (compareTasksEndAscending:)];
[filteredTasks sortUsingSelector: @selector (compareTasksEndDateAscending:)];
else if ([sort isEqualToString: @"location"])
[filteredTasks sortUsingSelector: @selector (compareTasksLocationAscending:)];
else if ([sort isEqualToString: @"category"])
Expand Down
2 changes: 1 addition & 1 deletion UI/Templates/SchedulerUI/UIxCalMainView.wox
Expand Up @@ -466,7 +466,7 @@
<!-- selected --></md-icon> <var:string label:value="Calendar"/>
</md-button>
</md-menu-item>
<md-menu-item ng-if="list.componentType == 'events'">
<md-menu-item>
<md-button ng-click="list.sort('start')">
<md-icon ng-class="{ 'icon-check': list.sortedBy('start') }">
<!-- selected --></md-icon> <var:string label:value="Start"/>
Expand Down

0 comments on commit 52cdb71

Please sign in to comment.