Skip to content

Commit 1e22e0f

Browse files
authored
Merge pull request #594 from coopdevs/improve_reports
Reports: more internal refactor and include new attributes
2 parents 88d7262 + 16c4e44 commit 1e22e0f

File tree

17 files changed

+100
-64
lines changed

17 files changed

+100
-64
lines changed

Gemfile.lock

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ GEM
133133
fabrication (2.21.1)
134134
faker (2.16.0)
135135
i18n (>= 1.6, < 2)
136-
ffi (1.14.2)
136+
ffi (1.15.0)
137137
formtastic (4.0.0)
138138
actionpack (>= 5.2.0)
139139
formtastic_i18n (0.6.0)
@@ -199,16 +199,16 @@ GEM
199199
method_source (1.0.0)
200200
mime-types (3.3.1)
201201
mime-types-data (~> 3.2015)
202-
mime-types-data (3.2021.0212)
202+
mime-types-data (3.2021.0225)
203203
mimemagic (0.3.5)
204204
mini_mime (1.0.2)
205205
mini_portile2 (2.5.0)
206-
minitest (5.14.3)
206+
minitest (5.14.4)
207207
net-scp (3.0.0)
208208
net-ssh (>= 2.6.5, < 7.0.0)
209209
net-ssh (6.1.0)
210210
netrc (0.11.0)
211-
nio4r (2.5.5)
211+
nio4r (2.5.7)
212212
nokogiri (1.11.1)
213213
mini_portile2 (~> 2.5.0)
214214
racc (~> 1.4)
@@ -279,7 +279,7 @@ GEM
279279
ffi (~> 1.0)
280280
rdiscount (2.2.0.2)
281281
redis (4.2.5)
282-
regexp_parser (2.0.3)
282+
regexp_parser (2.1.1)
283283
responders (3.0.1)
284284
actionpack (>= 5.0)
285285
railties (>= 5.0)
@@ -307,7 +307,7 @@ GEM
307307
rspec-mocks (~> 3.10)
308308
rspec-support (~> 3.10)
309309
rspec-support (3.10.2)
310-
rubocop (1.10.0)
310+
rubocop (1.11.0)
311311
parallel (~> 1.10)
312312
parser (>= 3.0.0.0)
313313
rainbow (>= 2.2.2, < 4.0)
@@ -390,7 +390,7 @@ GEM
390390
activemodel (>= 6.0.0)
391391
bindex (>= 0.4.0)
392392
railties (>= 6.0.0)
393-
webdrivers (4.5.0)
393+
webdrivers (4.6.0)
394394
nokogiri (~> 1.6)
395395
rubyzip (>= 1.3.0)
396396
selenium-webdriver (>= 3.0, < 4.0)

app/assets/javascripts/application.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
$(document).on('click', 'a[data-popup]', function(event) {
44
event.preventDefault();
55

6-
window.open($(this).attr('href'), 'popup', 'width=600,height=600');
6+
window.open($(this).attr('href'), 'popup', 'width=800,height=600');
77
});
88

99
$(document).on('click', 'span.show-password', function(event) {

app/decorators/member_report_decorator.rb

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,11 @@ def headers
1717
User.human_attribute_name(:username),
1818
User.human_attribute_name(:email),
1919
User.human_attribute_name(:phone),
20-
User.human_attribute_name(:alt_phone)
20+
User.human_attribute_name(:alt_phone),
21+
User.human_attribute_name(:created_at),
22+
User.human_attribute_name(:last_sign_in_at),
23+
User.human_attribute_name(:locale),
24+
Account.human_attribute_name(:balance)
2125
]
2226
end
2327

@@ -28,7 +32,11 @@ def rows
2832
member.user.username,
2933
member.user.email_if_real,
3034
member.user.phone,
31-
member.user.alt_phone
35+
member.user.alt_phone,
36+
member.user.created_at.to_s,
37+
member.user.last_sign_in_at.to_s,
38+
member.user.locale,
39+
member.account_balance.to_s
3240
]
3341
end
3442
end

app/decorators/post_report_decorator.rb

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,25 @@ def headers
1616
[
1717
"",
1818
@type.model_name.human,
19-
User.model_name.human
19+
Post.human_attribute_name(:tag_list),
20+
User.model_name.human,
21+
Post.human_attribute_name(:created_at)
2022
]
2123
end
2224

2325
def rows
2426
grouped_rows = []
2527

2628
@collection.each do |category, posts|
27-
grouped_rows << ["", category.try(:name) || "-", ""]
29+
grouped_rows << ["", category.try(:name) || "-", "", "", ""]
2830

2931
posts.each do |post|
3032
grouped_rows << [
3133
post.id,
3234
post.title,
33-
"#{post.user} (#{post.member_uid})"
35+
post.tag_list.to_s,
36+
"#{post.user} (#{post.member_uid})",
37+
post.created_at.to_s
3438
]
3539
end
3640
end

app/services/report/csv.rb

Lines changed: 0 additions & 14 deletions
This file was deleted.

app/services/report/csv/base.rb

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,26 @@
1+
require "csv"
2+
13
module Report
24
module Csv
35
class Base
6+
attr_accessor :decorator
7+
48
def name
5-
@decorator.name(:csv)
9+
decorator.name(:csv)
610
end
711

812
def mime_type
913
Mime[:csv]
1014
end
1115

1216
def run
13-
Report::Csv.run(@decorator.headers, @decorator.rows)
17+
::CSV.generate do |csv|
18+
csv << decorator.headers
19+
20+
decorator.rows.each do |row|
21+
csv << row
22+
end
23+
end
1424
end
1525
end
1626
end

app/services/report/csv/member.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ module Report
22
module Csv
33
class Member < Base
44
def initialize(org, collection)
5-
@decorator = MemberReportDecorator.new(org, collection)
5+
self.decorator = MemberReportDecorator.new(org, collection)
66
end
77
end
88
end

app/services/report/csv/post.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ module Report
22
module Csv
33
class Post < Base
44
def initialize(org, collection, type)
5-
@decorator = PostReportDecorator.new(org, collection, type)
5+
self.decorator = PostReportDecorator.new(org, collection, type)
66
end
77
end
88
end

app/services/report/pdf.rb

Lines changed: 0 additions & 17 deletions
This file was deleted.

app/services/report/pdf/base.rb

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,21 @@
11
module Report
22
module Pdf
33
class Base
4+
attr_accessor :decorator
5+
46
def name
5-
@decorator.name(:pdf)
7+
decorator.name(:pdf)
68
end
79

810
def mime_type
911
Mime[:pdf]
1012
end
1113

1214
def run
13-
Report::Pdf.run(@decorator.headers, @decorator.rows)
15+
pdf = Prawn::Document.new({ page_size: "A4", margin: 30 })
16+
pdf.table [decorator.headers] + decorator.rows
17+
18+
pdf.render
1419
end
1520
end
1621
end

0 commit comments

Comments
 (0)