Skip to content

Commit d2b6e72

Browse files
committed
Adds image URLs
1 parent 8ceba67 commit d2b6e72

File tree

1 file changed

+27
-9
lines changed

1 file changed

+27
-9
lines changed

lib/redmine_gtt_print/issue_to_json.rb

Lines changed: 27 additions & 9 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 = {}, custom_fields = {})
7+
def initialize(issue, layout, other_attributes = {}, custom_fields = {}, attachments = [])
88
@issue = issue
99
@layout = layout
10+
@attachments = attachments
1011
@custom_fields = custom_fields
1112
@other_attributes = other_attributes
1213
end
@@ -21,21 +22,31 @@ def call
2122
@custom_fields.store(cfv.custom_field.name, cfv)
2223
end
2324

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+
2433
json = {
2534
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)
2736
}
2837

2938
if data = @issue.geodata_for_print
3039
json[:attributes][:map] = self.class.map_data(data[:center], [data[:geojson]])
3140
end
3241

42+
pp json
43+
3344
json.to_json
3445
end
3546

3647
# the following static helpers are used by IssuesToJson as well
3748

38-
def self.attributes_hash(issue, other_attributes, custom_fields)
49+
def self.attributes_hash(issue, other_attributes, custom_fields, attachments)
3950
{
4051
id: issue.id,
4152
subject: issue.subject,
@@ -65,6 +76,19 @@ def self.attributes_hash(issue, other_attributes, custom_fields)
6576
# Custom text
6677
custom_text: other_attributes[:custom_text],
6778

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+
6892
# Experimental
6993
# issue: issue,
7094
# project: (Project.find issue.project_id),
@@ -74,12 +98,6 @@ def self.attributes_hash(issue, other_attributes, custom_fields)
7498
# author: (User.find issue.author_id),
7599
# assigned_to: (User.find issue.assigned_to_id),
76100

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-
83101
# journals: issue.visible_journals_with_index.map{|j|
84102
# {
85103
# user: { login: j.user&.login, id: j.user&.id, name: j.user&.name },

0 commit comments

Comments
 (0)