typus 3.1.0.rc18 → 3.1.0.rc19

Sign up to get free protection for your applications and to get access to all the features.
Files changed (138) hide show
  1. data/.gitignore +14 -11
  2. data/.travis.yml +12 -0
  3. data/CHANGELOG +253 -0
  4. data/Gemfile +69 -0
  5. data/Guardfile +11 -0
  6. data/README.md +14 -26
  7. data/Rakefile +24 -100
  8. data/app/assets/javascripts/typus/application.js +8 -2
  9. data/app/assets/javascripts/typus/custom.js +2 -0
  10. data/app/assets/javascripts/typus/jquery.application.js +14 -0
  11. data/app/assets/stylesheets/typus/application.css +18 -10
  12. data/app/assets/stylesheets/typus/content.css +0 -1
  13. data/app/assets/stylesheets/typus/custom.css +11 -0
  14. data/app/assets/stylesheets/typus/errors.css +1 -1
  15. data/app/assets/stylesheets/typus/forms.css +17 -5
  16. data/app/assets/stylesheets/typus/hacks.css +4 -0
  17. data/app/assets/stylesheets/typus/header.css +8 -2
  18. data/app/assets/stylesheets/typus/pagination.css +3 -3
  19. data/app/assets/stylesheets/typus/sidebar.css +4 -0
  20. data/app/assets/stylesheets/typus/tables.css +0 -1
  21. data/app/controllers/admin/account_controller.rb +1 -2
  22. data/app/controllers/admin/base_controller.rb +5 -2
  23. data/app/controllers/admin/dashboard_controller.rb +5 -0
  24. data/app/controllers/admin/resource_controller.rb +1 -2
  25. data/app/controllers/admin/resources_controller.rb +36 -51
  26. data/app/controllers/admin/session_controller.rb +2 -3
  27. data/app/helpers/admin/base_helper.rb +2 -5
  28. data/app/helpers/admin/resources/data_types/belongs_to_helper.rb +35 -27
  29. data/app/helpers/admin/resources/data_types/dragonfly_helper.rb +16 -3
  30. data/app/helpers/admin/resources/data_types/has_and_belongs_to_many_helper.rb +45 -13
  31. data/app/helpers/admin/resources/data_types/has_many_helper.rb +27 -19
  32. data/app/helpers/admin/resources/data_types/has_one_helper.rb +24 -11
  33. data/app/helpers/admin/resources/data_types/paperclip_helper.rb +1 -1
  34. data/app/helpers/admin/resources/data_types/string_helper.rb +1 -1
  35. data/app/helpers/admin/resources/data_types/text_helper.rb +1 -1
  36. data/app/helpers/admin/resources/data_types/transversal_helper.rb +1 -1
  37. data/app/helpers/admin/resources/data_types/tree_helper.rb +1 -1
  38. data/app/helpers/admin/resources/display_helper.rb +10 -9
  39. data/app/helpers/admin/resources/filters_helper.rb +3 -10
  40. data/app/helpers/admin/resources/form_helper.rb +12 -2
  41. data/app/helpers/admin/resources/list_helper.rb +13 -5
  42. data/app/helpers/admin/resources/relationships_helper.rb +0 -21
  43. data/app/helpers/admin/resources_helper.rb +3 -3
  44. data/app/mailers/admin/mailer.rb +9 -4
  45. data/app/views/admin/base/user_guide.html.erb +1 -1
  46. data/app/views/admin/dashboard/{show.html.erb → index.html.erb} +0 -0
  47. data/app/views/admin/dashboard/widgets/_applications.html.erb +32 -10
  48. data/app/views/admin/mailer/reset_password_instructions.html.erb +9 -0
  49. data/app/views/admin/mailer/reset_password_instructions.text.erb +9 -0
  50. data/app/views/admin/resources/edit.html.erb +3 -13
  51. data/app/views/admin/resources/index.html.erb +11 -4
  52. data/app/views/admin/resources/new.html.erb +2 -2
  53. data/app/views/admin/resources/show.html.erb +1 -1
  54. data/app/views/admin/shared/_head.html.erb +2 -2
  55. data/app/views/admin/templates/_belongs_to.html.erb +6 -9
  56. data/app/views/admin/templates/_dragonfly.html.erb +1 -1
  57. data/app/views/admin/templates/_dragonfly_form_preview.html.erb +21 -0
  58. data/app/views/admin/templates/_dragonfly_preview.html.erb +1 -1
  59. data/app/views/admin/templates/_has_and_belongs_to_many.html.erb +15 -0
  60. data/app/views/admin/templates/{_has_n.html.erb → _has_many.html.erb} +0 -0
  61. data/app/views/admin/templates/_password.html.erb +1 -1
  62. data/app/views/admin/templates/_selector.html.erb +1 -11
  63. data/app/views/admin/templates/_string.html.erb +2 -20
  64. data/app/views/admin/templates/_string_with_preview.html.erb +2 -3
  65. data/app/views/admin/templates/_text.html.erb +1 -8
  66. data/app/views/admin/templates/_text_with_ckeditor.html.erb +1 -1
  67. data/app/views/admin/templates/_text_with_ckeditor_and_assets.html.erb +12 -9
  68. data/app/views/helpers/admin/base/_apps.html.erb +12 -4
  69. data/app/views/helpers/admin/base/_login_info.html.erb +1 -1
  70. data/app/views/helpers/admin/resources/_filters.html.erb +2 -1
  71. data/app/views/helpers/admin/resources/_sidebar.html.erb +25 -41
  72. data/app/views/layouts/admin/base.html.erb +1 -1
  73. data/config/locales/typus.ca.yml +1 -1
  74. data/config/locales/typus.de.yml +40 -35
  75. data/config/locales/typus.el.yml +1 -1
  76. data/config/locales/typus.es.yml +1 -1
  77. data/config/locales/typus.fr.yml +1 -1
  78. data/config/locales/typus.hu.yml +1 -1
  79. data/config/locales/typus.it.yml +1 -1
  80. data/config/locales/typus.locale.models.yml.template +17 -0
  81. data/config/locales/typus.locale.yml.template +80 -0
  82. data/config/locales/typus.pt-BR.yml +1 -1
  83. data/config/locales/typus.pt-PT.yml +2 -2
  84. data/config/locales/typus.ru.yml +1 -1
  85. data/config/locales/typus.zh-CN.yml +1 -1
  86. data/config/routes.rb +5 -1
  87. data/lib/generators/templates/config/initializers/typus.rb +9 -0
  88. data/lib/generators/templates/config/typus/README +0 -6
  89. data/lib/support/active_record.rb +2 -10
  90. data/lib/support/string.rb +6 -1
  91. data/lib/typus.rb +49 -10
  92. data/lib/typus/authentication/base.rb +0 -4
  93. data/lib/typus/authentication/none_with_role.rb +15 -0
  94. data/lib/typus/configuration.rb +3 -7
  95. data/lib/typus/controller/ancestry.rb +1 -1
  96. data/lib/typus/controller/bulk.rb +6 -2
  97. data/lib/typus/controller/format.rb +38 -25
  98. data/lib/typus/orm/active_record/class_methods.rb +0 -1
  99. data/lib/typus/orm/active_record/search.rb +6 -2
  100. data/lib/typus/orm/base.rb +4 -3
  101. data/lib/typus/orm/mongoid.rb +4 -0
  102. data/lib/typus/orm/{mongo → mongoid}/class_methods.rb +4 -3
  103. data/lib/typus/resources.rb +9 -0
  104. data/lib/typus/version.rb +1 -1
  105. data/typus.gemspec +13 -13
  106. data/vendor/assets/chosen/chosen-sprite.png +0 -0
  107. data/vendor/assets/chosen/chosen.css +334 -0
  108. data/vendor/assets/chosen/chosen.jquery.min.js +10 -0
  109. data/vendor/assets/fancybox/jquery.fancybox-1.3.4.css +17 -17
  110. metadata +57 -131
  111. data/.gitmodules +0 -6
  112. data/app/assets/javascripts/typus.js +0 -8
  113. data/app/assets/stylesheets/typus.css +0 -20
  114. data/app/assets/stylesheets/typus/actions.css +0 -11
  115. data/app/views/admin/mailer/reset_password_link.text.erb +0 -9
  116. data/app/views/admin/templates/_belongs_to_with_autocomplete.html.erb +0 -26
  117. data/lib/typus/controller/associations.rb +0 -146
  118. data/lib/typus/controller/autocomplete.rb +0 -16
  119. data/vendor/assets/fancybox/jquery.easing-1.3.pack.js +0 -72
  120. data/vendor/assets/fancybox/jquery.fancybox-1.3.4.js +0 -1156
  121. data/vendor/assets/fancybox/jquery.mousewheel-3.0.4.pack.js +0 -14
  122. data/vendor/assets/formalize/css/_formalize.sass +0 -332
  123. data/vendor/assets/formalize/css/demo.css +0 -47
  124. data/vendor/assets/formalize/css/reset.css +0 -202
  125. data/vendor/assets/formalize/css/text.css +0 -81
  126. data/vendor/assets/formalize/js/dojo.formalize.js +0 -166
  127. data/vendor/assets/formalize/js/dojo.formalize.min.js +0 -1
  128. data/vendor/assets/formalize/js/extjs.formalize.js +0 -163
  129. data/vendor/assets/formalize/js/extjs.formalize.min.js +0 -1
  130. data/vendor/assets/formalize/js/jquery.formalize.js +0 -150
  131. data/vendor/assets/formalize/js/mootools.formalize.js +0 -155
  132. data/vendor/assets/formalize/js/mootools.formalize.min.js +0 -1
  133. data/vendor/assets/formalize/js/prototype.formalize.js +0 -163
  134. data/vendor/assets/formalize/js/prototype.formalize.min.js +0 -1
  135. data/vendor/assets/formalize/js/yui.formalize.js +0 -152
  136. data/vendor/assets/formalize/js/yui.formalize.min.js +0 -1
  137. data/vendor/assets/jquery-tokeninput/jquery.tokeninput.js +0 -736
  138. data/vendor/assets/jquery-tokeninput/token-input.css +0 -120
@@ -6,7 +6,7 @@
6
6
  "Actions": "Acções"
7
7
  "Active": "Activo"
8
8
  "Add": "Adicionar"
9
- "Add new": "Adicionar novo"
9
+ "Add New": "Adicionar novo"
10
10
  "Are you sure?": "Tem a certeza?"
11
11
  "Are you sure you want to sign out and end your session?": "Tem certeza que quer sair e encerrar sua sessão?"
12
12
 
@@ -32,7 +32,7 @@
32
32
  "Last 30 days": "Últimos 30 dias"
33
33
  "Last 7 days": "Últimos 7 dias"
34
34
  "List": "Lista"
35
- "Logged as": "Logado como"
35
+ "Logged in as": "Logado como"
36
36
  "Login": "Login"
37
37
 
38
38
  "New": "Novo"
@@ -31,7 +31,7 @@ ru:
31
31
  "Last few days": "Последние дней"
32
32
  "Last 7 days": "Последние 7 дней"
33
33
  "Last 30 days": "Последние 30 дней"
34
- "Logged as": "Вы вошли как"
34
+ "Logged in as": "Вы вошли как"
35
35
  "Login": "Редактировать"
36
36
 
37
37
  "New": "Новый"
@@ -30,7 +30,7 @@ zh-CN:
30
30
  "Last few days": "最近几天"
31
31
  "Last 30 days": "最近一个月"
32
32
  "Last 7 days": "最近一周"
33
- "Logged as": "登录为"
33
+ "Logged in as": "登录为"
34
34
  "Login": "登录"
35
35
 
36
36
  "New": "新建"
@@ -2,7 +2,11 @@ Rails.application.routes.draw do
2
2
 
3
3
  scope "admin", :module => :admin, :as => "admin" do
4
4
 
5
- match "/" => "dashboard#show", :as => "dashboard"
5
+ match "/" => redirect("/admin/dashboard")
6
+
7
+ match "dashboard" => "dashboard#index", :as => "dashboard_index"
8
+ match "dashboard/:application" => "dashboard#show", :as => "dashboard"
9
+
6
10
  match "user_guide" => "base#user_guide"
7
11
 
8
12
  if Typus.authentication == :session
@@ -6,6 +6,15 @@ Typus.setup do |config|
6
6
 
7
7
  # When mailer_sender is set, password recover is enabled. This email
8
8
  # address will be used in Admin::Mailer.
9
+ #
10
+ # Remember to setup the default url options for your specific environment
11
+ # Here is an example of development environment:
12
+ #
13
+ # config.action_mailer.default_url_options = { :host => 'localhost:3000' }
14
+ #
15
+ # This is a required Rails configuration. In production it must be the actual
16
+ # actual host of your application
17
+ #
9
18
  # config.mailer_sender = "admin@example.com"
10
19
 
11
20
  # Define paperclip attachment styles.
@@ -12,14 +12,11 @@ most common settings.
12
12
  show: title, category, is_published?
13
13
  relationship: title, status
14
14
  options:
15
- auto_generated:
16
15
  booleans:
17
16
  is_published: ["Yes, it is", "No, it isn't"]
18
17
  date_formats:
19
18
  created_at: post_long
20
19
  selectors:
21
- read_only:
22
- filter_by_date_range: valid_until
23
20
  templates:
24
21
  body: rich_text
25
22
  actions:
@@ -37,13 +34,10 @@ most common settings.
37
34
  end_year: 2015
38
35
  form_rows: 25
39
36
  minute_step: 15
40
- nil: 'nil'
41
37
  only_user_items: true
42
38
  per_page: 25
43
39
  start_year: 1990
44
40
 
45
- Note: To define namespace models use :: as a separator. (i.e. Delayed::Job)
46
-
47
41
  # Roles
48
42
 
49
43
  In this file you can configure the actions available for each of your models
@@ -1,11 +1,5 @@
1
1
  class ActiveRecord::Base
2
2
 
3
- def self.relationship_with(model)
4
- association = reflect_on_association(model.table_name.to_sym) ||
5
- reflect_on_association(model.model_name.underscore.to_sym)
6
- association.macro
7
- end
8
-
9
3
  #--
10
4
  # On a model:
11
5
  #
@@ -32,11 +26,11 @@ class ActiveRecord::Base
32
26
 
33
27
  array = values.first.is_a?(Array) ? values : values.map { |i| [i, i] }
34
28
 
35
- value = array.rassoc(send(attribute))
29
+ value = array.to_a.rassoc(send(attribute))
36
30
  value ? value.first : send(attribute)
37
31
  end
38
32
 
39
- def to_str
33
+ def to_label
40
34
  if respond_to?(:name) && send(:name).present?
41
35
  send(:name)
42
36
  else
@@ -44,6 +38,4 @@ class ActiveRecord::Base
44
38
  end
45
39
  end
46
40
 
47
- alias_method :to_label, :to_str
48
-
49
41
  end
@@ -12,11 +12,16 @@ class String
12
12
  remove_prefix.classify.constantize
13
13
  end
14
14
 
15
+ ##
16
+ # CRUD: create, read, update, delete
17
+ #
18
+ # You can read more at http://en.wikipedia.org/wiki/Create,_read,_update_and_delete
19
+ #
15
20
  def acl_action_mapper
16
21
  case self
17
22
  when "new", "create"
18
23
  "create"
19
- when "index", "show", "autocomplete"
24
+ when "index", "show"
20
25
  "read"
21
26
  when "edit", "update", "position", "toggle", "relate", "unrelate"
22
27
  "update"
@@ -23,8 +23,6 @@ module Typus
23
23
  autoload :Actions, "typus/controller/actions"
24
24
  autoload :ActsAsList, "typus/controller/acts_as_list"
25
25
  autoload :Ancestry, "typus/controller/ancestry"
26
- autoload :Associations, "typus/controller/associations"
27
- autoload :Autocomplete, "typus/controller/autocomplete"
28
26
  autoload :Bulk, "typus/controller/bulk"
29
27
  autoload :FeaturedImage, "typus/controller/featured_image"
30
28
  autoload :Filters, "typus/controller/filters"
@@ -38,19 +36,17 @@ module Typus
38
36
  autoload :Base, "typus/authentication/base"
39
37
  autoload :Devise, "typus/authentication/devise"
40
38
  autoload :None, "typus/authentication/none"
39
+ autoload :NoneWithRole, "typus/authentication/none_with_role"
41
40
  autoload :HttpBasic, "typus/authentication/http_basic"
42
41
  autoload :Session, "typus/authentication/session"
43
42
  end
44
43
 
45
- mattr_accessor :autocomplete
46
- @@autocomplete = nil
47
-
48
44
  mattr_accessor :admin_title
49
45
  @@admin_title = "Typus"
50
46
 
51
47
  mattr_accessor :admin_sub_title
52
48
  @@admin_sub_title = <<-CODE
53
- <a href="http://core.typuscms.com/">core.typuscms.com</a>
49
+ <a href="http://core.typuscmf.com/">core.typuscmf.com</a>
54
50
  CODE
55
51
 
56
52
  ##
@@ -121,6 +117,9 @@ module Typus
121
117
  mattr_accessor :image_thumb_size
122
118
  @@image_thumb_size = 'x100'
123
119
 
120
+ mattr_accessor :image_table_thumb_size
121
+ @@image_table_thumb_size = '25x25#'
122
+
124
123
  ##
125
124
  # Defines the default relationship table.
126
125
  #
@@ -149,12 +148,26 @@ module Typus
149
148
  end
150
149
 
151
150
  def applications
152
- Typus::Configuration.config.map { |i| i.last["application"] }.compact.uniq.sort
151
+ hash = {}
152
+
153
+ Typus::Configuration.config.map { |i| i.last["application"] }.compact.uniq.each do |app|
154
+ settings = app.extract_settings
155
+ hash[settings.first] = settings.size > 1 ? settings.last : 1000
156
+ end
157
+
158
+ hash.sort { |a1, a2| a1[1].to_i <=> a2[1].to_i }.map { |i| i.first }
153
159
  end
154
160
 
155
161
  # Lists modules of an application.
156
162
  def application(name)
157
- Typus::Configuration.config.map { |i| i.first if i.last["application"] == name }.compact.uniq
163
+ array = []
164
+
165
+ Typus::Configuration.config.each do |i|
166
+ settings = i.last["application"]
167
+ array << i.first if settings && settings.extract_settings.first.eql?(name)
168
+ end
169
+
170
+ array.compact.uniq
158
171
  end
159
172
 
160
173
  # Lists models from the configuration file.
@@ -184,17 +197,43 @@ module Typus
184
197
  detect_application_models.map do |model|
185
198
  class_name = model.sub(/\.rb$/,"").camelize
186
199
  klass = class_name.split("::").inject(Object) { |klass,part| klass.const_get(part) }
187
- class_name if klass < ActiveRecord::Base && !klass.abstract_class?
200
+ class_name if is_active_record?(klass) || is_mongoid?(klass)
188
201
  end.compact
189
202
  end
190
203
 
204
+ def is_active_record?(klass)
205
+ (defined?(ActiveRecord) && klass < ActiveRecord::Base && !klass.abstract_class?)
206
+ end
207
+ private :is_active_record?
208
+
209
+ def is_mongoid?(klass)
210
+ (defined?(Mongoid) && klass < Mongoid::Document)
211
+ end
212
+ private :is_mongoid?
213
+
191
214
  def user_class
192
215
  user_class_name.constantize
193
216
  end
194
217
 
218
+ def root
219
+ Rails.root.join(config_folder)
220
+ end
221
+
222
+ def model_configuration_files
223
+ app = Typus.root.join("*.yml")
224
+ plugins = Rails.root.join("vendor", "plugins", "*", "config", "typus", "*.yml")
225
+ Dir[app, plugins].reject { |f| f.match(/_roles.yml/) }.sort
226
+ end
227
+
228
+ def role_configuration_files
229
+ app = Typus.root.join("*_roles.yml")
230
+ plugins = Rails.root.join("vendor", "plugins", "*", "config", "typus", "*_roles.yml")
231
+ Dir[app, plugins].sort
232
+ end
233
+
195
234
  def reload!
196
235
  Typus::Configuration.roles!
197
- Typus::Configuration.config!
236
+ Typus::Configuration.models!
198
237
  end
199
238
 
200
239
  end
@@ -15,10 +15,6 @@ module Typus
15
15
  def set_attributes_on_create; end
16
16
  def set_attributes_on_update; end
17
17
 
18
- def not_allowed
19
- render :text => "Not allowed!", :status => :unprocessable_entity
20
- end
21
-
22
18
  end
23
19
  end
24
20
  end
@@ -0,0 +1,15 @@
1
+ module Typus
2
+ module Authentication
3
+ module NoneWithRole
4
+
5
+ protected
6
+
7
+ include Base
8
+
9
+ def authenticate
10
+ @admin_user = MyFakeUser.new
11
+ end
12
+
13
+ end
14
+ end
15
+ end
@@ -2,12 +2,10 @@ module Typus
2
2
  module Configuration
3
3
 
4
4
  # Read configuration from <tt>config/typus/*.yml</tt>.
5
- def self.config!
6
- files = Dir[File.join(Typus.config_folder, "*.yml").to_s].reject { |f| f.match(/_roles.yml/) }
7
-
5
+ def self.models!
8
6
  @@config = {}
9
7
 
10
- files.each do |file|
8
+ Typus.model_configuration_files.each do |file|
11
9
  if data = YAML::load_file(file)
12
10
  @@config.merge!(data)
13
11
  end
@@ -19,11 +17,9 @@ module Typus
19
17
 
20
18
  # Read roles from files <tt>config/typus/*_roles.yml</tt>.
21
19
  def self.roles!
22
- files = Dir[File.join(Typus.config_folder, "*_roles.yml").to_s].sort
23
-
24
20
  @@roles = {}
25
21
 
26
- files.each do |file|
22
+ Typus.role_configuration_files.each do |file|
27
23
  if data = YAML::load_file(file)
28
24
  data.compact.each do |key, value|
29
25
  @@roles[key] ? @@roles[key].merge!(value) : (@@roles[key] = value)
@@ -21,7 +21,7 @@ module Typus
21
21
 
22
22
  @items = Kaminari.paginate_array(items).page(params[:page]).per(1000)
23
23
 
24
- add_resource_action(default_action.titleize, {:action => default_action}, {})
24
+ set_default_action
25
25
  add_resource_action("Trash", {:action => "destroy"}, {:confirm => "#{Typus::I18n.t("Trash")}?", :method => 'delete'})
26
26
  end
27
27
 
@@ -21,10 +21,14 @@ module Typus
21
21
  private :set_bulk_action_for_trash
22
22
 
23
23
  def bulk
24
- if (ids = params[:selected_item_ids])
24
+ if (ids = params[:selected_item_ids]) && (action = params[:batch_action]).present?
25
25
  send(params[:batch_action], ids)
26
26
  else
27
- notice = Typus::I18n.t("Items must be selected in order to perform actions on them. No items have been changed.")
27
+ notice = if action.empty?
28
+ Typus::I18n.t("No bulk action selected.")
29
+ else
30
+ Typus::I18n.t("Items must be selected in order to perform actions on them. No items have been changed.")
31
+ end
28
32
  redirect_to :back, :notice => notice
29
33
  end
30
34
  end
@@ -6,43 +6,49 @@ module Typus
6
6
 
7
7
  protected
8
8
 
9
- def generate_html
9
+ def get_paginated_data
10
10
  items_per_page = @resource.typus_options_for(:per_page)
11
11
  @items = @resource.page(params[:page]).per(items_per_page)
12
12
  end
13
13
 
14
+ alias_method :generate_html, :get_paginated_data
15
+
14
16
  #--
15
17
  # TODO: Find in batches only works properly if it's used on models, not
16
18
  # controllers, so in this action does nothing. We should find a way
17
19
  # to be able to process large amounts of data.
18
20
  #++
19
21
  def generate_csv
20
- fields = @resource.typus_fields_for(:csv)
21
-
22
- filename = Rails.root.join("tmp", "export-#{@resource.to_resource}-#{Time.zone.now.to_s(:number)}.csv")
23
-
24
- options = { :conditions => @conditions, :batch_size => 1000 }
25
-
26
- ::CSV.open(filename, 'w') do |csv|
27
- csv << fields.keys
28
- @resource.find_in_batches(options) do |records|
29
- records.each do |record|
30
- csv << fields.map do |key, value|
31
- case value
32
- when :transversal
33
- a, b = key.split(".")
34
- record.send(a).send(b)
35
- when :belongs_to
36
- record.send(key).try(:to_label)
37
- else
38
- record.send(key)
22
+ if can_export?(:csv)
23
+ fields = @resource.typus_fields_for(:csv)
24
+
25
+ filename = Rails.root.join("tmp", "export-#{@resource.to_resource}-#{Time.zone.now.to_s(:number)}.csv")
26
+
27
+ options = { :conditions => @conditions, :batch_size => 1000 }
28
+
29
+ ::CSV.open(filename, 'w') do |csv|
30
+ csv << fields.keys
31
+ @resource.find_in_batches(options) do |records|
32
+ records.each do |record|
33
+ csv << fields.map do |key, value|
34
+ case value
35
+ when :transversal
36
+ a, b = key.split(".")
37
+ record.send(a).send(b)
38
+ when :belongs_to
39
+ record.send(key).try(:to_label)
40
+ else
41
+ record.send(key)
42
+ end
39
43
  end
40
- end
44
+ end
41
45
  end
42
46
  end
43
- end
44
47
 
45
- send_file filename
48
+ send_file filename
49
+ else
50
+ not_allowed
51
+ end
46
52
  end
47
53
 
48
54
  def generate_json
@@ -50,14 +56,21 @@ module Typus
50
56
  end
51
57
 
52
58
  def generate_xml
53
- export(:xml)
59
+ can_export?(:xml) ? export(:xml) : not_allowed
54
60
  end
55
61
 
56
62
  def export(format)
57
63
  fields = @resource.typus_fields_for(format).map { |i| i.first }
58
64
  methods = fields - @resource.column_names
59
65
  except = @resource.column_names - fields
60
- render format => @resource.send("to_#{format}", :methods => methods, :except => except)
66
+
67
+ get_paginated_data
68
+
69
+ render format => @items.send("to_#{format}", :methods => methods, :except => except)
70
+ end
71
+
72
+ def can_export?(format)
73
+ @resource.typus_options_for(:export).extract_settings.include?(format.to_s)
61
74
  end
62
75
 
63
76
  end
@@ -19,7 +19,6 @@ module Typus
19
19
  end
20
20
  end
21
21
 
22
- # Form and list fields
23
22
  def typus_fields_for(filter)
24
23
  ActiveSupport::OrderedHash.new.tap do |fields_with_type|
25
24
  get_typus_fields_for(filter).each do |field|