[Rt-commit] rt branch, 4.4/recent-tickets-list, repushed
Dustin Collins
strega at bestpractical.com
Fri Dec 9 15:53:50 EST 2016
The branch 4.4/recent-tickets-list was deleted and repushed:
was 0f6dcd6057a3e1e8852c811c5c0b7c35461967cc
now e5d11306cd1e3a8506fdcbbce3a45638c0c8c295
1: 0f6dcd6 ! 1: e5d1130 Add recently-viewed tickets to menu under Search -> Tickets
@@ -1,6 +1,6 @@
Author: Dustin Collins <strega at bestpractical.com>
- Add recent tickets to menu
+ Add recently-viewed tickets to menu under Search -> Tickets
Fixes: T#176566
@@ -13,63 +13,46 @@
+=head2 RecentlyViewedTickets TICKET
+
-+Returns an array of up to ten RT::Ticket objects ordered by recently viewed first.
++Returns a list of two-element (ticket id, timestamp) array references ordered by recently viewed first.
+
+=cut
+
+sub RecentlyViewedTickets {
+ my $self = shift;
++ my $content = $self->FirstAttribute('RecentlyViewedTickets');
++ return $content ? @{$content->Content} : ();
++}
++
++=head2 AddRecentlyViewedTicket TICKET
++
++Takes an RT::Ticket object and adds it to the current user's 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 $ticket->Id;
+
+ my @recentTickets;
-+ my $content = $self->FirstAttribute('RecentlyViewTickets');
-+ $content = $content ? $content->Content : {};
++ my $content = $self->FirstAttribute('RecentlyViewedTickets');
++ $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;
++ my $i = 0;
+ for (@recentTickets) {
+ my ($ticketId, $timestamp) = @$_;
+
+ #Skip the ticket if it exists in recents already
+ if ($ticketId != $ticket->Id) {
-+ push @tickets, [$ticketId, $timestamp];
++ push @tickets, $_;
+ if ($i >= $maxCount - 1) {
+ last;
+ }
@@ -81,7 +64,7 @@
+ unshift @tickets, [$ticket->Id, time()];
+
+ $self->SetAttribute(
-+ Name => 'RecentlyViewTickets',
++ Name => 'RecentlyViewedTickets',
+ Content => \@tickets,
+ );
+}
@@ -98,11 +81,11 @@
$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 ($ticketId, $timestamp) = @$_;
++ my $ticket = RT::Ticket->new($session{CurrentUser});
++ $ticket->Load($ticketId);
++ if ($ticket->Id) {
+ my $title = $ticket->Subject || loc("(No subject)");
+ if (length $title > 50) {
+ $title = substr($title, 0, 47);
@@ -125,7 +108,7 @@
);
push @Actions, loc('Marked all messages as seen');
}
-+ $TicketObj->CurrentUser->AddRecentlyViewedTicket($TicketObj) if $TicketObj->Id;
++ $TicketObj->CurrentUser->AddRecentlyViewedTicket($TicketObj);
}
}
@@ -137,7 +120,7 @@
Abort("No permission to view ticket");
}
-+$Ticket->CurrentUser->AddRecentlyViewedTicket($Ticket) if $Ticket->Id;
++$Ticket->CurrentUser->AddRecentlyViewedTicket($Ticket);
+
my $attachments = $Ticket->Attachments;
my $attachment_content = $Ticket->TextAttachments;
@@ -150,7 +133,7 @@
}
}
-+$TicketObj->CurrentUser->AddRecentlyViewedTicket($TicketObj) if $TicketObj->Id;
++$TicketObj->CurrentUser->AddRecentlyViewedTicket($TicketObj);
+
</%INIT>
<%ARGS>
@@ -163,7 +146,7 @@
}
}
-+$Ticket->CurrentUser->AddRecentlyViewedTicket($Ticket) if $Ticket->Id;
++$Ticket->CurrentUser->AddRecentlyViewedTicket($Ticket);
</%INIT>
@@ -175,7 +158,7 @@
push @results, ProcessObjectCustomFieldUpdates(Object => $TicketObj, ARGSRef => \%ARGS);
$TicketObj->ApplyTransactionBatch;
-+$TicketObj->CurrentUser->AddRecentlyViewedTicket($TicketObj) if $TicketObj->Id;
++$TicketObj->CurrentUser->AddRecentlyViewedTicket($TicketObj);
+
</%INIT>
@@ -189,7 +172,7 @@
Arguments => { id => $id },
);
+
-+$Ticket->CurrentUser->AddRecentlyViewedTicket($Ticket) if $Ticket->Id;
++$Ticket->CurrentUser->AddRecentlyViewedTicket($Ticket);
+
</%INIT>
@@ -203,7 +186,7 @@
# 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;
++$Ticket->CurrentUser->AddRecentlyViewedTicket($Ticket);
+
</%INIT>
@@ -217,7 +200,7 @@
my @actions = ProcessTicketReminders( TicketObj => $Ticket, ARGSRef => \%ARGS );
+
-+$Ticket->CurrentUser->AddRecentlyViewedTicket($Ticket) if $Ticket->Id;
++$Ticket->CurrentUser->AddRecentlyViewedTicket($Ticket);
+
</%INIT>
<%ARGS>
@@ -231,7 +214,7 @@
return $m->comp('Display.html', TicketObj => $TicketObj, %ARGS);
}
+
-+$TicketObj->CurrentUser->AddRecentlyViewedTicket($TicketObj) if $TicketObj->Id;
++$TicketObj->CurrentUser->AddRecentlyViewedTicket($TicketObj);
+
</%INIT>
More information about the rt-commit
mailing list