Skip to content

Commit 2c6568e

Browse files
committed
add all customfields and their values to the attributes hash. #9
1 parent c9ff3ca commit 2c6568e

File tree

2 files changed

+10
-9
lines changed

2 files changed

+10
-9
lines changed

lib/redmine_gtt_print/issue_to_json.rb

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,9 @@ def image_urls(issue)
6464
def self.attributes_hash(issue, other_attributes, image_urls)
6565
custom_fields = issue_custom_fields_by_name issue
6666

67-
{
67+
68+
69+
result = {
6870
id: issue.id,
6971
subject: issue.subject,
7072
project_id: issue.project_id,
@@ -93,13 +95,6 @@ def self.attributes_hash(issue, other_attributes, image_urls)
9395
# Custom text
9496
custom_text: other_attributes[:custom_text],
9597

96-
# Custom fields fbased on names
97-
cf_通報者: custom_fields["通報者"] || "",
98-
cf_通報手段: custom_fields["通報手段"] || "",
99-
cf_通報者電話番号: custom_fields["通報者電話番号"] || "",
100-
cf_通報者メールアドレス: custom_fields["通報者メールアドレス"] || "",
101-
cf_現地住所: custom_fields["現地住所"] || "",
102-
10398
# Image attachments (max. 4 iamges)
10499
image_url_1: image_urls[0] || "../#{RedmineGttPrint.tracker_config(issue.tracker)}/blank.png",
105100
image_url_2: image_urls[1] || "../#{RedmineGttPrint.tracker_config(issue.tracker)}/blank.png",
@@ -141,6 +136,10 @@ def self.attributes_hash(issue, other_attributes, image_urls)
141136
# }
142137
# }
143138
}
139+
140+
custom_fields.each{|name, value| result["cf_#{name}"] = value || ""}
141+
142+
result
144143
end
145144

146145
def self.issue_custom_fields_by_name(issue)

test/unit/issue_to_json_test.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,16 @@ class IssueToJsonTest < ActiveSupport::TestCase
1919

2020
setup do
2121
@issue = Issue.find 1
22-
@issue.update_attribute :geojson, test_geojson
22+
@issue.update_attributes geojson: test_geojson,
23+
custom_field_values: { '1' => 'MySQL' }
2324
end
2425

2526
test 'should build mapfish json' do
2627
assert j = RedmineGttPrint::IssueToJson.(@issue, 'das layout')
2728
assert h = JSON.parse(j)
2829
assert_equal 'das layout', h['layout']
2930
assert_equal @issue.subject, h['attributes']['subject']
31+
assert_equal 'MySQL', h['attributes']['cf_Database']
3032
assert map = h['attributes']['map']
3133
assert_equal 2, map['center'].size
3234
assert geo = map['layers'][0]['geoJson']

0 commit comments

Comments
 (0)