Changes between Version 1 and Version 2 of TracTicketsCustomFields


Ignore:
Timestamp:
08/11/15 13:16:01 (9 years ago)
Author:
trac
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • TracTicketsCustomFields

    v1 v2  
    1717   * label: Descriptive label.
    1818   * 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'')
    2025 * '''checkbox''': A boolean value check box.
    2126   * label: Descriptive label.
     
    2530   * label: Descriptive label.
    2631   * options: List of values, separated by '''|''' (vertical pipe).
    27    * value: Default value (Item #, starting at 0).
     32   * value: Default value (one of the values from options).
    2833   * order: Sort order placement.
    2934 * '''radio''': Radio buttons. Essentially the same as '''select'''.
    3035   * label: Descriptive label.
    3136   * options: List of values, separated by '''|''' (vertical pipe).
    32    * value: Default value (Item #, starting at 0).
     37   * value: Default value (one of the values from options).
    3338   * order: Sort order placement.
    3439 * '''textarea''': Multi-line text area.
    3540   * label: Descriptive label.
    3641   * value: Default text.
    37    * cols: Width in columns.
     42   * cols: Width in columns
    3843   * rows: Height in lines.
    3944   * order: Sort order placement.
     45   * format: Either `plain` for plain text or `wiki` to interpret the content as WikiFormatting. (''since 0.11.3'')
     46
     47Macros will be expanded when rendering `textarea` fields with format `wiki`, but not when rendering `text` fields with format `wiki`.
    4048
    4149=== Sample Config ===
     
    4856test_two = text
    4957test_two.label = Another text-box
    50 test_two.value = Just a default value
     58test_two.value = Default [mailto:joe@nospam.com owner]
     59test_two.format = wiki
    5160
    5261test_three = checkbox
     
    5766test_four.label = My selectbox
    5867test_four.options = one|two|third option|four
    59 test_four.value = 2
     68test_four.value = two
    6069
    6170test_five = radio
    6271test_five.label = Radio buttons are fun
    6372test_five.options = uno|dos|tres|cuatro|cinco
    64 test_five.value = 1
     73test_five.value = dos
    6574
    6675test_six = textarea
     
    7584=== Reports Involving Custom Fields ===
    7685
    77 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.
     86Custom 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`.
    7887
    79 The following example includes a custom ticket field named `progress` in the report:
     88{{{
     89#!sql
     90SELECT p.value AS __color__,
     91   id AS ticket, summary, owner, c.value AS progress
     92  FROM ticket t, enum p, ticket_custom c
     93  WHERE status IN ('assigned') AND t.id = c.ticket AND c.name = 'progress'
     94AND p.name = t.priority AND p.type = 'priority'
     95  ORDER BY p.value
     96}}}
     97'''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.
     98
     99However, 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.
    80100{{{
    81101#!sql
     
    96116Note in particular the `LEFT OUTER JOIN` statement here.
    97117
     118Note that if your config file uses an uppercase name, e.g.,
     119{{{
     120[ticket-custom]
     121
     122Progress_Type = text
     123}}}
     124you would use lowercase in the SQL:  `AND c.name = 'progress_type'`
     125
     126=== Updating the database ===
     127
     128As 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:
     129
     130{{{
     131#!sql
     132INSERT INTO ticket_custom
     133   (ticket, name, value)
     134   SELECT
     135      id AS ticket,
     136      'request_source' AS name,
     137      'None' AS value
     138   FROM ticket
     139   WHERE id NOT IN (
     140      SELECT ticket FROM ticket_custom
     141   );
     142}}}
     143
     144If 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:
     145
     146{{{
     147#!sql
     148INSERT INTO ticket_custom
     149   (ticket, name, value)
     150   SELECT
     151      id AS ticket,
     152      'request_source' AS name,
     153      'None' AS value
     154   FROM ticket
     155   WHERE id NOT IN (
     156      SELECT ticket FROM ticket_custom WHERE name = 'request_source'
     157   );
     158}}}
     159
    98160----
    99161See also: TracTickets, TracIni