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

Dustin Collins strega at bestpractical.com
Mon Nov 21 20:13:02 EST 2016


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

- Log -----------------------------------------------------------------
commit 53900844f01cb80c0e0dd79a0b4ef4de0011a21d
Author: Dustin Collins <strega at bestpractical.com>
Date:   Mon Nov 21 19:59:31 2016 -0500

    Add methods to store recently viewed tickets by user
    
    In order to allow recently viewed tickets to be stored for each user, two new methods are added.
    
    The method RT::User->RecentlyViewedTickets returns an ordered list of RT::Ticket objects.
    The order of the list is determined by the second method.
    
    The second method RT::User->AddRecentlyViewedTicket takes a single RT::Ticket object and adds the ticket to a stored list based on the current time. The method also truncates the list of tickets to be no greater then ten and handles moving existing tickets to the beginning of the list.

diff --git a/lib/RT/User.pm b/lib/RT/User.pm
index 29de4ae..b6b5c5d 100644
--- a/lib/RT/User.pm
+++ b/lib/RT/User.pm
@@ -2054,6 +2054,88 @@ 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;
+    }
+
+    #Create the array of RT::Ticket objects by sorting our hash by the recent
+    #timestamps in revers order then looping through and adding each RT::Ticket
+    #to the array, creating an array with the most recent ticket first
+    my @tickets;
+    for my $unixDate (reverse sort keys %recentTickets) {
+        my $id = $recentTickets{$unixDate};
+        my $ticket = new RT::Ticket($self);
+        $ticket->Load($id);
+        if ($ticket->Id) {
+            push @tickets, $ticket;
+        }
+    }
+
+    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;
+
+    #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;
+    }
+
+    #Remove the ticket if it exists in recents already
+    for my $unixDate (keys %recentTickets) {
+        if ($recentTickets{$unixDate} == $ticket->Id) {
+            $recentTickets{$unixDate} = undef;
+            last;
+        }
+    }
+
+    #Limit our existing recent tickets to 9
+    my %truncatedTickets;
+    my $count = 0;
+    for my $unixDate (sort keys %recentTickets) {
+        if ($recentTickets{$unixDate}) {
+            $truncatedTickets{$unixDate} = $recentTickets{$unixDate};
+            $count++;
+        }
+        if ($count >= 9) {
+            last;
+        }
+    }
+
+    #Add the new ticket
+    $truncatedTickets{time()} = $ticket->Id;
+
+    $self->SetAttribute(
+        Name    => 'RecentlyViewTickets',
+        Content => \%truncatedTickets,
+    );
+}
+
 =head2 Create PARAMHASH
 
 Create takes a hash of values and creates a row in the database:

commit acc0e6b5b346489298731d4993e5b3cd2847707c
Author: Dustin Collins <strega at bestpractical.com>
Date:   Mon Nov 21 20:05:09 2016 -0500

    Add recently viewed tickets portlet
    
    To allow users to see a short a list of tickets they recently view, a new Dashboards portlet is added.
    The portlet displays the recently viewed tickets returned from RT::User->RecentlyViewedTickets.

diff --git a/share/html/Elements/RecentTickets b/share/html/Elements/RecentTickets
new file mode 100644
index 0000000..b1cd626
--- /dev/null
+++ b/share/html/Elements/RecentTickets
@@ -0,0 +1,104 @@
+%# BEGIN BPS TAGGED BLOCK {{{
+%#
+%# COPYRIGHT:
+%#
+%# This software is Copyright (c) 1996-2016 Best Practical Solutions, LLC
+%#                                          <sales at bestpractical.com>
+%#
+%# (Except where explicitly superseded by other copyright notices)
+%#
+%#
+%# LICENSE:
+%#
+%# This work is made available to you under the terms of Version 2 of
+%# the GNU General Public License. A copy of that license should have
+%# been provided with this software, but in any event can be snarfed
+%# from www.gnu.org.
+%#
+%# This work is distributed in the hope that it will be useful, but
+%# WITHOUT ANY WARRANTY; without even the implied warranty of
+%# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+%# General Public License for more details.
+%#
+%# You should have received a copy of the GNU General Public License
+%# along with this program; if not, write to the Free Software
+%# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+%# 02110-1301 or visit their web page on the internet at
+%# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html.
+%#
+%#
+%# CONTRIBUTION SUBMISSION POLICY:
+%#
+%# (The following paragraph is not intended to limit the rights granted
+%# to you to modify and distribute this software under the terms of
+%# the GNU General Public License and is only of importance to you if
+%# you choose to contribute your changes and enhancements to the
+%# community by submitting them to Best Practical Solutions, LLC.)
+%#
+%# By intentionally submitting any modifications, corrections or
+%# derivatives to this work, or any other work intended for use with
+%# Request Tracker, to Best Practical Solutions, LLC, you confirm that
+%# you are the copyright holder for those contributions and you grant
+%# Best Practical Solutions,  LLC a nonexclusive, worldwide, irrevocable,
+%# royalty-free, perpetual, license to use, copy, create derivative
+%# works based on those contributions, and sublicense and distribute
+%# those contributions and any derivatives thereof.
+%#
+%# END BPS TAGGED BLOCK }}}
+
+<%ARGS>
+$User => undef
+$BaseURL => RT->Config->Get('WebPath') . $m->request_comp->path .'?'
+$Format => undef
+</%ARGS>
+
+<%INIT>
+
+unless (defined $User) {
+    $User = $session{CurrentUser};
+}
+
+my @Tickets;
+if (defined $User) {
+    @Tickets = $User->RecentlyViewedTickets;
+}
+
+unless (defined $Format) {
+    $Format = q{'<a href="__WebPath__/Ticket/Display.html?id=__id__">__id__</a>/TITLE:#',}
+            . q{'<a href="__WebPath__/Ticket/Display.html?id=__id__">__Subject__</a>/TITLE:Subject',}
+            . q{QueueName, ExtendedStatus, Owner};
+
+    # Scrub the html of the format string to remove any potential nasties.
+    $Format = $m->comp('/Elements/ScrubHTML', Content => $Format);
+}
+my @Format = $m->comp('/Elements/CollectionAsTable/ParseFormat', Format => $Format);
+
+</%INIT>
+
+<&| /Widgets/TitleBox, title => loc('Recently viewed tickets') &>
+<table cellspacing="0" class="ticket-list collection-as-table">
+
+<%PERL>
+$m->comp('/Elements/CollectionAsTable/Header',
+        %ARGS,
+        Format       => \@Format,
+        FormatString => $Format,
+        AllowSorting => 0,
+        BaseURL      => $BaseURL,
+);
+
+my $i = 0;
+for my $ticket (@Tickets) {
+    # Every ten rows, flush the buffer and put something on the page.
+    $m->flush_buffer unless ++$i % 10;
+    $m->comp('/Elements/CollectionAsTable/Row',
+        i         => $i,
+        record    => $ticket,
+        Format    => \@Format,
+    );
+}
+</%PERL>
+
+</table>
+
+</&>

commit 1c389bce1acc50d9708023dc4d58d6513bd79917
Author: Dustin Collins <strega at bestpractical.com>
Date:   Mon Nov 21 20:12:35 2016 -0500

    Add shared method to update recently viewed tickets
    
    In order to simplify the different ways to view a ticket, a new mason template is added to update a users recently viewed tickets.
    
    In order to update the users recently viewed tickets the BecomeRecent template is loaded in four major pages where a ticket is displayed with the intention of being viewed. These pages include Display.html, History.html, Modify.html and ModifyAll.html.
    
    Fixes: I#18820

diff --git a/share/html/Ticket/Display.html b/share/html/Ticket/Display.html
index 4c49857..3f5b8e5 100644
--- a/share/html/Ticket/Display.html
+++ b/share/html/Ticket/Display.html
@@ -50,6 +50,8 @@
     LinkRel => \%link_rel &>
 <& /Elements/Tabs &>
 
+<& /Ticket/Elements/BecomeRecent, Ticket => $TicketObj &>
+
 % $m->callback(CallbackName => 'BeforeActionList', %ARGS, Actions => \@Actions, ARGSRef => \%ARGS, Ticket => $TicketObj);
 
 <& /Elements/ListActions, actions => \@Actions &>
diff --git a/share/html/Ticket/History.html b/share/html/Ticket/Elements/BecomeRecent
similarity index 73%
copy from share/html/Ticket/History.html
copy to share/html/Ticket/Elements/BecomeRecent
index a71cad2..d652f4b 100644
--- a/share/html/Ticket/History.html
+++ b/share/html/Ticket/Elements/BecomeRecent
@@ -45,44 +45,13 @@
 %# those contributions and any derivatives thereof.
 %#
 %# END BPS TAGGED BLOCK }}}
-<& /Elements/Header, Title => loc("Ticket History # [_1] [_2]", $Ticket->Id, $Ticket->Subject) &>
-<& /Elements/Tabs &>
-
-% $m->callback( %ARGS, Ticket => $Ticket, CallbackName => 'BeforeActionList' );
-
-
-<br />
-      
-<& /Elements/ShowHistory,
-    Object => $Ticket,
-    ShowHeaders => $ARGS{'ShowHeaders'}, 
-    Attachments => $attachments,
-    AttachmentContent => $attachment_content,
-    DisplayPath => 'History.html',
-    &> 
-
-% $m->callback( %ARGS, CallbackName => 'AfterShowHistory', Ticket => $Ticket );
-
 <%ARGS>
-$id => undef
+$Ticket => undef
 </%ARGS>
-
 <%INIT>
 
-  
-
-my $Ticket = LoadTicket ($id);
-
-unless ($Ticket->CurrentUserHasRight('ShowTicket')) {
-    Abort("No permission to view ticket");
+if (defined $Ticket) {
+    $Ticket->CurrentUser->AddRecentlyViewedTicket($Ticket);
 }
 
-my $attachments = $Ticket->Attachments;
-my $attachment_content = $Ticket->TextAttachments;
-
-
 </%INIT>
-
-
-
-
diff --git a/share/html/Ticket/History.html b/share/html/Ticket/History.html
index a71cad2..ec46a0f 100644
--- a/share/html/Ticket/History.html
+++ b/share/html/Ticket/History.html
@@ -48,6 +48,8 @@
 <& /Elements/Header, Title => loc("Ticket History # [_1] [_2]", $Ticket->Id, $Ticket->Subject) &>
 <& /Elements/Tabs &>
 
+<& /Ticket/Elements/BecomeRecent Ticket => $TicketObj &>
+
 % $m->callback( %ARGS, Ticket => $Ticket, CallbackName => 'BeforeActionList' );
 
 
diff --git a/share/html/Ticket/Modify.html b/share/html/Ticket/Modify.html
index 937d76c..3766c9b 100644
--- a/share/html/Ticket/Modify.html
+++ b/share/html/Ticket/Modify.html
@@ -48,6 +48,8 @@
 <& /Elements/Header, Title => loc('Modify ticket #[_1]', $TicketObj->Id) &>
 <& /Elements/Tabs &>
 
+<& /Ticket/Elements/BecomeRecent Ticket => $TicketObj &>
+
 % $m->callback(CallbackName => 'BeforeActionList', Actions => \@results, ARGSRef => \%ARGS, Ticket => $TicketObj);
 
 <& /Elements/ListActions, actions => \@results &>
diff --git a/share/html/Ticket/ModifyAll.html b/share/html/Ticket/ModifyAll.html
index 97f579b..72ba8c0 100644
--- a/share/html/Ticket/ModifyAll.html
+++ b/share/html/Ticket/ModifyAll.html
@@ -48,6 +48,8 @@
 <& /Elements/Header, Title => loc("Ticket #[_1] Jumbo update: [_2]", $Ticket->Id, $Ticket->Subject) &>
 <& /Elements/Tabs &>
 
+<& /Ticket/Elements/BecomeRecent Ticket => $TicketObj &>
+
 % $m->callback(CallbackName => 'BeforeActionList', Actions => \@results, ARGSRef => \%ARGS, Ticket => $Ticket);
 <& /Elements/ListActions, actions => \@results &>
 

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


More information about the rt-commit mailing list