Changes between Version 5 and Version 6 of TracTicketsCustomFields


Ignore:
Timestamp:
Jan 28, 2010, 4:25:37 AM (14 years ago)
Author:
trac
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • TracTicketsCustomFields

    v5 v6  
    1 = カスタムチケット属性 =
    2 Trac ではチケットにユーザ定義の属性を追加できます。カスタムチケット属性を使用すると、定型で、プロジェクト特有のプロパティをチケットに持たせることができます。
     1= Custom Ticket Fields =
     2Trac supports adding custom, user-defined fields to the ticket module. Using custom fields, you can add typed, site-specific properties to tickets.
    33
    4 == 設定方法 ==
    5 カスタムチケット属性を設定するためには、 [wiki:TracIni trac.ini] ファイルを変更します。カスタムフィールドは、 trac.ini ファイルの `[ticket-custom]` セクションに書く必要があります。
     4== Configuration ==
     5Configuring custom ticket fields is done in the [wiki:TracIni trac.ini] file. All field definitions should be under a section named `[ticket-custom]`.
    66
    7 各属性の定義は以下のように記述します:
     7The syntax of each field definition is:
    88{{{
    9  属性名 = タイプ
    10  (属性名.オプション = 値)
     9 FIELD_NAME = TYPE
     10 (FIELD_NAME.OPTION = VALUE)
    1111 ...
    1212}}}
    13 構文の詳細は以下の例を見てください。
     13The example below should help to explain the syntax.
    1414
    15 === 属性のタイプとオプション ===
    16  * '''text''': シンプルな(1行の)テキスト。
    17    * label: 説明となるラベル
    18    * value: デフォルト値
    19    * order: ソート時の並び順 (フォーム内での相対的位置を決定します。)
    20  * '''checkbox''': ブーリアン値をもつチェックボックス。
    21    * label: 説明となるラベル。
    22    * value: デフォルト値 (0 または 1).
    23    * order: ソート時の並び順
    24  * '''select''': ドロップダウンするリストボックス。
    25    * label: 説明となるラベル。
    26    * options: リストに表示する値を '''|''' (vertical pipe) 区切りで記述。
    27    * value: デフォルト値 (0から始まるリスト内での番号) 。
    28    * order: ソート時の並び順
    29  * '''radio''': ラジオボタン。 HTML の '''select''' 要素と同じ。
    30    * label: 説明となるラベル。
    31    * options: リストに表示する値を '''|''' (vertical pipe) 区切りで記述。
    32    * value: デフォルト値 (0から始まるリスト内での番号) 。
    33    * order: ソート時の並び順
    34  * '''textarea''': 複数行のテキストエリア。
    35    * label: 説明となるラベル。
    36    * value: デフォルトで設定されるテキスト。
    37    * cols: 入力領域のカラム幅。
    38    * rows: 入力領域の行数。
    39    * order: ソート時の並び順
     15=== Available Field Types and Options ===
     16 * '''text''': A simple (one line) text field.
     17   * label: Descriptive label.
     18   * value: Default value.
     19   * order: Sort order placement. (Determines relative placement in forms with respect to other custom fields.)
     20 * '''checkbox''': A boolean value check box.
     21   * label: Descriptive label.
     22   * value: Default value (0 or 1).
     23   * order: Sort order placement.
     24 * '''select''': Drop-down select box. Uses a list of values.
     25   * label: Descriptive label.
     26   * options: List of values, separated by '''|''' (vertical pipe).
     27   * value: Default value (one of the values from options).
     28   * order: Sort order placement.
     29 * '''radio''': Radio buttons. Essentially the same as '''select'''.
     30   * label: Descriptive label.
     31   * options: List of values, separated by '''|''' (vertical pipe).
     32   * value: Default value (one of the values from options).
     33   * order: Sort order placement.
     34 * '''textarea''': Multi-line text area.
     35   * label: Descriptive label.
     36   * value: Default text.
     37   * cols: Width in columns.
     38   * rows: Height in lines.
     39   * order: Sort order placement.
    4040
    41 === サンプル ===
     41=== Sample Config ===
    4242{{{
    4343[ticket-custom]
     
    5757test_four.label = My selectbox
    5858test_four.options = one|two|third option|four
    59 test_four.value = 2
     59test_four.value = two
    6060
    6161test_five = radio
    6262test_five.label = Radio buttons are fun
    6363test_five.options = uno|dos|tres|cuatro|cinco
    64 test_five.value = 1
     64test_five.value = dos
    6565
    6666test_six = textarea
     
    7171}}}
    7272
    73 ''Note: `select` タイプのフィールドを非必須 (optional) にしたい場合、 `フィールド名.options` オプションの先頭に `バーティカルパイプ (|)` を設定してください。''
     73''Note: To make entering an option for a `select` type field optional, specify a leading `|` in the `fieldname.options` option.''
    7474
    75 === カスタム属性を含むレポート ===
     75=== Reports Involving Custom Fields ===
    7676
    77 カスタム属性を含む TracReports では比較的 SQL を間違えやすいです。 `ticket_custom` 表の `JOIN` はカスタム属性ごとにそれぞれ必要です。
     77Custom 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`.
    7878
    79 以下の例は `progress` という名前のカスタム属性を含むレポートです:
     79{{{
     80#!sql
     81SELECT p.value AS __color__,
     82   id AS ticket, summary, owner, c.value AS progress
     83  FROM ticket t, enum p, ticket_custom c
     84  WHERE status IN ('assigned') AND t.id = c.ticket AND c.name = 'progress'
     85AND p.name = t.priority AND p.type = 'priority'
     86  ORDER BY p.value
     87}}}
     88'''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.
     89
     90However, 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.
    8091{{{
    8192#!sql
     
    94105}}}
    95106
    96 この `LEFT OUTER JOIN` ステートメントに特に注意してください。
     107Note in particular the `LEFT OUTER JOIN` statement here.
     108
     109=== Updating the database ===
     110
     111As 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:
     112
     113{{{
     114#!sql
     115INSERT INTO ticket_custom
     116   (ticket, name, value)
     117   SELECT
     118      id AS ticket,
     119      'request_source' AS name,
     120      'None' AS value
     121   FROM ticket
     122   WHERE id NOT IN (
     123      SELECT ticket FROM ticket_custom
     124   );
     125}}}
     126
     127If 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:
     128
     129{{{
     130#!sql
     131INSERT INTO ticket_custom
     132   (ticket, name, value)
     133   SELECT
     134      id AS ticket,
     135      'request_source' AS name,
     136      'None' AS value
     137   FROM ticket
     138   WHERE id NOT IN (
     139      SELECT ticket FROM ticket_custom WHERE name = 'request_source'
     140   );
     141}}}
    97142
    98143----