HideTransactions: Difference between revisions

From Request Tracker Wiki
Jump to navigation Jump to search
m (4 revisions imported)
 
 
(2 intermediate revisions by the same user not shown)
Line 13: Line 13:
This is minimal example as starting point that hides all transactions created by the system user.
This is minimal example as starting point that hides all transactions created by the system user.


<%INIT>
    <%INIT>
$$skip = 1 if $Transaction-&gt;Creator == $RT::SystemUser-&gt;id;
    $$skip = 1 if $Transaction->Creator == $RT::SystemUser->id;
&lt;/%INIT&gt;
    </%INIT>
&lt;%ARGS&gt;
    <%ARGS>
$Transaction =&gt; undef
    $Transaction => undef
$skip =&gt; undef
    $skip => undef
&lt;/%ARGS&gt;
    </%ARGS>


== Sane template for your custom code ==
== Sane template for your custom code ==


<nowiki>&lt;%INIT&gt;
<code>
  # do nothing if transaction is already flagged for skipping
    <%INIT>
  # yes, this is possible, you may have many callbacks that
    # do nothing if transaction is already flagged for skipping
  # skip using different conditions
    # yes, this is possible, you may have many callbacks that
  return if $$skip;
    # skip using different conditions
 
    return if $$skip;
  # do nothing if it's not system user
 
  return unless $Transaction-&gt;Creator == $RT::SystemUser-&gt;id;
    # do nothing if it's not system user
 
    return unless $Transaction->Creator == $RT::SystemUser->id;
  # this is not good idea to skip some transaction types
 
  # even if those are created by system user
    # this is not good idea to skip some transaction types
  return if $SHOW{ $Transaction-&gt;Type };
    # even if those are created by system user
 
    return if $SHOW{ $Transaction->Type };
  ...
 
  here add your additional conditions
    ...
  ...
    here add your additional conditions
 
    ...
  &lt;/%INIT&gt;
 
  &lt;%ONCE&gt;
    </%INIT>
  my %SHOW = map { $_ =&gt; 1} qw(
    <%ONCE>
      Create Comment Correspond
    my %SHOW = map { $_ => 1} qw(
      EmailRecord CommentEmailRecord
        Create Comment Correspond
  );
        EmailRecord CommentEmailRecord
  &lt;/%ONCE&gt;
    );
  &lt;%ARGS&gt;
    </%ONCE>
  $Transaction =&gt; undef
    <%ARGS>
  $skip =&gt; undef
    $Transaction => undef
  &lt;/%ARGS&gt;
    $skip => undef
  </nowiki>
    </%ARGS>
</code>


== Additional code snippets ==
== Additional code snippets ==
Line 59: Line 60:
If you'd like to have an abbreviated history on the main ticket display, but would like the full history in the History tab display, then add the following:
If you'd like to have an abbreviated history on the main ticket display, but would like the full history in the History tab display, then add the following:


<nowiki>...
    ...
  # do nothing if we're on history page
    # do nothing if we're on history page
  return if $r-&gt;uri =~ /History\.html/;
    return if $r->uri =~ /History\.html/;
  ...
    ...
  </nowiki>


== RT::Extension::HistoryFilter ==
== RT::Extension::HistoryFilter ==

Latest revision as of 12:36, 8 January 2017

Hiding transactions in tickets' history

Introdduction

You should be familiar with CustomizingWithCallbacks as all examples here are based on 'SkipTransaction' callback in Ticket/Elements/ShowHistory Mason component. Create a Callback 'SkipTransaction' in local/html/Callbacks/<MyCallbacks>/Ticket/Elements/ShowHistory/SkipTransaction and pick code below.

For RT 4.2.0 and above Ticket/Elements/ShowHistory no longer exists.  You will need to hook Elements/ShowHistory's SkipTransaction instead.  Keep in mind that this means your transactions may apply to users or queues in addition to tickets and you should tread carefully.

SkipTransaction callback allows your code to set $$skip variable if you want to skip the current transaction.

Minimal example

This is minimal example as starting point that hides all transactions created by the system user.

   <%INIT>
   $$skip = 1 if $Transaction->Creator == $RT::SystemUser->id;
   </%INIT>
   <%ARGS>
   $Transaction => undef
   $skip => undef
   </%ARGS>

Sane template for your custom code

   <%INIT>
   # do nothing if transaction is already flagged for skipping
   # yes, this is possible, you may have many callbacks that
   # skip using different conditions
   return if $$skip;
   # do nothing if it's not system user
   return unless $Transaction->Creator == $RT::SystemUser->id;
   # this is not good idea to skip some transaction types
   # even if those are created by system user
   return if $SHOW{ $Transaction->Type };
   ...
   here add your additional conditions
   ...
   </%INIT>
   <%ONCE>
   my %SHOW = map { $_ => 1} qw(
       Create Comment Correspond
       EmailRecord CommentEmailRecord
   );
   </%ONCE>
   <%ARGS>
   $Transaction => undef
   $skip => undef
   </%ARGS>

Additional code snippets

Do not hide on History.html page

If you'd like to have an abbreviated history on the main ticket display, but would like the full history in the History tab display, then add the following:

   ...
   # do nothing if we're on history page
   return if $r->uri =~ /History\.html/;
   ...

RT::Extension::HistoryFilter

I created an extension where you can define which transaction types are shown on the ticket display page. The ticket history page shows always the full history. You can find it at github: http://github.com/cloos/rt-extension-historyfilter

See also

CustomizingWithCallbacks