Overlay for html/Tools/MyDay.html

When I started using RT, wandered around its menus playing “press and guess”, and I found the “My Day” screen under tools. I was really excited by the idea of it, but it wasn’t quite what I needed – my work flow works best ordered by staleness, and I really need a bit more context for each ticket.

I’ve created an Overlay for html/Tools/MyDay.html, which adds the last text attachment – it looks like this:

Here’s the code of the overlay:

<& /Elements/Header, Title => $title &>
<& /Elements/Tabs &>

<& /Elements/ListActions, actions => \@results &>

<h2><&|/l, $session{'CurrentUser'}->Name &>Active tickets for [_1]</&></h2>
<form method="post" action="MyDay.html">
<table width="100%" cellpadding="0" cellspacing="0" class="myday">
% while ( my $Ticket = $Tickets->Next()) {
% $i++;
% my $class =  $i % 2  ? 'class="evenline"' : 'class="oddline"';
<tr <%$class|n%>><td colspan="2"><h2><a
href="<%RT->Config->Get('WebPath')%>/Ticket/Display.html?id=<%$Ticket->Id%>"><%$Ticket->Id%>:
<%$Ticket->Subject%></a></h2></td></tr>
<tr <%$class|n%>><td><span class="label"><&|/l&>Worked</&>:</span><input size="3" name="UpdateTimeWorked-<%$Ticket->Id%>" /> <&|/l&>minutes</&>
</td>
<td rowspan="2"><span class="label"><&|/l&>Comments</&>:<br /></span><textarea name="UpdateContent-<%$Ticket->Id%>" rows="5"
cols="60"></textarea><br />
% my $Attachments = $Ticket->Attachments;
% my $final_note;
% while( my $attachment = $Attachments->Next ) {
%     next unless $attachment->ContentType =~ /text/;
%     $final_note = $attachment->Content; 
% }
<div class="messagebody">
<%$final_note%>
</div>

</td></tr>
<tr <%$class|n%>>
<td><span class="label"><&|/l&>Status</&>:</span> <& /Ticket/Elements/SelectStatus, Name=> 'UpdateStatus-'.$Ticket->Id, TicketObj => $Ticket &>
</td>
                  </tr>

% }
</table>
<& /Elements/Submit, Label => loc('Record all updates') ,  Reset => 1, ResetLabel => loc('Clear')&>
</form>
</html>
<%INIT>
my $title = loc("What I did today (Barton's local overlay)");

my $i = 0;
my @results;
foreach my $arg ( keys %ARGS ) {
    next unless ( $arg =~ /^UpdateStatus-(\d*)$/ );
    my $id     = $1;
    my $ticket = LoadTicket($id);
    next unless ( $ticket->id );
    if ( my $content = $ARGS{'UpdateContent-'.$id} ) {
        my ( $val, $msg ) = $ticket->Comment(
            Content   => $content,
            TimeTaken => $ARGS{ 'UpdateTimeWorked-' . $id }
        );
        push @results, loc( "Ticket [_1]: [_2]", $id, $msg );
    } elsif ( my $worked = $ARGS{ 'UpdateTimeWorked-' . $id } ) {
        my ( $val, $msg ) = $ticket->SetTimeWorked( $worked + $ticket->TimeWorked );
            push @results, loc( "Ticket [_1]: [_2]", $id, $msg );
    }

    if ( my $status = $ARGS{ 'UpdateStatus-' . $id } ) {
        if ( $status ne $ticket->Status ) {
            my ( $val, $msg ) = $ticket->SetStatus($status);
            push @results, loc( "Ticket [_1]: [_2]", $id, $msg );

        }
    }

}

my $Tickets = RT::Tickets->new($session{'CurrentUser'});
$Tickets->LimitOwner(VALUE => $session{'CurrentUser'}->Id);
$Tickets->LimitToActiveStatus;
$Tickets->OrderBy ( FIELD => 'LastUpdated', ORDER => 'ASC');


</%INIT>

Now… I’d like to use ShowTransactionAttachments which would do all the formatting goodness used on Ticket/Display.html, but I’m not sure how to call that and only process the last attachment.

the call to ShowTransactionAttachments in ./share/html/Elements/ShowTransaction looks like this:

$m->comp(
    'ShowTransactionAttachments',
    %ARGS,
    Parent => 0
)

So I’m assuming that I can call $m->comp() and pass in a hash in place of %ARGS with … @Attachments … somewhere.

Take a look at the code in share/html/Elements/ShowTransactionAttachments you’ll see the <%ARGS> section includes:

$Transaction
$Object => $Transaction->Object
$ShowHeaders => 0
$DownloadableHeaders => 1
$AttachmentPath => undef
$Attachments => {}
$AttachmentContent => {}
$Parent => 0
$ParentObj => undef
$WarnUnsigned => 0
$displayed_inline => {}

So to me it looks like you’ll need to fake the $ARGS{'Attachments'} that you pass to ShowTransactionAttachments so that it only contains the structure for the one attachment that you want, as well as providing the correct Transaction that this attachment is part of, whch is easy enough using the TransactionObj() method of RT::Attachment. The $ARGS{'Attachments'} that ShowTransactionAttachments is expecting appears to be a hash with the parent IDs (or zero) as the keys and each hash value is itself an array of attachments. So maybe something like this might work (not tested!):

 my $Attachments = $Ticket->Attachments;
 my $final_attachment;
 while( my $attachment = $Attachments->Next ) {
     next unless $attachment->ContentType =~ /text/;
     $final_attachment = $attachment; 
 }
 $m->comp(
     'ShowTransactionAttachments',
     Attachments => { '0' => [$final_attachment]},
     Parent => 0,
 );

I’ll let you know what happens!

Close, but no cigar.

<%PERL>
my $Attachments = $Ticket->Attachments;
my $final_attachment;
while( my $attachment = $Attachments->Next ) {
    next unless $attachment->ContentType =~ /text/;
    $final_attachment = $attachment;
}
$m->comp(
    '/Elements/ShowTransactionAttachments',
    Attachments => { '0' => [$final_attachment]},
    Parent => 0
);
</%PERL>

gives me [7] [Fri Jan 18 05:01:29 2019] [error]: no value sent for required parameter 'Transaction'

I think that you actually anticipated this…

I think that I just need to make it explicit… maybe something like this:

<%PERL>
my $Attachments = $Ticket->Attachments;
my $final_attachment;
while( my $attachment = $Attachments->Next ) {
    next unless $attachment->ContentType =~ /text/;
    $final_attachment = $attachment;
}
my $Transaction = $final_attachment->TransactionObj();
$m->comp(
    '/Elements/ShowTransactionAttachments',
    $Transaction,
    Attachments => { '0' => [$final_attachment]},
    Parent => 0
);
</%PERL>

This worked:

<%PERL>
my $Attachments = $Ticket->Attachments;
my $final_attachment;
while( my $attachment = $Attachments->Next ) {
    next unless $attachment->ContentType =~ /text/;
    $final_attachment = $attachment;
}
my $Transaction = $final_attachment->TransactionObj();
$m->comp(
    '/Elements/ShowTransactionAttachments',
    Transaction => $Transaction,
    Attachments => { '0' => [$final_attachment]},
    Parent => 0
);
</%PERL>

I think that I probably want to stick the perl code inside a <div>, so that I can control the wrapping, disable the download links and give it a label… but having said that, I’m very happy with the results.