Skip to content

Commit

Permalink
Merge pull request #11 from matsukei/v3.0.0
Browse files Browse the repository at this point in the history
Version 3.0.0
  • Loading branch information
Minoru Maeda authored Jul 22, 2020
2 parents 1a04b21 + c504863 commit f1b14aa
Show file tree
Hide file tree
Showing 14 changed files with 89 additions and 81 deletions.
17 changes: 17 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: Test

on: push

jobs:
test:
runs-on: ubuntu-latest
steps:
- name: redmine-plugin-test-action
uses: two-pack/[email protected]
with:
plugin_name: redmine_serial_number_field
redmine_version: v4.1
ruby_version: v2.6
database: postgresql
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
34 changes: 0 additions & 34 deletions .travis.yml

This file was deleted.

9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
## 3.0.0

- Added ISO format #8 (@rambowm)
- Dropped Redmine 4.0 support
- Redmine 4.1 support
- Fixed automatic serial number when copying issue
- チケットコピー時に自動採番されない #6 (@subaru019)
- [Review comments for this plugin on redmine.org](https://www.redmine.org/plugins/redmine_serial_number_field) (Jorge Garcia, Quan VN, qn wang)

## 2.0.0

- Support Redmine 4.0 (@nanego)
Expand Down
17 changes: 8 additions & 9 deletions README.en.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# Redmine Serial Number Field

[![Build Status](https://travis-ci.org/matsukei/redmine_serial_number_field.svg?branch=master)](https://travis-ci.org/matsukei/redmine_serial_number_field)

[日本語 »](https://github.com/matsukei/redmine_serial_number_field/blob/master/README.md)

Add a format to be serial number in the specified format as a issue custom field.
Expand Down Expand Up @@ -50,16 +48,17 @@ Add a format to be serial number in the specified format as a issue custom field

## Supported versions

* Redmine 4.0 (Ruby 2.2, 2.3, 2.4, 2.5, 2.6)
* Redmine 4.1 (Ruby 2.6)

## Format specifications

|Column used in year format |Year format|fiscal year(4/1 - 3/31)|Serial number format| result |
|---------------------------|-----------|-----------|--------------------|------------------------|
|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'|
|Column used in year format |Year format|fiscal year(4/1 - 3/31)|e.g. Regular expression |e.g Result (2015-03-31)|
|---------------------------|-----------|-----------------------|-------------------------|-----------------------|
|Issue#created_on |`yyyy` |No |`{yyyy}-{0000}` |`2015-0001` |
|^ |`yy` |No |`{yy}-{0000}` |`15-0001` |
|^ |`YYYY` |Yes |`{YYYY}-{0000}` |`2014-0001` |
|^ |`YY` |Yes |`{YY}-{0000}` |`14-0001` |
|^ |`ISO` |No |`{ISO}-{0000}` |`20150331-0001` |

* OK
* `{000000}` #=> `000001`
Expand Down
25 changes: 12 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# Redmine Serial Number Field

[![Build Status](https://travis-ci.org/matsukei/redmine_serial_number_field.svg?branch=master)](https://travis-ci.org/matsukei/redmine_serial_number_field)

[English »](https://github.com/matsukei/redmine_serial_number_field/blob/master/README.en.md)

Redmine に自動で連番を付加するカスタムフィールドを提供するプラグインです。
Expand All @@ -11,7 +9,7 @@ Redmine に自動で連番を付加するカスタムフィールドを提供す
* チケットに対するカスタムフィールドの書式として「自動採番」が利用可能になります。
* カスタムフィールドの新規作成後は、正規表現を編集することは、できません。
* チケットが登録できる、全てのユーザーは、自動採番の権限があります。
* 指定したフォーマットの連番を、チケット登録や更新時(一括操作も含む)に自動的に採番します。
* 指定した正規表現に基づいて、チケット登録や更新時(一括操作も含む)に自動的に採番します。
* カスタムフィールド単位での採番となります。同じカスタムフィールドを複数のプロジェクトで使用している場合は、それらのプロジェクトで連続した採番になります。
* カスタムフィールド項目は、チケットの閲覧時には表示します。しかし、登録および更新時には表示しません。
* チケットのフィルタ条件、検索対象など、カスタムフィールドの基本的なオプションも利用可能です。
Expand All @@ -31,7 +29,7 @@ Redmine に自動で連番を付加するカスタムフィールドを提供す

1. チケットの新しいカスタムフィールドを作成します。
2. 項目「書式」を自動採番に変更します。
3. 項目「正規表現」に連番フォーマットを指定します
3. 項目「正規表現」に年表記書式や連番書式を指定します
4. フィルタや検索条件として使いたい場合は、適宜チェックを入れます。
5. 自動採番をしたいトラッカーとプロジェクトを指定します。
6. 完了です。
Expand All @@ -50,24 +48,25 @@ Redmine に自動で連番を付加するカスタムフィールドを提供す

## Supported versions

* Redmine 4.0 (Ruby 2.2, 2.3, 2.4, 2.5, 2.6)
* Redmine 4.1 (Ruby 2.6)

## Format specifications

|採番対象の日付 |年表記フォーマット |年度(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'|
|採番対象の日付 |年表記書式 |年度(4/1 - 3/31) |例: 正規表現 |例: 結果(2015-03-31) |
|---------------------------|-----------|-----------------------|-------------------------|-----------------------|
|Issue#created_on |`yyyy` |No |`{yyyy}-{0000}` |`2015-0001` |
|^ |`yy` |No |`{yy}-{0000}` |`15-0001` |
|^ |`YYYY` |Yes |`{YYYY}-{0000}` |`2014-0001` |
|^ |`YY` |Yes |`{YY}-{0000}` |`14-0001` |
|^ |`ISO` |No |`{ISO}-{0000}` |`20150331-0001` |

* OK
* `{000000}` #=> `000001`
* `ABC-{yy}-{00}` #=> `ABC-15-01`
* NG
* 末尾が連番フォーマットでない場合
* 末尾が連番書式でない場合
* e.g. `ABC-{000}-{yy}`
* 年表記フォーマット、連番フォーマットでない場合
* 年表記書式、連番書式でない場合
* e.g. `{abc}-{yy}-{000}`

## Install
Expand Down
2 changes: 1 addition & 1 deletion app/patches/issue_patch.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ module IssuePatch

def assign_serial_number!
serial_number_fields.each do |cf|
next if assigned_serial_number?(cf)
next if assigned_serial_number?(cf) && !copy?

target_custom_value = serial_number_custom_value(cf)
new_serial_number = cf.format.generate_value(cf, self)
Expand Down
1 change: 1 addition & 0 deletions app/views/custom_fields/formats/_serial_number.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<em class="info">{yy}-{0000} #=> 15-0001</em>
<em class="info">{YYYY}-{0000} #=> 2014-0001</em>
<em class="info">{YY}-{0000} #=> 14-0001</em>
<em class="info">{ISO}-{0000} #=> 20150331-0001</em>
</p>

<%= f.hidden_field :is_required, :value => '0' %>
Expand Down
7 changes: 4 additions & 3 deletions app/views/issues/_remove_serial_number_field.html.erb
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
<script>
$(document).ready(function() {
$("input[class='serial_number_cf']").each(function(i, element) {
$(element).parent().remove();
document.addEventListener('DOMContentLoaded', function() {
const elements = document.querySelectorAll('input.serial_number_cf');
elements.forEach(function(element, i) {
element.parentElement.remove();
});
});
</script>
4 changes: 2 additions & 2 deletions config/locales/ja.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ ja:
activerecord:
errors:
messages:
end_must_numeric_format_in_serial_number: "の末尾は連番フォーマットでなければなりません"
invalid_format_in_serial_number: "に無効なフォーマットが含まれています"
end_must_numeric_format_in_serial_number: "の末尾は連番書式でなければなりません"
invalid_format_in_serial_number: "に無効な書式が含まれています"
4 changes: 2 additions & 2 deletions init.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
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 '2.0.0'
requires_redmine version_or_higher: '4.0'
version '3.0.0'
requires_redmine version_or_higher: '4.1'
url 'https://github.com/matsukei/redmine_serial_number_field'
author_url 'http://www.matsukei.co.jp/'
end
Expand Down
18 changes: 7 additions & 11 deletions lib/format.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,13 @@ class Format < Redmine::FieldFormat::Base
self.customized_class_names = %w(Issue)
self.form_partial = 'custom_fields/formats/serial_number'

MATCHERS = {
:TOW_DIGIT_NUMBER => /\d{2}/,
:FOUR_DIGIT_NUMBER => /\d{4}/,
:FORMAT_WRAPPER => /\{(.+?)\}/
}

FORMAT_WRAPPER = /\{(.+?)\}/
DATE_FORMATS = {
:'yyyy' => { :strftime => '%Y', :financial_year => false, :regexp => MATCHERS[:FOUR_DIGIT_NUMBER] },
:'yy' => { :strftime => '%y', :financial_year => false, :regexp => MATCHERS[:TOW_DIGIT_NUMBER] },
:'YYYY' => { :strftime => '%Y', :financial_year => true, :regexp => MATCHERS[:FOUR_DIGIT_NUMBER] },
:'YY' => { :strftime => '%y', :financial_year => true, :regexp => MATCHERS[:TOW_DIGIT_NUMBER] }
:'yyyy' => { :strftime => '%Y', :financial_year => false },
:'yy' => { :strftime => '%y', :financial_year => false },
:'YYYY' => { :strftime => '%Y', :financial_year => true },
:'YY' => { :strftime => '%y', :financial_year => true },
:'ISO' => { :strftime => '%Y%m%d', :financial_year => false }
}

def validate_custom_field(custom_field)
Expand Down Expand Up @@ -60,7 +56,7 @@ def max_custom_value(custom_field, datetime)

def replace_format_value(custom_field)
if block_given?
custom_field.regexp.gsub(MATCHERS[:FORMAT_WRAPPER]) do |format_value_with_brace|
custom_field.regexp.gsub(FORMAT_WRAPPER) do |format_value_with_brace|
# format_value_with_brace #=> e.g. '{yy}', '{0000}'
# $1.clone #=> e.g. 'yy', '0000'
yield($1.clone)
Expand Down
4 changes: 0 additions & 4 deletions test/database.travis.yml

This file was deleted.

27 changes: 25 additions & 2 deletions test/functional/issues_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ def test_get_new
end
end

def test_post_create_and_show_and_get_edit_update_with_current_created
# test_post_create
def test_post_create_and_show_and_get_edit_update_with_current_created_and_post_copy
# create
assert_difference 'Issue.count' do
assert_no_difference 'Journal.count' do
post :create, :params => {
Expand Down Expand Up @@ -100,6 +100,29 @@ def test_post_create_and_show_and_get_edit_update_with_current_created
end
assert_added_serial_number(issue.id, 'MCC-0001', @default_custom_field)
assert_added_serial_number(issue.id, 'MCC-0001', @for_all_custom_field)

# copy
assert_difference 'Issue.count' do
post :create, :params => {
:project_id => 1,
:issue => {
:tracker_id => 1,
:status_id => 2,
:subject => 'This is the test_copy issue',
:custom_field_values => {
@default_custom_field.id => 'MCC-0001'
}
},
:copy_from => issue.id,
:link_copy => 1
}
end
copied_issue = Issue.find_by_subject('This is the test_copy issue')
assert_redirected_to :controller => 'issues', :action => 'show', :id => copied_issue.id

assert_not_equal(issue.id, copied_issue.id)
assert_added_serial_number(copied_issue.id, 'MCC-0002', @default_custom_field)
assert_added_serial_number(copied_issue.id, 'MCC-0002', @for_all_custom_field)
end

def test_show_with_already_created
Expand Down
1 change: 1 addition & 0 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ def valid_regexp_values
[
'{yyyy}-{0000}', '{yy}-{0000}',
'{YYYY}-{0000}', '{YY}-{0000}',
'{ISO}-{000}',
'{0000}', '#{yyyy}-{00000}',
'OCG-{yy}-{00000}', '日本語{YYYY}-{00000}',
' {YY}-{00000}', '!{00000}'
Expand Down

0 comments on commit f1b14aa

Please sign in to comment.