ShowStatusInColor: Difference between revisions
m (8 revisions imported) |
|
(No difference)
|
Revision as of 15:37, 6 April 2016
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: <RTInstallationDir>/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: <RTInstallationDir>/local/html/Callbacks/<SiteCallbacks>/NoAuth/css/web2/main.css
- Create the file: <RTInstallationDir>/local/html/Callbacks/<SiteCallbacks>/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 <RTInstallationDir>/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
- Tested and works in RT 3.2.x
- Results in a a reference error in 3.2.2
- Error in 3.4.1 - http://lists.bestpractical.com/pipermail/rt-users/2005-May/030943.html
- Works in 3.4.2, small change needed - http://lists.bestpractical.com/pipermail/rt-users/2005-August/033080.html
- Works in 3.6.1, added localization support (2007/5/11)
- Changes for 3.6.5, see below (2008/2/5)
- Working as below in 3.8.2 - 2009-Feb-12 Baylink
(Baylink reads further down... wow. Everyone else already did this. :-)
Simply do the following:
- Create the directory: <RTInstallationDir>/local/html/Callbacks/MyCallbacks/Elements/RT__Ticket/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/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: <RTInstallationDir>/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\"> $priority </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"; }