16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
|
# File 'app/controllers/groups_controller.rb', line 16
def show
if @group
if request.format.html? || request.format.xls? || request.format.csv? || request.format.json?
Rack::MiniProfiler.step('groups#show controller: fetch memberships') do
if @group.group_of_groups?
@memberships = []
@child_groups = @group.child_groups - [@group.find_officers_parent_group]
else
@memberships = @group.memberships_for_member_list
end
end
if params[:valid_from].present?
@memberships = @memberships.started_after(params[:valid_from].to_datetime)
end
Rack::MiniProfiler.step('groups#show controller: cancan') do
allowed_members = @group.members.accessible_by(current_ability)
allowed_memberships = @group.memberships.where(descendant_id: allowed_members.map(&:id))
@memberships = @memberships & allowed_memberships
end
Rack::MiniProfiler.step('groups#show controller: fetch members') do
@members = @group.members.includes(:links_as_child).where(dag_links: {id: @memberships.map(&:id)})
@members = User.includes(:links_as_child).where(dag_links: {id: @memberships.map(&:id)}) if @members.empty?
@members = @memberships.collect { |membership| membership.user } if @members.empty?
end
@large_map_address_fields = []
@new_user_group_membership = @group.build_membership
end
end
if request.format.csv? || request.format.xls?
list_preset = params[:list]
list_preset_i18n = I18n.translate(list_preset) if list_preset.present?
@file_title = "#{@group.name} #{list_preset_i18n} #{Time.zone.now}".parameterize
if list_preset.in? ['member_development', 'join_statistics']
@list_export = ListExport.new(@group, list_preset)
else
@list_export = ListExport.new(@members, list_preset)
end
end
respond_to do |format|
format.html do
authorize! :read, @group
point_navigation_to @group
current_user.try(:update_last_seen_activity, "sieht sich Mitgliederlisten an: #{@group.title}", @group)
end
format.json do
authorize! :read, @group
render json: @group.serializable_hash.merge({member_count: @memberships.count})
end
format.csv do
authorize! :read, @group
authorize! :export_member_list, @group
bom = "\xEF\xBB\xBF".force_encoding('utf-8')
csv_data = bom + @list_export.to_csv
send_data csv_data, filename: "#{@file_title}.csv"
end
format.xls do
authorize! :read, @group
authorize! :export_member_list, @group
send_data(@list_export.to_xls, type: 'application/xls; charset=utf-8; header=present', filename: "#{@file_title}.xls")
end
format.pdf do
authorize! :read, @group
authorize! :export_member_list, @group
if params[:sender].present?
session[:address_labels_pdf_sender] = params[:sender]
end
options = {sender: params[:sender], book_rate: params[:book_rate]}
file_title = "#{I18n.t(:address_labels)} #{@group.name} #{Time.zone.now}".parameterize
send_data(@group.members_to_pdf(options), filename: "#{file_title}.pdf", type: 'application/pdf', disposition: 'attachment')
end
end
metric_logger.log_event @group.try(:attributes), type: :show_group
end
|