@@ -4,9 +4,10 @@ module RedmineGttPrint
4
4
# server.
5
5
#
6
6
class IssueToJson
7
- def initialize ( issue , layout , other_attributes = { } )
7
+ def initialize ( issue , layout , other_attributes = { } , custom_fields = { } )
8
8
@issue = issue
9
9
@layout = layout
10
+ @custom_fields = custom_fields
10
11
@other_attributes = other_attributes
11
12
end
12
13
@@ -15,9 +16,14 @@ def self.call(*_)
15
16
end
16
17
17
18
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
+
18
24
json = {
19
25
layout : @layout ,
20
- attributes : self . class . attributes_hash ( @issue , @other_attributes )
26
+ attributes : self . class . attributes_hash ( @issue , @other_attributes , @custom_fields )
21
27
}
22
28
23
29
if data = @issue . geodata_for_print
@@ -29,7 +35,7 @@ def call
29
35
30
36
# the following static helpers are used by IssuesToJson as well
31
37
32
- def self . attributes_hash ( issue , other_attributes )
38
+ def self . attributes_hash ( issue , other_attributes , custom_fields )
33
39
{
34
40
id : issue . id ,
35
41
subject : issue . subject ,
@@ -56,7 +62,7 @@ def self.attributes_hash(issue, other_attributes)
56
62
updated_on : issue . updated_on ,
57
63
58
64
# Custom text
59
- custom_text : other_attributes [ :custom_text ]
65
+ custom_text : other_attributes [ :custom_text ] ,
60
66
61
67
# Experimental
62
68
# issue: issue,
@@ -67,14 +73,12 @@ def self.attributes_hash(issue, other_attributes)
67
73
# author: (User.find issue.author_id),
68
74
# assigned_to: (User.find issue.assigned_to_id),
69
75
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
+
78
82
# journals: issue.visible_journals_with_index.map{|j|
79
83
# {
80
84
# user: { login: j.user&.login, id: j.user&.id, name: j.user&.name },
0 commit comments