[Bps-public-commit] r11621 - in RT-Extension-Reports: html/Reports/Types

sunnavy at bestpractical.com sunnavy at bestpractical.com
Mon Apr 7 09:24:20 EDT 2008


Author: sunnavy
Date: Mon Apr  7 09:24:20 2008
New Revision: 11621

Modified:
   RT-Extension-Reports/html/Reports/Types/ActiveOrInactive
   RT-Extension-Reports/html/Reports/Types/CreatedOrResolved
   RT-Extension-Reports/html/Reports/Types/General
   RT-Extension-Reports/html/Reports/Types/TicketsMoved
   RT-Extension-Reports/lib/RT/Extension/Reports/Filter.pm

Log:
wrap filter a bit further

Modified: RT-Extension-Reports/html/Reports/Types/ActiveOrInactive
==============================================================================
--- RT-Extension-Reports/html/Reports/Types/ActiveOrInactive	(original)
+++ RT-Extension-Reports/html/Reports/Types/ActiveOrInactive	Mon Apr  7 09:24:20 2008
@@ -122,18 +122,11 @@
 
     $tickets->UnLimit;
 
+    require RT::Extension::Reports::Filter;
     TICKET:
     while ( my $ticket = $tickets->Next ) {
-        require RT::Extension::Reports::Filter;
-        $Filter =~ s/\r/\n/g;
-        my @filters = split /\n+/, $Filter;
-        for ( @filters ) {
-            next unless /\S/;
-            s/^\s+//;
-            my ( $field, $op, $value ) = split /\s+/, $_;
-            next TICKET unless RT::Extension::Reports::Filter::filter( Ticket
-                    => $ticket, Value => $value, Operator => $op, Field =>
-                    $field );
+        if ( $Filter ) {
+            next TICKET unless RT::Extension::Reports::Filter::filter_ticket( Filter => $Filter, Ticket => $ticket );
         }
 
         my $tmp_date = RT::Date->new( $session{CurrentUser} );

Modified: RT-Extension-Reports/html/Reports/Types/CreatedOrResolved
==============================================================================
--- RT-Extension-Reports/html/Reports/Types/CreatedOrResolved	(original)
+++ RT-Extension-Reports/html/Reports/Types/CreatedOrResolved	Mon Apr  7 09:24:20 2008
@@ -128,18 +128,11 @@
 
     $tickets->UnLimit;
 
+    require RT::Extension::Reports::Filter;
     TICKET:
     while ( my $ticket = $tickets->Next ) {
-        require RT::Extension::Reports::Filter;
-        $Filter =~ s/\r/\n/g;
-        my @filters = split /\n+/, $Filter;
-        for ( @filters ) {
-            next unless /\S/;
-            s/^\s+//;
-            my ( $field, $op, $value ) = split /\s+/, $_;
-            next TICKET unless RT::Extension::Reports::Filter::filter( Ticket
-                    => $ticket, Value => $value, Operator => $op, Field =>
-                    $field );
+        if ( $Filter ) {
+            next TICKET unless RT::Extension::Reports::Filter::filter_ticket( Filter => $Filter, Ticket => $ticket );
         }
 
         if ( $Type eq 'created' && $ticket->CreatedObj->Unix >=

Modified: RT-Extension-Reports/html/Reports/Types/General
==============================================================================
--- RT-Extension-Reports/html/Reports/Types/General	(original)
+++ RT-Extension-Reports/html/Reports/Types/General	Mon Apr  7 09:24:20 2008
@@ -107,18 +107,11 @@
     my $tickets = RT::Tickets->new( $session{CurrentUser} );
     $tickets->UnLimit;
 
+    require RT::Extension::Reports::Filter;
     TICKET:
     while ( my $ticket = $tickets->Next ) {
-        require RT::Extension::Reports::Filter;
-        $Filter =~ s/\r/\n/g;
-        my @filters = split /\n+/, $Filter;
-        for ( @filters ) {
-            next unless /\S/;
-            s/^\s+//;
-            my ( $field, $op, $value ) = split /\s+/, $_;
-            next TICKET unless RT::Extension::Reports::Filter::filter( Ticket
-                    => $ticket, Value => $value, Operator => $op, Field =>
-                    $field );
+        if ( $Filter ) {
+            next TICKET unless RT::Extension::Reports::Filter::filter_ticket( Filter => $Filter, Ticket => $ticket );
         }
 
         my $tmp_date = RT::Date->new( $session{CurrentUser} );

Modified: RT-Extension-Reports/html/Reports/Types/TicketsMoved
==============================================================================
--- RT-Extension-Reports/html/Reports/Types/TicketsMoved	(original)
+++ RT-Extension-Reports/html/Reports/Types/TicketsMoved	Mon Apr  7 09:24:20 2008
@@ -99,7 +99,6 @@
 
 my ( @headers, $num, @results, %data );
 
-
 if ( $Run ) {
 
     if ( $GroupBy eq 'date' ) {
@@ -123,18 +122,12 @@
 
     $tickets->UnLimit;
 
+    require RT::Extension::Reports::Filter;
+
     TICKET:
     while ( my $ticket = $tickets->Next ) {
-        require RT::Extension::Reports::Filter;
-        $Filter =~ s/\r/\n/g;
-        my @filters = split /\n+/, $Filter;
-        for ( @filters ) {
-            next unless /\S/;
-            s/^\s+//;
-            my ( $field, $op, $value ) = split /\s+/, $_;
-            next TICKET unless RT::Extension::Reports::Filter::filter( Ticket
-                    => $ticket, Value => $value, Operator => $op, Field =>
-                    $field );
+        if ( $Filter ) {
+            next TICKET unless RT::Extension::Reports::Filter::filter_ticket( Filter => $Filter, Ticket => $ticket );
         }
 
         my $tmp_date = RT::Date->new( $session{CurrentUser} );

Modified: RT-Extension-Reports/lib/RT/Extension/Reports/Filter.pm
==============================================================================
--- RT-Extension-Reports/lib/RT/Extension/Reports/Filter.pm	(original)
+++ RT-Extension-Reports/lib/RT/Extension/Reports/Filter.pm	Mon Apr  7 09:24:20 2008
@@ -2,8 +2,6 @@
 use strict;
 use warnings;
 
-our @filters = qw/subject/;
-
 my $map;
 
 # for ticket
@@ -57,13 +55,46 @@
     }
 }
 
-sub filter {
+sub _filter_ticket {
     my %args = @_;
     return unless $args{Ticket};
     return _test( $args{Operator}, _value( $args{Ticket}, $args{Field} ),
         $args{Value} );
 }
 
+=head2 filter_ticket
+
+%args = ( Filter => $Filter, Ticket => $Ticket )
+$Filter is what you type in Filter area
+$Ticket is a Ticket Object.
+
+return 1 means the ticket satisify all the conditions, can't be thrown away.
+return 0 means otherwise
+
+
+=cut
+
+sub filter_ticket {
+    my %args   = @_;
+    my $filter = $args{Filter};
+    my $ticket = $args{Ticket};
+    $filter =~ s/\r/\n/g;
+    my @filters = split /\n+/, $filter;
+    for (@filters) {
+        next unless /\S/;
+        s/^\s+//;
+        my ( $field, $op, $value ) = split /\s+/, $_;
+        return 0
+          unless _filter_ticket(
+                  Ticket   => $ticket,
+                  Value    => $value,
+                  Operator => $op,
+                  Field    => $field
+          );
+    }
+    return 1;
+}
+
 sub _value {
     my $ticket = shift;
     my $field  = shift;
@@ -73,8 +104,8 @@
     my $m = $map;
     for my $f (@fields) {
         $m = $m->{$f};
-        unless ( $m ) {
-            $RT::Logger->error( "$field not supported" );
+        unless ($m) {
+            $RT::Logger->error("$field not supported");
             return unless $m;
         }
     }



More information about the Bps-public-commit mailing list