Changes between Version 3 and Version 4 of TracTicketsCustomFields


Ignore:
Timestamp:
Dec 30, 2016, 2:54:47 AM (7 years ago)
Author:
trac
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • TracTicketsCustomFields

    v3 v4  
    1 = カスタムチケット属性 = #CustomTicketFields
    2 Trac ではチケットにユーザ定義の属性を追加できます。カスタムチケット属性を使用すると、型付けされた、プロジェクト特有のプロパティをチケットに持たせることができます。
     1= Custom Ticket Fields
     2Trac supports adding custom, user-defined fields to the ticket module. With custom fields you can add typed, site-specific properties to tickets.
    33
    4 == 設定方法 == #Configuration
    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 === 属性のタイプとオプション === #AvailableFieldTypesandOptions
    16   * '''text''': シンプルな(1行の)テキスト
    17    * label: 説明となるラベル
    18    * value: デフォルト値
    19    * order: ソート時の並び順 (全てのカスタムフィールドで共通するソートの並び順)
    20    * format:
    21      * 通常のテキストを指す `plain`
    22      * WikiFormatting として整形を行う `wiki` (''0.11.3 以降'')
    23      * 参照可能な値として整形を行う `reference` (''1.0 以降'')
    24      * スペースで区切られた参照可能なリストとして整形を行う `list` のいずれかを指定する(''1.0 以降'')
    25  * '''checkbox''': ブーリアン値をもつチェックボックス
    26    * label: 説明となるラベル
    27    * value: デフォルト値 (0 または 1)
    28    * order: ソート時の並び順
    29  * '''select''': ドロップダウンするリストボックス
    30    * label: 説明となるラベル
    31    * options: リストに表示する値を '''|''' (vertical pipe) 区切りで記述
    32    * value: デフォルト値 (options の値から一つを指定)
    33    * order: ソート時の並び順
    34  * '''radio''': ラジオボタン。 HTML の '''select''' 要素と同じ
    35    * label: 説明となるラベル
    36    * options: リストに表示する値を '''|''' (vertical pipe) 区切りで記述
    37    * value: デフォルト値 (options の値から一つを指定)
    38    * order: ソート時の並び順
    39  * '''textarea''': 複数行のテキストエリア
    40    * label: 説明となるラベル
    41    * value: デフォルトで設定されるテキスト
    42    * cols: 入力領域のカラム幅
    43    * rows: 入力領域の行数
    44    * order: ソート時の並び順
    45    * format: 通常のテキストを指す `plain` もしくは WikiFormatting として整形を行う `wiki` のいずれかを指定する (''0.11.3 以降'')
     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; this 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
     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'')
     25 * '''checkbox''': A boolean value check box.
     26   * label: Descriptive label.
     27   * value: Default value, 0 or 1.
     28   * order: Sort order placement.
     29 * '''select''': Drop-down select box. Uses a list of values.
     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 * '''radio''': Radio buttons. Essentially the same as '''select'''.
     35   * label: Descriptive label.
     36   * options: List of values, separated by '''|''' (vertical pipe).
     37   * value: Default value, one of the values from options.
     38   * order: Sort order placement.
     39 * '''textarea''': Multi-line text area.
     40   * label: Descriptive label.
     41   * value: Default text.
     42   * cols: Width in columns. //(Removed in 1.1.2)//
     43   * rows: Height in lines.
     44   * order: Sort order placement.
     45   * format: Either `plain` for plain text or `wiki` to interpret the content as WikiFormatting.
     46 * '''time''': Date and time picker. (''Since 1.1.1.'')
     47   * label: Descriptive label.
     48   * value: Default date.
     49   * order: Sort order placement.
     50   * format: One of:
     51     * `relative` for relative dates.
     52     * `date` for absolute dates.
     53     * `datetime` for absolute date and time values.
    4654
    47 === サンプル === #SampleConfig
     55If the `label` is not specified, it will be created by capitalizing the custom field name and replacing underscores with whitespaces.
     56
     57Macros will be expanded when rendering `textarea` fields with format `wiki`, but not when rendering `text` fields with format `wiki`.
     58
     59=== Sample Config
    4860{{{
    4961[ticket-custom]
     
    7688test_six.cols = 60
    7789test_six.rows = 30
     90
     91test_seven = time
     92test_seven.label = A relative date
     93test_seven.format = relative
     94test_seven.value = now
     95
     96test_eight = time
     97test_eight.label = An absolute date
     98test_eight.format = date
     99test_eight.value = yesterday
     100
     101test_nine = time
     102test_nine.label = A date and time
     103test_nine.format = datetime
     104test_nine.value = in 2 hours
    78105}}}
    79106
    80 ''Note: `select` タイプのフィールドを非必須 (optional) にしたい場合、 `フィールド名.options` オプションの先頭に `バーティカルパイプ (|)` を設定してください。''
     107'''Note''': To make a `select` type field optional, specify a leading `|` in the `fieldname.options` option.
    81108
    82 === カスタム属性を含むレポート === #ReportsInvolvingCustomFields
     109=== Reports Involving Custom Fields
    83110
    84 カスタムチケット属性は `ticket` テーブルに保存されるのではなく、 `ticket_custom` テーブルに保存されます。したがって、レポートのカスタム属性を表示するためには `ticket` と `ticket_custom` の 2 テーブルを join する必要があります。 `progress` と設定されたカスタムチケット属性の使用例を示します。
     111Custom 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`.
    85112
    86113{{{
     
    93120  ORDER BY p.value
    94121}}}
    95 '''Note''' この例は progress が設定されたチケットだけを表示します。'''すべてのチケットを表示するのではありません。'''既にいくつかのチケットを作成した''後で''カスタムチケット属性を定義した場合、既に作成されたチケットにはカスタムチケット属性が定義されません。そのため上記のクエリではチケットが表示されないでしょう。既に作成されたチケットにカスタム属性を設定し直せば、カスタムチケット属性は定義されます。そして、上記のクエリによって表示されるでしょう。
     122'''Note''': This will only show tickets that have progress set in them. This 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.
    96123
    97 しかし、すべてのチケットエントリを ( progress が定義されていないエントリーも一緒に ) 表示したいのであれば、クエリにおいてあらゆるカスタムフィールドに `JOIN` を使用する必要があります。
     124However, 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:
    98125{{{
    99126#!sql
     
    112139}}}
    113140
    114 この `LEFT OUTER JOIN` ステートメントに特に注意してください。
     141Note in particular the `LEFT OUTER JOIN` statement here.
    115142
    116 === データベースを更新する === #Updatingthedatabase
     143Note that if your config file uses an uppercase name, e.g.,
     144{{{
     145[ticket-custom]
    117146
    118 上記に記述したとおり、カスタムフィールド設定以前に作成されたチケットには、該当するフィールドの値が定義されていない状態になります。以下のような SQL を Trac のデータベースで直接実行することで、カスタムフィールドの初期値を設定することができます (SQLite 向けの SQL ですので、 DBMS に応じて調整してください)。カスタムフィールド 'request_source' が存在しない、全てのチケットにデフォルト値 'None' が挿入されます:
     147Progress_Type = text
     148}}}
     149you would use lowercase in the SQL: `AND c.name = 'progress_type'`
     150
     151=== Updating the database
     152
     153As 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:
    119154
    120155{{{
     
    122157INSERT INTO ticket_custom
    123158   (ticket, name, value)
    124    SELECT
     159   SELECT 
    125160      id AS ticket,
    126161      'request_source' AS name,
    127162      'None' AS value
    128    FROM ticket
     163   FROM ticket 
    129164   WHERE id NOT IN (
    130165      SELECT ticket FROM ticket_custom
     
    132167}}}
    133168
    134 複数のカスタムフィールドを追加している場合、 {{{ticket}}} 表への副問合わせで対象となるカスタムフィールドの名前を指定しなければなりません (訳注: 通常は上記の例ではなく、こちらを使うといいでしょう):
     169If 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:
    135170
    136171{{{
     
    138173INSERT INTO ticket_custom
    139174   (ticket, name, value)
    140    SELECT
     175   SELECT 
    141176      id AS ticket,
    142177      'request_source' AS name,
    143178      'None' AS value
    144    FROM ticket
     179   FROM ticket 
    145180   WHERE id NOT IN (
    146181      SELECT ticket FROM ticket_custom WHERE name = 'request_source'