Changes between Version 8 and Version 9 of TracReports

Show
Ignore:
Timestamp:
01/17/08 22:31:17 (18 years ago)
Author:
trac (IP: 127.0.0.1)
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • TracReports

    v8 v9  
    1  
    21= Trac Reports = 
    32[[TracGuideToc]] 
     
    76 
    87Rather than have its own report definition format, TracReports relies on standard SQL 
    9 SELECT statements for custom report definition.  
     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 by 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.'' 
    1018 
    1119A report consists of these basic parts: 
    12  * ID -- Unique (sequential) identifier  
    13  * Title  -- Descriptive title 
    14  * Description  -- A brief description of the report, in WikiFormatting text. 
    15  * Report Body -- List of results from report query, formatted according to the methods described below. 
    16  * Footer -- Links to alternative download formats for this report. 
    17  
     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. 
    1825 
    1926== Changing Sort Order == 
     
    2330 
    2431 
    25 == Alternate Download Formats == 
    26 Aside from the default HTML view, reports can also be exported in a number of alternate formats. 
     32== Alternative Download Formats == 
     33Aside from the default HTML view, reports can also be exported in a number of alternative formats. 
    2734At the bottom of the report page, you will find a list of available data formats. Click the desired link to  
    28 download the alternate report format. 
     35download the alternative report format. 
    2936 
    3037=== Comma-delimited - CSV (Comma Separated Values) === 
    3138Export the report as plain text, each row on its own line, columns separated by a single comma (','). 
    32 '''Note:''' Column data is stripped from carriage returns, line feeds and commas to preserve structure. 
     39'''Note:''' Carriage returns, line feeds, and commas are stripped from column data to preserve the CSV structure. 
    3340 
    3441=== Tab-delimited === 
     
    3643 
    3744=== RSS - XML Content Syndication === 
    38 All reports support syndication using XML/RSS 2.0. To subscribe to a , click the the orange 'XML' icon at the bottom of the page. See TracRss for general information on RSS support in Trac. 
    39  
    40 ---- 
     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 
    4149== Creating Custom Reports == 
    4250 
     
    6169 * reporter 
    6270 * cc 
    63  * url 
    6471 * version 
    6572 * milestone 
     
    7481 
    7582'''Example:''' ''All active tickets, sorted by priority and time'' 
    76  
    77  
     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. 
    78214 
    79215----