Skip to content

Commit b50a4a5

Browse files
committed
custom fields by name
1 parent d0db4f0 commit b50a4a5

File tree

1 file changed

+16
-12
lines changed

1 file changed

+16
-12
lines changed

lib/redmine_gtt_print/issue_to_json.rb

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@ module RedmineGttPrint
44
# server.
55
#
66
class IssueToJson
7-
def initialize(issue, layout, other_attributes = {})
7+
def initialize(issue, layout, other_attributes = {}, custom_fields = {})
88
@issue = issue
99
@layout = layout
10+
@custom_fields = custom_fields
1011
@other_attributes = other_attributes
1112
end
1213

@@ -15,9 +16,14 @@ def self.call(*_)
1516
end
1617

1718
def call
19+
# makes custom fields accessible by name
20+
@issue.visible_custom_field_values.each do |cfv|
21+
@custom_fields.store(cfv.custom_field.name, cfv)
22+
end
23+
1824
json = {
1925
layout: @layout,
20-
attributes: self.class.attributes_hash(@issue, @other_attributes)
26+
attributes: self.class.attributes_hash(@issue, @other_attributes, @custom_fields)
2127
}
2228

2329
if data = @issue.geodata_for_print
@@ -29,7 +35,7 @@ def call
2935

3036
# the following static helpers are used by IssuesToJson as well
3137

32-
def self.attributes_hash(issue, other_attributes)
38+
def self.attributes_hash(issue, other_attributes, custom_fields)
3339
{
3440
id: issue.id,
3541
subject: issue.subject,
@@ -56,7 +62,7 @@ def self.attributes_hash(issue, other_attributes)
5662
updated_on: issue.updated_on,
5763

5864
# Custom text
59-
custom_text: other_attributes[:custom_text]
65+
custom_text: other_attributes[:custom_text],
6066

6167
# Experimental
6268
# issue: issue,
@@ -67,14 +73,12 @@ def self.attributes_hash(issue, other_attributes)
6773
# author: (User.find issue.author_id),
6874
# assigned_to: (User.find issue.assigned_to_id),
6975

70-
# custom_fields: issue.visible_custom_field_values.map {|cfv|
71-
# {
72-
# id: cfv.custom_field.id,
73-
# name: cfv.custom_field.name,
74-
# multiple: cfv.custom_field.multiple?,
75-
# value: cfv.value
76-
# }
77-
# },
76+
cf_通報者: custom_fields["通報者"] ? custom_fields["通報者"].value : "",
77+
cf_通報手段: custom_fields["通報手段"] ? custom_fields["通報手段"].value : "",
78+
cf_通報者電話番号: custom_fields["通報者電話番号"] ? custom_fields["通報者電話番号"].value : "",
79+
cf_通報者メールアドレス: custom_fields["通報者メールアドレス"] ? custom_fields["通報者メールアドレス"].value : "",
80+
cf_現地住所: custom_fields["現地住所"] ? custom_fields["現地住所"].value : "",
81+
7882
# journals: issue.visible_journals_with_index.map{|j|
7983
# {
8084
# user: { login: j.user&.login, id: j.user&.id, name: j.user&.name },

0 commit comments

Comments
 (0)