From 19cae13fbfa17207f58c2ad44cb94f57caf64356 Mon Sep 17 00:00:00 2001 From: Ivan Kohler Date: Sat, 5 Apr 2014 20:46:31 -0700 Subject: [PATCH] weekly view for RTx::Calendar, RT#16584 --- rt/lib/RTx/Calendar.pm | 15 ++- rt/share/html/NoAuth/css/calendar.css | 17 +++ rt/share/html/NoAuth/images/week-collapse.gif | Bin 0 -> 137 bytes rt/share/html/NoAuth/images/week-expand.gif | Bin 0 -> 150 bytes rt/share/html/Search/Calendar.html | 159 ++++++++++++++++++-------- 5 files changed, 141 insertions(+), 50 deletions(-) create mode 100644 rt/share/html/NoAuth/images/week-collapse.gif create mode 100644 rt/share/html/NoAuth/images/week-expand.gif diff --git a/rt/lib/RTx/Calendar.pm b/rt/lib/RTx/Calendar.pm index be127072c..88cfecd14 100644 --- a/rt/lib/RTx/Calendar.pm +++ b/rt/lib/RTx/Calendar.pm @@ -10,7 +10,7 @@ our $VERSION = "0.17"; RT->AddStyleSheets('calendar.css') if RT->can('AddStyleSheets'); -our @EXPORT_OK = qw( FirstDay LastDay ); +our @EXPORT_OK = qw( FirstDay LastDay LastDayOfWeek ); sub FirstDay { my ($year, $month, $matchday) = @_; @@ -37,6 +37,19 @@ sub LastDay { $day; } +sub LastDayOfWeek { + my ($year, $month, $day, $matchday) = @_; + my $set = DateTime::Set->from_recurrence( + next => sub { $_[0]->truncate( to => 'day' )->add( days => 1 ) } + ); + + my $day = DateTime->new( year => $year, month => $month, day => $day ); + + $day = $set->next($day) while $day->day_of_week != $matchday; + $day; + +} + # we can't use RT::Date::Date because it uses gmtime # and we need localtime sub LocalDate { diff --git a/rt/share/html/NoAuth/css/calendar.css b/rt/share/html/NoAuth/css/calendar.css index 93edccf4c..cc1f2c4d7 100644 --- a/rt/share/html/NoAuth/css/calendar.css +++ b/rt/share/html/NoAuth/css/calendar.css @@ -31,6 +31,11 @@ color:#505050; width:100%; } +.calendardate { + text-align: right; + width:100%; +} + table.rtxcalendar { width:100%; border-collapse: collapse; @@ -73,3 +78,15 @@ table.rtxcalendar td.aweekago { border-bottom: none; } +table.rtxcalendar td.controls { + background: #eeeeee; + width: 1%; + border-top: 1px solid #eeeeee; + border-left: 1px solid #eeeeee; + border-bottom: 1px solid #eeeeee; +} + +table.rtxcalendar td.controls:hover { + background-color: #CFDEFF; +} + diff --git a/rt/share/html/NoAuth/images/week-collapse.gif b/rt/share/html/NoAuth/images/week-collapse.gif new file mode 100644 index 0000000000000000000000000000000000000000..3c300bbc3d11c54d006b9aed30c3f60c90afb03c GIT binary patch literal 137 zcmZ?wbhEHbF~!fB>Y4fys4_dS&;iX-Ash9liNv&u*txp4V5nq?K09hRIdiBf9bK7lL08f{uIEtBo=O0lK4oy!6k7_0#?tvjm# literal 0 HcmV?d00001 diff --git a/rt/share/html/NoAuth/images/week-expand.gif b/rt/share/html/NoAuth/images/week-expand.gif new file mode 100644 index 0000000000000000000000000000000000000000..959687e29eb6fe73df05cc250589ee3a208e40a9 GIT binary patch literal 150 zcmV;H0BQe6Nk%w1VG95}0HFf_kdTna$H)Kw{{R30A^s6Va%Ew3Wn>_CX>@2HM@dak z03rDV0SW*E04x9i000XBJOBU!Qk*TPD7n+(iuBM6TTaqRIBCx|lH>QFp_7U&yOydl zTW);bv~I(@-;?neK%%f{dL5TJWX;%QDx=h?6?gqfv0QDn8>B%wnojwGLi;dTv7!I~ EJCP$j&Hw-a literal 0 HcmV?d00001 diff --git a/rt/share/html/Search/Calendar.html b/rt/share/html/Search/Calendar.html index 8a1b79609..db781d81b 100644 --- a/rt/share/html/Search/Calendar.html +++ b/rt/share/html/Search/Calendar.html @@ -7,6 +7,11 @@ $Order => undef $OrderBy => undef $RowsPerPage => undef $NewQuery => 0 +$WeekDay => undef +$WeekMonth => undef +$WeekYear => undef +$OrigMonth => undef +$OrigYear => undef <& /Elements/Header, Title => $title &> @@ -17,34 +22,39 @@ $NewQuery => 0 title_class=> 'inverse', color => "#993333" &> - - - + +
-% my ($PMonth, $PYear) = ($Month - 1, $Year); +% my($PMonth, $PYear, $NMonth, $NYear); +% unless ( $WeekDay ) { + + + + - - + + - -
+% ($PMonth, $PYear) = ($Month - 1, $Year); % if ($PMonth < 0) { % $PYear--; % $PMonth = 11; % } -«<%$rtdate->GetMonth($PMonth)%> - - <% $rtdate->GetMonth($Month). " $Year" %> - -% my ($NMonth, $NYear) = ($Month + 1, $Year); + «<%$rtdate->GetMonth($PMonth)%> + + <% $rtdate->GetMonth($Month). " $Year" %> + +% ($NMonth, $NYear) = ($Month + 1, $Year); % if ($NMonth > 11) { % $NYear++; % $NMonth = 0; % } -<%$rtdate->GetMonth($NMonth)%>» -
+ <%$rtdate->GetMonth($NMonth)%>» +
+% } + % for ( @{$week{$weekstart}} ) { % } @@ -53,6 +63,11 @@ $NewQuery => 0 +% if ( $WeekDay ) { + <& td_week_collapse, date=>$date, Month=>$OrigMonth, Year=>$OrigYear, QueryString=>$QueryString &> +% } else { + <& td_week_expand, date=>$date, Month=>$Month, Year=>$Year, QueryString=>$QueryString &> +% } % while ($date <= $end) { % % my $offmonth = $date->month != ($Month + 1); @@ -60,7 +75,7 @@ $NewQuery => 0 % my $is_yesterday = (DateTime->compare($yesterday, $date) == 0); % my $is_aweekago = (DateTime->compare($aweekago, $date) == 0); - + +% if ( $date <= $end ) { + +% if ( $WeekDay ) { + <& td_week_collapse, date=>$date, Month=>$OrigMonth, Year=>$OrigYear, QueryString=>$QueryString &> +% } else { + <& td_week_expand, date=>$date, Month=>$Month, Year=>$Year, QueryString=>$QueryString &> +% } +% } % } % } -
<%$rtdate->GetWeekday($_)%>
0 %>" >
<%$date->day%>
+ ><% ( $WeekDay ? $rtdate->GetMonth($date->month). ' ' : '' ). + $date->day + %> % my $sp = 3; % for my $t ( @{ $Tickets{$date->strftime("%F")} } ) { @@ -83,47 +100,61 @@ $NewQuery => 0 % $date = $set->next($date); % if ( $date->day_of_week == $startday_of_week ) { -
- - - +% unless ( $WeekDay ) { - + +
-«<%$rtdate->GetMonth($PMonth)%> - -
+ + + - -% my $year = (localtime)[5] + 1900; - + + + - - -
+ «<%$rtdate->GetMonth($PMonth)%> + + + + + +% my $year = (localtime)[5] + 1900; + %# <& /Elements/Submit&> - + - - -<%$rtdate->GetMonth($NMonth)%>» -
+
+ <%$rtdate->GetMonth($NMonth)%>» +
+ +% } +% #XXX an option to turn off "Calendar Preferences and Help" for embedded +% # (and weekly?) use @@ -166,7 +197,7 @@ my %legend = ( <%INIT> -use RTx::Calendar qw(FirstDay LastDay); +use RTx::Calendar qw(FirstDay LastDay LastDayOfWeek); my $title = loc("Calendar"); @@ -186,8 +217,15 @@ my $endday_of_week = ${$week{$weekstart}}[-1] || 7; my $today = DateTime->today; my $yesterday = $today->clone->subtract( days=>1 ); my $aweekago = $today->clone->subtract( days=>7 ); -my $date = FirstDay($Year, $Month + 1, $startday_of_week ); -my $end = LastDay ($Year, $Month + 1, $endday_of_week ); + +my( $date, $end); +if ( $WeekDay ) { + $date = DateTime->new( year=>$WeekYear, month=>$WeekMonth, day=>$WeekDay ); + $end = LastDayOfWeek( $WeekYear, $WeekMonth, $WeekDay, $endday_of_week ); +} else { + $date = FirstDay($Year, $Month + 1, $startday_of_week ); + $end = LastDay ($Year, $Month + 1, $endday_of_week ); +} # use this to loop over days until $end my $set = DateTime::Set->from_recurrence( @@ -235,3 +273,26 @@ $TempQuery .= RTx::Calendar::DatesClauses(\@Dates, $date->strftime("%F"), $end-> my %Tickets = RTx::Calendar::FindTickets($session{'CurrentUser'}, $TempQuery, \@Dates, $date->strftime("%F"), $end->strftime("%F")); +<%def td_week_expand> +<%args> + $date => undef + $Month => undef + $Year => undef + $QueryString => undef + + + + +<%def td_week_collapse> +<%args> + $date => undef + $Month => undef + $Year => undef + $QueryString => undef + + + -- 2.11.0
+ + + +