[Bps-public-commit] rt-extension-timetracking branch, time-search, updated. 0.09-12-g09919b0

? sunnavy sunnavy at bestpractical.com
Mon Aug 20 17:29:50 EDT 2018


The branch, time-search has been updated
       via  09919b08e61f9ccf9967803c084aceaf05465b9e (commit)
      from  bfaf16615629e508d46ffc3c0b2c1ee1058f9a47 (commit)

Summary of changes:
 html/Tools/TimeSearch.html       | 10 +++++++++-
 lib/RT/Extension/TimeTracking.pm | 23 +++++++++++++++++++++++
 2 files changed, 32 insertions(+), 1 deletion(-)

- Log -----------------------------------------------------------------
commit 09919b08e61f9ccf9967803c084aceaf05465b9e
Author: sunnavy <sunnavy at bestpractical.com>
Date:   Tue Aug 21 05:14:58 2018 +0800

    Add an option to automatically search all the children on TimeSearch page

diff --git a/html/Tools/TimeSearch.html b/html/Tools/TimeSearch.html
index b8693b3..1ff4bb0 100644
--- a/html/Tools/TimeSearch.html
+++ b/html/Tools/TimeSearch.html
@@ -20,6 +20,10 @@
     <td class="label"><&|/l&>End Date</&>:</td>
     <td class="value"><& /Elements/SelectDate, ShowTime => 0, Name => 'EndDate', Default => $end_date->Date(Format=>'ISO', Timezone => 'user') &></td>
 </tr>
+<tr>
+    <td class="label"><&|/l&>Include All Children?</&></td>
+    <td class="value"><& /Widgets/Form/Boolean:InputOnly, Name => 'IncludeChildren', CurrentValue => $IncludeChildren &></td>
+</tr>
 </table>
 <& /Elements/Submit, Name => 'DoSearch', Label => loc("Search") &>
 </form>
@@ -136,7 +140,10 @@ if ( $ARGS{DoSearch} ) {
         Actions   => \@results,
         Arguments => { StartDate => $StartDate, EndDate => $EndDate, Query => $Query },
     );
-    my @ticket_ids = map { $_->id } @{ $tickets->ItemsArrayRef };
+
+    my @tickets = map { $_, $IncludeChildren ? ( RT::Extension::TimeTracking->AllChildren( $_ ) ) : () }
+      @{ $tickets->ItemsArrayRef };
+    my @ticket_ids = List::MoreUtils::uniq( map { $_->id } @tickets );
 
     my $txns = RT::Transactions->new( $user );
     $txns->Limit(
@@ -229,4 +236,5 @@ if ( $ARGS{DoSearch} ) {
 $Query => undef
 $StartDate => undef
 $EndDate => undef
+$IncludeChildren => 1
 </%ARGS>
diff --git a/lib/RT/Extension/TimeTracking.pm b/lib/RT/Extension/TimeTracking.pm
index 89b06ab..32199b6 100644
--- a/lib/RT/Extension/TimeTracking.pm
+++ b/lib/RT/Extension/TimeTracking.pm
@@ -30,6 +30,29 @@ our %WEEK_INDEX = (
     Saturday  => 6,
 );
 
+sub AllChildren {
+    my $self = shift;
+    my $ticket = shift or return;
+
+    my @tickets;
+    my %seen;
+
+    my $find_children;
+    $find_children = sub {
+        my $parent = shift;
+        my $links  = $parent->Members;
+        while ( my $link = $links->Next ) {
+            my $obj = $link->BaseObj;
+            next unless $obj && UNIVERSAL::isa( $obj, 'RT::Ticket' );
+            next if $seen{ $obj->id }++;
+            push @tickets, $obj;
+            $find_children->( $obj );
+        }
+    };
+    $find_children->( $ticket );
+    return @tickets;
+}
+
 =head1 NAME
 
 RT-Extension-TimeTracking - Time Tracking Extension

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


More information about the Bps-public-commit mailing list