From: Ivan Kohler Date: Sun, 6 Apr 2014 03:46:31 +0000 (-0700) Subject: weekly view for RTx::Calendar, RT#16584 X-Git-Url: http://git.freeside.biz/gitweb/?p=freeside.git;a=commitdiff_plain;h=b7e8cfa78c29c9cc561cafa07dbcd82ff58acb50 weekly view for RTx::Calendar, RT#16584 --- 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 000000000..3c300bbc3 Binary files /dev/null and b/rt/share/html/NoAuth/images/week-collapse.gif differ 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 000000000..959687e29 Binary files /dev/null and b/rt/share/html/NoAuth/images/week-expand.gif differ 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 + + +
+ + + +