Skip to content

Commit

Permalink
Changed the numbering target #4, #5
Browse files Browse the repository at this point in the history
From project unit, serial number in custom field unit.
  • Loading branch information
maeda-m committed Jun 14, 2017
1 parent 4b0a6e4 commit 2ae7fa6
Show file tree
Hide file tree
Showing 9 changed files with 149 additions and 57 deletions.
26 changes: 17 additions & 9 deletions README.en.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,17 @@ Add a format to be serial number in the specified format as a issue custom field
* "Automatic serial number" is available as a format for custom fields for issues.
* After creating a new custom field, you can not edit the "Regular expression".
* Every user who can create a issue has automatic number assignment authority.
* Automatically assign sequential numbers of specified formats on a project basis at issue registration or update.
* It works not only for single issues but also for bulk operation.
* Automatically assign serial numbers in the specified format at issue registration or update(Including bulk operations).
* Assign a serial number for each custom field. If the same custom field is used for multiple projects, It will be consecutive numbers in those projects.
* Custom field items are displayed when viewing issues. However, it will not be displayed when registering or updating.
* Basic options for custom fields are also available, such as issue filter criteria and search target.

### Notes

#### When you change tracker or project of numbered issue

* If the changed tracker does not have the same custom field, the sequential number assigned will be deleted.
* If the tracker after change has the same custom field, the sequential numbers numbered will not change (there is a risk of duplication).
* If the changed tracker does not have the same custom field, the serial number assigned will be deleted.
* If the tracker after change has the same custom field, the serial numbers numbered will not change.

#### When you set permissions for custom fields in workflow

Expand All @@ -38,20 +38,28 @@ Add a format to be serial number in the specified format as a issue custom field
* If you create a new issue it will be automatically numbered.
* Issues already created will be numbered as they are updated.

## Screenshot

*Administration > Custom fields > Issues > Automatic serial number*

![usage.png](https://github.com/matsukei/redmine_serial_number_field/blob/master/doc/images/usage.en.png)

*Issues*

![issues.png](https://github.com/matsukei/redmine_serial_number_field/blob/master/doc/images/issues.png)

## Supported versions

* Redmine 3.2.x or higher

## Format specifications

|Column used in year format |Year format|fiscal year|Serial number format| result |
|Column used in year format |Year format|fiscal year(4/1 - 3/31)|Serial number format| result |
|---------------------------|-----------|-----------|--------------------|------------------------|
|created_on |`yy` |No |000 |2015-03-01 => '15001' |
|created_on |`yyyy` |No |0000 |2015-03-01 => '20150001'|
|created_on |`YY` |Yes |000 |2015-03-01 => '14001' |
|created_on |`YYYY` |Yes |0000 |2015-03-01 => '20140001'|
|Issue#created_on |`yy` |No |000 |2015-03-01 => '15001' |
|Issue#created_on |`yyyy` |No |0000 |2015-03-01 => '20150001'|
|Issue#created_on |`YY` |Yes |000 |2015-03-01 => '14001' |
|Issue#created_on |`YYYY` |Yes |0000 |2015-03-01 => '20140001'|

* OK
* `{000000}` #=> `000001`
Expand Down
26 changes: 17 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ Redmine に自動で連番を付加するカスタムフィールドを提供す
* チケットに対するカスタムフィールドの書式として「自動採番」が利用可能になります。
* カスタムフィールドの新規作成後は、正規表現を編集することは、できません。
* チケットが登録できる、全てのユーザーは、自動採番の権限があります。
* プロジェクト単位で、指定したフォーマットの連番を、チケット登録や更新時に自動的に採番します
* チケットの単体操作はもちろん、一括操作に対しても動作します
* 指定したフォーマットの連番を、チケット登録や更新時(一括操作も含む)に自動的に採番します
* カスタムフィールド単位での採番となります。同じカスタムフィールドを複数のプロジェクトで使用している場合は、それらのプロジェクトで連続した採番になります
* カスタムフィールド項目は、チケットの閲覧時には表示します。しかし、登録および更新時には表示しません。
* チケットのフィルタ条件、検索対象など、カスタムフィールドの基本的なオプションも利用可能です。

Expand All @@ -21,7 +21,7 @@ Redmine に自動で連番を付加するカスタムフィールドを提供す
#### 採番済みチケットのトラッカーやプロジェクトを変更した場合

* 変更後のトラッカーが同じカスタムフィールドを持っていない場合、採番された連番は削除されます。
* 変更後のトラッカーが同じカスタムフィールドを持っている場合、採番された連番は変化しません(重複の恐れがあります)
* 変更後のトラッカーが同じカスタムフィールドを持っている場合、採番された連番は変化しません。

#### ワークフローのカスタムフィールドに対する権限を設定した場合

Expand All @@ -38,20 +38,28 @@ Redmine に自動で連番を付加するカスタムフィールドを提供す
* 新たにチケットを作成すれば自動で採番されます。
* 既に作成されたチケットは何かしら更新すれば採番されます。

## Screenshot

*Administration > Custom fields > Issues > 自動採番*

![usage.png](https://github.com/matsukei/redmine_serial_number_field/blob/master/doc/images/usage.png)

*Issues*

![issues.png](https://github.com/matsukei/redmine_serial_number_field/blob/master/doc/images/issues.png)

## Supported versions

* Redmine 3.2.x or higher

## Format specifications

|採番対象の日付 |年表記フォーマット |年度 |連番フォーマット|結果 |
|--------------|-------------------|----------------|----------------|------------------------|
|created_on |`yy` |No |000 |2015-03-01 => '15001' |
|created_on |`yyyy` |No |0000 |2015-03-01 => '20150001'|
|created_on |`YY` |Yes |000 |2015-03-01 => '14001' |
|created_on |`YYYY` |Yes |0000 |2015-03-01 => '20140001'|
|採番対象の日付 |年表記フォーマット |年度(4/1 - 3/31)|連番フォーマット |結果 |
|----------------|-------------------|----------------|----------------|------------------------|
|Issue#created_on|`yy` |No |000 |2015-03-01 => '15001' |
|Issue#created_on|`yyyy` |No |0000 |2015-03-01 => '20150001'|
|Issue#created_on|`YY` |Yes |000 |2015-03-01 => '14001' |
|Issue#created_on|`YYYY` |Yes |0000 |2015-03-01 => '20140001'|

* OK
* `{000000}` #=> `000001`
Expand Down
Binary file added doc/images/issues.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified doc/images/usage.en.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion init.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name 'Redmine Serial Number Field'
author 'Matsukei Co.,Ltd'
description 'Add a format to be serial number in the specified format as a issue custom field.'
version '0.9.0'
version '1.0.0'
requires_redmine version_or_higher: '2.6'
url 'https://github.com/matsukei/redmine_serial_number_field'
author_url 'http://www.matsukei.co.jp/'
Expand Down
7 changes: 3 additions & 4 deletions lib/format.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def validate_custom_field(custom_field)

def generate_value(custom_field, issue)
datetime = issue.created_on.to_datetime || DateTime.now
value = max_custom_value(custom_field, issue, datetime)
value = max_custom_value(custom_field, datetime)

if value.present?
value.next
Expand All @@ -51,10 +51,9 @@ def date_format_keys
DATE_FORMATS.stringify_keys.keys
end

def max_custom_value(custom_field, issue, datetime)
def max_custom_value(custom_field, datetime)
matcher = generate_matcher(custom_field, datetime)
custom_values = custom_field.custom_values.where(
customized_id: issue.project.issues.map(&:id)).map(&:value)
custom_values = custom_field.custom_values.map(&:value)
# custom_values #=> e.g. ['2014-001', '2014-002', '14-0001', ...]
custom_values.select { |value| value =~ matcher }.sort.last
end
Expand Down
Loading

0 comments on commit 2ae7fa6

Please sign in to comment.