[Bps-public-commit] rtx-calendar branch multiple-days-events updated. 1.05-20-g8ba6818
BPS Git Server
git at git.bestpractical.com
Fri Sep 8 19:02:00 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 8ba681871c502ae3382e5c439c81759107785587 (commit)
from 9bc3c341436fd0ca5de3b584cd2beccea5fab6bb (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 8ba681871c502ae3382e5c439c81759107785587
Author: Ronaldo Richieri <ronaldo at bestpractical.com>
Date: Fri Sep 8 16:01:52 2023 -0300
Add Multiple Days Event to Calendar
diff --git a/html/Elements/CalendarEvent b/html/Elements/CalendarEvent
index b8023d9..db365cc 100644
--- a/html/Elements/CalendarEvent
+++ b/html/Elements/CalendarEvent
@@ -2,19 +2,45 @@
$Date => undef
$Object => undef
$DateTypes => undef
+$FirstDayOfWeek => undef
+$TicketsSpanningDays => undef
</%args>
-<div class="day">
-<small>
-
- <% RTx::Calendar::GetEventImg($Object, $today, $DateTypes, $IsReminder)|n %>
- <a href="<%$RT::WebPath%>/Ticket/Display.html?id=<%$TicketId%>"
+% my $icon = RTx::Calendar::GetEventImg($Object, $today, $DateTypes, $IsReminder);
+% my $spanning_tickets_for_the_day = $TicketsSpanningDays->{$today} || [];
+<div class="day" style="
% if ( $CalendarStatusColorMap{$status} ) {
- style="color: <%$CalendarStatusColorMap{$status}%>;"
+ background-color: <%$CalendarStatusColorMap{$status}%>;
+% }
+% if ( grep { $_ eq $TicketId } @$spanning_tickets_for_the_day ) {
+ z-index: 3;
+% }
+">
+<small>
+ <div class="event-icon" style="
+% # If it has an icon and it's a spanning day of a ticket, it's the
+% # last day of a spanning ticket
+% if (($icon && grep { $_ eq $TicketId } @$spanning_tickets_for_the_day )) {
+ float: right;
% }
- >
+ ">
+ <% $icon|n %>
+ </div>
+ <div class="event-info">
+% # If it has an icon and it's not a spanning day of a ticket, it's the
+% # first day of a spanning ticket and not the last, which is part of the
+% # spanning_tickets_for_the_day array.
+% if (
+% ($icon && !grep { $_ eq $TicketId } @$spanning_tickets_for_the_day )
+% || $FirstDayOfWeek ) {
+ <a href="<%$RT::WebPath%>/Ticket/Display.html?id=<%$TicketId%>">
<% $Object->QueueObj->Name %> #<% $TicketId %>
<% $display_owner ? 'by ' . $Object->OwnerObj->Name : '' %>
- <% length($Object->Subject) > 80 ? substr($Object->Subject, 0, 77) . "..." : $Object->Subject %></a></small><br />
+ <% length($Object->Subject) > 80 ? substr($Object->Subject, 0, 77) . "..." : $Object->Subject %>
+ </a>
+% }
+ </div>
+</small>
+
<span class="tip">
<a href="<%$RT::WebPath%>/Ticket/Display.html?id=<%$TicketId%>">
<% $Object->QueueObj->Name %> #<% $TicketId %>
diff --git a/html/Search/Calendar.html b/html/Search/Calendar.html
index d827a68..b0bc060 100644
--- a/html/Search/Calendar.html
+++ b/html/Search/Calendar.html
@@ -153,6 +153,9 @@ foreach my $TranslatedLegend (sort keys %CalendarIconsTranslated) {
<tbody>
<tr>
+% my %week_ticket_position;
+% my $first_day_of_week = 1;
+
% while ($date <= $end) {
% my @classes = ();
% push @classes, "offmonth" if $date->month != ($Month + 1);
@@ -160,19 +163,74 @@ foreach my $TranslatedLegend (sort keys %CalendarIconsTranslated) {
% push @classes, "yesterday" if (DateTime->compare($yesterday, $date) == 0);
% push @classes, "aweekago" if (DateTime->compare($aweekago, $date) == 0);
+<%perl>
+for my $t ( $SortCalendarEvents->( @{ $Tickets->{ $date->strftime("%F") } || [] } )) {
+ # 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 ) {
+ # new tickets should assume the first empty spot.
+ my $i = 0;
+ my $free_index = 0;
+ for my $index ( sort keys %week_ticket_position ) {
+ if ( $week_ticket_position{$index}{id} eq "" ) {
+ $free_index = $i;
+ last;
+ }
+ $i++;
+ }
+
+ # if we found a free spot, we place the ticket there
+ if ( $free_index != 0 ) {
+ $week_ticket_position{$free_index}{id} = $t->id;
+ $week_ticket_position{$free_index}{TicketObj} = $t;
+ }
+ # if not, we add it to the end of the array
+ else {
+ $week_ticket_position{((scalar keys %week_ticket_position)+1)}{id} = $t->id;
+ $week_ticket_position{((scalar keys %week_ticket_position))}{TicketObj} = $t;
+ }
+ }
+}
+
+# if none is available, then we add a new row
+# if it's the final day to present a event, clean its position of the week
+
+</%perl>
+
<td class="<% @classes %>"><div class="inside-day">
<div class="calendardate"><%$date->day%></div>
-
-% for my $t ( $SortCalendarEvents->( @{ $Tickets->{ $date->strftime("%F") } || [] } )) {
- <& /Elements/CalendarEvent, Object => $t, Date => $date, DateTypes => \%DateTypes &>
+% for my $index ( sort keys %week_ticket_position ) {
+% if ( grep { $_->id eq $week_ticket_position{$index}{id} }
+% @{ $Tickets->{ $date->strftime("%F") } || [] } ) {
+% my $t = $week_ticket_position{$index}{TicketObj};
+ <& /Elements/CalendarEvent,
+ Object => $t,
+ Date => $date,
+ DateTypes => \%DateTypes,
+ FirstDayOfWeek => $first_day_of_week,
+ TicketsSpanningDays => $TicketsSpanningDays,
+ &>
+% }
+% else {
+ <div class="day"> </div>
+% }
% }
+% # we loop over the positions of the week
+% # if position is set, call CalendarEvent element
+% # if not, add empty space
</div></td>
% $date = $set->next($date);
% if ( $date->day_of_week == $startday_of_week ) {
+% # we start a new week with empty positions
+% %week_ticket_position = ();
+% $first_day_of_week = 1;
</tr><tr>
% }
+% else {
+% $first_day_of_week = 0;
+% }
% }
</tr>
@@ -357,7 +415,7 @@ $TempQuery .= RTx::Calendar::DatesClauses(\@Dates, $date->strftime("%F"), $end->
$m->callback( CallbackName => 'BeforeFindTickets', ARGSRef => \%ARGS, QueryRef => \$TempQuery, FormatRef => \$TempFormat );
-my $Tickets = RTx::Calendar::FindTickets($session{'CurrentUser'}, $TempQuery, \@Dates, $date->strftime("%F"), $end->strftime("%F"));
+my ($Tickets, $TicketsSpanningDays) = RTx::Calendar::FindTickets($session{'CurrentUser'}, $TempQuery, \@Dates, $date->strftime("%F"), $end->strftime("%F"));
my $DownloadQueryString =
$m->comp(
diff --git a/lib/RTx/Calendar.pm b/lib/RTx/Calendar.pm
index 79121ea..38326c2 100644
--- a/lib/RTx/Calendar.pm
+++ b/lib/RTx/Calendar.pm
@@ -119,12 +119,14 @@ sub FindTickets {
Timezone => 'utc'
);
$end_date_unix = $end_date_unix->Unix;
+ my $first_day = 1;
while ( $current_date->Unix <= $end_date_unix )
{
my $dateindex = LocalDate( $current_date->Unix );
push @{ $TicketsSpanningDays{$dateindex} }, $Ticket->id
- unless $TicketsSpanningDaysAlreadySeen{$dateindex}
+ unless $first_day
+ || $TicketsSpanningDaysAlreadySeen{$dateindex}
{$Ticket}++;
push @{ $Tickets{$dateindex } },
$Ticket
@@ -135,6 +137,7 @@ sub FindTickets {
{$Ticket}++;
$current_date->AddDay();
+ $first_day = 0;
}
}
}
diff --git a/static/css/calendar.css b/static/css/calendar.css
index 96e9086..8d4acd9 100644
--- a/static/css/calendar.css
+++ b/static/css/calendar.css
@@ -2,10 +2,15 @@
table.rtxcalendar .day {
position: relative;
z-index: 1;
+ padding: 3px 3px 3px 6px;
+ margin-top: 4px;
+ margin-bottom: 4px;
+ width:102%;
+ height: 1.75rem;
+ left: -1px;
+ z-index: 4;
}
-
-
table.rtxcalendar .day:hover {
z-index: 5;
color:#000;
@@ -137,3 +142,14 @@ a.calendar-toggle-sidebar.sidebar-off::before {
.calendar-sidebar {
margin-right: 10px;
}
+
+.event-icon {
+ float: left;
+ margin-right: 5px;
+}
+
+.event-info a {
+ white-space: nowrap;
+ position: absolute;
+ color: white;
+}
-----------------------------------------------------------------------
Summary of changes:
html/Elements/CalendarEvent | 42 +++++++++++++++++++++++------
html/Search/Calendar.html | 66 ++++++++++++++++++++++++++++++++++++++++++---
lib/RTx/Calendar.pm | 5 +++-
static/css/calendar.css | 20 ++++++++++++--
4 files changed, 118 insertions(+), 15 deletions(-)
hooks/post-receive
--
rtx-calendar
More information about the Bps-public-commit
mailing list