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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 64cfd3b12930f20e315da307b4798cb865f9b7fc7abf5824c2715779877db6d4
4
- data.tar.gz: 42b5b86d09688bbe7da5b9d3e2804dbc703f15b183e477eb3338c6f765d0b0f3
3
+ metadata.gz: 9eb85dad4771de94e2be011517a7e7babff1decd5848d2e660e5feb353e0228b
4
+ data.tar.gz: 0cb7adb4f4aa0d313712655203abd2b8a6fe0d17bf5b0830666a888e8633f4b2
5
5
  SHA512:
6
- metadata.gz: d8185abb81f60a8e0f42bd71c6770c8e34582cd3bc5b76398cf964ff330dcfef185fe21c536b255638124776f1f40a8f94e52cffcbeae14e55bff380c41adea7
7
- data.tar.gz: 92ab81e54c28428bbc3daa6e137d570151d7ba41388610942fad71319c6eee05dfdd41d86be48161735025f0a00505cbdde65abf3c90fc899d8876c3a8631efd
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) %>
@@ -4,3 +4,4 @@ cs:
4
4
  label_advance_filters: Rozšířené
5
5
  label_use_setting: Zobrazit
6
6
  label_unfilled: Nevyplněno
7
+ label_export_as: "Stáhnout %{as}"
@@ -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
 
@@ -5,6 +5,14 @@ module AzaharaSchema
5
5
  super(model, attrs)
6
6
  end
7
7
 
8
+ def export_template
9
+ 'azahara_schema/exports/common'
10
+ end
11
+
12
+ def csv_template
13
+ export_template
14
+ end
15
+
8
16
  def always_visible_filters
9
17
  []
10
18
  end
@@ -1,3 +1,3 @@
1
1
  module AzaharaSchema
2
- VERSION = '0.2.3'
2
+ VERSION = '0.2.4'
3
3
  end
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.3
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