[Bps-public-commit] rtx-calendar branch allow-custom-field-based-events updated. 1.05-17-g17cf1f5

BPS Git Server git at git.bestpractical.com
Thu Aug 24 22:37:54 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-field-based-events has been updated
       via  17cf1f5e4c49bf7330eac605d66efb48e9b024fc (commit)
      from  72650586f5057a7da712c9c3324603d1036387e4 (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 17cf1f5e4c49bf7330eac605d66efb48e9b024fc
Author: Ronaldo Richieri <ronaldo at bestpractical.com>
Date:   Thu Aug 24 19:31:57 2023 -0300

    Refactor Custom Icon feature
    
    Renamed the method from GetEventIcon to GetEventImg and sticked it to
    only allow image files and not html code.
    
    Also, since all the Icons can be customized, we created a default setting
    for all the core Dates icons.
    
    Also renamed the Icon setting from CalendarCustomIcons to CalendarIcons,
    since it's not only for custom icons anymore.
    
    Add an extra loop to the icon get feature to treat icons that are the
    reflection of combined dates.
    
    Update POD mentioning where to place the custom images.

diff --git a/etc/RTxCalendar_Config.pm b/etc/RTxCalendar_Config.pm
new file mode 100644
index 0000000..526ae76
--- /dev/null
+++ b/etc/RTxCalendar_Config.pm
@@ -0,0 +1,11 @@
+Set(%CalendarIcons, (
+    'Reminder'     => 'reminder.png',
+    'Resolved'     => 'resolved.png',
+    'Starts, Due'  => 'starts_due.png',
+    'Created, Due' => 'created_due.png',
+    'Created'      => 'created.png',
+    'Due'          => 'due.png',
+    'Starts'       => 'starts.png',
+    'Started'      => 'started.png',
+    'LastUpdated'  => 'updated.png',
+));
diff --git a/html/Elements/CalendarEvent b/html/Elements/CalendarEvent
index f684aa0..a125970 100644
--- a/html/Elements/CalendarEvent
+++ b/html/Elements/CalendarEvent
@@ -6,7 +6,7 @@ $DateTypes => undef
 <div class="day">
 <small>
 
-    <% RTx::Calendar::GetEventIcon($Object, $today, $DateTypes, $IsReminder)|n %>
+    <% RTx::Calendar::GetEventImg($Object, $today, $DateTypes, $IsReminder)|n %>
 	<a href="<%$RT::WebPath%>/Ticket/Display.html?id=<%$TicketId%>" <% $StatusColor|n %>>
            <% $Object->QueueObj->Name %> #<% $TicketId %>
            <% $display_owner ? 'by ' . $Object->OwnerObj->Name : '' %>
diff --git a/html/Search/Calendar.html b/html/Search/Calendar.html
index fe64d11..d60d2b7 100644
--- a/html/Search/Calendar.html
+++ b/html/Search/Calendar.html
@@ -156,34 +156,35 @@ $FilterOnStatusClear => undef
         <div class="col-2 pl-1 pr-1"> </div>
         <div class="col-auto text-left pl-1 pr-1"><b><&|/l&>Event Types</&></b></div>
       </div>
-%     foreach my $legend (sort keys %legend) {
-        <div class="row">
-          <div class="col-3 text-right pl-1 pr-1">
-            <img src="<%$RT::WebImagesURL%>/<%$legend%>.png" />
-          </div>
-          <div class="col text-left pl-1 pr-1">
-%           my $more = 0;
-%           foreach ( @{$legend{$legend}} ) {
-              <% $more++ ? ', ' : '' %>
-              <&|/l&><% $_ %></&>
-%           }
-          </div>
-        </div>
-%     }
-%     if (RT->Config->Get('CalendarCustomIcons')) {
-%       my %CalendarCustomIcons = RT->Config->Get('CalendarCustomIcons');
-%       foreach my $legend (sort keys %CalendarCustomIcons) {
-%         my $legendLabel = $legend;
-%         $legendLabel =~ s/^CF\.\{(.*)\}/$1/;
+<%perl>
+my %CalendarIcons = RT->Config->Get('CalendarIcons');
+# Sort the legend after translation
+my %CalendarIconsTranslated;
+my $LegendLabel;
+foreach my $legend (sort { lc($a) cmp lc($b) } keys %CalendarIcons) {
+  my @LegendLabels = split ',', $legend;
+  $LegendLabel = join ', ',
+    map {
+      $_ =~ s/^\s+|\s+$//g;
+      $_ =~ s/^CF\.\{(.*)\}/$1/;
+      $_ = 'Last Updated' if $_ eq 'LastUpdated';
+      loc($_)
+    } @LegendLabels;
+  $CalendarIconsTranslated{$LegendLabel} = $legend;
+}
+foreach my $TranslatedLegend (sort keys %CalendarIconsTranslated) {
+</%perl>
           <div class="row">
             <div class="col-3 text-right pl-1 pr-1">
-              <span class="tip"><% $CalendarCustomIcons{$legend}|n %></span>
+              <span class="tip">
+                <img
+                src="<% $RT::WebImagesURL %>/<%
+                $CalendarIcons{$CalendarIconsTranslated{$TranslatedLegend}}|n %>" /></span>
             </div>
             <div class="col text-left pl-1 pr-1">
-              <&|/l&><% $legendLabel %></&>
+              <% $TranslatedLegend %>
             </div>
           </div>
-%       }
 %     }
     </div>
     <div class="col-6">
diff --git a/lib/RTx/Calendar.pm b/lib/RTx/Calendar.pm
index 780e59f..53d9348 100644
--- a/lib/RTx/Calendar.pm
+++ b/lib/RTx/Calendar.pm
@@ -160,71 +160,57 @@ sub SearchDefaultCalendar {
     }
 }
 
-sub GetEventIcon {
-    my $Object   = shift;
+sub GetEventImg {
+    my $Object      = shift;
     my $CurrentDate = shift;
-    my $DateTypes = shift;
+    my $DateTypes   = shift;
     my $IsReminder  = shift;
     my $EventIcon;
-    if (RT->Config->Get('CalendarCustomIcons')) {
-        my %CalendarCustomIcons = RT->Config->Get('CalendarCustomIcons');
-        for my $DateField (keys %CalendarCustomIcons) {
-            my $DateValue;
-            if ($DateField =~ /^CF\./){
+    my %CalendarIcons = RT->Config->Get('CalendarIcons');
+CALENDAR_ICON:
+    for my $DateField ( keys %CalendarIcons ) {
+
+      # Icon can be a combination of two dates such as Due-Created,
+      # or CF.{Date Field}-Created. It can be also single date such as Created
+        my @DatesToCompare = split( /,/, $DateField );
+    DATE_COMPARE:
+        for my $ComparedDate (@DatesToCompare) {
+            # trim spaces
+            $ComparedDate =~ s/^\s+|\s+$//g;
+            if ( $DateField eq 'Reminder' ) {
+                if ( $IsReminder
+                    && RTx::Calendar::LocalDate( $Object->DueObj->Unix ) eq
+                    $CurrentDate )
+                {
+                    $EventIcon = 'reminder.png';
+                    last CALENDAR_ICON;
+                }
+            } elsif ( $DateField =~ /^CF\./ ) {
                 my $cf = $DateField;
                 $cf =~ s/^CF\.\{(.*)\}/$1/;
-                $DateValue = $Object->FirstCustomFieldValue($cf);
-                next unless $DateValue;
+                my $DateValue = $Object->FirstCustomFieldValue($cf);
+                next CALENDAR_ICON unless $DateValue;
                 $DateValue =~ s/(.*) (.*)/$1/;
+                next CALENDAR_ICON unless $DateValue eq $CurrentDate;
             } else {
-                my $DateObj = $DateField . "Obj";
-                $DateValue = LocalDate( $Object->$DateObj->Unix );
-            }
-            if ($DateValue eq $CurrentDate) {
-                $EventIcon = $CalendarCustomIcons{$DateField};
-                return $EventIcon;
+                my $DateObj = $ComparedDate . "Obj";
+                my $DateValue
+                    = RTx::Calendar::LocalDate( $Object->$DateObj->Unix );
+                next CALENDAR_ICON unless $DateValue eq $CurrentDate;
             }
+
+            # If we are here, it means that all comparissons are true
+            $EventIcon = $CalendarIcons{$DateField};
         }
     }
-    if ($IsReminder and RTx::Calendar::LocalDate($Object->DueObj->Unix) eq $CurrentDate) {
-        $EventIcon = '<img src="' . $RT::WebImagesURL .  '/reminder.png" />';
-
-    } elsif ($DateTypes->{Resolved}
-               and RTx::Calendar::LocalDate($Object->ResolvedObj->Unix) eq $CurrentDate) {
-            $EventIcon = '<img src="' . $RT::WebImagesURL .  '/resolved.png" />';
-
-    } elsif ($DateTypes->{Starts} and $DateTypes->{Due}
-               and RTx::Calendar::LocalDate($Object->StartsObj->Unix) eq $CurrentDate and RTx::Calendar::LocalDate($Object->DueObj->Unix) eq $CurrentDate ) {
-        $EventIcon = '<img src="' . $RT::WebImagesURL .  '/starts_due.png" />';
-
-    } elsif ($DateTypes->{Due} and $DateTypes->{Created}
-               and RTx::Calendar::LocalDate($Object->DueObj->Unix) eq $CurrentDate and RTx::Calendar::LocalDate($Object->CreatedObj->Unix) eq $CurrentDate ) {
-        $EventIcon = '<img src="' . $RT::WebImagesURL .  '/created_due.png" />';
-
-    } elsif ($DateTypes->{Starts}
-               and RTx::Calendar::LocalDate($Object->StartsObj->Unix) eq $CurrentDate) {
-        $EventIcon = '<img src="' . $RT::WebImagesURL .  '/starts.png" />';
-
-    } elsif ($DateTypes->{Due}
-               and RTx::Calendar::LocalDate($Object->DueObj->Unix) eq $CurrentDate) {
-        $EventIcon = '<img src="' . $RT::WebImagesURL .  '/due.png" />';
-
-    } elsif ($DateTypes->{Created}
-               and RTx::Calendar::LocalDate($Object->CreatedObj->Unix) eq $CurrentDate) {
-        $EventIcon = '<img src="' . $RT::WebImagesURL .  '/created.png" />';
-
-    } elsif ($DateTypes->{Started}
-               and RTx::Calendar::LocalDate($Object->StartedObj->Unix) eq $CurrentDate) {
-        $EventIcon = '<img src="' . $RT::WebImagesURL .  '/started.png" />';
-
-    } elsif ($DateTypes->{LastUpdated}
-               and RTx::Calendar::LocalDate($Object->LastUpdatedObj->Unix) eq $CurrentDate) {
-        $EventIcon = '<img src="' . $RT::WebImagesURL .  '/updated.png" />';
-
+    if ($EventIcon) {
+        return '<img src="' . $RT::WebImagesURL . '/' . $EventIcon . '" />';
+    } else {
+        return '';
     }
-    return $EventIcon;
 }
 
+
 1;
 
 __END__
@@ -340,13 +326,15 @@ adding the C<$CalendarColorStatusMap> setting to your F<etc/RT_SiteConfig.pm>:
 =head3 Custom icons
 
 Custom Icons can be defined for the events in the calendar by adding the
-C<$CalendarCustomIcons> setting to your F<etc/RT_SiteConfig.pm>:
+C<$CalendarIcons> setting to your F<etc/RT_SiteConfig.pm>:
 
-    Set(%CalendarCustomIcons, (
+    Set(%CalendarIcons, (
         'CF.{Maintenance Estimated Start Date/Time - ET}'
-            => '<small class="ml-1"><i class="fas fa-cog"></i></small>'
+            => 'maint.png',
     ));
 
+The images should be placed on F<local/static/images>.
+
 =head1 USAGE
 
 A small help section is available in /Search/Calendar.html

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

Summary of changes:
 etc/RTxCalendar_Config.pm   | 11 +++++
 html/Elements/CalendarEvent |  2 +-
 html/Search/Calendar.html   | 45 +++++++++++----------
 lib/RTx/Calendar.pm         | 98 ++++++++++++++++++++-------------------------
 4 files changed, 78 insertions(+), 78 deletions(-)
 create mode 100644 etc/RTxCalendar_Config.pm


hooks/post-receive
-- 
rtx-calendar


More information about the Bps-public-commit mailing list