azahara_schema 0.2.3 → 0.2.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/app/views/azahara_schema/_schema.html.erb +6 -0
- data/app/views/azahara_schema/exports/common.csv.erb +7 -0
- data/config/locales/cs.yml +1 -0
- data/lib/azahara_schema/controller_additions.rb +11 -5
- data/lib/azahara_schema/model_schema.rb +8 -0
- data/lib/azahara_schema/version.rb +1 -1
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9eb85dad4771de94e2be011517a7e7babff1decd5848d2e660e5feb353e0228b
|
4
|
+
data.tar.gz: 0cb7adb4f4aa0d313712655203abd2b8a6fe0d17bf5b0830666a888e8633f4b2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 56dd290efccba57d7499d51a3fdd0763da4acc079d999eda11dc0e103211360de2449be8d670f42e156a0fbf9e5c7865b289066826981c4d41c26433fde4e83b
|
7
|
+
data.tar.gz: f1e6a8af44b113a8107330204a2a7db16a61287fb9cc01f17ca68fad617f7ff25630b905cb4c026fd3c2f9e8f318a1e113e70353ec9a044c8852d5ab989c3dc1
|
@@ -4,3 +4,9 @@
|
|
4
4
|
<% schema.outputs.each do |output| %>
|
5
5
|
<%= render output %>
|
6
6
|
<% end %>
|
7
|
+
<div class="exports text-right">
|
8
|
+
<%= link_to polymorphic_path(schema.model, schema.to_param.merge(format: :csv)) do %>
|
9
|
+
<i class="fa fa-file-o"></i>
|
10
|
+
<%= t('label_export_as', as: 'CSV') %>
|
11
|
+
<% end %>
|
12
|
+
</div>
|
@@ -0,0 +1,7 @@
|
|
1
|
+
<%= raw(CSV.generate(force_quotes: true) do |csv| %>
|
2
|
+
<% formatter = attribute_formatter_for(@resource_schema) %>
|
3
|
+
<% csv << @resource_schema.columns.collect{|c| c.attribute_name.human } %>
|
4
|
+
<% @resource_schema.entities.each do |entity| %>
|
5
|
+
<% csv << @resource_schema.columns.collect{|c| formatter.formatted_value(c, entity) } %>
|
6
|
+
<% end %>
|
7
|
+
<% end) %>
|
data/config/locales/cs.yml
CHANGED
@@ -2,23 +2,29 @@ module AzaharaSchema
|
|
2
2
|
module ControllerAdditions
|
3
3
|
|
4
4
|
def azahara_schema_index(**options)
|
5
|
-
resource_schema = self.class.cancan_resource_class.new(self).send(:collection_instance)
|
6
|
-
resource_schema.from_params(params)
|
5
|
+
@resource_schema = self.class.cancan_resource_class.new(self).send(:collection_instance)
|
6
|
+
@resource_schema.from_params(params)
|
7
7
|
respond_to do |format|
|
8
8
|
format.html
|
9
9
|
format.json {
|
10
10
|
json_result = {}
|
11
11
|
if params['_type'] == 'query'
|
12
|
-
json_result[:results] = resource_schema.entities.collect do |o|
|
12
|
+
json_result[:results] = @resource_schema.entities.collect do |o|
|
13
13
|
{id: o.id, text: o.to_s, residence: o.person.residence.to_s}
|
14
14
|
end
|
15
15
|
elsif params['_type'] == 'count'
|
16
|
-
json_result = {count: resource_schema.entity_count}
|
16
|
+
json_result = {count: @resource_schema.entity_count}
|
17
17
|
else
|
18
|
-
json_result = {entities: resource_schema, count: resource_schema.entity_count}
|
18
|
+
json_result = {entities: @resource_schema, count: @resource_schema.entity_count}
|
19
19
|
end
|
20
20
|
render json: json_result
|
21
21
|
}
|
22
|
+
format.csv {
|
23
|
+
require 'csv'
|
24
|
+
headers['Content-Disposition'] = "attachment; filename=\"#{@resource_schema.model.model_name.human(count: :other)}.csv\""
|
25
|
+
headers['Content-Type'] ||= 'text/csv'
|
26
|
+
render @resource_schema.csv_template, layout: false
|
27
|
+
}
|
22
28
|
end
|
23
29
|
end
|
24
30
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: azahara_schema
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ondřej Ezr
|
@@ -62,6 +62,7 @@ files:
|
|
62
62
|
- app/views/azahara_schema/_filters.html.erb
|
63
63
|
- app/views/azahara_schema/_index_form.html.erb
|
64
64
|
- app/views/azahara_schema/_schema.html.erb
|
65
|
+
- app/views/azahara_schema/exports/common.csv.erb
|
65
66
|
- app/views/layouts/action_schema/application.html.erb
|
66
67
|
- config/locales/cs.yml
|
67
68
|
- config/routes.rb
|