Skip to content

Commit 77d3e2a

Browse files
committed
issues json datasource format
1 parent 73dc6a0 commit 77d3e2a

File tree

2 files changed

+30
-5
lines changed

2 files changed

+30
-5
lines changed

lib/redmine_gtt_print/issues_to_json.rb

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
module RedmineGttPrint
24

35
# Transforms the given array of issues into JSON ready to be sent to the
@@ -17,10 +19,19 @@ def self.call(*_)
1719
def call
1820
hsh = {
1921
layout: @layout,
22+
outputFilename: "DailyList",
23+
outputFormat: "pdf",
24+
custom_text: @other_attributes[:custom_text],
2025
attributes: {
21-
issues: @issues.map{|i|
22-
IssueToJson.attributes_hash(i, @other_attributes)
23-
}
26+
datasource: [
27+
{
28+
table: {
29+
columns: %w( id status start_date created_on assigned_to_name subject ),
30+
data: @issues.map{|i| issue_to_data_row i}
31+
}
32+
}
33+
34+
]
2435
}
2536
}
2637

@@ -36,6 +47,19 @@ def call
3647
hsh.to_json
3748
end
3849

50+
private
51+
52+
def issue_to_data_row(i)
53+
[
54+
i.id,
55+
i.status.name,
56+
i.start_date,
57+
i.created_on,
58+
i.assigned_to&.name,
59+
i.subject
60+
]
61+
end
62+
3963
end
4064
end
4165

test/unit/issues_to_json_test.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,9 @@ class IssuesToJsonTest < ActiveSupport::TestCase
2424
assert j = RedmineGttPrint::IssuesToJson.(@issues, 'das layout')
2525
assert h = JSON.parse(j)
2626
assert_equal 'das layout', h['layout']
27-
assert_equal @issues[0].subject, h['attributes']['issues'][0]['subject']
28-
assert_equal @issues[1].subject, h['attributes']['issues'][1]['subject']
27+
assert table = h['attributes']['datasource'][0]['table']['data']
28+
assert_equal @issues[0].subject, table[0].last
29+
assert_equal @issues[1].subject, table[1].last
2930

3031
assert map = h['attributes']['map']
3132
assert_equal 2, map['center'].size

0 commit comments

Comments
 (0)