Changes between Version 1 and Version 2 of TracTicketsCustomFields
- Timestamp:
- Apr 23, 2014 1:23:13 PM (11 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
TracTicketsCustomFields
v1 v2 17 17 * label: Descriptive label. 18 18 * value: Default value. 19 * order: Sort order placement. (Determines relative placement in forms.) 19 * order: Sort order placement. (Determines relative placement in forms with respect to other custom fields.) 20 * format: One of: 21 * `plain` for plain text 22 * `wiki` to interpret the content as WikiFormatting (''since 0.11.3'') 23 * `reference` to treat the content as a queryable value (''since 1.0'') 24 * `list` to interpret the content as a list of queryable values, separated by whitespace (''since 1.0'') 20 25 * '''checkbox''': A boolean value check box. 21 26 * label: Descriptive label. … … 23 28 * order: Sort order placement. 24 29 * '''select''': Drop-down select box. Uses a list of values. 30 * label: Descriptive label. 25 31 * options: List of values, separated by '''|''' (vertical pipe). 26 * value: Default value ( Item #, starting at 0).32 * value: Default value (one of the values from options). 27 33 * order: Sort order placement. 28 34 * '''radio''': Radio buttons. Essentially the same as '''select'''. 29 35 * label: Descriptive label. 30 36 * options: List of values, separated by '''|''' (vertical pipe). 31 * value: Default value ( Item #, starting at 0).37 * value: Default value (one of the values from options). 32 38 * order: Sort order placement. 33 39 * '''textarea''': Multi-line text area. … … 37 43 * rows: Height in lines. 38 44 * order: Sort order placement. 45 * format: Either `plain` for plain text or `wiki` to interpret the content as WikiFormatting. (''since 0.11.3'') 39 46 40 47 === Sample Config === … … 47 54 test_two = text 48 55 test_two.label = Another text-box 49 test_two.value = Just a default value 56 test_two.value = Default [mailto:joe@nospam.com owner] 57 test_two.format = wiki 50 58 51 59 test_three = checkbox … … 56 64 test_four.label = My selectbox 57 65 test_four.options = one|two|third option|four 58 test_four.value = 266 test_four.value = two 59 67 60 68 test_five = radio 61 69 test_five.label = Radio buttons are fun 62 70 test_five.options = uno|dos|tres|cuatro|cinco 63 test_five.value = 171 test_five.value = dos 64 72 65 73 test_six = textarea … … 70 78 }}} 71 79 72 ''Note: To make anentering an option for a `select` type field optional, specify a leading `|` in the `fieldname.options` option.''80 ''Note: To make entering an option for a `select` type field optional, specify a leading `|` in the `fieldname.options` option.'' 73 81 74 82 === Reports Involving Custom Fields === 75 83 76 The SQL required for TracReports to include custom ticket fields is relatively hard to get right. You need a `JOIN` with the `ticket_custom` field for every custom field that should be involved.84 Custom ticket fields are stored in the `ticket_custom` table, not in the `ticket` table. So to display the values from custom fields in a report, you will need a join on the 2 tables. Let's use an example with a custom ticket field called `progress`. 77 85 78 The following example includes a custom ticket field named `progress` in the report: 86 {{{ 87 #!sql 88 SELECT p.value AS __color__, 89 id AS ticket, summary, owner, c.value AS progress 90 FROM ticket t, enum p, ticket_custom c 91 WHERE status IN ('assigned') AND t.id = c.ticket AND c.name = 'progress' 92 AND p.name = t.priority AND p.type = 'priority' 93 ORDER BY p.value 94 }}} 95 '''Note''' that this will only show tickets that have progress set in them, which is '''not the same as showing all tickets'''. If you created this custom ticket field ''after'' you have already created some tickets, they will not have that field defined, and thus they will never show up on this ticket query. If you go back and modify those tickets, the field will be defined, and they will appear in the query. If that's all you want, you're set. 96 97 However, if you want to show all ticket entries (with progress defined and without), you need to use a `JOIN` for every custom field that is in the query. 79 98 {{{ 80 99 #!sql … … 95 114 Note in particular the `LEFT OUTER JOIN` statement here. 96 115 116 === Updating the database === 117 118 As noted above, any tickets created before a custom field has been defined will not have a value for that field. Here's a bit of SQL (tested with SQLite) that you can run directly on the Trac database to set an initial value for custom ticket fields. Inserts the default value of 'None' into a custom field called 'request_source' for all tickets that have no existing value: 119 120 {{{ 121 #!sql 122 INSERT INTO ticket_custom 123 (ticket, name, value) 124 SELECT 125 id AS ticket, 126 'request_source' AS name, 127 'None' AS value 128 FROM ticket 129 WHERE id NOT IN ( 130 SELECT ticket FROM ticket_custom 131 ); 132 }}} 133 134 If you added multiple custom fields at different points in time, you should be more specific in the subquery on table {{{ticket}}} by adding the exact custom field name to the query: 135 136 {{{ 137 #!sql 138 INSERT INTO ticket_custom 139 (ticket, name, value) 140 SELECT 141 id AS ticket, 142 'request_source' AS name, 143 'None' AS value 144 FROM ticket 145 WHERE id NOT IN ( 146 SELECT ticket FROM ticket_custom WHERE name = 'request_source' 147 ); 148 }}} 149 97 150 ---- 98 151 See also: TracTickets, TracIni