[Rt-commit] rt branch, 4.4/recent-tickets-list, created. rt-4.4.1-154-gd77fa01
Dustin Collins
strega at bestpractical.com
Fri Dec 9 17:12:31 EST 2016
The branch, 4.4/recent-tickets-list has been created
at d77fa0177dae3ca9b002728698544d27cf74d1c2 (commit)
- Log -----------------------------------------------------------------
commit 0ce4d256d5e05a88121e9e5a91a27f07bbdd8d5c
Author: Dustin Collins <strega at bestpractical.com>
Date: Fri Dec 9 17:08:55 2016 -0500
Make test looking for ticket subject more focused
This test is looking for the lack of a particular ticket's subject
anywhere on the page. Instead, make sure that particular ticket's
subject is absent specifically from the search results table. That way,
recently-viewed tickets (and any other feature which displays tickets in
non-traditional ways) won't break this test.
diff --git a/t/web/cf_datetime.t b/t/web/cf_datetime.t
index 18ccf87..a3cd5be 100644
--- a/t/web/cf_datetime.t
+++ b/t/web/cf_datetime.t
@@ -159,8 +159,8 @@ diag 'check search build page';
$m->find_all_inputs( type => 'text', name_regex => qr/test cf datetime/ );
is_results_number( { $cf_op->name => '=', $cf_field->name => '2010-05-04', }, 1 );
- $m->content_contains( '2010-05-04', 'got the right ticket' );
- $m->content_lacks( '2010-05-06', 'did not get the wrong ticket' );
+ like($m->dom->at('table.ticket-list')->all_text, qr/2010-05-04/, 'got the right ticket');
+ unlike($m->dom->at('table.ticket-list')->all_text, qr/2010-05-06/, 'did not get the wrong ticket');
my $shanghai = RT::Test->load_or_create_user(
Name => 'shanghai',
commit d77fa0177dae3ca9b002728698544d27cf74d1c2
Author: Dustin Collins <strega at bestpractical.com>
Date: Fri Dec 9 14:36:50 2016 -0500
Add recently-viewed tickets to menu under Search -> Tickets
Fixes: T#176566
diff --git a/lib/RT/User.pm b/lib/RT/User.pm
index 29de4ae..19d33cd 100644
--- a/lib/RT/User.pm
+++ b/lib/RT/User.pm
@@ -2054,6 +2054,64 @@ sub ToggleBookmark {
return $is_bookmarked;
}
+=head2 RecentlyViewedTickets TICKET
+
+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('RecentlyViewedTickets');
+ $content = $content ? $content->Content : [];
+ if (defined $content) {
+ @recentTickets = @$content;
+ }
+
+ my @tickets;
+ my $i = 0;
+ for (@recentTickets) {
+ my ($ticketId, $timestamp) = @$_;
+
+ #Skip the ticket if it exists in recents already
+ if ($ticketId != $ticket->Id) {
+ push @tickets, $_;
+ if ($i >= $maxCount - 1) {
+ last;
+ }
+ }
+ $i++;
+ }
+
+ #Add the new ticket
+ unshift @tickets, [$ticket->Id, time()];
+
+ $self->SetAttribute(
+ Name => 'RecentlyViewedTickets',
+ 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..083d89d 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'));
+ for ($session{CurrentUser}->RecentlyViewedTickets) {
+ 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);
+ $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..0eb73d8 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);
}
}
diff --git a/share/html/Ticket/History.html b/share/html/Ticket/History.html
index a71cad2..d398676 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);
+
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..3a73553 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);
+
</%INIT>
<%ARGS>
$id => undef
diff --git a/share/html/Ticket/ModifyAll.html b/share/html/Ticket/ModifyAll.html
index 97f579b..e4fdb0e 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);
</%INIT>
diff --git a/share/html/Ticket/ModifyDates.html b/share/html/Ticket/ModifyDates.html
index 9fd892a..54263e1 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);
+
</%INIT>
diff --git a/share/html/Ticket/ModifyLinks.html b/share/html/Ticket/ModifyLinks.html
index ba8a7c9..9d901c4 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);
+
</%INIT>
diff --git a/share/html/Ticket/ModifyPeople.html b/share/html/Ticket/ModifyPeople.html
index 08bee71..c0c9d53 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);
+
</%INIT>
diff --git a/share/html/Ticket/Reminders.html b/share/html/Ticket/Reminders.html
index 0d3f9cb..8fe8207 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);
+
</%INIT>
<%ARGS>
$id => undef
diff --git a/share/html/Ticket/Update.html b/share/html/Ticket/Update.html
index 5f873a6..4b157ee 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);
+
</%INIT>
<%ARGS>
-----------------------------------------------------------------------
More information about the rt-commit
mailing list