Difference between revisions of "ShowStatusInColor"

From Request Tracker Wiki
Jump to navigation Jump to search
m (Fix: Correct directory path display without wiki links)
 
(5 intermediate revisions by 4 users not shown)
Line 7: Line 7:
Below is a modified local/html/Elements/ShowLink. It will display inter-ticket links colored to match the status of the ticket with the same color scheme used in graphs, via inline CSS. --Jerrad
Below is a modified local/html/Elements/ShowLink. It will display inter-ticket links colored to match the status of the ticket with the same color scheme used in graphs, via inline CSS. --Jerrad


  <nowiki>&lt;a href="&lt;%$URI-&gt;Resolver-&gt;HREF%&gt;"&gt;
  <pre>&lt;a href="&lt;%$URI-&gt;Resolver-&gt;HREF%&gt;"&gt;
% if ($URI-&gt;IsLocal) {
  % if ($URI-&gt;IsLocal) {
% my $member = $URI-&gt;Object;
  % my $member = $URI-&gt;Object;
% if (UNIVERSAL::isa($member, "RT::Ticket")) {
  % if (UNIVERSAL::isa($member, "RT::Ticket")) {
 
#Customization
  #Customization
&lt;%perl&gt;
  &lt;%perl&gt;
require RT::Graph::Tickets;
  require RT::Graph::Tickets;
my $status = $member-&gt;Status;
  my $status = $member-&gt;Status;
my $class  = $member-&gt;QueueObj-&gt;IsInactiveStatus($status)?'ticket-inactive':'';
  my $class  = $member-&gt;QueueObj-&gt;IsInactiveStatus($status)?'ticket-inactive':'';
my $color  = $RT::Graph::Tickets::ticket_status_style{$status}-&gt;{'fontcolor'};
  my $color  = $RT::Graph::Tickets::ticket_status_style{$status}-&gt;{'fontcolor'};
&lt;/%perl&gt;
  &lt;/%perl&gt;
&lt;span class="&lt;% $class %&gt;" style="color: &lt;% $color %&gt;"&gt;
  &lt;span class="&lt;% $class %&gt;" style="color: &lt;% $color %&gt;"&gt;
 
&lt;%$member-&gt;Id%&gt;: (&lt;%$member-&gt;OwnerObj-&gt;Name%&gt;) &lt;%$member-&gt;Subject%&gt; [&lt;% loc($member-&gt;Status) %&gt;]
  &lt;%$member-&gt;Id%&gt;: (&lt;%$member-&gt;OwnerObj-&gt;Name%&gt;) &lt;%$member-&gt;Subject%&gt; [&lt;% loc($member-&gt;Status) %&gt;]
&lt;/span&gt;
  &lt;/span&gt;
 
% } elsif ( UNIVERSAL::can($member, 'Name')) {
  % } elsif ( UNIVERSAL::can($member, 'Name')) {
&lt;%$URI-&gt;Resolver-&gt;AsString%&gt;: &lt;%$member-&gt;Name%&gt;
  &lt;%$URI-&gt;Resolver-&gt;AsString%&gt;: &lt;%$member-&gt;Name%&gt;
% } else {
  % } else {
&lt;%$URI-&gt;Resolver-&gt;AsString%&gt;
  &lt;%$URI-&gt;Resolver-&gt;AsString%&gt;
% }
  % }
% } else {
  % } else {
&lt;%$URI-&gt;Resolver-&gt;AsString%&gt;
  &lt;%$URI-&gt;Resolver-&gt;AsString%&gt;
% }
  % }
&lt;/a&gt;
  &lt;/a&gt;
&lt;%ARGS&gt;
  &lt;%ARGS&gt;
$URI =&gt; undef
  $URI =&gt; undef
&lt;/%ARGS&gt;
  &lt;/%ARGS&gt;
</nowiki>
  </pre>


=== Full-featured ===
=== Full-featured ===
Line 46: Line 46:
(And Baylink, in turn, moved it to the top; if you're running older code, read on down. In particular, I modified the Colored-Priority code to use inline styles and reverse out the color into the background a bit further down.)
(And Baylink, in turn, moved it to the top; if you're running older code, read on down. In particular, I modified the Colored-Priority code to use inline styles and reverse out the color into the background a bit further down.)


* Create the directory: &lt;[[RTInstallationDir]]&gt;/local/html/Callbacks/[[MyCallbacks]]/Elements/[[RT  Ticket|RT__Ticket]]/[[ColumnMap]]
* Create the directory: `<RTInstallationDir>/local/html/Callbacks/MyCallbacks/Elements/RT__Ticket/ColumnMap`


You can do that, in Linux, by typing
You can do that, in Linux, by typing


# mkdir -p local/html/Callbacks/[[MyCallbacks]]/Elements/[[RT  Ticket|RT__Ticket]]/[[ColumnMap]]
<pre># mkdir -p local/html/Callbacks/MyCallbacks/Elements/RT__Ticket/ColumnMap</pre>


from your RT installation directory, which is /opt/rt3 unless someone built it differently.
from your RT installation directory, which is /opt/rt3 unless someone built it differently.
Line 58: Line 58:
Then you can
Then you can


# cd local/html/Callbacks/[[MyCallbacks]]/Elements/[[RT  Ticket|RT__Ticket]]/[[ColumnMap]]
<pre># cd local/html/Callbacks/MyCallbacks/Elements/RT__Ticket/ColumnMap</pre>


to create the file, which is '''also named''' [[ColumnMap]], and should contain this:
to create the file, which is '''also named''' [[ColumnMap]], and should contain this:


------8&lt;-----------------------------8&lt;----------
----
 
8&lt;-----------------------------8&lt;----------
<pre>
  &lt;%INIT&gt;
  &lt;%INIT&gt;
   
   
Line 94: Line 95:
  &lt;/%ARGS&gt;
  &lt;/%ARGS&gt;


------8&lt;-----------------------------8&lt;----------
----
8&lt;-----------------------------8&lt;----------
</pre>


* Onto the next part...
* Onto the next part...
* RT 3.8 and up use a different CSS theme. Web2 is the default theme.
* RT 3.8 and up use a different CSS theme. Web2 is the default theme.
* If you use other themes you will need to do the following steps for each theme you use.
* If you use other themes you will need to do the following steps for each theme you use.
* Create the directory: &lt;[[RTInstallationDir]]&gt;/local/html/Callbacks/&lt;[[SiteCallbacks]]&gt;/[[NoAuth]]/css/web2/main.css
* Create the directory: <RTInstallationDir>/local/html/Callbacks/<SiteCallbacks>/NoAuth/css/web2/main.css`
* Create the file: &lt;[[RTInstallationDir]]&gt;/local/html/Callbacks/&lt;[[SiteCallbacks]]&gt;/[[NoAuth]]/css/web2/main.css/End
* Create the file: `<RTInstallationDir>/local/html/Callbacks/<SiteCallbacks>/NoAuth/css/web2/main.css/End`


And in that file, put:
And in that file, put:


<pre>
@import "statuscolor.css";
@import "statuscolor.css";


* In the directory just created '&lt;[[RTInstallationDir]]&gt;/local/html/[[NoAuth]]/css/web2' you will need to create a new file.
* In the directory just created `<RTInstallationDir>/local/html/NoAuth/css/web2` you will need to create a new file.
* Name the file statuscolor.css and place the following content in it.
* Name the file statuscolor.css and place the following content in it.


Line 140: Line 144:
   font-weight: bold;
   font-weight: bold;
  }
  }
</pre>


* Don't forget to clear your Mason cache (apache restart, unless you've enabled $[[DevelMode]] in [[RT SiteConfig|RT_SiteConfig]].pm) and perform a "hard" refresh in your browser (Shift + Ctrl + R) to clear your local CSS cache.
* Don't forget to clear your Mason cache (apache restart, unless you've enabled $[[DevelMode]] in [[RT SiteConfig|RT_SiteConfig]].pm) and perform a "hard" refresh in your browser (Shift + Ctrl + R) to clear your local CSS cache.


So basically what you will get from the above is the status' listed in the statuscolor.css file will be colored. You may edit the statuscolor.css file to suit your needs. Just make sure you follow the convention of the file format i.e. to color status stalled you would use something like:
So basically what you will get from the above is the status' listed in the statuscolor.css file will be colored. You may edit the statuscolor.css file to suit your needs. Just make sure you follow the convention of the file format i.e. to color status stalled you would use something like:


<pre>
.statusstalled {
.statusstalled {


Line 152: Line 159:


}
}
</pre>


and so on so forth. Next thing to note is that along with coloring the status this also puts an REP flag next to any tickets where the last reply is by the requestor or cc (i.e. not the staff) (Thanks Johan Baarman !)
and so on so forth. Next thing to note is that along with coloring the status this also puts an REP flag next to any tickets where the last reply is by the requestor or cc (i.e. not the staff) (Thanks Johan Baarman !)
Line 181: Line 189:
This uses a similar statuscolor.css file found elsewhere on this page. Follow those instructions for setup, or use the following contents.
This uses a similar statuscolor.css file found elsewhere on this page. Follow those instructions for setup, or use the following contents.


/* Status Colours */
/* Status Colours */
.statusnew { color: #bb0000; text-align: left; font-weight: bold;}
.statusopen { color: #0000bb; text-align: left; font-weight: bold;}
.statusnew { color: #bb0000; text-align: left; font-weight: bold;}  
.statusreply { color: #009900; text-align: left; font-weight: bold;}
.statusopen { color: #0000bb; text-align: left; font-weight: bold;}
.statusresolved { color: #737373; text-align: left; font-weight: bold;}
.statusreply { color: #009900; text-align: left; font-weight: bold;}
.statusrejected { color: #884444; text-align: left; font-weight: bold;}
.statusresolved { color: #737373; text-align: left; font-weight: bold;}  
.statusstalled { color: #884444; text-align: left; font-weight: bold;}
.statusrejected { color: #884444; text-align: left; font-weight: bold;}
.statusstalled { color: #884444; text-align: left; font-weight: bold;}




The files should map to your system like so:
The files should map to your system like so:
<pre>


  &lt;RTInstallationDir&gt;/local/html/
  &lt;RTInstallationDir&gt;/local/html/
  `-- MyCallbacks
  `-- Callbacks
     `-- MyCallbacks
     `-- MyCallbacks
         |-- Elements
         |-- Elements
Line 201: Line 211:
         `-- NoAuth
         `-- NoAuth
             `-- css
             `-- css
                 `-- web2|aleron
                 `-- web2|aileron
                     `-- main.css
                     `-- main.css
                         `-- End
                         `-- End
Line 207: Line 217:
  `-- NoAuth/
  `-- NoAuth/
     `-- css
     `-- css
         `-- web2|aleron
         `-- web2|aileron
             `-- statuscolor.css
             `-- statuscolor.css
</pre>


Here's the complete &lt;RTInstallationDir&gt;/local/html/Callbacks/MyCallbacks/Elements/RT__Ticket/ColumnMap/[[ColumnMap]] script.
Here's the complete `<RTInstallationDir>/local/html/Callbacks/MyCallbacks/Elements/RT__Ticket/ColumnMap/ColumnMap` script.


  <nowiki>&lt;%INIT&gt;
  <pre>&lt;%INIT&gt;
 
     
  # Show status in colour.
      # Show status in colour.
  sub statusInColor {
      sub statusInColor {
  my $Ticket = shift;
      my $Ticket = shift;
  my $status = $Ticket-&gt;Status;
      my $status = $Ticket-&gt;Status;
  my $css = "status" . lc $status;
      my $css = "status" . lc $status;
  my $cssreply = "status" . lc "reply";
      my $cssreply = "status" . lc "reply";
  my $LastUpdater = $Ticket-&gt;LastUpdatedByObj-&gt;EmailAddress;
      my $LastUpdater = $Ticket-&gt;LastUpdatedByObj-&gt;EmailAddress;
  my $TicketRequestors = $Ticket-&gt;Requestors-&gt;MemberEmailAddressesAsString;
      my $TicketRequestors = $Ticket-&gt;Requestors-&gt;MemberEmailAddressesAsString;
  my $TicketCC = $Ticket-&gt;Cc-&gt;MemberEmailAddressesAsString;
      my $TicketCC = $Ticket-&gt;Cc-&gt;MemberEmailAddressesAsString;
  my $CurrentUser = $session{'CurrentUser'}-&gt;EmailAddress;
      my $CurrentUser = $session{'CurrentUser'}-&gt;EmailAddress;
 
     
  # Added $CurentUser ne $LastUpdater to prevent showing New Reply tag when the last updater is the current user.
      # Added $CurentUser ne $LastUpdater to prevent showing New Reply tag when the last updater is the current user.
  if (($CurrentUser ne $LastUpdater) &amp;&amp; ($TicketRequestors =~ $LastUpdater) || ($TicketCC =~ $LastUpdater))
      if (($CurrentUser ne $LastUpdater) &amp;&amp; ($TicketRequestors =~ $LastUpdater) || ($TicketCC =~ $LastUpdater))
  {
      {
  my $txn = $Ticket-&gt;SeenUpTo or return \"&lt;div class=\"$css\"&gt;$status&lt;/div&gt;";
      my $txn = $Ticket-&gt;SeenUpTo or return \"&lt;div class=\"$css\"&gt;$status&lt;/div&gt;";
  #      my $TicketLink = RT-&gt;Config-&gt;Get('WebPath') ."/Ticket/Display.html?id=". $Ticket-&gt;id. "#txn-".$txn-&gt;id;
      #      my $TicketLink = RT-&gt;Config-&gt;Get('WebPath') ."/Ticket/Display.html?id=". $Ticket-&gt;id. "#txn-".$txn-&gt;id;
  # Comment out the line above and uncomment the following line to mark posts as seen when following link.
      # Comment out the line above and uncomment the following line to mark posts as seen when following link.
  my $TicketLink = RT-&gt;Config-&gt;Get('WebPath') ."/Ticket/Display.html?id=". $Ticket-&gt;id ."&amp;MarkAsSeen=1".  "#txn-".$txn-&gt;id;
      my $TicketLink = RT-&gt;Config-&gt;Get('WebPath') ."/Ticket/Display.html?id=". $Ticket-&gt;id ."&amp;MarkAsSeen=1".  "#txn-".$txn-&gt;id;
  $status = "&lt;div class=\"$css\"&gt;$status &lt;a href=\"$TicketLink\"&gt;&lt;span class=\"$cssreply\"&gt;New Reply&lt;/span&gt;&lt;/a&gt;&lt;/div&gt;";
      $status = "&lt;div class=\"$css\"&gt;$status &lt;a href=\"$TicketLink\"&gt;&lt;span class=\"$cssreply\"&gt;New Reply&lt;/span&gt;&lt;/a&gt;&lt;/div&gt;";
  }
      }
  else {
      else {
  $status = "&lt;div class=\"$css\"&gt;$status&lt;/div&gt;";
      $status = "&lt;div class=\"$css\"&gt;$status&lt;/div&gt;";
  }
      }
 
     
  return \"$status";
      return \"$status";
 
     
  }
      }
 
     
  # Show extended status in colour. This will change the front page and other search pages where the ExtendedStatus is displayed.
      # Show extended status in colour. This will change the front page and other search pages where the ExtendedStatus is displayed.
  sub extStatusInColor {
      sub extStatusInColor {
  my $Ticket = shift;
      my $Ticket = shift;
  if ( my $count = $Ticket-&gt;HasUnresolvedDependencies ) {
      if ( my $count = $Ticket-&gt;HasUnresolvedDependencies ) {
  my $status;
      my $status;
 
     
  if ( $Ticket-&gt;HasUnresolvedDependencies( Type =&gt; 'approval' )
      if ( $Ticket-&gt;HasUnresolvedDependencies( Type =&gt; 'approval' )
  or $Ticket-&gt;HasUnresolvedDependencies( Type =&gt; 'code' ) ) {
      or $Ticket-&gt;HasUnresolvedDependencies( Type =&gt; 'code' ) ) {
  $status = "&lt;em&gt;" . loc('(pending approval)') . "&lt;/em&gt;";
      $status = "&lt;em&gt;" . loc('(pending approval)') . "&lt;/em&gt;";
  } else {
      } else {
  $status = "&lt;em&gt;" . loc('(pending [quant,_1,other ticket])',$count) . "&lt;/em&gt;";
      $status = "&lt;em&gt;" . loc('(pending [quant,_1,other ticket])',$count) . "&lt;/em&gt;";
  }
      }
  return \$status;
      return \$status;
  } else {
      } else {
  return statusInColor($Ticket);
      return statusInColor($Ticket);
 
     
  }
      }
  }
      }
 
     
  # Set the priority numbers to a colour.
      # Set the priority numbers to a colour.
  sub PriorityInColor {
      sub PriorityInColor {
  my $Ticket = shift;
      my $Ticket = shift;
 
     
  my $priority = $Ticket-&gt;Priority;
      my $priority = $Ticket-&gt;Priority;
  my $colors = undef;
      my $colors = undef;
 
     
  # Change priority numbers to reflect your priority system.
      # Change priority numbers to reflect your priority system.
  if ($priority &gt;= '50') {
      if ($priority &gt;= '50') {
  $colors = "#FF0000";
      $colors = "#FF0000";
  } elsif ($priority &gt;= '45') {
      } elsif ($priority &gt;= '45') {
  $colors = "#FF2000";
      $colors = "#FF2000";
  } elsif ($priority &gt;= '40') {
      } elsif ($priority &gt;= '40') {
  $colors = "#FF4000";
      $colors = "#FF4000";
  } elsif ($priority &gt;= '35') {
      } elsif ($priority &gt;= '35') {
  $colors = "#FF6A00";
      $colors = "#FF6A00";
  } elsif ($priority &gt;= '30') {
      } elsif ($priority &gt;= '30') {
  $colors = "#FF6600";
      $colors = "#FF6600";
  } elsif ($priority &gt;= '25') {
      } elsif ($priority &gt;= '25') {
  $colors = "#FFA000";
      $colors = "#FFA000";
  } elsif ($priority &gt;= '20') {
      } elsif ($priority &gt;= '20') {
  $colors = "#0033CC";
      $colors = "#0033CC";
  } elsif ($priority &gt;= '15') {
      } elsif ($priority &gt;= '15') {
  $colors = "#809FFE";
      $colors = "#809FFE";
  } elsif ($priority &gt;= '10') {
      } elsif ($priority &gt;= '10') {
  $colors = "#004600";
      $colors = "#004600";
  } elsif ($priority &gt;= '5') {
      } elsif ($priority &gt;= '5') {
  $colors = "#006400";
      $colors = "#006400";
  } elsif ($priority &gt;= '0') {
      } elsif ($priority &gt;= '0') {
  $colors = "#009000";
      $colors = "#009000";
  }
      }
 
     
  if ($colors) {
      if ($colors) {
  $priority = "&lt;div style=\"color: $colors;\"&gt;$priority&lt;/div&gt;"
      $priority = "&lt;div style=\"color: $colors;\"&gt;$priority&lt;/div&gt;"
  }
      }
 
     
  return \"&lt;b&gt;$priority&lt;/b&gt;";
      return \"&lt;b&gt;$priority&lt;/b&gt;";
  }
      }
 
     
  # Comment out any line to disable colour change.
      # Comment out any line to disable colour change.
  $COLUMN_MAP-&gt;{Priority}-&gt;{value} = \&amp;PriorityInColor;
      $COLUMN_MAP-&gt;{Priority}-&gt;{value} = \&amp;PriorityInColor;
  $COLUMN_MAP-&gt;{Status}-&gt;{value} = \&amp;statusInColor;
      $COLUMN_MAP-&gt;{Status}-&gt;{value} = \&amp;statusInColor;
  $COLUMN_MAP-&gt;{ExtendedStatus}-&gt;{value} = \&amp;extStatusInColor;
      $COLUMN_MAP-&gt;{ExtendedStatus}-&gt;{value} = \&amp;extStatusInColor;
 
     
  &lt;/%INIT&gt;
      &lt;/%INIT&gt;
  &lt;%ARGS&gt;
      &lt;%ARGS&gt;
  $COLUMN_MAP =&gt; undef
      $COLUMN_MAP =&gt; undef
  &lt;/%ARGS&gt;
      &lt;/%ARGS&gt;
  </nowiki>
      </pre>


----
----
Line 327: Line 338:
Simply do the following:
Simply do the following:


* Create the directory: &lt;[[RTInstallationDir]]&gt;/local/html/Callbacks/[[MyCallbacks]]/Elements/[[RT  Ticket|RT__Ticket]]/[[ColumnMap]]
* Create the directory: `<RTInstallationDir>/local/html/Callbacks/MyCallbacks/Elements/RT__Ticket/ColumnMap`
* Put the contents of the following file into the file: &lt;[[RTInstallationDir]]&gt;/local/html/Callbacks/[[MyCallbacks]]/Elements/[[RT  Ticket|RT__Ticket]]/[[ColumnMap]]/[[ColumnMap]]
* Put the contents of the following file into the file: `<RTInstallationDir>/local/html/Callbacks/MyCallbacks]]/Elements/RT__Ticket/ColumnMap/ColumnMap`


Note: in debian the right path is /usr/local/share/request-tracker3.6/html/Callbacks/[[MyCallbacks]]/Elements/[[RT  Ticket|RT__Ticket]]/[[ColumnMap]]/[[ColumnMap]]
Note: in debian the right path is `/usr/local/share/request-tracker3.6/html/Callbacks/MyCallbacks/Elements/RT__Ticket/ColumnMap/ColumnMap`


----
----
 
<pre>
  &lt;%INIT&gt;
  &lt;%INIT&gt;
   
   
Line 390: Line 401:
  $COLUMN_MAP =&gt; undef
  $COLUMN_MAP =&gt; undef
  &lt;/%ARGS&gt;
  &lt;/%ARGS&gt;
</pre>


===== Priority color =====
===== Priority color =====
Line 395: Line 407:
by Riccardo Capecchi
by Riccardo Capecchi


My users wanted also the priority coloured in shade of red and yellow based on priority (red = big problem), i used the above code and added these lines to show a coloured field priority. You must add these lines with or without the above code into the file: &lt;[[RTInstallationDir]]&gt;/local/html/Callbacks/[[MyCallbacks]]/Elements/[[RT  Ticket|RT__Ticket]]/[[ColumnMap]]/[[ColumnMap]]
My users wanted also the priority coloured in shade of red and yellow based on priority (red = big problem), i used the above code and added these lines to show a coloured field priority. You must add these lines with or without the above code into the file: `<RTInstallationDir>/local/html/Callbacks/MyCallbacks/Elements/RT__Ticket/ColumnMap/ColumnMap`


edit: $priority is an integer, not a string. I've used &gt;= operator instead of ge operator.
edit: $priority is an integer, not a string. I've used &gt;= operator instead of ge operator.


<pre>
----
----


Line 436: Line 449:
  }
  }
  $COLUMN_MAP-&gt;{Priority}-&gt;{value} = \&amp;PriorityInColor;
  $COLUMN_MAP-&gt;{Priority}-&gt;{value} = \&amp;PriorityInColor;
</pre>


(This one also works in 3.8.2 as of 2009-Feb-12; I've modified it slightly to colorize the '''background''', and also to use inline CSS instead of deprecated tags. If you use both, put this one '''inside''' the other one's %INIT tags. --Baylink)
(This one also works in 3.8.2 as of 2009-Feb-12; I've modified it slightly to colorize the '''background''', and also to use inline CSS instead of deprecated tags. If you use both, put this one '''inside''' the other one's %INIT tags. --Baylink)
Line 445: Line 459:
As an alternative to the above, you might choose to use CSS to define styling of the Status field. I have the following setup:
As an alternative to the above, you might choose to use CSS to define styling of the Status field. I have the following setup:


In file $RT_HOME/local/html/Callbacks/[[MyCallbacks]]/Elements/[[RT  Ticket|RT__Ticket]]/[[ColumnMap]]/[[ColumnMap]] replace the above status[[InColor]] method with the following:
In file `$RT_HOME/local/html/Callbacks/MyCallbacks/Elements/RT__Ticket/ColumnMap/ColumnMap` replace the above status[[InColor]] method with the following:


<pre>
  sub statusInColor {
  sub statusInColor {
     my $Ticket = shift;
     my $Ticket = shift;
Line 461: Line 476:
     return \"$status";
     return \"$status";
  }
  }
</pre>


In file $RT_HOME/local/html/Callbacks/[[MyCallbacks]]/[[NoAuth]]/webrt.css/Default
In file `$RT_HOME/local/html/Callbacks/MyCallbacks/NoAuth/webrt.css/Default`


<pre>
  /* Status Colours */
  /* Status Colours */
   
   
Line 495: Line 512:
   font-weight: bold;
   font-weight: bold;
  }
  }
</pre>


== RT 3.6.5 (and up?) ==
== RT 3.6.5 (and up?) ==
Line 502: Line 520:
The problem with newer version is that the CSS file is not read from the directory mentioned above. Follow the steps below to solve it:
The problem with newer version is that the CSS file is not read from the directory mentioned above. Follow the steps below to solve it:


Create a directory $RT_HOME/local/html/[[NoAuth]]/css/3.5-default/ and copy $RT_HOME/share/html/[[NoAuth]]/css/3.5-default/main.css to it. Now edit the local main.css file and add the following line at the end: import "statuscolor.css"; Create a new local file $RT_HOME/local/html/[[NoAuth]]/css/3.5-default/statuscolor.css and populate it with the above css tags. I've also changed the .statustesting above to .statusreply in my statuscolor.css file in order to color replies.
Create a directory `$RT_HOME/local/html/NoAuth/css/3.5-default/` and copy `$RT_HOME/share/html/NoAuth/css/3.5-default/main.css` to it. Now edit the local main.css file and add the following line at the end: import "statuscolor.css"; Create a new local file `$RT_HOME/local/html/NoAuth/css/3.5-default/statuscolor.css` and populate it with the above css tags. I've also changed the .statustesting above to .statusreply in my statuscolor.css file in order to color replies.


In addition to coloring the status, the following alternative status[[InColor]] function will set a "REP" flag for each status to indicate a ticket that had been updated by anyone else than the staff, i.e. requestor or any of the [[CCs]], in case any of the users are colorblind.
In addition to coloring the status, the following alternative status[[InColor]] function will set a "REP" flag for each status to indicate a ticket that had been updated by anyone else than the staff, i.e. requestor or any of the [[CCs]], in case any of the users are colorblind.


<pre>
  sub statusInColor {
  sub statusInColor {
     my $Ticket = shift;
     my $Ticket = shift;
Line 525: Line 544:
     return \"$status";
     return \"$status";
  }
  }
</pre>

Latest revision as of 14:34, 23 April 2018

Colorize ticket links based on status or, as in one example below, by priority.

RT 3.8.2

Simple

Below is a modified local/html/Elements/ShowLink. It will display inter-ticket links colored to match the status of the ticket with the same color scheme used in graphs, via inline CSS. --Jerrad

<a href="<%$URI->Resolver->HREF%>">
   % if ($URI->IsLocal) {
   % my $member = $URI->Object;
   % if (UNIVERSAL::isa($member, "RT::Ticket")) {
   
   #Customization
   <%perl>
   require RT::Graph::Tickets;
   my $status = $member->Status;
   my $class  = $member->QueueObj->IsInactiveStatus($status)?'ticket-inactive':'';
   my $color  = $RT::Graph::Tickets::ticket_status_style{$status}->{'fontcolor'};
   </%perl>
   <span class="<% $class %>" style="color: <% $color %>">
   
   <%$member->Id%>: (<%$member->OwnerObj->Name%>) <%$member->Subject%> [<% loc($member->Status) %>]
   </span>
   
   % } elsif ( UNIVERSAL::can($member, 'Name')) {
   <%$URI->Resolver->AsString%>: <%$member->Name%>
   % } else {
   <%$URI->Resolver->AsString%>
   % }
   % } else {
   <%$URI->Resolver->AsString%>
   % }
   </a>
   <%ARGS>
   $URI => undef
   </%ARGS>
   

Full-featured

by Dan Cook, updated with CSS callback dox by Matt Zagrabelny

This is how I've set things up. I have shamelessly robbed most of this from the posts above (Thanks Guys!).

(And Baylink, in turn, moved it to the top; if you're running older code, read on down. In particular, I modified the Colored-Priority code to use inline styles and reverse out the color into the background a bit further down.)

  • Create the directory: `/local/html/Callbacks/MyCallbacks/Elements/RT__Ticket/ColumnMap`

You can do that, in Linux, by typing

# mkdir -p local/html/Callbacks/MyCallbacks/Elements/RT__Ticket/ColumnMap

from your RT installation directory, which is /opt/rt3 unless someone built it differently.

  • Note: There are 2 underscores between RT and Ticket

Then you can

# cd local/html/Callbacks/MyCallbacks/Elements/RT__Ticket/ColumnMap

to create the file, which is also named ColumnMap, and should contain this:


8<-----------------------------8<----------

 <%INIT>
 
 sub statusInColor {
    my $Ticket = shift;
    my $status = $Ticket->Status;
    my $css = "status" . lc $status;
    my $LastUpdater = $Ticket->LastUpdatedByObj->EmailAddress;
    my $TicketRequestors = $Ticket->Requestors->MemberEmailAddressesAsString;
    my $TicketCC = $Ticket->Cc->MemberEmailAddressesAsString;
 
    if (($TicketRequestors =~ $LastUpdater) || ($TicketCC =~ $LastUpdater))
    {
        $css = "status" . lc "reply";
        $status = "<div class=\"$css\">$status REP</div>";
    }
    else {
        $status = "<div class=\"$css\">$status</div>";
    }
 
    return \"$status";
 }
 
 
 $COLUMN_MAP->{Status}->{value} = \&statusInColor;
 
 </%INIT>
 <%ARGS>
 $COLUMN_MAP => undef
 </%ARGS>

----
8<-----------------------------8<----------
  • Onto the next part...
  • RT 3.8 and up use a different CSS theme. Web2 is the default theme.
  • If you use other themes you will need to do the following steps for each theme you use.
  • Create the directory: /local/html/Callbacks//NoAuth/css/web2/main.css`
  • Create the file: `/local/html/Callbacks//NoAuth/css/web2/main.css/End`

And in that file, put:

@import "statuscolor.css";

* In the directory just created `<RTInstallationDir>/local/html/NoAuth/css/web2` you will need to create a new file.
* Name the file statuscolor.css and place the following content in it.

 /* Status Colours */
 
 .statusnew {
  color: #bb0000;
  text-align: left;
  font-weight: bold;
 }
 
 .statusopen {
  color: #0000bb;
  text-align: left;
  font-weight: bold;
 }
 
 .statusreply {
  color: #00bb00;
  text-align: left;
  font-weight: bold;
 }
 
 .statusresolved {
  color: #888888;
  text-align: left;
  font-weight: bold;
 }
 
 .statusrejected {
  color: #884444;
  text-align: left;
  font-weight: bold;
 }
  • Don't forget to clear your Mason cache (apache restart, unless you've enabled $DevelMode in RT_SiteConfig.pm) and perform a "hard" refresh in your browser (Shift + Ctrl + R) to clear your local CSS cache.


So basically what you will get from the above is the status' listed in the statuscolor.css file will be colored. You may edit the statuscolor.css file to suit your needs. Just make sure you follow the convention of the file format i.e. to color status stalled you would use something like:

.statusstalled {

 color: #884422;
 text-align: left;
 font-weight: bold;

}

and so on so forth. Next thing to note is that along with coloring the status this also puts an REP flag next to any tickets where the last reply is by the requestor or cc (i.e. not the staff) (Thanks Johan Baarman !)


RT 3.8.x/4.0.x

Full featured ColumnMap script

by Alex Young

Confirmed working with 3.8.2, 3.8.6, 3.8.8.

Confirmed working with 4.0.x, but ColumnMap file is renamed to Once, and web2 location is changed to aileron.

I have combined the scripts on this wiki page to work in 3.8.x/4.0.x, so thanks to all the people that did all the hard work! Only the ColumnMap file is different from the other guides on this page.

Changes from the other scripts

  • Changes REP flag to New Reply.
  • Doesn't display New Reply when the current user is the last to comment.
  • New Reply tag is displayed in its own colour, while keeping the default status colours.
  • New Reply tag links to the last unread message and can mark the messages as read.
  • New Reply tag isn't displayed if there are no unread messages.
  • Changed colours for Priorities. Removed light colours that prevented the text from being easily read on a white background.
  • Updated Extended Status code to display number of pending tickets.

This uses a similar statuscolor.css file found elsewhere on this page. Follow those instructions for setup, or use the following contents.

/* Status Colours */

.statusnew { color: #bb0000; text-align: left; font-weight: bold;} 
.statusopen { color: #0000bb; text-align: left; font-weight: bold;}
.statusreply { color: #009900; text-align: left; font-weight: bold;}
.statusresolved { color: #737373; text-align: left; font-weight: bold;} 
.statusrejected { color: #884444; text-align: left; font-weight: bold;}
.statusstalled { color: #884444; text-align: left; font-weight: bold;}


The files should map to your system like so:


 <RTInstallationDir>/local/html/
 `-- Callbacks
     `-- MyCallbacks
         |-- Elements
         |   `-- RT__Ticket
         |       `-- ColumnMap
         |           `-- ColumnMap|Once
         `-- NoAuth
             `-- css
                 `-- web2|aileron
                     `-- main.css
                         `-- End
 <RTInstallationDir>/local/html/
 `-- NoAuth/
     `-- css
         `-- web2|aileron
             `-- statuscolor.css

Here's the complete `/local/html/Callbacks/MyCallbacks/Elements/RT__Ticket/ColumnMap/ColumnMap` script.

<%INIT>
      
      # Show status in colour.
      sub statusInColor {
      	my $Ticket = shift;
      	my $status = $Ticket->Status;
      	my $css = "status" . lc $status;
      	my $cssreply = "status" . lc "reply";
      	my $LastUpdater = $Ticket->LastUpdatedByObj->EmailAddress;
      	my $TicketRequestors = $Ticket->Requestors->MemberEmailAddressesAsString;
      	my $TicketCC = $Ticket->Cc->MemberEmailAddressesAsString;
      	my $CurrentUser = $session{'CurrentUser'}->EmailAddress;
      
      # Added $CurentUser ne $LastUpdater to prevent showing New Reply tag when the last updater is the current user.
      	if (($CurrentUser ne $LastUpdater) && ($TicketRequestors =~ $LastUpdater) || ($TicketCC =~ $LastUpdater))
      	{
      		my $txn = $Ticket->SeenUpTo or return \"<div class=\"$css\">$status</div>";
      #       my $TicketLink = RT->Config->Get('WebPath') ."/Ticket/Display.html?id=". $Ticket->id. "#txn-".$txn->id;
      # Comment out the line above and uncomment the following line to mark posts as seen when following link.
      		my $TicketLink = RT->Config->Get('WebPath') ."/Ticket/Display.html?id=". $Ticket->id ."&MarkAsSeen=1".  "#txn-".$txn->id;
      		$status = "<div class=\"$css\">$status <a href=\"$TicketLink\"><span class=\"$cssreply\">New Reply</span></a></div>";
      	}
      	else {
      		$status = "<div class=\"$css\">$status</div>";
      	}
      
      	return \"$status";
      
      }
      
      # Show extended status in colour. This will change the front page and other search pages where the ExtendedStatus is displayed.
      sub extStatusInColor {
      	my $Ticket = shift;
      	if ( my $count = $Ticket->HasUnresolvedDependencies ) {
      		my $status;
      
      		if ( $Ticket->HasUnresolvedDependencies( Type => 'approval' )
      				or $Ticket->HasUnresolvedDependencies( Type => 'code' ) ) {
      			$status = "<em>" . loc('(pending approval)') . "</em>";
      		} else {
      			$status = "<em>" . loc('(pending [quant,_1,other ticket])',$count) . "</em>";
      			}
      		return \$status;
      	} else {
      		return statusInColor($Ticket);
      
      	}
      }
      
      # Set the priority numbers to a colour.
      sub PriorityInColor {
      	my $Ticket = shift;
      
      	my $priority = $Ticket->Priority;
      	my $colors = undef;
      
      # Change priority numbers to reflect your priority system.
      	if ($priority >= '50') {
      		$colors = "#FF0000";
      	} elsif ($priority >= '45') {
      		$colors = "#FF2000";
      	} elsif ($priority >= '40') {
      		$colors = "#FF4000";
      	} elsif ($priority >= '35') {
      		$colors = "#FF6A00";
      	} elsif ($priority >= '30') {
      		$colors = "#FF6600";
      	} elsif ($priority >= '25') {
      		$colors = "#FFA000";
      	} elsif ($priority >= '20') {
      		$colors = "#0033CC";
      	} elsif ($priority >= '15') {
      		$colors = "#809FFE";
      	} elsif ($priority >= '10') {
      		$colors = "#004600";
      	} elsif ($priority >= '5') {
      		$colors = "#006400";
      	} elsif ($priority >= '0') {
      		$colors = "#009000";
      	}
      
      	if ($colors) {
      		$priority = "<div style=\"color: $colors;\">$priority</div>"
      	}
      
      		return \"<b>$priority</b>";
      }
      
      # Comment out any line to disable colour change.
      $COLUMN_MAP->{Priority}->{value} = \&PriorityInColor;
      $COLUMN_MAP->{Status}->{value} = \&statusInColor;
      $COLUMN_MAP->{ExtendedStatus}->{value} = \&extStatusInColor;
      
      </%INIT>
      <%ARGS>
      $COLUMN_MAP => undef
      </%ARGS>
      

Earlier forms

(Baylink reads further down... wow. Everyone else already did this. :-)

Simply do the following:

  • Create the directory: `/local/html/Callbacks/MyCallbacks/Elements/RT__Ticket/ColumnMap`
  • Put the contents of the following file into the file: `/local/html/Callbacks/MyCallbacks]]/Elements/RT__Ticket/ColumnMap/ColumnMap`

Note: in debian the right path is `/usr/local/share/request-tracker3.6/html/Callbacks/MyCallbacks/Elements/RT__Ticket/ColumnMap/ColumnMap`


 <%INIT>
 
 sub statusInColor {
    my $Ticket = shift;
    my $status = $Ticket->Status;
    my $color = undef;
 
    if ($status eq 'new') {
        $color = "900000";
    } elsif ($status eq 'open') {
        $color = "#AA8000";
    } elsif ($status eq 'stalled') {
        $color = "#000090";
    } elsif ($status eq 'rejected') {
        $color = "#999999";
    } elsif ($status eq 'resolved') {
        $color = "009000";
    }
 
    $status = loc($status);
 
    if ( $Ticket->HasUnresolvedDependencies ) {
        $status = "<i>$status<i>"
    }
 
    if ($color) {
        $status = "<font color=$color>$status</font>"
    }
 
    return \"<b>$status</b>";
 }
 
 sub extStatusInColor {
    my $Ticket = shift;
 
    if ( $Ticket->HasUnresolvedDependencies ) {
        my $status;
        if ( $Ticket->HasUnresolvedDependencies( Type => 'approval' )
             or $Ticket->HasUnresolvedDependencies( Type => 'code' ) ) {
            $status = "<em>" . loc('(pending approval)') . "</em>";
        } else {
            $status = "<em>" . loc('(pending other Collection)') . "</em>";
        }
        return \$status;
    } else {
        return statusInColor($Ticket);
    }
 }
 
 $COLUMN_MAP->{Status}->{value} = \&statusInColor;
 $COLUMN_MAP->{ExtendedStatus}->{value} = \&extStatusInColor;
 
 </%INIT>
 <%ARGS>
 $COLUMN_MAP => undef
 </%ARGS>
Priority color

by Riccardo Capecchi

My users wanted also the priority coloured in shade of red and yellow based on priority (red = big problem), i used the above code and added these lines to show a coloured field priority. You must add these lines with or without the above code into the file: `/local/html/Callbacks/MyCallbacks/Elements/RT__Ticket/ColumnMap/ColumnMap`

edit: $priority is an integer, not a string. I've used >= operator instead of ge operator.

----

 sub PriorityInColor {
   my $Ticket = shift;
 
   my $priority = $Ticket->Priority;
   my $colors = undef;
 
   if ($priority >= 90) {
       $colors = "#FF0000";
   } elsif ($priority >= 80) {
       $colors = "#FF2000";
   } elsif ($priority >= 70) {
       $colors = "#FF4000";
   } elsif ($priority >= 60) {
       $colors = "#FF6000";
   } elsif ($priority >= 50) {
       $colors = "#FF8000";
   } elsif ($priority >= 40) {
       $colors = "#FFA000";
   } elsif ($priority >= 30) {
       $colors = "#FFC000";
   } elsif ($priority >= 20) {
       $colors = "#FFE000";
   } elsif ($priority >= 10) {
       $colors = "#FFFF00";
   } elsif ($priority >= 0) {
       $colors = "009000";
   }
 
   if ($colors) {
       $priority = "<font style=\"color:black;background-color:$colors\">&nbsp;$priority&nbsp;</font>"
   }
 
   return \"<b>$priority</b>";
 }
 $COLUMN_MAP->{Priority}->{value} = \&PriorityInColor;

(This one also works in 3.8.2 as of 2009-Feb-12; I've modified it slightly to colorize the background, and also to use inline CSS instead of deprecated tags. If you use both, put this one inside the other one's %INIT tags. --Baylink)

Using CSS For Styling

by Graham Briggs

As an alternative to the above, you might choose to use CSS to define styling of the Status field. I have the following setup:

In file `$RT_HOME/local/html/Callbacks/MyCallbacks/Elements/RT__Ticket/ColumnMap/ColumnMap` replace the above statusInColor method with the following:

 sub statusInColor {
    my $Ticket = shift;
    my $status = $Ticket->Status;
    my $css = "status" . lc $status;
    $css =~ s/[\W]//g;
 
    if ( $Ticket->HasUnresolvedDependencies ) {
        $status = "<i>$status<i>";
    }
 
    $status = "<div class=\"$css\">$status</div>";
 
    return \"$status";
 }

In file `$RT_HOME/local/html/Callbacks/MyCallbacks/NoAuth/webrt.css/Default`

 /* Status Colours */
 
 .statusnew {
   color: #bb0000;
   text-align: center;
   font-weight: bold;
 }
 
 .statusopen {
   color: #0000bb;
   text-align: center;
   font-weight: bold;
 }
 
 .statustesting {
   color: #00bb00;
   text-align: center;
   font-weight: bold;
 }
 
 .statusresolved {
   color: #888888;
   text-align: center;
   font-weight: bold;
 }
 
 .statusrejected {
   color: #884444;
   text-align: center;
   font-weight: bold;
 }

RT 3.6.5 (and up?)

Thanks Johan Baarman for the solution.

The problem with newer version is that the CSS file is not read from the directory mentioned above. Follow the steps below to solve it:

Create a directory `$RT_HOME/local/html/NoAuth/css/3.5-default/` and copy `$RT_HOME/share/html/NoAuth/css/3.5-default/main.css` to it. Now edit the local main.css file and add the following line at the end: import "statuscolor.css"; Create a new local file `$RT_HOME/local/html/NoAuth/css/3.5-default/statuscolor.css` and populate it with the above css tags. I've also changed the .statustesting above to .statusreply in my statuscolor.css file in order to color replies.

In addition to coloring the status, the following alternative statusInColor function will set a "REP" flag for each status to indicate a ticket that had been updated by anyone else than the staff, i.e. requestor or any of the CCs, in case any of the users are colorblind.

 sub statusInColor {
    my $Ticket = shift;
    my $status = $Ticket->Status;
    my $css = "status" . lc $status;
    my $LastUpdater = $Ticket->LastUpdatedByObj->EmailAddress;
    my $TicketRequestors = $Ticket->Requestors->MemberEmailAddressesAsString;
    my $TicketCC = $Ticket->Cc->MemberEmailAddressesAsString;
 
    if (($TicketRequestors =~ $LastUpdater) || ($TicketCC =~ $LastUpdater))
    {
        $css = "status" . lc "reply";
        $status = "<div class=\"$css\">$status REP</div>";
    }
    else {
        $status = "<div class=\"$css\">$status</div>";
    }
 
    return \"$status";
 }