alchemy-custom-model 2.0.3 → 2.1.0
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 32dfcdd9c7960977963a3758ef1af6d517362b28
|
4
|
+
data.tar.gz: ec7f6360bd70622e39f25904c6b5f680667507a7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 80de05b395cebc79fca0426fc5d759dae0d651709f4c14de7a3e290cc50cb7ad2b4fc1e83d9ace7b94428d538bfd340c5a90885e7a6d214b8e3997414f374de1
|
7
|
+
data.tar.gz: 9519f06da535bc01c2de997224a5d385ccf380b8533ca02fb4efec48a72e5f2ed935ce2138df8cd4250a0238e7d59e9241bccf2f1522e67f585004ac6130cf01
|
@@ -74,6 +74,26 @@ module Alchemy::Custom::Model
|
|
74
74
|
end
|
75
75
|
end
|
76
76
|
|
77
|
+
def export_csv
|
78
|
+
|
79
|
+
@query = base_class.ransack(params[:q])
|
80
|
+
@objects = @query.result(distinct: true)
|
81
|
+
@objects = @objects.accessible_by(current_ability)
|
82
|
+
@objects = @objects.page(params[:page]).
|
83
|
+
per(params[:per_page] ||
|
84
|
+
(base_class::DEFAULT_PER_PAGE if base_class.const_defined? :DEFAULT_PER_PAGE) ||
|
85
|
+
25)
|
86
|
+
|
87
|
+
|
88
|
+
send_data generate_csv, filename: "export_member.csv", disposition: :attachment, type: "text/csv"
|
89
|
+
|
90
|
+
end
|
91
|
+
|
92
|
+
def export_csv_full
|
93
|
+
@objects = base_class.all.accessible_by(current_ability)
|
94
|
+
send_data generate_csv, filename: "export_member.csv", disposition: :attachment, type: "text/csv"
|
95
|
+
end
|
96
|
+
|
77
97
|
|
78
98
|
class << self
|
79
99
|
|
@@ -202,6 +222,28 @@ module Alchemy::Custom::Model
|
|
202
222
|
end
|
203
223
|
|
204
224
|
|
225
|
+
def generate_csv
|
226
|
+
header_csv = self.columns_csv.collect {|attr| base_class.human_attribute_name(attr)}
|
227
|
+
|
228
|
+
CSV.generate(headers: true) do |csv|
|
229
|
+
csv << header_csv
|
230
|
+
@objects.each do |member|
|
231
|
+
csv_row = self.columns_csv.collect do |attr|
|
232
|
+
member.send attr
|
233
|
+
end
|
234
|
+
csv << csv_row
|
235
|
+
end
|
236
|
+
end
|
237
|
+
end
|
238
|
+
|
239
|
+
|
240
|
+
protected
|
241
|
+
|
242
|
+
def columns_csv
|
243
|
+
table_columns
|
244
|
+
end
|
245
|
+
|
246
|
+
|
205
247
|
|
206
248
|
end
|
207
249
|
end
|
@@ -1,4 +1,3 @@
|
|
1
|
-
|
2
1
|
<% content_for(:toolbar) do %>
|
3
2
|
<%= render 'alchemy/admin/partials/site_select' %>
|
4
3
|
<%= render 'language_tree_select' %>
|
@@ -32,6 +31,28 @@
|
|
32
31
|
}
|
33
32
|
end
|
34
33
|
|
34
|
+
if can?(:export_csv, base_class) and check_presence_polymorphic_path([:export_csv, :admin, base_class.to_s.demodulize.downcase.pluralize ], :get, format: :csv)
|
35
|
+
buttons << {
|
36
|
+
icon: "download",
|
37
|
+
label: t(:export_selected_data),
|
38
|
+
url: polymorphic_path([:export_csv, :admin, base_class.to_s.demodulize.downcase.pluralize],format: :csv),
|
39
|
+
title: t(:export_selected_data),
|
40
|
+
dialog: false,
|
41
|
+
if_permitted_to: [:export_csv, base_class]
|
42
|
+
}
|
43
|
+
end
|
44
|
+
|
45
|
+
if can?(:export_csv_full, base_class) and check_presence_polymorphic_path([:export_csv_full, :admin, base_class.to_s.demodulize.downcase.pluralize ], :get, format: :csv)
|
46
|
+
buttons << {
|
47
|
+
icon: "file-archive",
|
48
|
+
label: t(:export_all_data),
|
49
|
+
url: polymorphic_path([:export_csv_full, :admin, base_class.to_s.demodulize.downcase.pluralize],format: :csv),
|
50
|
+
title: t(:export_all_data),
|
51
|
+
dialog: false,
|
52
|
+
if_permitted_to: [:export_csv_full, base_class]
|
53
|
+
}
|
54
|
+
end
|
55
|
+
|
35
56
|
%>
|
36
57
|
|
37
58
|
<% toolbar(
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: alchemy-custom-model
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0
|
4
|
+
version: 2.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alessandro Baccanelli
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2019-
|
12
|
+
date: 2019-07-09 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: alchemy_cms
|