[rt-commit] r306 - in rt/branches/rt-3.1: html/Elements lib/RT

jesse at fsck.com jesse at fsck.com
Sun Dec 14 23:32:48 EST 2003


Author: jesse
Date: 2003-12-14 23:24:16 -0500 (Sun, 14 Dec 2003)
New Revision: 306

Modified:
   rt/branches/rt-3.1/html/Elements/MyRequests
   rt/branches/rt-3.1/lib/RT/Tickets_Overlay.pm
   rt/branches/rt-3.1/lib/RT/Tickets_Overlay_SQL.pm
Log:
better docs and a first example of the use in MyRequests. wants more generalization.


Modified: rt/branches/rt-3.1/html/Elements/MyRequests
===================================================================
--- rt/branches/rt-3.1/html/Elements/MyRequests	2003-12-14 18:23:46 UTC (rev 305)
+++ rt/branches/rt-3.1/html/Elements/MyRequests	2003-12-15 04:24:16 UTC (rev 306)
@@ -34,45 +34,64 @@
 % while (my $Ticket = $MyTickets->Next) {
 % $i++;
 <TR class="<% $i%2 ? 'oddline' : 'evenline'%>" >
-<TD ALIGN=RIGHT>
-<%$Ticket->Id%>
-</TD>
+% my @cols = $MyTickets->DisplayColumns;
+% foreach my $col (@cols) {
 <TD>
-<A HREF="<% $RT::WebPath %>/Ticket/Display.html?id=<%$Ticket->Id%>">
-<%$Ticket->Subject || loc('(no subject)')%>
-</A>
-</TD>
-<TD>
-<%$Ticket->QueueObj->Name%>
-</TD>
-<TD>
-% if ($Ticket->HasUnresolvedDependencies ) {
-%     if ($Ticket->HasUnresolvedDependencies( Type => 'approval'  )) { 
-<em><&|/l&>(pending approval)</&></em>
-%     } else {
-<em><&|/l&>(pending other tickets)</&></em>
-%     }
+% if ($map->{$col}) { $col = $map->{$col} ;
+% $m->out(&{$col->{value}}($Ticket));
+
+% my $cmd = "\$Ticket->$col()";
+% eval {$m->out(eval $cmd)}|| $m->out($@);
 % } else {
-<%loc($Ticket->Status)%>
+
+%$col =~ s/##(.*?)##/&{$map->{$1}->{value}}($Ticket);/ge;
+<%$col|n%>
 % }
+
 </TD>
-<TD>
-<%$Ticket->OwnerObj->Name%>
-</TD>
+% }
+
 </TR>
 % }
 </TABLE>
-<& /Elements/TitleBoxEnd &>
+<& /Elements/TitleBoxEnd &> 
+<%INIT>
 
+my $map = {
+    QueueName             => { value => sub { return $_[0]->QueueObj->Name}},
+    OwnerName             => { value => sub { return $_[0]->OwnerObj->Name}},
+    id             => { value => sub { return $_[0]->id}},
+    Status             => { value => sub { return $_[0]->Status}},
+    Subject             => { value => sub { return $_[0]->Subject}},
+    ExtendedStatus => {
+        title => loc('Status'),
+        value => sub {
+            my $Ticket = shift;
 
-<%INIT>
+            if ( $Ticket->HasUnresolvedDependencies ) {
+                if (    $Ticket->HasUnresolvedDependencies( Type => 'approval' )
+                     or $Ticket->HasUnresolvedDependencies( Type => 'code' ) ) {
+                    return "<em>" . loc('(pending approval)') . "</em>";
+                }
+                else {
+                    return "<em>" . loc('(pending other tickets)') . "</em>";
+                }
+            }
+            else {
+                return loc( $Ticket->Status );
+            }
+
+          }
+    }
+};
+
 my $rows = 10;
 my $MyTickets;
 $MyTickets = new RT::Tickets ($session{'CurrentUser'});
-$MyTickets->LimitWatcher(TYPE => 'Requestor', VALUE => $session{'CurrentUser'}->EmailAddress);
-$MyTickets->LimitStatus(VALUE => "open");
-$MyTickets->LimitStatus(VALUE => "new");
-$MyTickets->RowsPerPage($rows);
-$MyTickets->OrderBy(FIELD => 'Priority', ORDER => 'DESC');
 
+$MyTickets->FromSQL("SELECT '<a href=\"/Ticket/Display.html?id=##id##\">##id##</a>', '<a href=\"/Ticket/Display.html?id=##id##\">##Subject##</a>', QueueName, ExtendedStatus, OwnerName WHERE Requestor = '".$session{'CurrentUser'}->EmailAddress."' AND ( Status = 'new' OR Status = 'open')");
+
+
+$MyTickets->OrderBy(FIELD => 'Priority', ORDER => 'DESC'); 
+
 </%INIT>

Modified: rt/branches/rt-3.1/lib/RT/Tickets_Overlay.pm
===================================================================
--- rt/branches/rt-3.1/lib/RT/Tickets_Overlay.pm	2003-12-14 18:23:46 UTC (rev 305)
+++ rt/branches/rt-3.1/lib/RT/Tickets_Overlay.pm	2003-12-15 04:24:16 UTC (rev 306)
@@ -1695,6 +1695,7 @@
     $self->{'primary_key'} = "id";
     delete $self->{'items_array'};
     delete $self->{'item_map'};
+    delete $self->{'columns_to_display'};
     $self->SUPER::_Init(@_);
 
     $self->_InitSQL;

Modified: rt/branches/rt-3.1/lib/RT/Tickets_Overlay_SQL.pm
===================================================================
--- rt/branches/rt-3.1/lib/RT/Tickets_Overlay_SQL.pm	2003-12-14 18:23:46 UTC (rev 305)
+++ rt/branches/rt-3.1/lib/RT/Tickets_Overlay_SQL.pm	2003-12-15 04:24:16 UTC (rev 306)
@@ -24,6 +24,8 @@
 use strict;
 use warnings;
 
+use RT::Tickets;
+
 # Import configuration data from the lexcial scope of __PACKAGE__ (or
 # at least where those two Subroutines are defined.)
 
@@ -124,7 +126,6 @@
 my $re_select = qr[(?i:SELECT)];
 my $re_where = qr[(?i:WHERE)];
 my $re_value  = qr[$RE{delimited}{-delim=>qq{\'\"}}|\d+];
-my $re_column  = qr[$RE{delimited}{-delim=>qq{\'\"}}|\d+];
 my $re_keyword = qr[$RE{delimited}{-delim=>qq{\'\"}}|(?:\{|\}|\w|\.)+];
 my $re_op     = qr[=|!=|>=|<=|>|<|(?i:IS NOT)|(?i:IS)|(?i:NOT LIKE)|(?i:LIKE)]; # long to short
 my $re_paren  = qr'\(|\)';
@@ -182,7 +183,6 @@
   while ($string =~ /(
                       $re_select
                       |$re_where
-                      |$re_column
                       |$re_aggreg
                       |$re_op
                       |$re_keyword
@@ -193,12 +193,13 @@
     my $current = 0;
 
     # Highest priority is last
-    $current = OP      if _match($re_op,$val);
+    $current = OP      if _match($re_op,$val) ;
     $current = VALUE   if _match($re_value,$val);
     $current = KEYWORD if _match($re_keyword,$val) && ($want & KEYWORD);
     $current = AGGREG  if _match($re_aggreg,$val);
     $current = PAREN   if _match($re_paren,$val);
-    $current = COLUMN if _match($re_column,$val) && ($want & COLUMN);
+    $current = COLUMN if _match($re_keyword,$val) && ($want & COLUMN);
+    $current = WHERE if _match($re_where,$val) && ($want & WHERE);
     $current = SELECT if _match($re_select,$val);
 
 
@@ -210,6 +211,8 @@
 
     # State Machine:
 
+    $RT::Logger->debug("We've just found a '$current' called '$val'");
+
     # Parens are highest priority
     if ($current & PAREN) {
       if ($val eq "(") {
@@ -230,7 +233,14 @@
     }
 
     elsif ($current & COLUMN ) {
-        push @{$self->{'columns_to_display'}}, $val;
+      if ($val =~ /$RE{delimited}{-delim=>qq{\'\"}}/) {
+        substr($val,0,1) = "";
+        substr($val,-1,1) = "";
+      }
+      # Unescape escaped characters
+      $val =~ s!\\(.)!$1!g;     
+        $self->_DisplayColumn($val);
+
         $want = COLUMN | WHERE;
 
     } 
@@ -381,15 +391,63 @@
 
 =begin testing
 
+use RT::Tickets;
 
 my $query = "SELECT id WHERE Status = 'open'";
 
 my $tix = RT::Tickets->new($RT::SystemUser);
 
-my ($id, $msg)  
+my ($id, $msg)  = $tix->FromSQL($query);
 
+ok ($id, $msg);
 
+my @cols =  $tix->DisplayColumns;
 
+ok ($cols[0] == 'id', "We're  displaying the ticket id");
+ok ($cols[1] == undef, "We're  displaying the ticket id");
+
+
+my $query = "SELECT id, Status WHERE Status = 'open'";
+
+my $tix = RT::Tickets->new($RT::SystemUser);
+
+my ($id, $msg)  = $tix->FromSQL($query);
+
+ok ($id, $msg);
+
+my @cols =  $tix->DisplayColumns;
+
+ok ($cols[0] == 'id', "We're only displaying the ticket id");
+ok ($cols[1] == 'Status', "We're only displaying the ticket id");
+
+my $query = qq[SELECT id, Status, '<A href="/Ticket/Display.html?id=##id##">Subject, this: ##Subject##</a>' WHERE Status = 'open'];
+
+my $tix = RT::Tickets->new($RT::SystemUser);
+
+my ($id, $msg)  = $tix->FromSQL($query);
+
+ok ($id, $msg);
+
+my @cols =  $tix->DisplayColumns;
+
+ok ($cols[0] == 'id', "We're only displaying the ticket id");
+ok ($cols[1] == 'Status', "We're only displaying the ticket id");
+
+
+
+$query = "Status = 'open'";
+my ($id, $msg)  = $tix->FromSQL($query);
+
+ok ($id, $msg);
+
+my @cols =  $tix->DisplayColumns;
+
+ok ($cols[0] == undef, "We haven't explicitly asked to display anything");
+
+
+
+
+
 =end testing
 
 
@@ -400,13 +458,15 @@
 
   $self->CleanSlate;
   $self->_InitSQL();
-  return (1,"No Query") unless $query;
 
+  return (1,$self->loc("No Query")) unless $query;
+
   $self->{_sql_query} = $query;
   eval { $self->_parser( $query ); };
-  $RT::Logger->error( $@ ) if $@;
-  return(0,$@) if $@;
-
+    if ($@) {
+        $RT::Logger->error( $@ );
+        return(0,$@);
+    }
   # We only want to look at EffectiveId's (mostly) for these searches.
   unless (exists $self->{_sql_looking_at}{'effectiveid'}) {
   $self->SUPER::Limit( FIELD           => 'EffectiveId',
@@ -443,7 +503,41 @@
 
 }
 
+=head2 _DisplayColumn COL
 
+Add COL to this search's list of "Columns to display"
+
+COL can either be a
+
+LiteralColumnName
+"QuotedString" (Containing ##LiteralColumnName## to embed the colum name inside it)
+
+What else?
+
+
+
+=cut
+
+sub _DisplayColumn {
+    my $self = shift;
+    my $col = shift;
+    push @{$self->{'columns_to_display'}}, $col;
+
+
+}
+
+=head2 DisplayColumns 
+
+Returns an array of the columns to show in the printed results of this object
+
+=cut
+
+sub DisplayColumns {
+    my $self = shift;
+    return (@{$self->{'columns_to_display'}});
+}
+
+
 1;
 
 =pod




More information about the Rt-commit mailing list