[Bps-public-commit] rtx-calendar branch allow-custom-fields-on-calendar created. 1.05-1-g0932a07

BPS Git Server git at git.bestpractical.com
Fri Jul 28 19:13:18 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, allow-custom-fields-on-calendar has been created
        at  0932a078217fb11e3101054aa37505bbff67c498 (commit)

- Log -----------------------------------------------------------------
commit 0932a078217fb11e3101054aa37505bbff67c498
Author: Ronaldo Richieri <ronaldo at bestpractical.com>
Date:   Fri Jul 28 16:10:17 2023 -0300

    Allow date time Custom Fields to be used in Calendar
    
    It's possible now to add __CustomField.{Custom Field Name}__ to search
    format so it will appear on calendar.

diff --git a/html/Elements/CalendarEvent b/html/Elements/CalendarEvent
index 5b8a6c5..0f891b1 100644
--- a/html/Elements/CalendarEvent
+++ b/html/Elements/CalendarEvent
@@ -41,6 +41,8 @@ $DateTypes => undef
 %           and RTx::Calendar::LocalDate($Object->LastUpdatedObj->Unix) eq $today) {
     <img src="<%$RT::WebImagesURL%>/updated.png" />
 
+% } else {
+    <img src="<%$RT::WebImagesURL%>/reminder.png" />
 % }
 
 	<a href="<%$RT::WebPath%>/Ticket/Display.html?id=<%$TicketId%>">
@@ -60,6 +62,9 @@ $DateTypes => undef
 %
 %    if ($attr =~ /(.*)->ISO$/ and $Object->$1->Unix <= 0) {
 %        $value = '-';
+%    } elsif ($attr =~ /CustomField\.\{(.*)\}$/) {
+%        my $cf = $1;
+%        $value = $Object->FirstCustomFieldValue($cf);
 %    } else {
 %        my $method = '$Object->'.$attr.'()';
 %        $method =~ s/->ISO\(\)$/->ISO( Timezone => 'user' )/;
@@ -123,6 +128,7 @@ for my $field (@display_fields) {
     my $label = $field;
     $label =~ s'Obj-.(?:AsString|Name|ISO)''g;
     $label =~ s'-\>MemberEmailAddressesAsString''g;
+    $label =~ s/CustomField\.\{(.*)\}/$1/g;
     $label_of{$field} = $label;
 }
 
diff --git a/html/Search/Calendar.html b/html/Search/Calendar.html
index 9c5e71e..ab2ba5d 100644
--- a/html/Search/Calendar.html
+++ b/html/Search/Calendar.html
@@ -192,6 +192,17 @@ my $title = loc("Calendar");
 
 my @DateTypes = qw/Created Starts Started Due LastUpdated Resolved/;
 
+# push Date Time CFs to DateTypes
+my $CFs = RT::CustomFields->new($session{'CurrentUser'});
+$CFs->Limit(
+  FIELD => 'Type',
+  VALUE => 'DateTime',
+);
+
+while ( my $CF = $CFs->Next ) {
+  push @DateTypes, 'CustomField.{' . $CF->Name . '}';
+}
+
 my $rtdate = RT::Date->new($session{'CurrentUser'});
 
 my $weekstart = 'Sunday'; #RT::SiteConfig?  user pref?
@@ -244,6 +255,8 @@ $TempFormat = $Format if $Format;
 
 # we search all date types in Format string
 my @Dates = grep { $TempFormat =~ m/__${_}(Relative)?__/ } @DateTypes;
+# replace CustomField with CF
+ at Dates = map { $_ =~ s/^CustomField\.(.*)$/CF.$1/; $_ } @Dates;
 
 # used to display or not a date in Element/CalendarEvent
 my %DateTypes = map { $_ => 1 } @Dates;
diff --git a/lib/RTx/Calendar.pm b/lib/RTx/Calendar.pm
index 9bb375d..8f3c9c1 100644
--- a/lib/RTx/Calendar.pm
+++ b/lib/RTx/Calendar.pm
@@ -71,14 +71,24 @@ sub FindTickets {
 
         # How to find the LastContacted date ?
         for my $Date (@$Dates) {
-            my $DateObj = $Date . "Obj";
-            push @{ $Tickets{ LocalDate( $Ticket->$DateObj->Unix ) } },
+            my $dateindex;
+            if ($Date =~ /^CF\./){
+                my $cf = $Date;
+                $cf =~ s/^CF\.\{(.*)\}/$1/;
+                $dateindex = $Ticket->FirstCustomFieldValue($cf);
+                $dateindex =~ s/(.*) (.*)/$1/;
+                print STDERR "CF: $cf, dateindex: $dateindex\n";
+            } else {
+                my $DateObj = $Date . "Obj";
+                $dateindex = LocalDate( $Ticket->$DateObj->Unix );
+            }
+            push @{ $Tickets{$dateindex } },
                 $Ticket
 
                 # if reminder, check it's refering to a ticket
                 unless ( $Ticket->Type eq 'reminder'
                 and not $Ticket->RefersTo->First )
-                or $AlreadySeen{ LocalDate( $Ticket->$DateObj->Unix ) }
+                or $AlreadySeen{ $dateindex }
                 {$Ticket}++;
         }
     }

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


hooks/post-receive
-- 
rtx-calendar


More information about the Bps-public-commit mailing list