bootstrap_admin 0.0.18 → 1.0.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: db471f923e62f81baa4449b884b64fd7580bc4a1
4
- data.tar.gz: 46a424404f30ea8d28e7f32490a969cfa79f489e
3
+ metadata.gz: 1c5a7149bdccd86b79ae1b9d28b8120328f2297a
4
+ data.tar.gz: fa6ed728a44b1ace28761610fe369416d0f44d2f
5
5
  SHA512:
6
- metadata.gz: 849064a01fb36b2b2671ba51806052f79c0ac26b0b004a06f5f8e4f2926f09572162f4f1782ebc0f20b006c3b06ae81b68cfad4f3ec45573794c67f153cd8511
7
- data.tar.gz: f609ff21d9cb80f4495ded9d681c80cd6712ec2e54ff9d633e25bb7c643b9b0aedf36d186a0f9d67a9c82979156e9ca686a381688464b2dd0be7e0008e9eadbc
6
+ metadata.gz: ef09e63d8c141c469ba603337a66fdbde4d081eb47f57c4b720e2273eadf8399b5e17df16d5f5a549c546d3563411fb5ef57d70ed0d9bd9ae7b20162627d4490
7
+ data.tar.gz: a300ec7519b19bc2d5722abdb69673dd09d3ff2e464a611a821f5936dbd396479cec94d86a806024a2c05f90e69b267ac70d89a9565993ccc173fe18b1c492f1
@@ -216,7 +216,7 @@ module BootstrapAdminHelper
216
216
  # =============================================================================
217
217
  # @return [String] the model instance name for the current controller
218
218
  def model_name_for controller
219
- model_for(controller).model_name.underscore
219
+ model_for(controller).model_name.to_s.underscore
220
220
  end
221
221
 
222
222
  # =============================================================================
@@ -238,16 +238,9 @@ module BootstrapAdminHelper
238
238
  def attributes
239
239
  return @attributes if @attributes
240
240
  model_klass = model_for controller
241
-
242
241
  fields = bootstrap_admin_config.send("#{params[:action]}_fields") ||
243
242
  bootstrap_admin_config.send("action_fields") ||
244
- model_klass.accessible_attributes.
245
- reject(&:blank?).
246
- map{|att| real_attribute_name att }.
247
- reject do |att|
248
- att.to_s =~ /(.+)_attributes/ &&
249
- model_klass.reflect_on_all_associations.map(&:name).include?($1.to_sym)
250
- end
243
+ find_attributes_for_class(model_klass)
251
244
 
252
245
  @attributes = fields.map do |att|
253
246
  BootstrapAdmin::Attribute.new att,
@@ -294,4 +287,20 @@ module BootstrapAdminHelper
294
287
  end
295
288
  end
296
289
 
290
+ # ==============================================================================
291
+ # Finds attributes for the given model class
292
+ # @param model_klass [ActiveRecord::Base] The model to get attributes from
293
+ # @return [Array of Symbol] attributes for the given model
294
+ def find_attributes_for_class model_klass
295
+ attributes = BootstrapAdmin.filter_ignored_fields(model_klass.attribute_names)
296
+
297
+ attributes.map{|att| real_attribute_name att }.
298
+ reject{|att|
299
+ att.to_s =~ /(.+)_attributes/ &&
300
+ model_klass.reflect_on_all_associations
301
+ .map(&:name)
302
+ .include?($1.to_sym)
303
+ }
304
+ end
305
+
297
306
  end
@@ -55,6 +55,19 @@ module BootstrapAdmin
55
55
  @@ui_styles = {
56
56
  index: %w(table-bordered table-striped)
57
57
  }
58
+
59
+ # =============================================================================
60
+ mattr_accessor :default_ignored_fields
61
+ @@default_ignored_fields = %i(id created_at updated_at)
62
+
63
+ def self.default_ignored_field_symbols
64
+ @@default_ignored_fields.map(&:to_sym)
65
+ end
66
+
67
+ def self.filter_ignored_fields fields
68
+ Array(fields).map(&:to_sym) - default_ignored_field_symbols
69
+ end
70
+
58
71
  # =============================================================================
59
72
  # Setup BootstrapAdmin
60
73
  # Run rails generate bootstrap_admin:install
@@ -28,7 +28,7 @@ module BootstrapAdmin
28
28
  # =============================================================================
29
29
  # Creates a new item
30
30
  def create
31
- instance model_class.new(params[model_name])
31
+ instance model_class.new( find_permitted_fields(:new) )
32
32
  instance.save
33
33
  namespaced_response instance
34
34
  end
@@ -40,7 +40,7 @@ module BootstrapAdmin
40
40
  # =============================================================================
41
41
  # Updates the existing item
42
42
  def update
43
- instance.update_attributes params[model_name]
43
+ instance.update_attributes find_permitted_fields(:update)
44
44
  namespaced_response instance
45
45
  end
46
46
 
@@ -98,7 +98,7 @@ module BootstrapAdmin
98
98
  instance_variable_set "@#{collection_name}", collection_var
99
99
  else
100
100
  unless cvar = instance_variable_get("@#{collection_name}")
101
- cvar = model_class.scoped
101
+ cvar = model_class.default_scoped
102
102
  instance_variable_set "@#{collection_name}", cvar
103
103
  end
104
104
  cvar
@@ -111,6 +111,18 @@ module BootstrapAdmin
111
111
  self.class.name.sub("Controller", "").underscore.split('/').last
112
112
  end
113
113
 
114
+ # ==============================================================================
115
+ # Strong Parameters stuff...
116
+ def find_permitted_fields action_name
117
+ fields = (
118
+ send("permitted_#{action_name}_fields") ||
119
+ send("permitted_fields") ||
120
+ BootstrapAdmin.filter_ignored_fields( model_class.attribute_names )
121
+ ).map(&:to_sym)
122
+
123
+ params.require(model_name).permit(*fields)
124
+ end
125
+
114
126
  private
115
127
  # =============================================================================
116
128
  # Prepares a response using the controllers reponder.
@@ -24,6 +24,11 @@ module BootstrapAdmin
24
24
  alias_method :create_fields, :form_fields
25
25
  alias_method :update_fields, :form_fields
26
26
 
27
+ attr_accessor :permitted_new_fields
28
+ attr_accessor :permitted_update_fields
29
+ attr_accessor :permitted_search_fields
30
+ attr_accessor :permitted_fields
31
+
27
32
  # Fields to be used on ALL actions
28
33
  # These are used when none of the {action}_fields are defined
29
34
  attr_accessor :action_fields
@@ -96,11 +96,11 @@ module BootstrapAdmin
96
96
  # =============================================================================
97
97
  def search_fields resource
98
98
  if controller.searchable_fields.blank?
99
- accessible = resource.accessible_attributes.reject &:blank?
100
- text_fields = resource.columns.
101
- select{|c| [:string, :text].include? c.type}.
102
- map(&:name)
103
- text_fields & accessible
99
+ BootstrapAdmin.filter_ignored_fields(
100
+ resource.columns.
101
+ select{|c| [:string, :text].include? c.type}.
102
+ map{|c| c.name.to_sym}
103
+ )
104
104
  else
105
105
  controller.searchable_fields
106
106
  end
@@ -1,3 +1,3 @@
1
1
  module BootstrapAdmin
2
- VERSION = "0.0.18"
2
+ VERSION = "1.0.0"
3
3
  end
@@ -8,11 +8,20 @@ BootstrapAdmin.setup do |config|
8
8
  # ==> Paginator configuration
9
9
  # Configure the number of results shown per page by the paginator.
10
10
  # Default value: 10
11
+ #
11
12
  # config.paginator_page_size = 10
12
13
 
13
14
  # ==> UI Styles
14
15
  # Configure the css class names that each action wrapper will have
15
16
  # Default value: {index: %w(table-bordered table-striped)}
17
+ #
16
18
  # config.ui_styles[:index] << "my_awesome_style_class"
17
19
 
20
+ # ==> Default ignored fields
21
+ # Define the fields that the automatic view generator should ignore
22
+ # when building the index view and the new/edit forms.
23
+ # Default value: %i(id created_at updated_at)
24
+ #
25
+ # config.default_ignored_fields += %i(some other fields)
26
+
18
27
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bootstrap_admin
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.18
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ivo Jesus
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2015-07-18 00:00:00.000000000 Z
12
+ date: 2015-07-19 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails