active_scaffold 3.4.12 → 3.4.13

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: 3e90634abde41880d285eb02b74524c356bb44ba
4
- data.tar.gz: 10e6bd5dcdd6ca95f8bbfc43cb6b65e6a162293e
3
+ metadata.gz: fd09ee16b2e93880391fad8eab47d2b2e41687c4
4
+ data.tar.gz: 186a9efd135d86b371ae7cf93206634753aed0ca
5
5
  SHA512:
6
- metadata.gz: ec33031cbabe0367c55e532adff3557527c309a700404bd0e19570e76ad4e199ae257f49fe4668a0550f33906aa5cdbeab2a0475b90222de85df356dd36ed38e
7
- data.tar.gz: cdaf43ba742dddfa274acc83610e2a7895cf471139da9868eb588c46c20c723a12c261567f8e2b1e212ebdd587a10017d8c3fc90e0ba2d3d65801de943315c6a
6
+ metadata.gz: 4cf41d9f68f77f7bd4ce86e457ad7ce536a4cf646a088b196867cacd74d654f428966f30f148f11aa2972a00575609e14bdd9b3ccb297ece4833927315a7de7f
7
+ data.tar.gz: cff3c6c6c20eabb9a99961a1991fb7ddaada2baef7476170c5c508a8017a8fbea6d986710d153ba3ebb38cb0d058fc122d1ee5046741ed1920e8e98c8f26682d
data/CHANGELOG CHANGED
@@ -1,3 +1,13 @@
1
+ = 3.4.13
2
+ - fix parent_prefixes deprecation on rails 4.2
3
+ - set parent record on add existing
4
+ - add record_select_params_for_add_existing to allow to set params on record select browse url, so add existing records are filtered
5
+ - fix search with date and boolean columns on rails 4.2
6
+ - fix cache association for has many through
7
+ - move handle_user_settings and check_input_device filters to Actions::Core so filters are not added to ActionController::Base, see cb2fabd
8
+ - allow to use search and field_search without AJAX
9
+ - allow to remove reset button in search and field_search
10
+
1
11
  = 3.4.12
2
12
  - Workaround for counter_cache bug on polymorphic associations on rails4
3
13
  - Improve use of CRUD actions without list action
@@ -1,8 +1,8 @@
1
- <% url_options = params_for(:action => :index, :search => nil) -%>
1
+ <% url_options ||= params_for(:action => :index, :search => nil) -%>
2
2
  <%=
3
3
  options = {:id => element_form_id(:action => 'search'),
4
4
  :class => "as_form search",
5
- :remote => true,
5
+ :remote => xhr ||= request.xhr?,
6
6
  :method => :get,
7
7
  'data-loading' => true}
8
8
  form_tag url_options, options %>
@@ -28,7 +28,7 @@ form_tag url_options, options %>
28
28
  </ol>
29
29
  <p class="form-footer">
30
30
  <%= submit_tag as_(:search), :class => "submit" %>
31
- <%= link_to as_(:reset), url_for(url_options.merge(:search => '')), :class => 'as_cancel reset', :remote => true, :data => {:refresh => true} %>
31
+ <%= link_to as_(:reset), url_for(url_options.merge(:search => '')), :class => 'as_cancel reset', :remote => true, :data => {:refresh => true} unless local_assigns[:skip_reset] %>
32
32
  <%= loading_indicator_tag(:action => :search) %>
33
33
  </p>
34
34
  </form>
@@ -35,7 +35,7 @@ add_new_url = params_for(:controller => controller_path, :action => 'edit_associ
35
35
 
36
36
  <% if show_add_existing -%>
37
37
  <% if remote_controller and remote_controller.respond_to? :uses_record_select? and remote_controller.uses_record_select? -%>
38
- <%= link_to_record_select as_(:add_existing), remote_controller.controller_path, :onselect => "ActiveScaffold.record_select_onselect(#{url_for(edit_associated_url).to_json}, #{active_scaffold_id.to_json}, id);" -%>
38
+ <%= link_to_record_select as_(:add_existing), remote_controller.controller_path, record_select_params_for_add_existing(column.association, edit_associated_url, parent_record) -%>
39
39
  <% else -%>
40
40
  <% select_options = options_from_collection_for_select(sorted_association_options_find(column.association, nil, parent_record), :to_param, :to_label)
41
41
  add_existing_id = "#{sub_form_id(:association => column.name, :id => parent_record.id || temporary_id || 99999999999)}-add-existing"
@@ -9,7 +9,7 @@
9
9
  <tr>
10
10
  <td>
11
11
  <div class="active-scaffold show_search-view <%= "#{id_from_controller params[:controller]}-view" %> view">
12
- <%= render :partial => active_scaffold_config.list.search_partial %>
12
+ <%= render :partial => active_scaffold_config.list.search_partial, :locals => {:xhr => true} %>
13
13
  </div>
14
14
  </td>
15
15
  </tr>
@@ -3,12 +3,12 @@
3
3
  <%=
4
4
  options = {:id => element_form_id(:action => 'search'),
5
5
  :class => "as_form search#{' live' if live_search}",
6
- :remote => true,
6
+ :remote => xhr ||= request.xhr?,
7
7
  :'data-loading' => true,
8
8
  :method => :get}
9
9
  form_tag url_options, options %>
10
10
  <%= search_field_tag :search, (search_params if search_params.is_a? String), :class => 'text-input', :id => search_input_id, :size => 50, :autocomplete => :off, :placeholder => as_(live_search ? :live_search : :search_terms) %>
11
11
  <%= submit_tag as_(:search), :class => "submit", :style => ('display:none;' if live_search) %>
12
- <%= link_to as_(:reset), url_for(url_options.merge(:search => '')), :class => 'as_cancel reset', :remote => true, :data => {:refresh => true} %>
12
+ <%= link_to as_(:reset), url_for(url_options.merge(:search => '')), :class => 'as_cancel reset', :remote => true, :data => {:refresh => true} unless local_assigns[:skip_reset] %>
13
13
  <%= loading_indicator_tag(:action => :search) %>
14
14
  </form>
@@ -2,6 +2,8 @@ module ActiveScaffold::Actions
2
2
  module Core
3
3
  def self.included(base)
4
4
  base.class_eval do
5
+ before_filter :handle_user_settings
6
+ before_filter :check_input_device
5
7
  before_filter :register_constraints_with_action_columns, :unless => :nested?
6
8
  after_filter :clear_flashes
7
9
  after_filter :clear_storage
@@ -13,6 +15,8 @@ module ActiveScaffold::Actions
13
15
  base.helper_method :loading_embedded?
14
16
  base.helper_method :calculate_query
15
17
  base.helper_method :new_model
18
+ base.helper_method :touch_device?
19
+ base.helper_method :hover_via_click?
16
20
  end
17
21
  def render_field
18
22
  if request.get?
@@ -208,9 +212,9 @@ module ActiveScaffold::Actions
208
212
  next if active_scaffold_constraints[key]
209
213
  next if nested? and nested.param_name == key
210
214
  conditions[key] = if value.is_a?(Array)
211
- value.map {|v| v == '' && not_string ? nil : column.type_cast(v) }
215
+ value.map {|v| v == '' && not_string ? nil : ActiveScaffold::Core.column_type_cast(v, column) }
212
216
  else
213
- value == '' && not_string ? nil : column.type_cast(value)
217
+ value == '' && not_string ? nil : ActiveScaffold::Core.column_type_cast(value, column)
214
218
  end
215
219
  end
216
220
  conditions
@@ -234,6 +238,36 @@ module ActiveScaffold::Actions
234
238
  @record = find_if_allowed(params[:id], crud_type_or_security_options, klass)
235
239
  end
236
240
 
241
+ # at some point we need to pass the session and params into config. we'll just take care of that before any particular action occurs by passing those hashes off to the UserSettings class of each action.
242
+ def handle_user_settings
243
+ if self.class.uses_active_scaffold?
244
+ storage = active_scaffold_config.store_user_settings ? active_scaffold_session_storage : {}
245
+ active_scaffold_config.actions.each do |action_name|
246
+ conf_instance = active_scaffold_config.send(action_name) rescue next
247
+ next if conf_instance.class::UserSettings == ActiveScaffold::Config::Base::UserSettings # if it hasn't been extended, skip it
248
+ conf_instance.user = conf_instance.class::UserSettings.new(conf_instance, storage, params)
249
+ end
250
+ end
251
+ end
252
+
253
+ def check_input_device
254
+ if request.env["HTTP_USER_AGENT"] && request.env["HTTP_USER_AGENT"][/(iPhone|iPod|iPad)/i]
255
+ session[:input_device_type] = 'TOUCH'
256
+ session[:hover_supported] = false
257
+ else
258
+ session[:input_device_type] = 'MOUSE'
259
+ session[:hover_supported] = true
260
+ end if session[:input_device_type].nil?
261
+ end
262
+
263
+ def touch_device?
264
+ session[:input_device_type] == 'TOUCH'
265
+ end
266
+
267
+ def hover_via_click?
268
+ session[:hover_supported] == false
269
+ end
270
+
237
271
  # call this method in your action_link action to simplify processing of actions
238
272
  # eg for member action_link :fire
239
273
  # process_action_link_action do |record|
@@ -19,7 +19,17 @@ module ActiveScaffold::Actions
19
19
 
20
20
  # NOTE: we don't check whether the user is allowed to update this record, because if not, we'll still let them associate the record. we'll just refuse to do more than associate, is all.
21
21
  @record = @column.association.klass.find(params[:associated_id]) if params[:associated_id]
22
- @record ||= build_associated(@column.association, @parent_record)
22
+ if @record
23
+ if association = active_scaffold_config.columns[params[:child_association]].association.reverse
24
+ if @record.class.reflect_on_association(association).collection?
25
+ @record.send(association) << @parent_record
26
+ else
27
+ @record.send("#{association}=", @parent_record)
28
+ end
29
+ end
30
+ else
31
+ @record = build_associated(@column.association, @parent_record)
32
+ end
23
33
  @scope = params[:scope]
24
34
  end
25
35
 
@@ -2,14 +2,6 @@ module ActiveScaffold
2
2
  module Core
3
3
  def self.included(base)
4
4
  base.extend(ClassMethods)
5
- base.module_eval do
6
- # TODO: these should be in actions/core
7
- before_filter :handle_user_settings
8
- before_filter :check_input_device
9
- end
10
-
11
- base.helper_method :touch_device?
12
- base.helper_method :hover_via_click?
13
5
  base.helper_method :active_scaffold_constraints
14
6
  end
15
7
 
@@ -36,36 +28,6 @@ module ActiveScaffold
36
28
  session_index = active_scaffold_session_storage_key
37
29
  session.delete(session_index) unless session[session_index].present?
38
30
  end
39
-
40
- # at some point we need to pass the session and params into config. we'll just take care of that before any particular action occurs by passing those hashes off to the UserSettings class of each action.
41
- def handle_user_settings
42
- if self.class.uses_active_scaffold?
43
- storage = active_scaffold_config.store_user_settings ? active_scaffold_session_storage : {}
44
- active_scaffold_config.actions.each do |action_name|
45
- conf_instance = active_scaffold_config.send(action_name) rescue next
46
- next if conf_instance.class::UserSettings == ActiveScaffold::Config::Base::UserSettings # if it hasn't been extended, skip it
47
- conf_instance.user = conf_instance.class::UserSettings.new(conf_instance, storage, params)
48
- end
49
- end
50
- end
51
-
52
- def check_input_device
53
- if request.env["HTTP_USER_AGENT"] && request.env["HTTP_USER_AGENT"][/(iPhone|iPod|iPad)/i]
54
- session[:input_device_type] = 'TOUCH'
55
- session[:hover_supported] = false
56
- else
57
- session[:input_device_type] = 'MOUSE'
58
- session[:hover_supported] = true
59
- end if session[:input_device_type].nil?
60
- end
61
-
62
- def touch_device?
63
- session[:input_device_type] == 'TOUCH'
64
- end
65
-
66
- def hover_via_click?
67
- session[:hover_supported] == false
68
- end
69
31
 
70
32
  module ClassMethods
71
33
  def active_scaffold(model_id = nil, &block)
@@ -121,8 +83,8 @@ module ActiveScaffold
121
83
  end
122
84
 
123
85
  module Prefixes
124
- def parent_prefixes
125
- @parent_prefixes ||= super << 'active_scaffold_overrides'
86
+ define_method Rails.version < '4.2' ? 'parent_prefixes' : 'local_prefixes' do
87
+ @local_prefixes ||= super() << 'active_scaffold_overrides'
126
88
  end
127
89
  end
128
90
 
@@ -273,5 +235,13 @@ module ActiveScaffold
273
235
  end
274
236
  raise ActiveScaffold::ControllerNotFound, "Could not find " + error_message.join(" or "), caller
275
237
  end
238
+
239
+ def self.column_type_cast(value, column)
240
+ if Rails.version < '4.2'
241
+ column.type_cast value
242
+ else
243
+ column.cast_type.type_cast_from_user value
244
+ end
245
+ end
276
246
  end
277
247
  end
@@ -26,7 +26,7 @@ module ActiveScaffold
26
26
  tokens.collect do |value|
27
27
  columns.inject([phrase]) do |condition, column|
28
28
  Array(column.search_sql).size.times do
29
- condition.push(column.text? ? like_pattern.sub('?', value) : column.column.type_cast(value))
29
+ condition.push(column.text? ? like_pattern.sub('?', value) : ActiveScaffold::Core.column_type_cast(value, column.column))
30
30
  end
31
31
  condition
32
32
  end
@@ -52,7 +52,7 @@ module ActiveScaffold
52
52
  else
53
53
  case search_ui
54
54
  when :boolean, :checkbox
55
- ["%{search_sql} = ?", column.column ? column.column.type_cast(value) : value]
55
+ ["%{search_sql} = ?", column.column ? ActiveScaffold::Core.column_type_cast(value, column.column) : value]
56
56
  when :integer, :decimal, :float
57
57
  condition_for_numeric(column, value)
58
58
  when :string, :range
@@ -65,7 +65,7 @@ module ActiveScaffold
65
65
  if column.text?
66
66
  ["%{search_sql} #{ActiveScaffold::Finder.like_operator} ?", like_pattern.sub('?', value)]
67
67
  else
68
- ["%{search_sql} = ?", column.column.type_cast(value)]
68
+ ["%{search_sql} = ?", ActiveScaffold::Core.column_type_cast(value, column.column)]
69
69
  end
70
70
  end
71
71
  end
@@ -100,7 +100,7 @@ module ActiveScaffold
100
100
  if column.text?
101
101
  ["%{search_sql} #{ActiveScaffold::Finder.like_operator} ?", like_pattern.sub('?', value)]
102
102
  else
103
- ["%{search_sql} = ?", column.column.type_cast(value)]
103
+ ["%{search_sql} = ?", ActiveScaffold::Core.column_type_cast(value, column.column)]
104
104
  end
105
105
  elsif ActiveScaffold::Finder::NullComparators.include?(value[:opt])
106
106
  condition_for_null_type(column, value[:opt], like_pattern)
@@ -109,6 +109,10 @@ module ActiveScaffold
109
109
  nil
110
110
  end
111
111
  end
112
+
113
+ def record_select_params_for_add_existing(association, edit_associated_url_options, record)
114
+ {:onselect => "ActiveScaffold.record_select_onselect(#{url_for(edit_associated_url_options).to_json}, #{active_scaffold_id.to_json}, id);"}
115
+ end
112
116
  end
113
117
  end
114
118
  end
@@ -38,7 +38,7 @@ module ActiveScaffold
38
38
  end
39
39
  as_(:association, :scope => :human_conditions, :column => column.active_record_class.human_attribute_name(column.name), :value => associated.join(', '))
40
40
  when :boolean, :checkbox
41
- label = column.column.type_cast(value) ? as_(:true) : as_(:false)
41
+ label = ActiveScaffold::Core.column_type_cast(value, column.column) ? as_(:true) : as_(:false)
42
42
  as_(:boolean, :scope => :human_conditions, :column => column.active_record_class.human_attribute_name(column.name), :value => label)
43
43
  when :null
44
44
  "#{column.active_record_class.human_attribute_name(column.name)} #{as_(value.to_sym)}"
@@ -193,7 +193,7 @@ module ActiveScaffold
193
193
  logger.warn "ActiveScaffold: Enable eager loading for #{column.name} association to reduce SQL queries"
194
194
  elsif column.associated_limit > 0
195
195
  # load at least one record more, is needed to display '...'
196
- association.target = association.reader.limit(column.associated_limit + 1).select(column.select_associated_columns || '*').to_a
196
+ association.target = association.reader.limit(column.associated_limit + 1).select(column.select_associated_columns || "#{association.klass.quoted_table_name}.*").to_a
197
197
  elsif @cache_associations
198
198
  association.target = []
199
199
  end
@@ -137,7 +137,7 @@ module ActiveScaffold
137
137
  select_options << [as_(:true), true]
138
138
  select_options << [as_(:false), false]
139
139
 
140
- select_tag(options[:name], options_for_select(select_options, column.column.type_cast(options[:value])), :id => options[:id])
140
+ select_tag(options[:name], options_for_select(select_options, ActiveScaffold::Core.column_type_cast(options[:value], column.column)), :id => options[:id])
141
141
  end
142
142
  # we can't use checkbox ui because it's not possible to decide whether search for this field or not
143
143
  alias_method :active_scaffold_search_checkbox, :active_scaffold_search_boolean
@@ -2,7 +2,7 @@ module ActiveScaffold
2
2
  module Version
3
3
  MAJOR = 3
4
4
  MINOR = 4
5
- PATCH = 12
5
+ PATCH = 13
6
6
 
7
7
  STRING = [MAJOR, MINOR, PATCH].compact.join('.')
8
8
  end
@@ -5,6 +5,7 @@ require 'test_helper'
5
5
  class ActionColumnsTest < MiniTest::Test
6
6
  def setup
7
7
  @columns = ActiveScaffold::DataStructures::ActionColumns.new([:a, :b])
8
+ @columns.action = stub(:core => stub(:model_id => 'model_stub'))
8
9
  end
9
10
 
10
11
  def test_label
@@ -0,0 +1,14 @@
1
+ require 'test_helper'
2
+
3
+ class SearchColumnHelpersTest < ActionView::TestCase
4
+ include ActiveScaffold::Helpers::SearchColumnHelpers
5
+
6
+ def setup
7
+ @column = ActiveScaffold::DataStructures::Column.new(:adult, Person)
8
+ @record = Person.new
9
+ end
10
+
11
+ def test_choices_for_boolean_search_ui
12
+ assert_dom_equal "<select name=\"search[adult]\"><option value=\"\">- select -</option>\n<option value=\"true\">True</option>\n<option value=\"false\" selected=\"selected\">False</option></select>", active_scaffold_search_boolean(@column, :object => @record, :name => "search[adult]", :value => '0')
13
+ end
14
+ end
@@ -92,6 +92,11 @@ class FinderTest < MiniTest::Test
92
92
  page = @klass.send :find_page, :pagination => :infinite
93
93
  end
94
94
 
95
+ def test_condition_for_column
96
+ column = ActiveScaffold::DataStructures::Column.new('adult', Person)
97
+ assert_equal ['"people"."adult" = ?', false], ClassWithFinder.condition_for_column(column, '0')
98
+ end
99
+
95
100
  private
96
101
  def relation_class
97
102
  @klass.active_scaffold_config.model.send(:relation).class
@@ -0,0 +1,9 @@
1
+ require 'test_helper'
2
+
3
+ class RenderTest < ActionController::TestCase
4
+ tests AddressesController
5
+ test 'render activescaffold views' do
6
+ get :index
7
+ assert_template 'list'
8
+ end
9
+ end
@@ -48,6 +48,7 @@ ActiveRecord::Schema.define do
48
48
  t.integer 'buildings_count', :null => false, :default => 0
49
49
  t.integer 'floors_count', :null => false, :default => 0
50
50
  t.integer 'contacts_count', :null => false, :default => 0
51
+ t.boolean 'adult', :null => false, :default => false
51
52
  t.datetime "created_at"
52
53
  t.datetime "updated_at"
53
54
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_scaffold
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.4.12
4
+ version: 3.4.13
5
5
  platform: ruby
6
6
  authors:
7
7
  - Many, see README
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-12-19 00:00:00.000000000 Z
11
+ date: 2015-01-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: shoulda
@@ -336,6 +336,7 @@ files:
336
336
  - test/helpers/form_column_helpers_test.rb
337
337
  - test/helpers/list_column_helpers_test.rb
338
338
  - test/helpers/pagination_helpers_test.rb
339
+ - test/helpers/search_column_helpers_test.rb
339
340
  - test/misc/active_record_permissions_test.rb
340
341
  - test/misc/attribute_params_test.rb
341
342
  - test/misc/calculation_test.rb
@@ -344,6 +345,7 @@ files:
344
345
  - test/misc/convert_numbers_format_test.rb
345
346
  - test/misc/finder_test.rb
346
347
  - test/misc/lang_test.rb
348
+ - test/misc/render_test.rb
347
349
  - test/misc/tableless_test.rb
348
350
  - test/mock_app/.gitignore
349
351
  - test/mock_app/Rakefile
@@ -462,6 +464,7 @@ test_files:
462
464
  - test/helpers/form_column_helpers_test.rb
463
465
  - test/helpers/list_column_helpers_test.rb
464
466
  - test/helpers/pagination_helpers_test.rb
467
+ - test/helpers/search_column_helpers_test.rb
465
468
  - test/misc/active_record_permissions_test.rb
466
469
  - test/misc/attribute_params_test.rb
467
470
  - test/misc/calculation_test.rb
@@ -470,6 +473,7 @@ test_files:
470
473
  - test/misc/convert_numbers_format_test.rb
471
474
  - test/misc/finder_test.rb
472
475
  - test/misc/lang_test.rb
476
+ - test/misc/render_test.rb
473
477
  - test/misc/tableless_test.rb
474
478
  - test/mock_app/.gitignore
475
479
  - test/mock_app/Rakefile