Search code examples
trac

How to color tickets in a Trac report by component?


In Trac (1.2) I want to create a report with all tickets sorted by modification time where the color should indicate the component (or whether it is closed).

I assumed that setting __color__ by component would do the trick, but the report following report shows all active tickets as white:

SELECT 
  DISTINCT 
   component AS __color__,
   (CASE status 
      WHEN 'closed' THEN 'color: #777; background: #ddd; border-color: #ccc;'
    END) AS __style__,
   id AS ticket, summary, component, milestone, status, resolution, 
   t.time AS created, changetime AS modified,
   priority AS _priority, reporter AS _reporter, cc AS _cc
  FROM ticket t
  LEFT JOIN enum p ON p.name = t.priority AND p.type = 'priority'
  LEFT JOIN ticket_change tc ON id = tc.ticket
  ORDER BY
    changetime DESC

How do I change the color based on what component a ticket refers to?


Solution

  • Inspired by the answer by @RjOllos I chose to set __color__ by using a case statement:

    (CASE component
       WHEN 'COMPONENT1' THEN 1
       WHEN 'COMPONENT2' THEN 2
       WHEN 'COMPONENT3a' THEN 4
       WHEN 'COMPONENT3b' THEN 4
       WHEN 'COMPONENT4' THEN 5
       ELSE 3
     END) AS __color__,
    

    This has the advantage that the rows keep having alternating colors.