[freeside-commits] branch FREESIDE_3_BRANCH updated. a9fbd6a9c213d60b57778a170c15576697adef9e

Ivan ivan at 420.am
Sun Apr 13 02:20:21 PDT 2014


The branch, FREESIDE_3_BRANCH has been updated
       via  a9fbd6a9c213d60b57778a170c15576697adef9e (commit)
      from  2513882cf22e165f704cf3a0f9891dedb213a310 (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 a9fbd6a9c213d60b57778a170c15576697adef9e
Author: Ivan Kohler <ivan at freeside.biz>
Date:   Sun Apr 13 02:20:19 2014 -0700

    installers (calendaring), RT#16584

diff --git a/rt/lib/RTx/Calendar.pm b/rt/lib/RTx/Calendar.pm
index 88cfecd..7ddf186 100644
--- a/rt/lib/RTx/Calendar.pm
+++ b/rt/lib/RTx/Calendar.pm
@@ -10,7 +10,8 @@ our $VERSION = "0.17";
 RT->AddStyleSheets('calendar.css')
     if RT->can('AddStyleSheets');
 
-our @EXPORT_OK = qw( FirstDay LastDay LastDayOfWeek );
+our @EXPORT_OK = qw( FirstDay LastDay LastDayOfWeek DatesClauses LocalDate
+                     SearchDefaultCalendar FindTickets );
 
 sub FirstDay {
     my ($year, $month, $matchday) = @_;
@@ -43,10 +44,10 @@ sub LastDayOfWeek {
 	next => sub { $_[0]->truncate( to => 'day' )->add( days => 1 ) }
     );
 
-    my $day = DateTime->new( year => $year, month => $month, day => $day );
+    my $dt = DateTime->new( year => $year, month => $month, day => $day );
 
-    $day = $set->next($day) while $day->day_of_week != $matchday;
-    $day;
+    $dt = $set->next($dt) while $dt->day_of_week != $matchday;
+    $dt;
 
 }
 
diff --git a/rt/lib/RTx/Schedule.pm b/rt/lib/RTx/Schedule.pm
new file mode 100644
index 0000000..4c6e1f9
--- /dev/null
+++ b/rt/lib/RTx/Schedule.pm
@@ -0,0 +1,117 @@
+package RTx::Schedule;
+use base qw( Exporter );
+
+use strict;
+use RTx::Calendar qw( FindTickets LocalDate );
+
+our $VERSION = '0.01';
+
+our @EXPORT_OK = qw( UserDaySchedule );
+
+#ala Calendar.html
+# Default Query and Format
+our $DefaultFormat = "__Starts__ __Due__";
+our $DefaultQuery = "( Status = 'new' OR Status = 'open' OR Status = 'stalled')
+ AND ( Type = 'reminder' OR 'Type' = 'ticket' )";
+
+sub UserDaySchedule {
+  my %arg = @_;
+  my $username = $arg{username};
+  my $date = $arg{date};
+
+  my $Tickets;
+  if ( $arg{Tickets} ) {
+    $Tickets = $arg{Tickets};
+  } else {
+
+     my $Query = $DefaultQuery;
+
+#    # we overide them if needed
+#    $TempQuery  = $Query  if $Query;
+#    $TempFormat = $Format if $Format;
+
+#    # we search all date types in Format string
+#    my @Dates = grep { $TempFormat =~ m/__${_}(Relative)?__/ } @DateTypes;
+
+     my @Dates = qw( Starts Due );
+
+#    # used to display or not a date in Element/CalendarEvent
+#    my %DateTypes = map { $_ => 1 } @Dates;
+#
+#    $TempQuery .= DatesClauses(\@Dates, $start->strftime("%F"), $end->strftime("%F"));
+
+    my %t = FindTickets( $arg{CurrentUser}, $Query, \@Dates, $date x2 );
+
+    $Tickets = $t{ $date };
+  }
+
+  #XXX block out unavailable times
+  #alas.  abstractions break, freeside-specific stuff to get availability
+  # move availability to RT side?  make it all callback/pluggable?
+
+  return (
+
+    #avail/unavailable times
+    'avail'     => {
+    },
+
+    #block out / show / color code existing appointments
+    'scheduled' => {
+      map {
+            #$_->Id => [ $_->StartsObj, $t->DueObj ];
+
+            my($sm, $sh) = ($_->StartsObj->Localtime('user'))[1,2];
+            my $starts = $sh*60 + $sm;
+
+            my($dm, $dh) = ($_->DueObj->Localtime('user'))[1,2];
+            my $due = $dh*60 + $dm;
+
+            #XXX color code existing appointments by... city?  proximity?  etc.
+            my $col = '99ff99'; #green
+
+            $_->Id => [ $starts, $due, $col, $_ ];
+          }
+        grep {
+                   LocalDate($_->StartsObj->Unix) eq $date
+               and $_->OwnerObj->Name eq $username
+             }
+          @$Tickets
+    },
+
+  );
+
+}
+
+1;
+
+__END__
+
+=head1 NAME
+
+RTx::Schedule - Scheduling extension for Request Tracker
+
+=head1 DESCRIPTION
+
+This RT extension adds scheduling functionality to Request Tracker.
+
+=head1 CONFIGURATION
+
+CalendarWeeklyStartMin (default 480, 8am)
+
+CalendarWeeklyEndMin (default 1080, 6pm)
+
+CalendarWeeklySizeMin (default 30)
+
+CalendarWeeklySlots (unused now?)
+
+=head1 AUTHOR
+
+Ivan Kohler
+
+=head1 COPYRIGHT
+
+Copyright 2014 Freeside Internet Services, Inc.
+
+This program is free software; you can redistribute it and/or
+modify it under the same terms as Request Tracker itself.
+
diff --git a/rt/share/html/Elements/CalendarDaySchedule b/rt/share/html/Elements/CalendarDaySchedule
index 0f9f909..f378674 100644
--- a/rt/share/html/Elements/CalendarDaySchedule
+++ b/rt/share/html/Elements/CalendarDaySchedule
@@ -1,32 +1,63 @@
 <%args>
-$Date      => undef
-$Tickets   => undef
-$DateTypes => undef
- at username  => ()
+$Date        => undef
+$Tickets     => undef
+$DateTypes   => undef
+ at username    => ()
+$CurrentUser => undef
 </%args>
 % foreach my $username ( @username ) {
 %   my $mapname = "$username-$date";
-<span class="calendarright"><% $username %><img src="<%$RT::WebPath%>/Schedule/UserBar?Username=<%$username%>;Date=<%$date%>" useMap="#<%$mapname%>"><span><br>
-<MAP name="<%$mapname%>">
-%# false laziness w/Schedule/UserBar
-%#XXX block out unavailable times
-%#alas.  abstractions break, freeside-specific stuff to get availability
-%# move availability to RT side?  make it all callback/pluggable?
-%
-%#XXX block out / show / color code existing appointments
+%   my $img = "$RT::WebPath/Schedule/UserBar?Username=$username;Date=$date";
+    <span class="calendarright"
+    ><% $username %><img src    = "<%$img|n%>"
+                         useMap = "#<%$mapname%>"
+                         height = <%$height%>
+                         width  = <%$width%>
+    ></span><br>
+
+    <MAP name="<%$mapname%>">
+
+%   my %schedule = UserDaySchedule( CurrentUser => $CurrentUser,
+%                                   username    => $username,
+%                                   'date'      => $Date->strftime('%F'),
+%                                 );
+
+%   #XXX block out unavailable times
 %
-<AREA onmouseover="overlib('XX miles away<BR>more info')"
-      onmouseout="nd(); return true;"
-      shape = "rect"
-      coords="0,0,59,11"
-      href="test_href"
-%#    alt=
-%#    title=
->
-</MAP>
+%   #block out / show / color code existing appointments
+%   foreach my $id ( keys %{ $schedule{'scheduled'} } ) {
+%     my( $starts, $due, $col, $t ) = @{ $schedule{'scheduled'}->{$id} };
+%     my $s = int(($starts-$stime)/10);
+%     my $e = int(($due-$stime)/10)-1;
+      <AREA
+         onmouseover = "overlib('<%$id%>: XX miles away<BR>more info', BGCOLOR, '#000000', FGCOLOR, '#<%$col%>')"
+         onmouseout  = "nd(); return true;"
+         shape       = "rect"
+         coords      = "<%$s%>,0,<%$e%>,<%$height-1%>"
+%#         href        = "test_href"
+%#         alt         =
+%#         title       =
+      >
+%   }
+
+    </MAP>
+
 % }
+<%once>
+
+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 $width = int( ( $etime - $stime ) / 10 );
+my $height = 12; #Schedule/UserBar
+
+</%once>
 <%init>
 
+use RTx::Schedule qw( UserDaySchedule );
+
 my( $date, $time ) = split('T', $Date);
 
 </%init>
diff --git a/rt/share/html/Elements/CalendarSlotSchedule b/rt/share/html/Elements/CalendarSlotSchedule
index 3af90ff..fb5b7c1 100644
--- a/rt/share/html/Elements/CalendarSlotSchedule
+++ b/rt/share/html/Elements/CalendarSlotSchedule
@@ -8,39 +8,47 @@
   @username => ()
 </%ARGS>
 % foreach my $username ( @username ) {
-
-    <td class="weekly
-%#               <%   $is_today     ? 'today'
-%#                  : $is_yesterday ? 'yesterday'
-%#                  : $is_aweekago  ? 'aweekago'
-%#                  : ''
-%#               %>
-                   "
-    >
-%       for my $t (@Tickets) {
-%         next unless $t->OwnerObj->Name eq $username;
 %
-%         next unless RTx::Calendar::LocalDate($t->StartsObj->Unix)
-%                     eq $Date->strftime('%F'); #today
+%   my %schedule = UserDaySchedule( username => $username,
+%                                   'date'   => $Date->strftime('%F'),
+%                                   Tickets  => \@Tickets,
+%                                 );
+%
+%   my $bgcolor = 'ffffff';
+%   my $content = '';
+%
+%   #XXX block out unavailable times
 %
-%         my($sm, $sh) = ($t->StartsObj->Localtime('user'))[1,2];
-%         my $starts = $sh*60 + $sm;
+%   #block out / show / color code existing appointments
+%       foreach my $id ( keys %{ $schedule{'scheduled'} } ) {
 %
-%         my($dm, $dh) = ($t->DueObj->Localtime('user'))[1,2];
-%         my $due = $dh*60 + $dm;
+%         my( $starts, $due, $col, $t ) = @{ $schedule{'scheduled'}->{$id} };
 %
 %         next if $starts >= ($tod_row+$timestep) || $due < $tod_row;
 %
-%         warn $starts. ' = '. ($tod_row+$timestep);
 %         if ( $starts >= $tod_row ) {
-            <% $t->Id %>
+%           $bgcolor = $col;
+%           $content .= ($content?', ':''). $id; #XXX more
 %         } else {
-            cont<% $t->Id %>...
+%           $bgcolor = $col;
 %         }
 %       }
-    </td>
+
+    <td style="background:#<%$bgcolor%>" class="weekly
+%#               <%   $is_today     ? 'today'
+%#                  : $is_yesterday ? 'yesterday'
+%#                  : $is_aweekago  ? 'aweekago'
+%#                  : ''
+%#               %>
+                   "
+    ><% $content %></td>
 % }
 <%ONCE>
 my $default_slots = RT->Config->Get('CalendarWeeklySlots') || 5;
 my $default_timestep = RT->Config->Get('CalendarWeeklySizeMin') || 30; #1/2h
 </%ONCE>
+<%INIT>
+
+use RTx::Schedule qw( UserDaySchedule );
+
+</%INIT>
diff --git a/rt/share/html/Schedule/UserBar b/rt/share/html/Schedule/UserBar
index 5e834a0..2345fe8 100644
--- a/rt/share/html/Schedule/UserBar
+++ b/rt/share/html/Schedule/UserBar
@@ -1,6 +1,7 @@
 <%perl>
 
 use GD;
+use RTx::Schedule qw( UserDaySchedule );
 
 my $im = new GD::Image($width, $height) or die;
 
@@ -10,11 +11,21 @@ my $black = $im->colorAllocate(0,0,0);
 # Put a black frame around the picture
 $im->rectangle(0,0,$width-1,$height-1,$black);
 
+my %schedule = UserDaySchedule( CurrentUser => $session{CurrentUser},
+                                username    => $Username,
+                                'date'      => $Date,
+                              );
+
 #XXX block out unavailable times
-#alas.  abstractions break, freeside-specific stuff to get availability
-# move availability to RT side?  make it all callback/pluggable?
 
-#XXX block out / show / color code existing appointments
+#block out / show / color code existing appointments
+foreach my $id ( keys %{ $schedule{'scheduled'} } ) {
+
+  my( $starts, $due, $col, $t ) = @{ $schedule{'scheduled'}->{$id} };
+  my $color = $im->colorAllocate( unpack 'C*', pack 'H*', $col );
+  $im->filledRectangle( int(($starts-$stime)/10), 1, int(($due-$stime)/10)-1, $height-2, $color );
+
+}
 
 $r->content_type('image/png');
 $m->clear_buffer;
@@ -33,7 +44,7 @@ $stime = 480 unless $stime =~ /^\d+$/; #8am
 my $etime    = RT->Config->Get('CalendarWeeklyEndMin');
 $etime = 1080 unless $etime =~ /^\d+$/; #6pm
 
-my $width = ( $etime - $stime ) / 10;
-my $height = 12;
+my $width = int( ( $etime - $stime ) / 10 );
+my $height = 12; #Elements/CalendarDaySchedule
 
 </%once>
diff --git a/rt/share/html/Search/Calendar.html b/rt/share/html/Search/Calendar.html
index a6df9fc..d86a5b5 100644
--- a/rt/share/html/Search/Calendar.html
+++ b/rt/share/html/Search/Calendar.html
@@ -205,7 +205,7 @@ $slots       => $default_slots
 %               my($m, $h) = ($Ticket->$meth->Localtime('user'))[1,2];
 %               my $tod = $h*60 + $m;
 %
-%               RTx::Calendar::LocalDate($Ticket->$meth->Unix) eq $date->strftime('%F') #today
+%               LocalDate($Ticket->$meth->Unix) eq $date->strftime('%F') #today
 %                 && $tod >= $row && $tod < ($row+$timestep); #and in timeslot
 %             } keys %DateTypes;
 %           next unless keys %dt;
@@ -265,9 +265,10 @@ $slots       => $default_slots
 %       if ( defined($Display) && $Display =~ /^(\w+)$/ ) {
 %
 %         my $el = "/Elements/CalendarDay$1";
-          <& $el, Tickets   => $Tickets{$date->strftime("%F")},
-                  Date      => $date,
-                  DateTypes => \%DateTypes,
+          <& $el, CurrentUser => $session{CurrentUser},
+                  Tickets     => $Tickets{$date->strftime("%F")},
+                  Date        => $date,
+                  DateTypes   => \%DateTypes,
                   @DisplayArgs,
           &>
 %
@@ -397,7 +398,8 @@ while ( $wt < $etime ) { push @week_rows, $wt; $wt+=$timestep }
 
 </%ONCE>
 <%INIT>
-use RTx::Calendar qw(FirstDay LastDay LastDayOfWeek);
+use RTx::Calendar qw( FirstDay LastDay LastDayOfWeek DatesClauses LocalDate
+                      SearchDefaultCalendar FindTickets );
 
 $Embed =~ /^[\w\.]*$/ or die 'xss';
 
@@ -468,7 +470,7 @@ my $TempQuery = "( Status = 'new' OR Status = 'open' OR Status = 'stalled')
  AND ( Owner = '" . $session{CurrentUser}->Id ."' OR Owner = 'Nobody'  )
  AND ( Type = 'reminder' OR 'Type' = 'ticket' )";
 
-if ( my $Search = RTx::Calendar::SearchDefaultCalendar($session{CurrentUser}) ) {
+if ( my $Search = SearchDefaultCalendar($session{CurrentUser}) ) {
   $TempFormat = $Search->SubValue('Format');
   $TempQuery = $Search->SubValue('Query');
 }
@@ -483,11 +485,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, $start->strftime("%F"), $end->strftime("%F"));
+$TempQuery .= DatesClauses(\@Dates, $start->strftime("%F"), $end->strftime("%F"));
 
 # print STDERR ("-" x 30), "\n", $TempQuery, "\n";
 
-my %Tickets = RTx::Calendar::FindTickets($session{'CurrentUser'}, $TempQuery, \@Dates, $start->strftime("%F"), $end->strftime("%F"));
+my %Tickets = FindTickets($session{'CurrentUser'}, $TempQuery, \@Dates, $start->strftime("%F"), $end->strftime("%F"));
 
 </%INIT>
 <%def td_week_expand>

-----------------------------------------------------------------------

Summary of changes:
 rt/lib/RTx/Calendar.pm                      |    9 +-
 rt/lib/RTx/Schedule.pm                      |  117 +++++++++++++++++++++++++++
 rt/share/html/Elements/CalendarDaySchedule  |   73 ++++++++++++-----
 rt/share/html/Elements/CalendarSlotSchedule |   50 +++++++-----
 rt/share/html/Schedule/UserBar              |   21 ++++-
 rt/share/html/Search/Calendar.html          |   18 +++--
 6 files changed, 229 insertions(+), 59 deletions(-)
 create mode 100644 rt/lib/RTx/Schedule.pm




More information about the freeside-commits mailing list