[Rt-commit] rt branch, 4.4/recent-tickets-list, created. rt-4.4.1-153-g0f6dcd6

Dustin Collins strega at bestpractical.com
Fri Dec 9 14:38:47 EST 2016


The branch, 4.4/recent-tickets-list has been created
        at  0f6dcd6057a3e1e8852c811c5c0b7c35461967cc (commit)

- Log -----------------------------------------------------------------
commit 0f6dcd6057a3e1e8852c811c5c0b7c35461967cc
Author: Dustin Collins <strega at bestpractical.com>
Date:   Fri Dec 9 14:36:50 2016 -0500

    Add recent tickets to menu
    
    Fixes: T#176566

diff --git a/lib/RT/User.pm b/lib/RT/User.pm
index 29de4ae..0238f42 100644
--- a/lib/RT/User.pm
+++ b/lib/RT/User.pm
@@ -2054,6 +2054,81 @@ sub ToggleBookmark {
     return $is_bookmarked;
 }
 
+=head2 RecentlyViewedTickets TICKET
+
+Returns an array of up to ten RT::Ticket objects ordered by recently viewed first.
+
+=cut
+
+sub RecentlyViewedTickets {
+    my $self = shift;
+
+    my @recentTickets;
+    my $content = $self->FirstAttribute('RecentlyViewTickets');
+    $content = $content ? $content->Content : {};
+    if (defined $content) {
+        @recentTickets = @$content;
+    }
+
+    my @tickets;
+    for (@recentTickets) {
+        my ($id, $timestamp) = @$_;
+        my $ticket = RT::Ticket->new($self);
+        $ticket->Load($id);
+        if ($ticket->Id) {
+            push @tickets, [$ticket, $timestamp];
+        }
+    }
+
+    return @tickets;
+}
+
+=head2 AddRecentlyViewedTicket TICKET
+
+Takes an RT::Ticket object and adds it to the current users RecentlyViewedTickets
+
+=cut
+
+sub AddRecentlyViewedTicket {
+    my $self   = shift;
+    my $ticket = shift;
+
+    my $maxCount = 10; #The max number of tickets to keep
+
+    #Nothing to do without a ticket
+    return unless defined $ticket->Id;
+
+    my @recentTickets;
+    my $content = $self->FirstAttribute('RecentlyViewTickets');
+    $content = $content ? $content->Content : {};
+    if (defined $content) {
+        @recentTickets = @$content;
+    }
+
+    my @tickets;
+    my $i;
+    for (@recentTickets) {
+        my ($ticketId, $timestamp) = @$_;
+        
+        #Skip the ticket if it exists in recents already
+        if ($ticketId != $ticket->Id) {
+            push @tickets, [$ticketId, $timestamp];
+            if ($i >= $maxCount - 1) {
+                last;
+            }
+        }
+        $i++;
+    }
+
+    #Add the new ticket
+    unshift @tickets, [$ticket->Id, time()];
+
+    $self->SetAttribute(
+        Name    => 'RecentlyViewTickets',
+        Content => \@tickets,
+    );
+}
+
 =head2 Create PARAMHASH
 
 Create takes a hash of values and creates a row in the database:
diff --git a/share/html/Elements/Tabs b/share/html/Elements/Tabs
index e672e3b..51afb2a 100644
--- a/share/html/Elements/Tabs
+++ b/share/html/Elements/Tabs
@@ -573,6 +573,23 @@ my $build_main_nav = sub {
     $tickets->child( simple => title => loc('Simple Search'), path => "/Search/Simple.html" );
     $tickets->child( new    => title => loc('New Search'),    path => "/Search/Build.html?NewQuery=1" );
 
+    my $recents = $tickets->child( recent => title => loc('Recently Viewed'), path => "/Search/RecentlyViewedTickets.html" );
+    my $dateFormatter = RT::Date->new(RT->SystemUser);
+    for ($session{CurrentUser}->RecentlyViewedTickets) {
+        my ($ticket, $timestamp) = @$_;
+        my $ticketId = $ticket->Id;
+        if ($ticketId) {
+            my $title = $ticket->Subject || loc("(No subject)");
+            if (length $title > 50) {
+                $title = substr($title, 0, 47);
+                $title =~ s/\s+$//;
+                $title .= "...";
+            }
+            $title = "#$ticketId: " . $title;
+            $recents->child( "$ticketId" => title => $title, path => "/Ticket/Display.html?id=" . $ticket->Id );
+        }
+    }
+
     $search->child( articles => title => loc('Articles'),   path => "/Articles/Article/Search.html" )
         if $session{CurrentUser}->HasRight( Right => 'ShowArticlesMenu', Object => RT->System );
 
diff --git a/share/html/Ticket/Display.html b/share/html/Ticket/Display.html
index 4c49857..f280d8d 100644
--- a/share/html/Ticket/Display.html
+++ b/share/html/Ticket/Display.html
@@ -207,6 +207,7 @@ if ($ARGS{'id'} eq 'new') {
             );
             push @Actions, loc('Marked all messages as seen');
         }
+        $TicketObj->CurrentUser->AddRecentlyViewedTicket($TicketObj) if $TicketObj->Id;
     }
 }
 
diff --git a/share/html/Ticket/History.html b/share/html/Ticket/History.html
index a71cad2..38adb7a 100644
--- a/share/html/Ticket/History.html
+++ b/share/html/Ticket/History.html
@@ -77,6 +77,8 @@ unless ($Ticket->CurrentUserHasRight('ShowTicket')) {
     Abort("No permission to view ticket");
 }
 
+$Ticket->CurrentUser->AddRecentlyViewedTicket($Ticket) if $Ticket->Id;
+
 my $attachments = $Ticket->Attachments;
 my $attachment_content = $Ticket->TextAttachments;
 
diff --git a/share/html/Ticket/Modify.html b/share/html/Ticket/Modify.html
index 937d76c..a897697 100644
--- a/share/html/Ticket/Modify.html
+++ b/share/html/Ticket/Modify.html
@@ -117,6 +117,8 @@ unless ($TicketObj->CurrentUserHasRight('ShowTicket')) {
     }
 }
 
+$TicketObj->CurrentUser->AddRecentlyViewedTicket($TicketObj) if $TicketObj->Id;
+
 </%INIT>
 <%ARGS>
 $id => undef
diff --git a/share/html/Ticket/ModifyAll.html b/share/html/Ticket/ModifyAll.html
index 97f579b..7aefcc6 100644
--- a/share/html/Ticket/ModifyAll.html
+++ b/share/html/Ticket/ModifyAll.html
@@ -216,6 +216,7 @@ unless ($Ticket->CurrentUserHasRight('ShowTicket')) {
     }
 }
 
+$Ticket->CurrentUser->AddRecentlyViewedTicket($Ticket) if $Ticket->Id;
 
 </%INIT>
 
diff --git a/share/html/Ticket/ModifyDates.html b/share/html/Ticket/ModifyDates.html
index 9fd892a..05bfad3 100644
--- a/share/html/Ticket/ModifyDates.html
+++ b/share/html/Ticket/ModifyDates.html
@@ -71,6 +71,8 @@ push @results, ProcessTicketDates( TicketObj => $TicketObj, ARGSRef => \%ARGS);
 push @results, ProcessObjectCustomFieldUpdates(Object => $TicketObj, ARGSRef => \%ARGS);
 $TicketObj->ApplyTransactionBatch;
 
+$TicketObj->CurrentUser->AddRecentlyViewedTicket($TicketObj) if $TicketObj->Id;
+
 </%INIT>
 
 
diff --git a/share/html/Ticket/ModifyLinks.html b/share/html/Ticket/ModifyLinks.html
index ba8a7c9..5e211b0 100644
--- a/share/html/Ticket/ModifyLinks.html
+++ b/share/html/Ticket/ModifyLinks.html
@@ -82,6 +82,9 @@ MaybeRedirectForResults(
     Actions     => \@results,
     Arguments   => { id => $id },
 );
+
+$Ticket->CurrentUser->AddRecentlyViewedTicket($Ticket) if $Ticket->Id;
+
 </%INIT>
       
       
diff --git a/share/html/Ticket/ModifyPeople.html b/share/html/Ticket/ModifyPeople.html
index 08bee71..0127cd1 100644
--- a/share/html/Ticket/ModifyPeople.html
+++ b/share/html/Ticket/ModifyPeople.html
@@ -137,6 +137,9 @@ for my $rule (map {@{$_->Rules}} @txns) {
 
 # Use tkt squelch list to get recipients who will NOT get mail:
 $recips{$_->Content} = 0 for $Ticket->SquelchMailTo;
+
+$Ticket->CurrentUser->AddRecentlyViewedTicket($Ticket) if $Ticket->Id;
+
 </%INIT>
 
 
diff --git a/share/html/Ticket/Reminders.html b/share/html/Ticket/Reminders.html
index 0d3f9cb..966964c 100644
--- a/share/html/Ticket/Reminders.html
+++ b/share/html/Ticket/Reminders.html
@@ -68,6 +68,9 @@
 my $Ticket = LoadTicket($id);
 
 my @actions = ProcessTicketReminders( TicketObj => $Ticket, ARGSRef => \%ARGS );
+
+$Ticket->CurrentUser->AddRecentlyViewedTicket($Ticket) if $Ticket->Id;
+
 </%INIT>
 <%ARGS>
 $id => undef
diff --git a/share/html/Ticket/Update.html b/share/html/Ticket/Update.html
index 5f873a6..3552f95 100644
--- a/share/html/Ticket/Update.html
+++ b/share/html/Ticket/Update.html
@@ -349,6 +349,9 @@ if ( !$checks_failure && !$skip_update && exists $ARGS{SubmitTicket} ) {
     $m->callback( Ticket => $TicketObj, ARGSRef => \%ARGS, CallbackName => 'BeforeDisplay' );
     return $m->comp('Display.html', TicketObj => $TicketObj, %ARGS);
 }
+
+$TicketObj->CurrentUser->AddRecentlyViewedTicket($TicketObj) if $TicketObj->Id;
+
 </%INIT>
 
 <%ARGS>

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


More information about the rt-commit mailing list