active_scaffold 3.4.37 → 3.4.38

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: a4cba196e4425cbbb6fbf33eb6e53865030e87cf
4
- data.tar.gz: ebf4fdae5434832d4c412c9d67f58a9d13aca510
3
+ metadata.gz: f85e22fd8b8ed0d15b333d211f081e24ee2484d6
4
+ data.tar.gz: 8b490194e7d7adc60a00d0a3c14d718948078c69
5
5
  SHA512:
6
- metadata.gz: dfc1186e00611b378bd728334cb52c9279df90bd02572abb27b31a3b39957181cd9aaae180397c186fa75850cbc8b44357b8f69797371ffc026ca833991a5776
7
- data.tar.gz: 9a1ab9e777c2703f022c36e6d031a16a7af211af985cd37aad4e22286814603782eccb881e61b96c022ff80f870c1e2b82844c6e6569cf973f6cc81a0da17ab2
6
+ metadata.gz: 4e238be107e91bde560a8eef3e60ce62d5018c3918a03779c3782f12f770e47ee68bafa96253b520629f437630e2e828f5e88266eb545117378024435fef4099
7
+ data.tar.gz: faf799e2a71c5c80fa71f6c8bd0f2fe84b580e01b793f52ac259520d90b2a5bc4e890383553e560a596f0c2388677c2935fa44febc3e97da9dd69f398fc7de1f
data/CHANGELOG CHANGED
@@ -1,3 +1,11 @@
1
+ = 3.4.38
2
+ - ensure add_existing and delete_existing are removed when list is not nested
3
+ - add :percentage list_ui, use jquery ui slider, set slider options on column.options[:slider], :value_method (default to column name), :min_method and :max_method to get value, min and max options from record
4
+ - fix default required for column with :checkbox form_ui and inclusion validator on rails 3.2
5
+ - fix search on habtm column on postgresql
6
+ - fix for format_number_value with nil
7
+ - add includes for sorting columns only if columns is not displayed, add to includes for postgresql, to outer_joins for others
8
+
1
9
  = 3.4.37
2
10
  - return valid css class for subgroups, e.g. when name with dot is used for translation scopes
3
11
  - check permissions for add existing and delete existing, use nested parent record authorized for update nested association column
@@ -296,12 +296,14 @@ jQuery(document).ready(function($) {
296
296
  ActiveScaffold.live_search(document);
297
297
  ActiveScaffold.auto_paginate(document);
298
298
  ActiveScaffold.draggable_lists('.draggable-lists', document);
299
+ ActiveScaffold.sliders(document);
299
300
  if (ActiveScaffold.config.warn_changes) ActiveScaffold.setup_warn_changes();
300
301
  jQuery(document).on('as:element_updated', function(e) {
301
302
  ActiveScaffold.load_embedded(e.target);
302
303
  ActiveScaffold.enable_js_form_buttons(e.target);
303
304
  ActiveScaffold.live_search(e.target);
304
305
  ActiveScaffold.draggable_lists('.draggable-lists', e.target);
306
+ ActiveScaffold.sliders(e.target);
305
307
  });
306
308
  jQuery(document).on('as:element_updated', '.active-scaffold', function(e) {
307
309
  if (e.target != this) return;
@@ -314,6 +316,7 @@ jQuery(document).ready(function($) {
314
316
  ActiveScaffold.live_search(action_link.adapter);
315
317
  ActiveScaffold.auto_paginate(action_link.adapter);
316
318
  ActiveScaffold.draggable_lists('.draggable-lists', action_link.adapter);
319
+ ActiveScaffold.sliders(action_link.adapter);
317
320
  });
318
321
  });
319
322
 
@@ -443,6 +446,13 @@ var ActiveScaffold = {
443
446
  enable_js_form_buttons: function(element) {
444
447
  jQuery('.as-js-button', element).show();
445
448
  },
449
+ sliders: function(element) {
450
+ $('.as-slider', element).each(function() {
451
+ var opts = $(this).data('slider');
452
+ $(this).slider(opts);
453
+ if (opts.disabled) $(this).find('.ui-slider-handle').hide();
454
+ });
455
+ },
446
456
  load_embedded: function(element) {
447
457
  jQuery('.active-scaffold-component .load-embedded', element).each(function(index, item) {
448
458
  item = jQuery(item);
@@ -52,3 +52,7 @@ float: none;
52
52
  .active-scaffold li.form-element dt {
53
53
  padding: 4px 0;
54
54
  }
55
+
56
+ .as-slider.ui-state-disabled {
57
+ filter: alpha(Opacity=100);
58
+ }
@@ -212,6 +212,18 @@ display:inline;
212
212
  text-align: right;
213
213
  }
214
214
 
215
+ .as-slider { display: block; }
216
+ .as-slider .ui-slider-range {
217
+ border: 0;
218
+ height: 100%;
219
+ border-radius: 5px;
220
+ border-top-right-radius: 0;
221
+ border-bottom-right-radius: 0;
222
+ }
223
+ .as-slider.ui-state-disabled {
224
+ opacity: 1;
225
+ }
226
+
215
227
  /* Table :: Actions (Edit, Delete)
216
228
  ============================= */
217
229
  .active-scaffold tr.record td.actions {
@@ -47,13 +47,14 @@ module ActiveScaffold::Actions
47
47
  filtered_columns = []
48
48
  text_search = active_scaffold_config.field_search.text_search
49
49
  columns = active_scaffold_config.field_search.columns
50
+ count_includes = active_scaffold_config.list.user.count_includes
50
51
  search_params.each do |key, value|
51
52
  next unless columns.include? key
52
53
  column = active_scaffold_config.columns[key]
53
54
  search_condition = self.class.condition_for_column(column, value, text_search)
54
55
  next if search_condition.blank?
55
56
 
56
- if active_scaffold_config.list.user.count_includes.nil? && column.includes.present? && list_columns.include?(column)
57
+ if count_includes.nil? && column.includes.present? && list_columns.include?(column)
57
58
  active_scaffold_references << column.includes
58
59
  elsif column.search_joins.present?
59
60
  active_scaffold_outer_joins << column.search_joins
@@ -64,7 +64,7 @@ module ActiveScaffold::Actions
64
64
  end
65
65
 
66
66
  # The actual algorithm to prepare for the list view
67
- def set_includes_for_columns(action = :list)
67
+ def set_includes_for_columns(action = :list, sorting = active_scaffold_config.list.user.sorting)
68
68
  @cache_associations = true
69
69
  columns =
70
70
  if respond_to?(:"#{action}_columns", true)
@@ -72,12 +72,33 @@ module ActiveScaffold::Actions
72
72
  else
73
73
  active_scaffold_config.send(action).columns.collect_visible(:flatten => true)
74
74
  end
75
- sorting = active_scaffold_config.list.user.sorting
76
- columns_for_joins, columns_for_includes = columns.select { |c| c.includes.present? }.partition do |c|
77
- sorting.sorts_on?(c) || (c.plural_association? && c.association.macro == :has_and_belongs_to_many && c.association.respond_to?(:scope) && c.association.scope)
75
+ joins_cols, preload_cols = columns.select { |c| c.includes.present? }.partition do |col|
76
+ includes_need_join?(col, sorting)
78
77
  end
79
- active_scaffold_preload.concat columns_for_includes.map(&:includes).flatten.uniq
80
- active_scaffold_references.concat columns_for_joins.map(&:includes).flatten.uniq
78
+ active_scaffold_references.concat joins_cols.map(&:includes).flatten.uniq
79
+ active_scaffold_preload.concat preload_cols.map(&:includes).flatten.uniq
80
+ set_includes_for_sorting(columns, sorting) if Rails::VERSION::MAJOR >= 4 && sorting.sorts_by_sql?
81
+ end
82
+
83
+ def set_includes_for_sorting(columns, sorting)
84
+ sorting.each do |col, _|
85
+ if col.includes.present? && !columns.include?(col)
86
+ if active_scaffold_config.model.connection.needs_order_expressions_in_select?
87
+ active_scaffold_references << col.includes
88
+ else
89
+ active_scaffold_outer_joins << col.includes
90
+ end
91
+ end
92
+ end
93
+ end
94
+
95
+ def includes_need_join?(column, sorting = active_scaffold_config.list.user.sorting)
96
+ sorting.sorts_on?(column) || scoped_habtm?(column)
97
+ end
98
+
99
+ def scoped_habtm?(column)
100
+ assoc = column.association if column.plural_association?
101
+ assoc && assoc.macro == :has_and_belongs_to_many && assoc.respond_to?(:scope) && assoc.scope
81
102
  end
82
103
 
83
104
  def get_row(crud_type_or_security_options = :read)
@@ -53,8 +53,7 @@ module ActiveScaffold::Actions
53
53
  end
54
54
 
55
55
  def include_habtm_actions
56
- return unless nested?
57
- if nested.habtm?
56
+ if nested? && nested.habtm?
58
57
  # Production mode is ok with adding a link everytime the scaffold is nested - we are not ok with that.
59
58
  active_scaffold_config.action_links.add('new_existing', :label => :add_existing, :type => :collection, :security_method => :add_existing_authorized?) unless active_scaffold_config.action_links['new_existing']
60
59
  if active_scaffold_config.nested.shallow_delete
@@ -26,11 +26,11 @@ module ActiveScaffold::Actions
26
26
  @filtered = !search_conditions.blank?
27
27
  active_scaffold_conditions.concat search_conditions if @filtered
28
28
 
29
- references, outer_joins = columns.partition { |column| column.includes.present? && list_columns.include?(column) }
30
- outer_joins.collect!(&:search_joins)
31
- references.collect!(&:includes)
32
- active_scaffold_outer_joins.concat outer_joins.flatten.uniq.compact
33
- active_scaffold_references.concat references.flatten.uniq.compact
29
+ references, outer_joins = columns.partition do |column|
30
+ column.includes.present? && list_columns.include?(column)
31
+ end
32
+ active_scaffold_references.concat references.map(&:includes).flatten.uniq.compact
33
+ active_scaffold_outer_joins.concat outer_joins.map(&:search_joins).flatten.uniq.compact
34
34
 
35
35
  active_scaffold_config.list.user.page = nil
36
36
  else
@@ -426,7 +426,8 @@ module ActiveScaffold::DataStructures
426
426
  end
427
427
 
428
428
  def inclusion_validator_for_checkbox?(val)
429
- @form_ui == :checkbox && [[true, false], [false, true]].include?(val.options[:with] || val.options[:within])
429
+ @form_ui == :checkbox &&
430
+ [[true, false], [false, true]].include?(val.options[:with] || val.options[:within] || val.options[:in])
430
431
  end
431
432
 
432
433
  def default_select_columns
@@ -20,9 +20,17 @@ module ActiveScaffold
20
20
  initializer 'active_scaffold.active_record' do
21
21
  ActiveSupport.on_load :active_record do
22
22
  include ActiveScaffold::ActiveRecordPermissions::ModelUserAccess::Model
23
- ActiveRecord::Associations::Association.send :include, ActiveScaffold::Tableless::Association
24
- ActiveRecord::Associations::CollectionAssociation.send :include, ActiveScaffold::Tableless::CollectionAssociation
25
- ActiveRecord::Associations::SingularAssociation.send :include, ActiveScaffold::Tableless::SingularAssociation
23
+ module ActiveRecord::Associations
24
+ Association.send :include, ActiveScaffold::Tableless::Association
25
+ CollectionAssociation.send :include, ActiveScaffold::Tableless::CollectionAssociation
26
+ SingularAssociation.send :include, ActiveScaffold::Tableless::SingularAssociation
27
+ end
28
+ module ActiveRecord::ConnectionAdapters
29
+ AbstractAdapter.send :include, ActiveScaffold::ConnectionAdapters::AbstractAdapter
30
+ if defined?(PostgreSQLAdapter)
31
+ PostgreSQLAdapter.send :include, ActiveScaffold::ConnectionAdapters::PostgreSQLAdapter
32
+ end
33
+ end
26
34
  end
27
35
  end
28
36
 
@@ -0,0 +1,15 @@
1
+ module ActiveScaffold
2
+ module ConnectionAdapters
3
+ module AbstractAdapter
4
+ def needs_order_expressions_in_select?
5
+ false
6
+ end
7
+ end
8
+
9
+ module PostgreSQLAdapter
10
+ def needs_order_expressions_in_select?
11
+ true
12
+ end
13
+ end
14
+ end
15
+ end
@@ -352,11 +352,6 @@ module ActiveScaffold
352
352
  :select => options[:select]
353
353
  }
354
354
  if Rails::VERSION::MAJOR >= 4
355
- if options[:sorting].try(:sorts_by_sql?)
356
- options[:sorting].each do |col, _|
357
- finder_options[:outer_joins] << col.includes if col.includes.present?
358
- end
359
- end
360
355
  finder_options.merge!(:references => active_scaffold_references)
361
356
  end
362
357
 
@@ -14,8 +14,8 @@ module ActiveScaffold
14
14
  nested_parent_record.id
15
15
  end
16
16
 
17
- def nested_id
18
- "#{nested.parent_scaffold.controller_path}-#{nested_parent_id}-#{params[:controller]}" if nested?
17
+ def nested_id(controller = params[:controller])
18
+ "#{nested.parent_scaffold.controller_path}-#{nested_parent_id}-#{controller}" if nested?
19
19
  end
20
20
 
21
21
  def active_scaffold_id
@@ -84,6 +84,14 @@ module ActiveScaffold
84
84
  options.delete(:disabled) if inplace_edit?(record, column)
85
85
  check_box(:record, column.name, options)
86
86
  end
87
+
88
+ def active_scaffold_column_percentage(record, column)
89
+ options = column.options[:slider] || {}
90
+ options = options.merge(min: record.send(options[:min_method])) if options[:min_method]
91
+ options = options.merge(max: record.send(options[:max_method])) if options[:max_method]
92
+ value = record.send(options[:value_method]) if options[:value_method]
93
+ as_slider options.merge(value: value || record.send(column.name))
94
+ end
87
95
 
88
96
  def column_override(column)
89
97
  override_helper column, 'column'
@@ -124,17 +132,19 @@ module ActiveScaffold
124
132
  end
125
133
 
126
134
  def format_number_value(value, options = {})
127
- value = case options[:format]
128
- when :size
129
- number_to_human_size(value, options[:i18n_options] || {})
130
- when :percentage
131
- number_to_percentage(value, options[:i18n_options] || {})
132
- when :currency
133
- number_to_currency(value, options[:i18n_options] || {})
134
- when :i18n_number
135
- send("number_with_#{value.is_a?(Integer) ? 'delimiter' : 'precision'}", value, options[:i18n_options] || {})
136
- else
137
- value
135
+ if value
136
+ value = case options[:format]
137
+ when :size
138
+ number_to_human_size(value, options[:i18n_options] || {})
139
+ when :percentage
140
+ number_to_percentage(value, options[:i18n_options] || {})
141
+ when :currency
142
+ number_to_currency(value, options[:i18n_options] || {})
143
+ when :i18n_number
144
+ send("number_with_#{value.is_a?(Integer) ? 'delimiter' : 'precision'}", value, options[:i18n_options] || {})
145
+ else
146
+ value
147
+ end
138
148
  end
139
149
  clean_column_value(value)
140
150
  end
@@ -541,6 +541,10 @@ module ActiveScaffold
541
541
  def format_column_calculation(column, calculation)
542
542
  "#{"#{as_(column.calculate)}: " unless column.calculate.is_a? Proc}#{format_column_value nil, column, calculation}"
543
543
  end
544
+
545
+ def as_slider(options)
546
+ content_tag(:span, '', class: 'as-slider', data: {slider: options})
547
+ end
544
548
 
545
549
  def clean_column_name(name)
546
550
  name.to_s.gsub('?', '')
@@ -2,7 +2,7 @@ module ActiveScaffold
2
2
  module Version
3
3
  MAJOR = 3
4
4
  MINOR = 4
5
- PATCH = 37
5
+ PATCH = 38
6
6
 
7
7
  STRING = [MAJOR, MINOR, PATCH].compact.join('.')
8
8
  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.37
4
+ version: 3.4.38
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: 2016-04-12 00:00:00.000000000 Z
11
+ date: 2016-05-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -302,6 +302,7 @@ files:
302
302
  - lib/active_scaffold/extensions/action_controller_rendering.rb
303
303
  - lib/active_scaffold/extensions/action_controller_rescueing.rb
304
304
  - lib/active_scaffold/extensions/action_view_rendering.rb
305
+ - lib/active_scaffold/extensions/connection_adapter.rb
305
306
  - lib/active_scaffold/extensions/left_outer_joins.rb
306
307
  - lib/active_scaffold/extensions/localize.rb
307
308
  - lib/active_scaffold/extensions/name_option_for_datetime.rb