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