From 4f7725315c140dac53d390ec607b8d221166f6ac Mon Sep 17 00:00:00 2001 From: Ivan Kohler Date: Wed, 9 Apr 2014 21:02:16 -0700 Subject: [PATCH] installers (calendaring), RT#16584 --- httemplate/elements/select-time.html | 20 +-- rt/share/html/Elements/CalendarDaySchedule | 12 ++ rt/share/html/NoAuth/css/calendar.css | 8 + rt/share/html/Search/Calendar.html | 228 ++++++++++++++++++++++------- rt/share/html/Search/Schedule.html | 9 ++ 5 files changed, 203 insertions(+), 74 deletions(-) create mode 100644 rt/share/html/Elements/CalendarDaySchedule create mode 100644 rt/share/html/Search/Schedule.html diff --git a/httemplate/elements/select-time.html b/httemplate/elements/select-time.html index 6e22e1e3d..e7b404bbb 100644 --- a/httemplate/elements/select-time.html +++ b/httemplate/elements/select-time.html @@ -6,7 +6,7 @@ || $curr_value == $t ? 'SELECTED' : '' %> - ><% pretty_time($t) %> + ><% FS::sched_avail::pretty_time($t) %> % } % } @@ -28,22 +28,4 @@ if ( $opt{'onchange'} ) { $onchange = 'onChange="'. $onchange. '"' unless $onchange =~ /^onChange=/i; } -sub pretty_time { - my $t = shift; - - return 'Midnight' if $t == 0 || $t == 1440; - return 'Noon' if $t == 720; - - my $h = int( $t / 60 ); - my $m = $t % 60; - - my $ap = 'AM'; - if ( $h == 0 || $h == 24 ) { $h = 12; } - elsif ( $h == 12 ) { $ap = 'PM'; } - elsif ( $h > 12 ) { $ap = 'PM'; $h -= 12; } - - sprintf('%02d:%02d'." $ap", $h, $m); - -} - diff --git a/rt/share/html/Elements/CalendarDaySchedule b/rt/share/html/Elements/CalendarDaySchedule new file mode 100644 index 000000000..08e1a51a5 --- /dev/null +++ b/rt/share/html/Elements/CalendarDaySchedule @@ -0,0 +1,12 @@ +<%args> +$Date => undef +$Tickets => undef +$DateTypes => undef +@username => () + +% foreach my $username ( @username ) { +<% $username %>---sparkline--*
+% } +<%init> + + diff --git a/rt/share/html/NoAuth/css/calendar.css b/rt/share/html/NoAuth/css/calendar.css index 826c83658..14cbabc73 100644 --- a/rt/share/html/NoAuth/css/calendar.css +++ b/rt/share/html/NoAuth/css/calendar.css @@ -36,6 +36,10 @@ color:#505050; width:100%; } +.calendarright { + float: right; +} + table.rtxcalendar { width:100%; border-collapse: collapse; @@ -60,6 +64,10 @@ table.rtxcalendar tbody th { font-weight: normal; } +table.rtxcalendar td.weekly { + width: auto; +} + table.rtxcalendar td.offmonth { background: #f8f8f8; color: #aaa; diff --git a/rt/share/html/Search/Calendar.html b/rt/share/html/Search/Calendar.html index a693bd645..e6282b58a 100644 --- a/rt/share/html/Search/Calendar.html +++ b/rt/share/html/Search/Calendar.html @@ -12,29 +12,37 @@ $WeekMonth => undef $WeekYear => undef $OrigMonth => undef $OrigYear => undef +$Embed => undef +$DayDisplay => undef +@DayDisplayArgs => () -<& /Elements/Header, Title => $title &> -<& /Elements/Tabs &> - % my $title; % if ( $WeekMonth ) { -% if ( $date->month == $end->month ) { -% $title = $rtdate->GetMonth( $date->month -1 ). ' '. -% $date->day. '-'. $end->day. ', '. $date->year; -% } elsif ( $date->year == $end->year ) { +% if ( $start->month == $end->month ) { +% $title = $rtdate->GetMonth( $start->month -1 ). ' '. +% $start->day. '-'. $end->day. ', '. $start->year; +% } elsif ( $start->year == $end->year ) { % $title = -% $rtdate->GetMonth( $date->month -1 ). ' '. $date->day. ' - '. +% $rtdate->GetMonth( $start->month -1 ). ' '. $start->day. ' - '. % $rtdate->GetMonth( $end->month -1 ). ' '. $end->day. ', '. $end->year; % } else { % $title = -% $rtdate->GetMonth( $date->month -1 ). ' '.$date->day. ', '. $date->year. +% $rtdate->GetMonth( $start->month -1 ).' '.$start->day.', '.$start->year. % ' - '. % $rtdate->GetMonth( $end->month -1 ). ' '.$end->day. ', '. $end->year; % } % } else { % $title = $rtdate->GetMonth($Month) . " $Year" % } + +% unless ( $Embed ) { + +<& /Elements/Header, Title => $title &> +<& /Elements/Tabs &> + +% } + <&| /Widgets/TitleBox, title => loc('Calendar for '). $title, title_class=> 'inverse', @@ -51,7 +59,7 @@ $OrigYear => undef % $PYear--; % $PMonth = 11; % } - «<%$rtdate->GetMonth($PMonth)%> + «<%$rtdate->GetMonth($PMonth)%> <% $rtdate->GetMonth($Month). " $Year" %> @@ -62,7 +70,7 @@ $OrigYear => undef % $NYear++; % $NMonth = 0; % } - <%$rtdate->GetMonth($NMonth)%>» + <%$rtdate->GetMonth($NMonth)%>» @@ -74,7 +82,7 @@ $OrigYear => undef > % for ( @{$week{$weekstart}} ) { -<%$rtdate->GetWeekday($_)%> +><%$rtdate->GetWeekday($_)%> % } @@ -84,25 +92,27 @@ $OrigYear => undef % if ( $WeekDay ) { valign="middle"> - <& week_collapse, date=>$date, Month=>$OrigMonth, Year=>$OrigYear, QueryString=>$QueryString &> + <& week_collapse, date=>$start, Month=>$OrigMonth, Year=>$OrigYear, QueryString=>$QueryString, Embed=>$Embed, &> % } else { - <& td_week_expand, date=>$date, Month=>$Month, Year=>$Year, QueryString=>$QueryString &> + <& td_week_expand, date=>$start, Month=>$Month, Year=>$Year, QueryString=>$QueryString, Embed=>$Embed, &> % } % if ( $WeekDay ) { -% $date = $start; +% my $date = $start; % while ($date <= $end) { % % my $is_today = (DateTime->compare($today, $date) == 0); % my $is_yesterday = (DateTime->compare($yesterday, $date) == 0); % my $is_aweekago = (DateTime->compare($aweekago, $date) == 0); - undef % if ( $date <= $end ) { #a second week? not going to work for week view yet valign="middle"> - <& week_collapse, date=>$date, Month=>$OrigMonth, Year=>$OrigYear, QueryString=>$QueryString &> + <& week_collapse, date=>$date, Month=>$OrigMonth, Year=>$OrigYear, QueryString=>$QueryString, Embed=>$Embed, &> % } % } % } #while ($date <= $end) +% my $sday = 0; +% my @slots = ( [], [], [], [], [], [], [] ); % foreach my $row ( @week_rows ) { + <& td_time, $row &> % $date = $start; +% $sday = 0; % while ($date <= $end) { % % my $is_today = (DateTime->compare($today, $date) == 0); % my $is_yesterday = (DateTime->compare($yesterday, $date) == 0); % my $is_aweekago = (DateTime->compare($aweekago, $date) == 0); - +%# +%# class="<% $is_today ? 'today' +%# : $is_yesterday ? 'yesterday' +%# : $is_aweekago ? 'aweekago' +%# : '' +%# %>" +%# > % #XXX display these in a time aware fashion %#% my $sp = 3; @@ -154,7 +169,77 @@ $OrigYear => undef %#% } %# <% ($sp>0) ? '
'x$sp : '' |n %> - +% for my $t ( @{ $Tickets{$date->strftime("%F")} } ) { +% +% #XXX off by 1h on daylight savings boundaries... two sundays a year +% my $starts = ($t->StartsObj->Unix - $t->StartsObj->SetToMidnight(Timezone=>'user'))/60; +% +% if ( $starts >= $row && $starts < ($row + $timestep) ) { +% #then we're a new entry, find a slot for us +% my $s = 0; +% while ( ref($slots[$sday]->[$s]) ) { $s++ } +% $slots[$sday]->[$s] = [ $t->Id, $t ]; +% } +% +% #XXX also off by 1h on daylight savings boundaries +% my $due = $t->DueObj->Unix - $t->DueObj->SetToMidnight; +% +% if ( $due <= $row && $due > ($row + $timestep ) ) { +% #then find our slot and remove us +% @{ $slots[$sday] } = +% map { (!ref($_) || $_->[0] != $t->Id) ? $_ : '' } +% @{ $slots[$sday] }; +% } +% +% } +% +% pop @{ $slots[$sday] } while @{ $slots[$sday] } && !ref($slots[$sday]->[-1]); +% +% #now display: +% +% if ( scalar(@{$slots[$sday]}) > $slots ) { +% #overflow situation, eek... could be handled better, how? + + + class="weekly + <% $is_today ? 'today' + : $is_yesterday ? 'yesterday' + : $is_aweekago ? 'aweekago' + : '' + %>" + >MULTIPLE + + +% } else { +% +% foreach my $slot ( @{ $slots[$sday] } ) { +% my( $id, $ticket ) = @$slot; + + <% $id %> + + +% } +% +% if ( scalar(@{$slots[$sday]}) < $slots ) { + + + class="weekly + <% $is_today ? 'today' + : $is_yesterday ? 'yesterday' + : $is_aweekago ? 'aweekago' + : '' + %>" + > + +% } +% +% } % $date = $set->next($date); % if ( $date->day_of_week == $startday_of_week ) { @@ -162,16 +247,18 @@ $OrigYear => undef % if ( $date <= $end ) { #a second week? not going to work for week view yet valign="middle"> - <& week_collapse, date=>$date, Month=>$OrigMonth, Year=>$OrigYear, QueryString=>$QueryString &> + <& week_collapse, date=>$date, Month=>$OrigMonth, Year=>$OrigYear, QueryString=>$QueryString, Embed=>$Embed, &> % } % } - +% +% $sday++; % } #while ($date <= $end) % } #foreach my $row ( @week_rows ) - +% % } else { - +% +% my $date = $start; % while ($date <= $end) { % % my $offmonth = !$WeekDay && $date->month != ($Month + 1); @@ -179,7 +266,8 @@ $OrigYear => undef % my $is_yesterday = (DateTime->compare($yesterday, $date) == 0); % my $is_aweekago = (DateTime->compare($aweekago, $date) == 0); - undef %>calendardate" ><% $date->day %> -% my $sp = 3; -% for my $t ( @{ $Tickets{$date->strftime("%F")} } ) { -% $sp--; - <& /Elements/CalendarEvent, Object => $t, Date => $date, DateTypes => \%DateTypes &> +% if ( defined($DayDisplay) && $DayDisplay =~ /^(\w+)$/ ) { +% +% my $el = "/Elements/CalendarDay$1"; + <& $el, Tickets => $Tickets{$date->strftime("%F")}, + Date => $date, + DateTypes => \%DateTypes, + @DayDisplayArgs, + &> +% +% } else { +% +% my $sp = 3; +% for my $t ( @{ $Tickets{$date->strftime("%F")} } ) { +% $sp--; + <& /Elements/CalendarEvent, Object => $t, Date => $date, DateTypes => \%DateTypes &> +% } + <% ($sp>0) ? '
'x$sp : '' |n %> +% % } - <% ($sp>0) ? '
'x$sp : '' |n %> @@ -206,7 +307,7 @@ $OrigYear => undef % if ( $date <= $end ) { - <& td_week_expand, date=>$date, Month=>$Month, Year=>$Year, QueryString=>$QueryString &> + <& td_week_expand, date=>$date, Month=>$Month, Year=>$Year, QueryString=>$QueryString, Embed=>$Embed, &> % } % } @@ -221,11 +322,11 @@ $OrigYear => undef
- «<%$rtdate->GetMonth($PMonth)%> + «<%$rtdate->GetMonth($PMonth)%> -
+
- <%$rtdate->GetMonth($NMonth)%>» + <%$rtdate->GetMonth($NMonth)%>»
% } -% #XXX an option to turn off "Calendar Preferences and Help" for embedded -% # (and weekly?) use +% unless ( $Embed ) { + @@ -281,6 +382,8 @@ $OrigYear => undef
+% } + <%ONCE> @@ -296,12 +399,16 @@ my %legend = ( 'starts_due' => ['Starts','Due'], ); -my $stime = 480; #8am -my $etime = 1080; #6pm -my $timestep = 30; #1/2h -#my $timestep = 120; #2h +my $stime = RT->Config->Get('CalendarWeeklyStartMin'); +$stime = 480 unless $stime =~ /^\d+$/; #8am +my $etime = RT->Config->Get('CalendarWeeklyEndMin'); +$etime = 1080 unless $etime =~ /^\d+$/; #6pm + +my $timestep = RT->Config->Get('CalendarWeeklySizeMin') || 30; #1/2h my $rowspan = ($etime-$stime) / $timestep; +my $slots = RT->Config->Get('CalendarWeeklySlots') || 5; + my $wt = $stime; my @week_rows = (); while ( $wt < $etime ) { push @week_rows, $wt; $wt+=$timestep } @@ -310,6 +417,8 @@ while ( $wt < $etime ) { push @week_rows, $wt; $wt+=$timestep } <%INIT> use RTx::Calendar qw(FirstDay LastDay LastDayOfWeek); +$Embed =~ /^[\w\.]+$/ or die 'xss'; + my $title = loc("Calendar"); my @DateTypes = qw/Created Starts Started Due LastUpdated Resolved/; @@ -344,25 +453,32 @@ if ( $WeekDay ) { $start = FirstDay($Year, $Month + 1, $startday_of_week ); $end = LastDay ($Year, $Month + 1, $endday_of_week ); } -my $date = $start; # use this to loop over days until $end my $set = DateTime::Set->from_recurrence( next => sub { $_[0]->truncate( to => 'day' )->add( days => 1 ) } ); -my $QueryString = +my $QueryString; +if ($Query) { + $QueryString = $m->comp( '/Elements/QueryString', Query => $Query, Format => $Format, Order => $Order, OrderBy => $OrderBy, - Rows => $RowsPerPage - ) - if ($Query); - -$QueryString ||= 'NewQuery=1'; + Rows => $RowsPerPage, + @DayDisplayArgs, + ); +} else { + $QueryString = + $m->comp( + '/Elements/QueryString', + NewQuery => 1, + @DayDisplayArgs, + ); +} # Default Query and Format my $TempFormat = "__Starts__ __Due__"; @@ -385,11 +501,11 @@ my @Dates = grep { $TempFormat =~ m/__${_}(Relative)?__/ } @DateTypes; # used to display or not a date in Element/CalendarEvent my %DateTypes = map { $_ => 1 } @Dates; -$TempQuery .= RTx::Calendar::DatesClauses(\@Dates, $date->strftime("%F"), $end->strftime("%F")); +$TempQuery .= RTx::Calendar::DatesClauses(\@Dates, $start->strftime("%F"), $end->strftime("%F")); # print STDERR ("-" x 30), "\n", $TempQuery, "\n"; -my %Tickets = RTx::Calendar::FindTickets($session{'CurrentUser'}, $TempQuery, \@Dates, $date->strftime("%F"), $end->strftime("%F")); +my %Tickets = RTx::Calendar::FindTickets($session{'CurrentUser'}, $TempQuery, \@Dates, $start->strftime("%F"), $end->strftime("%F")); <%def td_week_expand> @@ -398,9 +514,10 @@ my %Tickets = RTx::Calendar::FindTickets($session{'CurrentUser'}, $TempQuery, \@ $Month => undef $Year => undef $QueryString => undef + $Embed => undef - + @@ -410,8 +527,9 @@ my %Tickets = RTx::Calendar::FindTickets($session{'CurrentUser'}, $TempQuery, \@ $Month => undef $Year => undef $QueryString => undef + $Embed => undef - + <%def td_time> diff --git a/rt/share/html/Search/Schedule.html b/rt/share/html/Search/Schedule.html new file mode 100644 index 000000000..12d268500 --- /dev/null +++ b/rt/share/html/Search/Schedule.html @@ -0,0 +1,9 @@ +<& /Elements/Header, Title => 'Schedule' &> + +<& /Search/Calendar.html, + @_, + Embed => 'Schedule.html', + DayDisplay => 'Schedule', + DayDisplayArgs => [ username => $ARGS{username} ], +&> + -- 2.11.0