Changes between Initial Version and Version 1 of TracReports


Ignore:
Timestamp:
Oct 11, 2005, 12:24:32 AM (17 years ago)
Author:
trac
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • TracReports

    v1 v1  
     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
     8SELECT statements for custom report definition.
     9
     10A report consists of these basic parts:
     11 * ID -- Unique (sequential) identifier
     12 * Title  -- Descriptive title
     13 * Description  -- A brief description of the report, in WikiFormatting text.
     14 * Report Body -- List of results from report query, formatted according to the methods described below.
     15 * Footer -- Links to alternative download formats for this report.
     16
     17
     18== Changing Sort Order ==
     19Simple reports - ungrouped reports to be specific - can be changed to be sorted by any column simply by clicking the column header.
     20
     21If a column header is a hyperlink (red), click the column you would like to sort by. Clicking the same header again reverses the order.
     22
     23
     24== Alternate Download Formats ==
     25Aside from the default HTML view, reports can also be exported in a number of alternate formats.
     26At the bottom of the report page, you will find a list of available data formats. Click the desired link to
     27download the alternate report format.
     28
     29=== Comma-delimited - CSV (Comma Separated Values) ===
     30Export the report as plain text, each row on its own line, columns separated by a single comma (',').
     31'''Note:''' Carriage returns, line feeds, and commas are stripped from column data to preserve the CSV structure.
     32
     33=== Tab-delimited ===
     34Like above, but uses tabs (     ) instead of comma.
     35
     36=== RSS - XML Content Syndication ===
     37All 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.
     38
     39----
     40== Creating Custom Reports ==
     41
     42''Creating a custom report requires a comfortable knowledge of SQL.''
     43
     44A report is basically a single named SQL query, executed and presented by
     45Trac.  Reports can be viewed and created from a custom SQL expression directly
     46in from the web interface.
     47
     48Typically, a report consists of a SELECT-expression from the 'ticket' table,
     49using the available columns and sorting the way you want it.
     50
     51== Ticket columns ==
     52The ''ticket'' table has the following columns:
     53 * id
     54 * time
     55 * changetime
     56 * component
     57 * severity 
     58 * priority
     59 * owner
     60 * reporter
     61 * cc
     62 * url
     63 * version
     64 * milestone
     65 * status
     66 * resolution
     67 * summary
     68 * description
     69
     70See TracTickets for a detailed description of the column fields.
     71
     72'''all active tickets, sorted by priority and time'''
     73
     74'''Example:''' ''All active tickets, sorted by priority and time''
     75{{{
     76SELECT id AS ticket, status, severity, priority, owner,
     77       time as created, summary FROM ticket
     78  WHERE status IN ('new', 'assigned', 'reopened')
     79  ORDER BY priority, time
     80}}}
     81
     82
     83----
     84
     85
     86== Advanced Reports: Dynamic Variables ==
     87For more flexible reports, Trac supports the use of ''dynamic variables'' in report SQL statements.
     88In short, dynamic variables are ''special'' strings that are replaced by custom data before query execution.
     89
     90=== Using Variables in a Query ===
     91The syntax for dynamic variables is simple, any upper case word beginning with '$' is considered a variable.
     92
     93Example:
     94{{{
     95SELECT id AS ticket,summary FROM ticket WHERE priority='$PRIORITY'
     96}}}
     97
     98To 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 '$'.
     99
     100Example:
     101{{{
     102 http://projects.edgewall.com/trac/reports/14?PRIORITY=high
     103}}}
     104
     105To use multiple variables, separate them with an '&'.
     106
     107Example:
     108{{{
     109 http://projects.edgewall.com/trac/reports/14?PRIORITY=high&SEVERITY=critical
     110}}}
     111
     112
     113=== Special/Constant Variables ===
     114There is one ''magic'' dynamic variable to allow practical reports, its value automatically set without having to change the URL.
     115
     116 * $USER -- Username of logged in user.
     117
     118Example (''List all tickets assigned to me''):
     119{{{
     120SELECT id AS ticket,summary FROM ticket WHERE owner='$USER'
     121}}}
     122
     123
     124----
     125
     126
     127== Advanced Reports: Custom Formatting ==
     128Trac is also capable of more advanced reports, including custom layouts,
     129result grouping and user-defined CSS styles. To create such reports, we'll use
     130specialized SQL statements to control the output of the Trac report engine.
     131
     132== Special Columns ==
     133To format reports, TracReports looks for 'magic' column names in the query
     134result. These 'magic' names are processed and affect the layout and style of the
     135final report.
     136
     137=== Automatically formatted columns ===
     138 * '''ticket''' -- Ticket ID number. Becomes a hyperlink to that ticket.
     139 * '''created, modified, date, time''' -- Format cell as a date and/or time.
     140
     141 * '''description''' -- Ticket description field, parsed through the wiki engine.
     142
     143'''Example:'''
     144{{{
     145SELECT id as ticket, created, status, summary FROM ticket
     146}}}
     147
     148=== Custom formatting columns ===
     149Columns whose names begin and end with 2 underscores (Example: '''_''''''_color_''''''_''') are
     150assumed to be ''formatting hints'', affecting the appearance of the row.
     151 
     152 * '''_''''''_group_''''''_''' -- Group results based on values in this column. Each group will have its own header and table.
     153 * '''_''''''_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.
     154 * '''_''''''_style_''''''_''' -- A custom CSS style expression to use for the current row.
     155
     156'''Example:''' ''List active tickets, grouped by milestone, colored by priority''
     157{{{
     158SELECT p.value AS __color__,
     159     t.milestone AS __group__,
     160     (CASE owner WHEN 'daniel' THEN 'font-weight: bold; background: red;' ELSE '' END) AS __style__,
     161       t.id AS ticket, summary
     162  FROM ticket t,enum p
     163  WHERE t.status IN ('new', 'assigned', 'reopened')
     164    AND p.name=t.priority AND p.type='priority'
     165  ORDER BY t.milestone, p.value, t.severity, t.time
     166}}}
     167
     168'''Note:''' A table join is used to match ''ticket'' priorities with their
     169numeric representation from the ''enum'' table.
     170
     171=== Changing layout of report rows ===
     172By default, all columns on each row are display on a single row in the HTML
     173report, possibly formatted according to the descriptions above. However, it's
     174also possible to create multi-line report entries.
     175
     176 * '''column_''' -- ''Break row after this''. By appending an underscore ('_') to the column name, the remaining columns will be be continued on a second line.
     177
     178 * '''_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.
     179
     180 * '''_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).
     181
     182'''Example:''' ''List active tickets, grouped by milestone, colored by priority, with  description and multi-line layout''
     183
     184{{{
     185SELECT p.value AS __color__,
     186       t.milestone AS __group__,
     187       (CASE owner
     188          WHEN 'daniel' THEN 'font-weight: bold; background: red;'
     189          ELSE '' END) AS __style__,
     190       t.id AS ticket, summary AS summary_,             -- ## Break line here
     191       component,version, severity, milestone, status, owner,
     192       time AS created, changetime AS modified,         -- ## Dates are formatted
     193       description AS _description_,                    -- ## Uses a full row
     194       changetime AS _changetime, reporter AS _reporter -- ## Hidden from HTML output
     195  FROM ticket t,enum p
     196  WHERE t.status IN ('new', 'assigned', 'reopened')
     197    AND p.name=t.priority AND p.type='priority'
     198  ORDER BY t.milestone, p.value, t.severity, t.time
     199}}}
     200
     201=== Reporting on custom fields ===
     202
     203If 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.
     204
     205If 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.
     206
     207----
     208See also: TracTickets, TracQuery, TracGuide