[Bps-public-commit] rtx-calendar branch multiple-days-events updated. 1.05-30-gd9edab5

BPS Git Server git at git.bestpractical.com
Fri Sep 22 19:16:56 UTC 2023


This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "rtx-calendar".

The branch, multiple-days-events has been updated
       via  d9edab5d52683efb5cbacbb4acf77d30d8912546 (commit)
      from  cd887c193f957952ec5bcddf5a79b5cc27d7bb5a (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit d9edab5d52683efb5cbacbb4acf77d30d8912546
Author: Ronaldo Richieri <ronaldo at bestpractical.com>
Date:   Fri Sep 22 16:10:07 2023 -0300

    Remove the daily events sorting sub routine from the settings
    
    The CalendarSortingEvents setting was introduced to allow the user to
    sort the daily events in the calendar. That was first implemented for
    giving a possibility sort events by status, grouping the events that are
    in the same status together. Although that could be useful in a few
    cases, it was a blocker to implement the multiple days events feature.
    
    Since this feature was never introduced in a final version of the
    extension, it is safe to remove it and sort the events by date.
    
    Now the events are sorted by the first date field of the search format.
    
    In order to make this sorting, we are using the GetDate method that was
    previously a private method of the RTx::Calendar package. So we renamed
    it from _GetDate to GetDate and made it public.

diff --git a/etc/RTxCalendar_Config.pm b/etc/RTxCalendar_Config.pm
index 6340a1f..5241e22 100644
--- a/etc/RTxCalendar_Config.pm
+++ b/etc/RTxCalendar_Config.pm
@@ -18,12 +18,6 @@ Set(%CalendarStatusColorMap, (
     'stalled'                               => '#FF0000',
 ));
 
-Set($CalendarSortEvents, sub {
-    my @Tickets = @_;
-    my @SortedTickets = sort { lc($a->Status) cmp lc($b->Status) } @Tickets;
-    return @SortedTickets;
-});
-
 Set(@CalendarFilterStatuses, qw(new open stalled rejected resolved));
 
 Set(@CalendarFilterDefaultStatuses, qw(new open));
diff --git a/html/Elements/Calendar b/html/Elements/Calendar
index c621d40..d3177ae 100644
--- a/html/Elements/Calendar
+++ b/html/Elements/Calendar
@@ -86,7 +86,10 @@ while ($date <= $end) {
   push @classes, "yesterday" if (DateTime->compare($yesterday, $date) == 0);
   push @classes, "aweekago"  if (DateTime->compare($aweekago,  $date) == 0);
 
-  for my $t ( $SortCalendarEvents->( @{ $Tickets->{ $date->strftime("%F") } || [] } )) {
+  for my $t ( RTx::Calendar::SortCalendarEvents(
+                \@{ $Tickets->{ $date->strftime("%F") } || [] },
+                $sorting_field,
+                $session{CurrentUser} ) ) {
     # check if ticket was already displayed this week, if not, we need to find a
     # position for it
     unless ( grep { $week_ticket_position{$_}{id} eq $t->id } keys %week_ticket_position ) {
@@ -319,5 +322,5 @@ my $DownloadQueryString =
         OrderBy => $OrderBy,
       );
 
-my $SortCalendarEvents = RT->Config->Get("CalendarSortEvents");
+my $sorting_field = $Dates[0] || '';
 </%INIT>
diff --git a/html/Elements/MyCalendar b/html/Elements/MyCalendar
index fb2e227..cf84c1b 100644
--- a/html/Elements/MyCalendar
+++ b/html/Elements/MyCalendar
@@ -23,7 +23,10 @@ while ($date <= $end) {
   my @classes = ();
   push @classes, "today"     if (DateTime->compare($today,     $date) == 0);
   push @classes, "yesterday" if (DateTime->compare($yesterday, $date) == 0);
-  for my $t ( $SortCalendarEvents->( @{ $Tickets->{ $date->strftime("%F") } || [] } )) {
+  for my $t ( RTx::Calendar::SortCalendarEvents(
+                \@{ $Tickets->{ $date->strftime("%F") } || [] },
+                $sorting_field,
+                $session{CurrentUser} ) ) {
     # check if ticket was already displayed this week, if not, we need to find a
     # position for it
     unless ( grep { $week_ticket_position{$_}{id} eq $t->id } keys %week_ticket_position ) {
@@ -143,5 +146,5 @@ $m->callback( CallbackName => 'BeforeFindTickets', ARGSRef => \%ARGS, QueryRef =
 
 my ($Tickets, $TicketsSpanningDays) = RTx::Calendar::FindTickets($session{'CurrentUser'}, $Query, \@Dates);
 
-my $SortCalendarEvents = RT->Config->Get("CalendarSortEvents");
+my $sorting_field = $Dates[0] || '';
 </%INIT>
diff --git a/lib/RTx/Calendar.pm b/lib/RTx/Calendar.pm
index 83ca93a..8b93753 100644
--- a/lib/RTx/Calendar.pm
+++ b/lib/RTx/Calendar.pm
@@ -106,7 +106,7 @@ sub FindTickets {
             # $dateindex is the date to use as key in the Tickets Hash
             # in the YYYY-MM-DD format
             # Tickets are then groupd by date in the %Tickets hash
-            my $dateindex = _GetDate( $Date, $Ticket, $CurrentUser );
+            my $dateindex = GetDate( $Date, $Ticket, $CurrentUser );
 
             push @{ $Tickets{$dateindex } },
                 $Ticket
@@ -126,8 +126,8 @@ sub FindTickets {
                 grep { $_ eq $multiple_days_events->{$event}{'Ends'} } @$Dates;
             my $starts_field = $multiple_days_events->{$event}{'Starts'};
             my $ends_field   = $multiple_days_events->{$event}{'Ends'};
-            my $starts_date  = _GetDate( $starts_field, $Ticket, $CurrentUser );
-            my $ends_date    = _GetDate( $ends_field,   $Ticket, $CurrentUser );
+            my $starts_date  = GetDate( $starts_field, $Ticket, $CurrentUser );
+            my $ends_date    = GetDate( $ends_field,   $Ticket, $CurrentUser );
 
             # Loop through all days between start and end and add the ticket
             # to it
@@ -173,11 +173,16 @@ sub FindTickets {
     }
 }
 
-sub _GetDate {
+sub GetDate {
     my $date_field = shift;
     my $Ticket = shift;
     my $CurrentUser = shift;
 
+    unless ($date_field) {
+        $RT::Logger->debug("No date field provided. Using created date.");
+        $date_field = 'Created';
+    }
+
     if ($date_field =~ /^CF\./){
         my $cf = $date_field;
         $cf =~ s/^CF\.\{(.*)\}/$1/;
@@ -206,6 +211,19 @@ sub _GetDate {
     }
 }
 
+sub SortCalendarEvents {
+    my $tickets_of_the_day = shift;
+    my $sorting_field = shift;
+    my $current_user = shift;
+    my @sorted_tickets = sort {
+        my ($a_value, $b_value);
+        $a_value = RTx::Calendar::GetDate( $sorting_field, $a, $current_user );
+        $b_value = RTx::Calendar::GetDate( $sorting_field, $b, $current_user );
+        ($a_value cmp $b_value)
+    } @$tickets_of_the_day;
+    return @sorted_tickets;
+}
+
 #
 # Take a user object and return the search with Description "calendar" if it exists
 #

-----------------------------------------------------------------------

Summary of changes:
 etc/RTxCalendar_Config.pm |  6 ------
 html/Elements/Calendar    |  7 +++++--
 html/Elements/MyCalendar  |  7 +++++--
 lib/RTx/Calendar.pm       | 26 ++++++++++++++++++++++----
 4 files changed, 32 insertions(+), 14 deletions(-)


hooks/post-receive
-- 
rtx-calendar


More information about the Bps-public-commit mailing list