TracReports (diff) - Xwrits - Trac

Changes from Version 1 of TracReports

Show
Ignore:
Author:
trac (IP: 127.0.0.1)
Timestamp:
10/30/06 19:35:43 (9 months ago)
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • TracReports

    vv1 
     1= Trac Reports = 
     2[[TracGuideToc]] 
     3 
     4The Trac reports module provides a simple, yet powerful reporting facility 
     5to present information about tickets in the Trac database. 
     6 
     7Rather than have its own report definition format, TracReports relies on standard SQL 
     8`SELECT` statements for custom report definition.  
     9 
     10  '''Note:''' ''The report module is being phased out in its current form because it seriously limits the ability of the Trac team to make adjustments to the underlying database schema. We believe that the [wiki:TracQuery query module] is a good replacement that provides more flexibility and better usability. While there are certain reports that cannot yet be handled by the query module, we intend to further enhance it so that at some point the reports module can be completely removed. This also means that there will be no major enhancements to the report module anymore.'' 
     11 
     12  ''You can already completely replace the reports module by the query module simply be disabling the former in [wiki:TracIni trac.ini]:'' 
     13  {{{ 
     14  [components] 
     15  trac.ticket.report.* = disabled 
     16  }}} 
     17  ''This will make the query module the default handler for the “View Tickets” navigation item. We encourage you to try this configuration and report back what kind of features of reports you are missing, if any.'' 
     18 
     19A report consists of these basic parts: 
     20 * '''ID''' -- Unique (sequential) identifier  
     21 * '''Title'''  -- Descriptive title 
     22 * '''Description'''  -- A brief description of the report, in WikiFormatting text. 
     23 * '''Report Body''' -- List of results from report query, formatted according to the methods described below. 
     24 * '''Footer''' -- Links to alternative download formats for this report. 
     25 
     26== Changing Sort Order == 
     27Simple reports - ungrouped reports to be specific - can be changed to be sorted by any column simply by clicking the column header.  
     28 
     29If a column header is a hyperlink (red), click the column you would like to sort by. Clicking the same header again reverses the order. 
     30 
     31 
     32== Alternate Download Formats == 
     33Aside from the default HTML view, reports can also be exported in a number of alternate formats. 
     34At the bottom of the report page, you will find a list of available data formats. Click the desired link to  
     35download the alternate report format. 
     36 
     37=== Comma-delimited - CSV (Comma Separated Values) === 
     38Export the report as plain text, each row on its own line, columns separated by a single comma (','). 
     39'''Note:''' Carriage returns, line feeds, and commas are stripped from column data to preserve the CSV structure. 
     40 
     41=== Tab-delimited === 
     42Like above, but uses tabs (     ) instead of comma. 
     43 
     44=== RSS - XML Content Syndication === 
     45All reports support syndication using XML/RSS 2.0. To subscribe to an RSS feed, click the orange 'XML' icon at the bottom of the page. See TracRss for general information on RSS support in Trac. 
     46 
     47---- 
     48 
     49== Creating Custom Reports == 
     50 
     51''Creating a custom report requires a comfortable knowledge of SQL.'' 
     52 
     53A report is basically a single named SQL query, executed and presented by 
     54Trac.  Reports can be viewed and created from a custom SQL expression directly 
     55in from the web interface. 
     56 
     57Typically, a report consists of a SELECT-expression from the 'ticket' table, 
     58using the available columns and sorting the way you want it. 
     59 
     60== Ticket columns == 
     61The ''ticket'' table has the following columns: 
     62 * id 
     63 * time 
     64 * changetime 
     65 * component 
     66 * severity   
     67 * priority  
     68 * owner 
     69 * reporter 
     70 * cc 
     71 * version 
     72 * milestone 
     73 * status 
     74 * resolution 
     75 * summary 
     76 * description 
     77 
     78See TracTickets for a detailed description of the column fields. 
     79 
     80'''all active tickets, sorted by priority and time''' 
     81 
     82'''Example:''' ''All active tickets, sorted by priority and time'' 
     83{{{ 
     84SELECT id AS ticket, status, severity, priority, owner,  
     85       time as created, summary FROM ticket  
     86  WHERE status IN ('new', 'assigned', 'reopened') 
     87  ORDER BY priority, time 
     88}}} 
     89 
     90 
     91---- 
     92 
     93 
     94== Advanced Reports: Dynamic Variables == 
     95For more flexible reports, Trac supports the use of ''dynamic variables'' in report SQL statements.  
     96In short, dynamic variables are ''special'' strings that are replaced by custom data before query execution. 
     97 
     98=== Using Variables in a Query === 
     99The syntax for dynamic variables is simple, any upper case word beginning with '$' is considered a variable. 
     100 
     101Example: 
     102{{{ 
     103SELECT id AS ticket,summary FROM ticket WHERE priority='$PRIORITY' 
     104}}} 
     105 
     106To assign a value to $PRIORITY when viewing the report, you must define it as an argument in the report URL, leaving out the the leading '$'. 
     107 
     108Example: 
     109{{{ 
     110 http://projects.edgewall.com/trac/reports/14?PRIORITY=high 
     111}}} 
     112 
     113To use multiple variables, separate them with an '&'. 
     114 
     115Example: 
     116{{{ 
     117 http://projects.edgewall.com/trac/reports/14?PRIORITY=high&SEVERITY=critical 
     118}}} 
     119 
     120 
     121=== Special/Constant Variables === 
     122There is one ''magic'' dynamic variable to allow practical reports, its value automatically set without having to change the URL.  
     123 
     124 * $USER -- Username of logged in user. 
     125 
     126Example (''List all tickets assigned to me''): 
     127{{{ 
     128SELECT id AS ticket,summary FROM ticket WHERE owner='$USER' 
     129}}} 
     130 
     131 
     132---- 
     133 
     134 
     135== Advanced Reports: Custom Formatting == 
     136Trac is also capable of more advanced reports, including custom layouts, 
     137result grouping and user-defined CSS styles. To create such reports, we'll use 
     138specialized SQL statements to control the output of the Trac report engine. 
     139 
     140== Special Columns == 
     141To format reports, TracReports looks for 'magic' column names in the query 
     142result. These 'magic' names are processed and affect the layout and style of the  
     143final report. 
     144 
     145=== Automatically formatted columns === 
     146 * '''ticket''' -- Ticket ID number. Becomes a hyperlink to that ticket.  
     147 * '''created, modified, date, time''' -- Format cell as a date and/or time. 
     148 
     149 * '''description''' -- Ticket description field, parsed through the wiki engine. 
     150 
     151'''Example:''' 
     152{{{ 
     153SELECT id as ticket, created, status, summary FROM ticket  
     154}}} 
     155 
     156=== Custom formatting columns === 
     157Columns whose names begin and end with 2 underscores (Example: '''_''''''_color_''''''_''') are 
     158assumed to be ''formatting hints'', affecting the appearance of the row. 
     159  
     160 * '''_''''''_group_''''''_''' -- Group results based on values in this column. Each group will have its own header and table. 
     161 * '''_''''''_color_''''''_''' -- Should be a numeric value ranging from 1 to 5 to select a pre-defined row color. Typically used to color rows by issue priority. 
     162 * '''_''''''_style_''''''_''' -- A custom CSS style expression to use for the current row.  
     163 
     164'''Example:''' ''List active tickets, grouped by milestone, colored by priority'' 
     165{{{ 
     166SELECT p.value AS __color__, 
     167     t.milestone AS __group__, 
     168     (CASE owner WHEN 'daniel' THEN 'font-weight: bold; background: red;' ELSE '' END) AS __style__, 
     169       t.id AS ticket, summary 
     170  FROM ticket t,enum p 
     171  WHERE t.status IN ('new', 'assigned', 'reopened')  
     172    AND p.name=t.priority AND p.type='priority' 
     173  ORDER BY t.milestone, p.value, t.severity, t.time 
     174}}} 
     175 
     176'''Note:''' A table join is used to match ''ticket'' priorities with their 
     177numeric representation from the ''enum'' table. 
     178 
     179=== Changing layout of report rows === 
     180By default, all columns on each row are display on a single row in the HTML 
     181report, possibly formatted according to the descriptions above. However, it's 
     182also possible to create multi-line report entries. 
     183 
     184 * '''column_''' -- ''Break row after this''. By appending an underscore ('_') to the column name, the remaining columns will be be continued on a second line. 
     185 
     186 * '''_column_''' -- ''Full row''. By adding an underscore ('_') both at the beginning and the end of a column name, the data will be shown on a separate row. 
     187 
     188 * '''_column'''  --  ''Hide data''. Prepending an underscore ('_') to a column name instructs Trac to hide the contents from the HTML output. This is useful for information to be visible only if downloaded in other formats (like CSV or RSS/XML). 
     189 
     190'''Example:''' ''List active tickets, grouped by milestone, colored by priority, with  description and multi-line layout'' 
     191 
     192{{{ 
     193SELECT p.value AS __color__, 
     194       t.milestone AS __group__, 
     195       (CASE owner  
     196          WHEN 'daniel' THEN 'font-weight: bold; background: red;'  
     197          ELSE '' END) AS __style__, 
     198       t.id AS ticket, summary AS summary_,             -- ## Break line here 
     199       component,version, severity, milestone, status, owner, 
     200       time AS created, changetime AS modified,         -- ## Dates are formatted 
     201       description AS _description_,                    -- ## Uses a full row 
     202       changetime AS _changetime, reporter AS _reporter -- ## Hidden from HTML output 
     203  FROM ticket t,enum p 
     204  WHERE t.status IN ('new', 'assigned', 'reopened')  
     205    AND p.name=t.priority AND p.type='priority' 
     206  ORDER BY t.milestone, p.value, t.severity, t.time 
     207}}} 
     208 
     209=== Reporting on custom fields === 
     210 
     211If you have added custom fields to your tickets (experimental feature in v0.8, see TracTicketsCustomFields), you can write a SQL query to cover them. You'll need to make a join on the ticket_custom table, but this isn't especially easy. 
     212 
     213If you have tickets in the database ''before'' you declare the extra fields in trac.ini, there will be no associated data in the ticket_custom table. To get around this, use SQL's "LEFT OUTER JOIN" clauses. See TracIniReportCustomFieldSample for some examples. 
     214 
     215---- 
     216See also: TracTickets, TracQuery, TracGuide