@@ -4,9 +4,10 @@ module RedmineGttPrint
4
4
# server.
5
5
#
6
6
class IssueToJson
7
- def initialize ( issue , layout , other_attributes = { } , custom_fields = { } )
7
+ def initialize ( issue , layout , other_attributes = { } , custom_fields = { } , attachments = [ ] )
8
8
@issue = issue
9
9
@layout = layout
10
+ @attachments = attachments
10
11
@custom_fields = custom_fields
11
12
@other_attributes = other_attributes
12
13
end
@@ -21,21 +22,31 @@ def call
21
22
@custom_fields . store ( cfv . custom_field . name , cfv )
22
23
end
23
24
25
+ # collects image attachment URL's
26
+ @issue . attachments . each do |a |
27
+ if a . image?
28
+ # TODO: url construction doesn't look safe
29
+ @attachments << "#{ Setting . protocol } ://#{ Setting . host_name } /attachments/download/#{ a . id } /#{ a . filename } "
30
+ end
31
+ end
32
+
24
33
json = {
25
34
layout : @layout ,
26
- attributes : self . class . attributes_hash ( @issue , @other_attributes , @custom_fields )
35
+ attributes : self . class . attributes_hash ( @issue , @other_attributes , @custom_fields , @attachments )
27
36
}
28
37
29
38
if data = @issue . geodata_for_print
30
39
json [ :attributes ] [ :map ] = self . class . map_data ( data [ :center ] , [ data [ :geojson ] ] )
31
40
end
32
41
42
+ pp json
43
+
33
44
json . to_json
34
45
end
35
46
36
47
# the following static helpers are used by IssuesToJson as well
37
48
38
- def self . attributes_hash ( issue , other_attributes , custom_fields )
49
+ def self . attributes_hash ( issue , other_attributes , custom_fields , attachments )
39
50
{
40
51
id : issue . id ,
41
52
subject : issue . subject ,
@@ -65,6 +76,19 @@ def self.attributes_hash(issue, other_attributes, custom_fields)
65
76
# Custom text
66
77
custom_text : other_attributes [ :custom_text ] ,
67
78
79
+ # Custom fields fbased on names
80
+ cf_通報者 : custom_fields [ "通報者" ] ? custom_fields [ "通報者" ] . value : "" ,
81
+ cf_通報手段 : custom_fields [ "通報手段" ] ? custom_fields [ "通報手段" ] . value : "" ,
82
+ cf_通報者電話番号 : custom_fields [ "通報者電話番号" ] ? custom_fields [ "通報者電話番号" ] . value : "" ,
83
+ cf_通報者メールアドレス : custom_fields [ "通報者メールアドレス" ] ? custom_fields [ "通報者メールアドレス" ] . value : "" ,
84
+ cf_現地住所 : custom_fields [ "現地住所" ] ? custom_fields [ "現地住所" ] . value : "" ,
85
+
86
+ # Image attachments (max. 4 iamges)
87
+ image_url_1 : attachments . at ( 0 ) ? attachments . at ( 0 ) : "" ,
88
+ image_url_2 : attachments . at ( 1 ) ? attachments . at ( 1 ) : "" ,
89
+ image_url_3 : attachments . at ( 2 ) ? attachments . at ( 2 ) : "" ,
90
+ image_url_4 : attachments . at ( 3 ) ? attachments . at ( 3 ) : "" ,
91
+
68
92
# Experimental
69
93
# issue: issue,
70
94
# project: (Project.find issue.project_id),
@@ -74,12 +98,6 @@ def self.attributes_hash(issue, other_attributes, custom_fields)
74
98
# author: (User.find issue.author_id),
75
99
# assigned_to: (User.find issue.assigned_to_id),
76
100
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
- cf_現地住所 : custom_fields [ "現地住所" ] ? custom_fields [ "現地住所" ] . value : "" ,
82
-
83
101
# journals: issue.visible_journals_with_index.map{|j|
84
102
# {
85
103
# user: { login: j.user&.login, id: j.user&.id, name: j.user&.name },
0 commit comments