[Bps-public-commit] rtx-calendar branch multiple-days-events updated. 1.05-44-gd662636
BPS Git Server
git at git.bestpractical.com
Mon Oct 16 14:39:04 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 d662636f53d7fcd033fa81c748dd9641383fd6f1 (commit)
from 10ada4eac29a1d1611b06a04e9785f55a9f4d2bd (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 d662636f53d7fcd033fa81c748dd9641383fd6f1
Author: Ronaldo Richieri <ronaldo at bestpractical.com>
Date: Mon Oct 16 11:37:55 2023 -0300
Load event details with Ajax call when hovering event title
For improving performance, the event details are loaded now with an Ajax
call when hovering the event title.
diff --git a/html/Elements/CalendarEvent b/html/Elements/CalendarEvent
index 515e1e0..d06e38c 100644
--- a/html/Elements/CalendarEvent
+++ b/html/Elements/CalendarEvent
@@ -67,46 +67,9 @@ if ( ( !grep { $_ eq $TicketId } @$spanning_tickets_for_tomorrow ) ) {
<% $display_owner ? 'by ' . $Object->OwnerObj->Name : '' %>
<% length($Object->Subject) > 80 ? substr($Object->Subject, 0, 77) . "..." : $Object->Subject %>
</a>
+% # Placeholder for the event details that will be loaded via AJAX on hover
<span class="tip">
- <a href="<%$RT::WebPath%>/Ticket/Display.html?id=<%$TicketId%>">
- <% $Object->QueueObj->Name %> #<% $TicketId %>
- </a>
- :</strong> <% $subject%><br />
- <br />
-
-<%perl>
-# logic taken from Ticket/Search/Results.tsv
- foreach my $attr (@display_fields) {
- my $value;
-
- if ($attr =~ /(.*)->ISO$/ and $Object->$1->Unix <= 0) {
- $value = '-';
- } elsif ($attr =~ /CustomField\.\{(.*)\}$/) {
- my $cf = $1;
- my $cf_obj = $Object->LoadCustomFieldByIdentifier($cf);
- unless ($cf_obj->id) {
- $RT::Logger->debug("Custom field '$cf' not available for ticket #".$Object->id);
- next;
- }
- $value = $Object->FirstCustomFieldValue($cf);
- if (grep { $_ eq $cf_obj->Type} qw(DateTime Date)) {
- my $date_value = RT::Date->new($session{'CurrentUser'});
- my $date_format = $cf_obj->Type eq 'DateTime' ? 'ISO' : 'unknown';
- $date_value->Set(Format => $date_format, Value => $value);
- $value = $date_value->AsString( Timezone => 'user', Time => $cf_obj->Type eq 'DateTime' ? 1 : 0 );
- }
- } else {
- my $method = '$Object->'.$attr.'()';
- $method =~ s/->ISO\(\)$/->ISO( Timezone => 'user' )/;
- $value = eval $method;
- if ($@) {die "<b>Check your CalendarPopupFields config in etc/RT_SiteConfig.pm</b>.<br /><br />Failed to find \"$attr\" - ". $@};
- }
-</%perl>
- <strong><&|/l&><% $label_of{$attr} %></&>:</strong> <% $value %><br />
-% }
-
- <br />
-</span>
+ </span>
% }
</div>
</small>
@@ -146,31 +109,4 @@ my $display_owner = $RT::CalendarDisplayOwner;
$display_owner ||= RT->Config->Get('CalendarDisplayOwner')
if RT->can('Config');
-
-# 3.6 config
-my @display_fields = @RT::CalendarPopupFields;
-
-# 3.8 config
-# the if condition is weird but it doesn't work with 3.8.0 without the last part
- at display_fields = RT->Config->Get('CalendarPopupFields')
- if 0 == @display_fields and RT->can('Config') and RT->Config->Get('CalendarPopupFields');
-
-# default
-if (0 == @display_fields) {
- @display_fields = qw(OwnerObj->Name CreatedObj->ISO StartsObj->ISO
- StartedObj->ISO LastUpdatedObj->ISO DueObj->ISO
- ResolvedObj->ISO Status Priority
- Requestors->MemberEmailAddressesAsString);
-}
-
-
-my %label_of;
-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;
-}
-
</%init>
diff --git a/html/Helpers/CalendarEventInfo b/html/Helpers/CalendarEventInfo
new file mode 100644
index 0000000..debc8d3
--- /dev/null
+++ b/html/Helpers/CalendarEventInfo
@@ -0,0 +1,89 @@
+<%args>
+$event
+</%args>
+<%init>
+my @event_details = split /-/, $event;
+my $object_type = $event_details[0]; # ticket or reminder
+my $ticket_id = $event_details[1];
+my $Object = RT::Ticket->new($session{'CurrentUser'});
+$Object->Load($ticket_id);
+
+my $status;
+my $TicketId;
+my $subject = $Object->Subject;
+
+if ($Object->Type eq 'reminder') {
+ if ($Object->RefersTo->First) {
+ my $ticket = $Object->RefersTo->First->TargetObj;
+ $TicketId = $ticket->Id;
+ $subject = $Object->Subject . " (" . $ticket->Subject . ")";
+ $status = $Object->Status;
+ }
+} else {
+ $TicketId = $Object->Id;
+ $subject = $Object->Subject;
+ $status = $Object->Status;
+}
+
+# 3.6 config
+my @display_fields = @RT::CalendarPopupFields;
+
+# 3.8 config
+# the if condition is weird but it doesn't work with 3.8.0 without the last part
+ at display_fields = RT->Config->Get('CalendarPopupFields')
+ if 0 == @display_fields and RT->can('Config') and RT->Config->Get('CalendarPopupFields');
+
+# default
+if (0 == @display_fields) {
+ @display_fields = qw(OwnerObj->Name CreatedObj->ISO StartsObj->ISO
+ StartedObj->ISO LastUpdatedObj->ISO DueObj->ISO
+ ResolvedObj->ISO Status Priority
+ Requestors->MemberEmailAddressesAsString);
+}
+
+my %label_of;
+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;
+}
+</%init>
+<a href="<%$RT::WebPath%>/Ticket/Display.html?id=<%$TicketId%>">
+ <% $Object->QueueObj->Name %> #<% $TicketId %>
+</a>
+:</strong> <% $subject%><br />
+<br />
+<%perl>
+# logic taken from Ticket/Search/Results.tsv
+foreach my $attr (@display_fields) {
+ my $value;
+
+ if ($attr =~ /(.*)->ISO$/ and $Object->$1->Unix <= 0) {
+ $value = '-';
+ } elsif ($attr =~ /CustomField\.\{(.*)\}$/) {
+ my $cf = $1;
+ my $cf_obj = $Object->LoadCustomFieldByIdentifier($cf);
+ unless ($cf_obj->id) {
+ $RT::Logger->debug("Custom field '$cf' not available for ticket #".$Object->id);
+ next;
+ }
+ $value = $Object->FirstCustomFieldValue($cf);
+ if (grep { $_ eq $cf_obj->Type} qw(DateTime Date)) {
+ my $date_value = RT::Date->new($session{'CurrentUser'});
+ my $date_format = $cf_obj->Type eq 'DateTime' ? 'ISO' : 'unknown';
+ $date_value->Set(Format => $date_format, Value => $value);
+ $value = $date_value->AsString( Timezone => 'user', Time => $cf_obj->Type eq 'DateTime' ? 1 : 0 );
+ }
+ } else {
+ my $method = '$Object->'.$attr.'()';
+ $method =~ s/->ISO\(\)$/->ISO( Timezone => 'user' )/;
+ $value = eval $method;
+ if ($@) {die "<b>Check your CalendarPopupFields config in etc/RT_SiteConfig.pm</b>.<br /><br />Failed to find \"$attr\" - ". $@};
+ }
+</%perl>
+ <strong><&|/l&><% $label_of{$attr} %></&>:</strong> <% $value %><br />
+% }
+<br />
+% $m->abort;
diff --git a/static/js/calendar.js b/static/js/calendar.js
index 07a3958..ae9c819 100644
--- a/static/js/calendar.js
+++ b/static/js/calendar.js
@@ -7,6 +7,11 @@ jQuery(function() {
changeCalendarMonth();
});
+ jQuery('div[data-object]>small>div.event-info>a.event-title').hover(
+ function(e) {
+ loadCalendarEventDetails(e);
+ }
+ );
});
/*
@@ -52,3 +57,20 @@ function changeCalendarMonth() {
var querystring = jQuery('.changeCalendarMonth #querystring').val();
window.location.href = "?Month=" + month + "&Year=" + year + "&" + querystring;
}
+
+function loadCalendarEventDetails(e) {
+ // data-object
+ var event = jQuery(e.currentTarget).parents('[data-object]').attr('data-object');
+ // remove hover event from the element to run only once
+ jQuery(e.currentTarget).off('mouseenter mouseleave');
+
+ var url = RT.Config.WebHomePath + '/Helpers/CalendarEventInfo?event=' + event;
+
+ jQuery.ajax({
+ url: url,
+ success: function(data) {
+ jQuery(e.currentTarget).parents('[data-object]')
+ .find('div.event-info>span.tip').html(data);
+ }
+ });
+}
-----------------------------------------------------------------------
Summary of changes:
html/Elements/CalendarEvent | 68 +-------------------------------
html/Helpers/CalendarEventInfo | 89 ++++++++++++++++++++++++++++++++++++++++++
static/js/calendar.js | 22 +++++++++++
3 files changed, 113 insertions(+), 66 deletions(-)
create mode 100644 html/Helpers/CalendarEventInfo
hooks/post-receive
--
rtx-calendar
More information about the Bps-public-commit
mailing list