active_scaffold 3.6.0.rc2 → 3.6.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.rdoc +20 -0
- data/README.md +10 -9
- data/app/assets/javascripts/jquery/active_scaffold.js +2 -2
- data/app/views/active_scaffold_overrides/_field_search.html.erb +8 -0
- data/app/views/active_scaffold_overrides/_form_association_record.html.erb +18 -4
- data/app/views/active_scaffold_overrides/_search.html.erb +7 -0
- data/lib/active_scaffold/actions/list.rb +1 -1
- data/lib/active_scaffold/bridges/bitfields/list_ui.rb +19 -0
- data/lib/active_scaffold/bridges/bitfields.rb +1 -1
- data/lib/active_scaffold/config/list.rb +1 -1
- data/lib/active_scaffold/data_structures/action_columns.rb +1 -1
- data/lib/active_scaffold/data_structures/nested_info.rb +2 -2
- data/lib/active_scaffold/extensions/action_view_rendering.rb +66 -25
- data/lib/active_scaffold/extensions/cow_proxy.rb +0 -4
- data/lib/active_scaffold/extensions/localize.rb +1 -1
- data/lib/active_scaffold/helpers/form_column_helpers.rb +2 -2
- data/lib/active_scaffold/helpers/list_column_helpers.rb +6 -2
- data/lib/active_scaffold/helpers/search_column_helpers.rb +14 -7
- data/lib/active_scaffold/helpers/view_helpers.rb +1 -1
- data/lib/active_scaffold/tableless.rb +16 -2
- data/lib/active_scaffold/version.rb +1 -1
- data/lib/generators/active_scaffold/install_generator.rb +51 -3
- data/test/data_structures/action_columns_test.rb +1 -1
- data/test/extensions/action_view_rendering_test.rb +20 -0
- data/test/misc/constraints_test.rb +1 -1
- data/test/misc/tableless_test.rb +8 -0
- data/test/mock_app/app/controllers/people_controller.rb +2 -0
- data/test/mock_app/app/controllers/roles_controller.rb +4 -0
- data/test/mock_app/app/views/active_scaffold_overrides/_form.html.erb +2 -0
- data/test/mock_app/app/views/active_scaffold_overrides/list.html.erb +2 -0
- data/test/mock_app/app/views/people/_first_name_form_column.html.erb +2 -0
- data/test/mock_app/app/views/people/_form.html.erb +2 -0
- data/test/mock_app/app/views/people/list.html.erb +2 -0
- data/test/test_helper.rb +2 -2
- metadata +26 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a5f95a3c7624f3802f29e275341ce3184e9979d91644b48395126b4009fd103e
|
4
|
+
data.tar.gz: af61fae0cf8128ec58d90f4e40b6cbdb95400d5491e790a638bafb1dd8bb4909
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 35795f0bf6eb16148401b4df273c93a02064a3c25d100e58aa17c9de97f48629be77ad4043e30e73e25e208f49318a4ffe877f1d0a2ffee61147fa2cfe8dcc0d
|
7
|
+
data.tar.gz: 8be4d03e807f6a621b7812854d062d472d51047399e435303be25ce85522a29486b8d4d48acf6b7d2e72f22def1960c8801e6409bc45651483d15ff2ec9c9a94
|
data/CHANGELOG.rdoc
CHANGED
@@ -1,3 +1,23 @@
|
|
1
|
+
= 3.6.3
|
2
|
+
- Fix search on nested or embedded lists with rails_ujs
|
3
|
+
- Fix inplace edit when collection action link opens a view with table and th
|
4
|
+
|
5
|
+
= 3.6.2
|
6
|
+
- Fix count query when association's primary key is string
|
7
|
+
- Fix unauthorized_columns and constraint_columns with threadsafe enabled
|
8
|
+
- Fix changing list.sorting and column.sort_by per request when threadsafe is enabled
|
9
|
+
|
10
|
+
= 3.6.1
|
11
|
+
- Display group cols vertically when subform layout is vertical
|
12
|
+
- Fix html attributes for input datetime on field search, when jquery ui is not used
|
13
|
+
- Fix constraint columns for nested list on through assocaitions
|
14
|
+
- Support rails 6.1
|
15
|
+
|
16
|
+
= 3.6.0
|
17
|
+
- Fix i18n at ruby 3.0.0
|
18
|
+
- Add list helper for bitfield column, so it display labels of selected checkboxes in list
|
19
|
+
- Support rails 6.0
|
20
|
+
|
1
21
|
= 3.6.0.rc2
|
2
22
|
- Fix subform crud in subform subgroup when controller is embedded
|
3
23
|
- Fix sorting for mongoid models, broken in 3.6.0.rc1
|
data/README.md
CHANGED
@@ -1,6 +1,7 @@
|
|
1
|
+
|
1
2
|
Overview
|
2
3
|
========
|
3
|
-
[![Build status](https://travis-ci.
|
4
|
+
[![Build status](https://travis-ci.com/activescaffold/active_scaffold.svg?branch=master)](https://travis-ci.com/activescaffold/active_scaffold)
|
4
5
|
[![Code Climate](https://codeclimate.com/github/activescaffold/active_scaffold/badges/gpa.svg)](https://codeclimate.com/github/activescaffold/active_scaffold)
|
5
6
|
[![Test Coverage](https://codeclimate.com/github/activescaffold/active_scaffold/badges/coverage.svg)](https://codeclimate.com/github/activescaffold/active_scaffold)
|
6
7
|
[![Dependency Status](https://gemnasium.com/activescaffold/active_scaffold.svg)](https://gemnasium.com/activescaffold/active_scaffold)
|
@@ -8,13 +9,13 @@ Overview
|
|
8
9
|
[![Inline docs](https://inch-ci.org/github/activescaffold/active_scaffold.svg?branch=master)](https://inch-ci.org/github/activescaffold/active_scaffold)
|
9
10
|
[![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT)
|
10
11
|
|
11
|
-
ActiveScaffold provides a quick and powerful user interfaces for CRUD (create, read, update, delete) operations for Rails applications. It offers additonal features including searching, pagination & layout control. Rails >= 4.2.0 is supported, ruby >= 2.3 required.
|
12
|
+
ActiveScaffold provides a quick and powerful user interfaces for CRUD (create, read, update, delete) operations for Rails applications. It offers additonal features including searching, pagination & layout control. Rails >= 4.2.0 and Rails <= 6.1 is supported, ruby >= 2.3 required.
|
12
13
|
|
13
14
|
Branch Details
|
14
15
|
--------------
|
15
|
-
3-5-stable supports rails >= 4.0.x and ruby >= 2.0.0
|
16
|
-
3-4-stable supports rails >= 3.2.x and ruby >= 1.9.3
|
17
|
-
3-3-stable supports rails
|
16
|
+
3-5-stable supports rails >= 4.0.x and <= 5.1.x, and ruby >= 2.0.0
|
17
|
+
3-4-stable supports rails >= 3.2.x and <= 4.2.x, and ruby >= 1.9.3
|
18
|
+
3-3-stable supports rails 3.2.x and ruby >= 1.8
|
18
19
|
rails-3.2 supports Rails 3.1 & 3.2, and is the current source of the 3.2.x line of gems.
|
19
20
|
|
20
21
|
Quick Start
|
@@ -25,12 +26,12 @@ Added to Gemfile
|
|
25
26
|
|
26
27
|
gem 'active_scaffold'
|
27
28
|
|
28
|
-
For rails >= 5.1, add jquery to application.js before rails-ujs
|
29
|
-
|
30
|
-
//= require jquery
|
29
|
+
For rails >= 5.1, add jquery-rails to Gemfile, and install generator will jquery to application.js before rails-ujs. Also it's possible to load jquery in your layout before application.js using CDN (e.g. jquery-rails-cdn). You can replace rails-ujs with jquery_ujs, although rails-ujs should work (never load both).
|
31
30
|
|
32
31
|
gem 'jquery-rails'
|
33
32
|
|
33
|
+
For rails >= 6.0, installer generator will create app/assets/javascripts/application.js, add it to assets.precompile array and add javascript_include_tag in layout, as ActiveScaffold doesn't work with webpack yet. Jquery may be loaded by packs or assets pipeline.
|
34
|
+
|
34
35
|
Run the following commands, for rails 4.2
|
35
36
|
|
36
37
|
bundle install
|
@@ -39,7 +40,7 @@ Run the following commands, for rails 4.2
|
|
39
40
|
rails g active_scaffold:resource Model [attrs]
|
40
41
|
bundle exec rake db:migrate
|
41
42
|
|
42
|
-
Or run the following commands, for rails 5
|
43
|
+
Or run the following commands, for rails >= 5
|
43
44
|
|
44
45
|
bundle install
|
45
46
|
rails g active_scaffold:install
|
@@ -1024,7 +1024,7 @@ var ActiveScaffold = {
|
|
1024
1024
|
|
1025
1025
|
if (my_parent.is('td')) {
|
1026
1026
|
var column_no = my_parent.prevAll('td').length;
|
1027
|
-
column_heading = my_parent.closest('
|
1027
|
+
column_heading = my_parent.closest('table').find('th:eq(' + column_no + ')');
|
1028
1028
|
} else if (my_parent.is('th')) {
|
1029
1029
|
column_heading = my_parent;
|
1030
1030
|
}
|
@@ -1464,7 +1464,7 @@ ActiveScaffold.ActionLink.Table = ActiveScaffold.ActionLink.Abstract.extend({
|
|
1464
1464
|
else {
|
1465
1465
|
throw 'Unknown position "' + this.position + '"'
|
1466
1466
|
}
|
1467
|
-
ActiveScaffold.highlight(this.adapter.find('td').first().children());
|
1467
|
+
ActiveScaffold.highlight(this.adapter.find('td').first().children().not('script'));
|
1468
1468
|
ActiveScaffold.focus_first_element_of_form(this.adapter);
|
1469
1469
|
}
|
1470
1470
|
});
|
@@ -9,8 +9,16 @@
|
|
9
9
|
data: {loading: true},
|
10
10
|
method: :get
|
11
11
|
}
|
12
|
+
|
13
|
+
hidden_params = url_options.except(:controller, :action, :id, :search).to_query.split(Rack::Utils::DEFAULT_SEP)
|
12
14
|
-%>
|
15
|
+
|
13
16
|
<%= form_tag url_options, options %>
|
17
|
+
<% hidden_params.each do |pair| -%>
|
18
|
+
<% key, value = pair.split('=', 2).map { |str| Rack::Utils.unescape(str) } -%>
|
19
|
+
<%= hidden_field_tag(key, value) %>
|
20
|
+
<% end -%>
|
21
|
+
|
14
22
|
<ol class="form">
|
15
23
|
<% visibles, hiddens = visibles_and_hiddens(active_scaffold_config.field_search) %>
|
16
24
|
<% visibles.each do |column| -%>
|
@@ -84,10 +84,24 @@
|
|
84
84
|
|
85
85
|
<% columns_groups.each do |columns_group| %>
|
86
86
|
<%= content_tag row_tag, :class => 'associated-record' do %>
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
87
|
+
<% if layout == :vertical %>
|
88
|
+
<% columns_group.each_column(for: record.class, crud_type: :read, flatten: true) do |col| %>
|
89
|
+
<%
|
90
|
+
col_class = default_col_class.clone
|
91
|
+
col_class << 'required' if col.required?
|
92
|
+
col_class << col.css_class unless col.css_class.nil? || col.css_class.is_a?(Proc)
|
93
|
+
col_class << 'hidden' if column_renders_as(col) == :hidden
|
94
|
+
%>
|
95
|
+
<%= content_tag column_tag, :class => col_class, :colspan => (columns_length if column_tag == :td) do %>
|
96
|
+
<%= active_scaffold_render_subform_column(col, scope, crud_type, readonly, false, record) %>
|
97
|
+
<% end %>
|
98
|
+
<% end %>
|
99
|
+
<% else %>
|
100
|
+
<%= content_tag column_tag, :colspan => (columns_length if column_tag == :td) do %>
|
101
|
+
<% columns_group.each_column(for: record.class, crud_type: :read, flatten: true) do |col| %>
|
102
|
+
<%= active_scaffold_render_subform_column(col, scope, crud_type, readonly, true, record) %>
|
103
|
+
<% end %>
|
104
|
+
<% end %>
|
91
105
|
<% end %>
|
92
106
|
<% end %>
|
93
107
|
<% end %>
|
@@ -10,8 +10,15 @@
|
|
10
10
|
data: {loading: true},
|
11
11
|
method: :get
|
12
12
|
}
|
13
|
+
|
14
|
+
hidden_params = url_options.except(:controller, :action, :id, :search).to_query.split(Rack::Utils::DEFAULT_SEP)
|
13
15
|
-%>
|
16
|
+
|
14
17
|
<%= form_tag url_options, options do %>
|
18
|
+
<% hidden_params.each do |pair| -%>
|
19
|
+
<% key, value = pair.split('=', 2).map { |str| Rack::Utils.unescape(str) } -%>
|
20
|
+
<%= hidden_field_tag(key, value) %>
|
21
|
+
<% end -%>
|
15
22
|
<%= 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) %>
|
16
23
|
<%= submit_tag as_(submit_text), :class => "submit", :style => ('display:none;' if live_search) %>
|
17
24
|
<%= link_to as_(:reset), url_for(url_options.merge(:search => '')), :class => 'as_cancel reset', :remote => true, :data => {:refresh => true} unless local_assigns[:skip_reset] %>
|
@@ -161,7 +161,7 @@ module ActiveScaffold::Actions
|
|
161
161
|
|
162
162
|
def count_query_on_association_class(column)
|
163
163
|
key = column.association.primary_key || :id
|
164
|
-
query = column.association.klass.where(column.association.foreign_key => @records.map(&key))
|
164
|
+
query = column.association.klass.where(column.association.foreign_key => @records.map(&key.to_sym))
|
165
165
|
if column.association.as
|
166
166
|
query.where!(column.association.reverse_association.foreign_type => active_scaffold_config.model.name)
|
167
167
|
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module ActiveScaffold
|
2
|
+
module Bridges
|
3
|
+
class Bitfields
|
4
|
+
module ListColumnHelpers
|
5
|
+
def format_column_value(record, column, value = nil)
|
6
|
+
if record.class.respond_to?(:bitfields) && record.class.bitfields&.include?(column.name)
|
7
|
+
value = record.bitfield_values(column.name).select { |_, v| v }.keys
|
8
|
+
safe_join active_scaffold_config.columns.select { |c| c.name.in? value }.map(&:label), ', '
|
9
|
+
else
|
10
|
+
super
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
ActionView::Base.class_eval do
|
18
|
+
include ActiveScaffold::Bridges::Bitfields::ListColumnHelpers
|
19
|
+
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
class ActiveScaffold::Bridges::Bitfields < ActiveScaffold::DataStructures::Bridge
|
2
2
|
def self.install
|
3
|
-
|
3
|
+
Dir[File.join(__dir__, 'bitfields', '*.rb')].each { |file| require file }
|
4
4
|
ActiveScaffold::Config::Core.send :prepend, ActiveScaffold::Bridges::Bitfields::BitfieldsBridge
|
5
5
|
ActiveScaffold::Config::Core.after_config_callbacks << :_setup_bitfields
|
6
6
|
end
|
@@ -292,7 +292,7 @@ module ActiveScaffold::Config
|
|
292
292
|
@_sorting = sorting
|
293
293
|
else
|
294
294
|
@_sorting = default_sorting
|
295
|
-
@_sorting.set(
|
295
|
+
@_sorting.set(*@sorting) if @sorting
|
296
296
|
if @conf.columns.constraint_columns.present?
|
297
297
|
@_sorting.constraint_columns = @conf.columns.constraint_columns
|
298
298
|
end
|
@@ -131,8 +131,8 @@ module ActiveScaffold::DataStructures
|
|
131
131
|
protected
|
132
132
|
|
133
133
|
def setup_constrained_fields
|
134
|
-
@constrained_fields =
|
135
|
-
@constrained_fields ||=
|
134
|
+
@constrained_fields = [] if association.belongs_to? || association.through?
|
135
|
+
@constrained_fields ||= Array(association.foreign_key).map(&:to_sym)
|
136
136
|
return unless child_association && child_association != association
|
137
137
|
|
138
138
|
@constrained_fields << child_association.name
|
@@ -45,31 +45,7 @@ module ActiveScaffold #:nodoc:
|
|
45
45
|
@_view_paths ||= lookup_context.view_paths.clone
|
46
46
|
@_last_template ||= lookup_context.last_template
|
47
47
|
end
|
48
|
-
|
49
|
-
template = parts.pop
|
50
|
-
prefix = parts.join('/')
|
51
|
-
|
52
|
-
options = args[1] || {}
|
53
|
-
options[:locals] ||= {}
|
54
|
-
if view_stack.last
|
55
|
-
options[:locals] = view_stack.last[:locals].merge!(options[:locals]) if view_stack.last[:locals]
|
56
|
-
options[:object] ||= view_stack.last[:object] if view_stack.last[:object]
|
57
|
-
end
|
58
|
-
options[:template] = template
|
59
|
-
# if prefix is active_scaffold_overrides we must try to render with this prefix in following paths
|
60
|
-
if prefix != 'active_scaffold_overrides'
|
61
|
-
options[:prefixes] = lookup_context.prefixes.drop((lookup_context.prefixes.find_index(prefix) || -1) + 1)
|
62
|
-
else
|
63
|
-
options[:prefixes] = ['active_scaffold_overrides']
|
64
|
-
last_view_path = File.expand_path(File.dirname(File.dirname(lookup_context.last_template.inspect)), Rails.root)
|
65
|
-
new_view_paths = view_paths.drop(view_paths.find_index { |path| path.to_s == last_view_path } + 1)
|
66
|
-
if @lookup_context
|
67
|
-
@lookup_context = build_lookup_context(new_view_paths)
|
68
|
-
else
|
69
|
-
lookup_context.view_paths = new_view_paths
|
70
|
-
end
|
71
|
-
end
|
72
|
-
result = super options
|
48
|
+
result = super options_for_render_super(args[1])
|
73
49
|
@lookup_context = @_lookup_context if @_lookup_context # rails 6
|
74
50
|
lookup_context.view_paths = @_view_paths if @_view_paths # rails < 6
|
75
51
|
lookup_context.last_template = @_last_template if @_last_template # rails < 6
|
@@ -103,6 +79,46 @@ module ActiveScaffold #:nodoc:
|
|
103
79
|
|
104
80
|
private
|
105
81
|
|
82
|
+
def options_for_render_super(options)
|
83
|
+
options ||= {}
|
84
|
+
options[:locals] ||= {}
|
85
|
+
if view_stack.last
|
86
|
+
options[:locals] = view_stack.last[:locals].merge!(options[:locals]) if view_stack.last[:locals]
|
87
|
+
options[:object] ||= view_stack.last[:object] if view_stack.last[:object]
|
88
|
+
end
|
89
|
+
|
90
|
+
parts = @virtual_path.split('/')
|
91
|
+
options[:template] = parts.pop
|
92
|
+
prefix = parts.join('/')
|
93
|
+
# if prefix is active_scaffold_overrides we must try to render with this prefix in following paths
|
94
|
+
if prefix != 'active_scaffold_overrides'
|
95
|
+
options[:prefixes] = lookup_context.prefixes.drop((lookup_context.prefixes.find_index(prefix) || -1) + 1)
|
96
|
+
else
|
97
|
+
options[:prefixes] = ['active_scaffold_overrides']
|
98
|
+
update_view_paths
|
99
|
+
end
|
100
|
+
options
|
101
|
+
end
|
102
|
+
|
103
|
+
def update_view_paths
|
104
|
+
last_view_path =
|
105
|
+
if @lookup_context # rails 6
|
106
|
+
File.expand_path(File.dirname(File.dirname(@lookup_context.last_template.short_identifier.to_s)), Rails.root)
|
107
|
+
else
|
108
|
+
File.expand_path(File.dirname(File.dirname(lookup_context.last_template.inspect)), Rails.root)
|
109
|
+
end
|
110
|
+
new_view_paths = view_paths.drop(view_paths.find_index { |path| path.to_s == last_view_path } + 1)
|
111
|
+
if @lookup_context # rails 6
|
112
|
+
if respond_to? :build_lookup_context # rails 6.0
|
113
|
+
build_lookup_context(new_view_paths)
|
114
|
+
else # rails 6.1
|
115
|
+
@lookup_context = ActionView::LookupContext.new(new_view_paths)
|
116
|
+
end
|
117
|
+
else
|
118
|
+
lookup_context.view_paths = new_view_paths
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
106
122
|
def render_embedded(options)
|
107
123
|
require 'digest/md5'
|
108
124
|
|
@@ -153,5 +169,30 @@ module ActionView
|
|
153
169
|
Base.class_eval do
|
154
170
|
include ActiveScaffold::RenderingHelper
|
155
171
|
end
|
172
|
+
|
173
|
+
if Gem.loaded_specs['rails'].version.segments.first >= 6
|
174
|
+
RenderingHelper.class_eval do
|
175
|
+
# override the render method to use our @lookup_context instead of the
|
176
|
+
# memoized @_lookup_context
|
177
|
+
def render(options = {}, locals = {}, &block)
|
178
|
+
case options
|
179
|
+
when Hash
|
180
|
+
in_rendering_context(options) do |_|
|
181
|
+
# previously set view paths and lookup context are lost here
|
182
|
+
# if you use view_renderer, so instead create a new renderer
|
183
|
+
# with our context
|
184
|
+
temp_renderer = ActionView::Renderer.new(@lookup_context)
|
185
|
+
if block_given?
|
186
|
+
temp_renderer.render_partial(self, options.merge(partial: options[:layout]), &block)
|
187
|
+
else
|
188
|
+
temp_renderer.render(self, options)
|
189
|
+
end
|
190
|
+
end
|
191
|
+
else
|
192
|
+
view_renderer.render_partial(self, partial: options, locals: locals, &block)
|
193
|
+
end
|
194
|
+
end
|
195
|
+
end
|
196
|
+
end
|
156
197
|
end
|
157
198
|
end
|
@@ -3,7 +3,7 @@ class Object
|
|
3
3
|
if key.present?
|
4
4
|
scope = [:active_scaffold, *options.delete(:scope)]
|
5
5
|
options = options.reverse_merge(:scope => scope, :default => key.is_a?(String) ? key : key.to_s.titleize)
|
6
|
-
text = I18n.translate(key.to_s, options).html_safe # rubocop:disable Rails/OutputSafety
|
6
|
+
text = I18n.translate(key.to_s, **options).html_safe # rubocop:disable Rails/OutputSafety
|
7
7
|
# text = nil if text.include?('translation missing:')
|
8
8
|
end
|
9
9
|
text || key
|
@@ -740,14 +740,14 @@ module ActiveScaffold
|
|
740
740
|
|
741
741
|
# Minimum
|
742
742
|
unless options[:min]
|
743
|
-
min = validators.map { |v| v.options[:
|
743
|
+
min = validators.map { |v| v.options[:greater_than_or_equal_to] }.compact.max
|
744
744
|
greater_than = validators.map { |v| v.options[:greater_than] }.compact.max
|
745
745
|
numerical_constraints[:min] = [min, (greater_than + margin if greater_than)].compact.max
|
746
746
|
end
|
747
747
|
|
748
748
|
# Maximum
|
749
749
|
unless options[:max]
|
750
|
-
max = validators.map { |v| v.options[:
|
750
|
+
max = validators.map { |v| v.options[:less_than_or_equal_to] }.compact.min
|
751
751
|
less_than = validators.map { |v| v.options[:less_than] }.compact.min
|
752
752
|
numerical_constraints[:max] = [max, (less_than - margin if less_than)].compact.min
|
753
753
|
end
|
@@ -170,8 +170,12 @@ module ActiveScaffold
|
|
170
170
|
|
171
171
|
def column_association_size(record, column, value)
|
172
172
|
cached_counts = @counts&.dig(column.name)
|
173
|
-
|
174
|
-
|
173
|
+
if cached_counts
|
174
|
+
key = column.association.primary_key if count_on_association_class?(column)
|
175
|
+
cached_counts[record.send(key || :id)] || 0
|
176
|
+
else
|
177
|
+
value.size
|
178
|
+
end
|
175
179
|
end
|
176
180
|
|
177
181
|
def format_number_value(value, options = {})
|
@@ -245,16 +245,23 @@ module ActiveScaffold
|
|
245
245
|
options = column.options.merge(options)
|
246
246
|
type = "#{'date' unless options[:discard_date]}#{'time' unless options[:discard_time]}"
|
247
247
|
use_select = options.delete(:use_select)
|
248
|
-
|
248
|
+
from_name = "#{options[:name]}[from]"
|
249
|
+
to_name = "#{options[:name]}[to]"
|
249
250
|
if use_select
|
250
|
-
|
251
|
-
|
251
|
+
helper = "select_#{type}"
|
252
|
+
fields = [
|
253
|
+
send(helper, field_search_datetime_value(from_value), options.reverse_merge(include_blank: true, prefix: from_name)),
|
254
|
+
send(helper, field_search_datetime_value(to_value), options.reverse_merge(include_blank: true, prefix: to_name))
|
255
|
+
]
|
256
|
+
else
|
257
|
+
helper = "#{type}#{'_local' if type == 'datetime'}_field_tag"
|
258
|
+
fields = [
|
259
|
+
send(helper, from_name, field_search_datetime_value(from_value), options.except(:name, :object).merge(id: "#{options[:id]}_from")),
|
260
|
+
send(helper, to_name, field_search_datetime_value(to_value), options.except(:name, :object).merge(id: "#{options[:id]}_to"))
|
261
|
+
]
|
252
262
|
end
|
253
263
|
|
254
|
-
safe_join
|
255
|
-
send(helper, field_search_datetime_value(from_value), options.reverse_merge(default_from_options || {})),
|
256
|
-
send(helper, field_search_datetime_value(to_value), options.reverse_merge(default_to_options || {}))
|
257
|
-
], ' - '
|
264
|
+
safe_join fields, ' - '
|
258
265
|
end
|
259
266
|
|
260
267
|
def active_scaffold_search_date(column, options)
|
@@ -41,7 +41,7 @@ module ActiveScaffold
|
|
41
41
|
restore_view_paths = lookup_context.view_paths
|
42
42
|
lookup_context.view_paths = @_view_paths
|
43
43
|
end
|
44
|
-
lookup_context.exists?(template_name, '', partial).tap do
|
44
|
+
(@_lookup_context || lookup_context).exists?(template_name, '', partial).tap do
|
45
45
|
lookup_context.view_paths = restore_view_paths if @_view_paths
|
46
46
|
end
|
47
47
|
end
|
@@ -34,11 +34,17 @@ class ActiveScaffold::Tableless < ActiveRecord::Base # rubocop:disable Rails/App
|
|
34
34
|
def columns(table_name)
|
35
35
|
klass.columns
|
36
36
|
end
|
37
|
+
|
38
|
+
if Rails.version >= '6.0.0'
|
39
|
+
def data_sources
|
40
|
+
klass ? [klass.table_name] : []
|
41
|
+
end
|
42
|
+
end
|
37
43
|
end
|
38
44
|
|
39
45
|
class Column < ActiveRecord::ConnectionAdapters::Column
|
40
46
|
if Rails.version >= '5.0.0'
|
41
|
-
def initialize(name, default, sql_type = nil, null = true)
|
47
|
+
def initialize(name, default, sql_type = nil, null = true, **)
|
42
48
|
metadata = ActiveRecord::Base.connection.send :fetch_type_metadata, sql_type
|
43
49
|
super(name, default, metadata, null)
|
44
50
|
end
|
@@ -149,9 +155,17 @@ class ActiveScaffold::Tableless < ActiveRecord::Base # rubocop:disable Rails/App
|
|
149
155
|
def execute_simple_calculation(operation, column_name, distinct)
|
150
156
|
@klass.execute_simple_calculation(self, operation, column_name, distinct)
|
151
157
|
end
|
158
|
+
|
159
|
+
def implicit_order_column
|
160
|
+
@klass.implicit_order_column
|
161
|
+
end
|
162
|
+
|
163
|
+
def exists?
|
164
|
+
limit(1).to_a.present?
|
165
|
+
end
|
152
166
|
end
|
153
167
|
|
154
|
-
class Relation < ActiveRecord::Relation
|
168
|
+
class Relation < ::ActiveRecord::Relation
|
155
169
|
include RelationExtension
|
156
170
|
end
|
157
171
|
class << self
|
@@ -14,18 +14,23 @@ module ActiveScaffold
|
|
14
14
|
def add_to_javascript_manifest
|
15
15
|
file = 'app/assets/javascripts/application.js'
|
16
16
|
unless File.exist?(file)
|
17
|
+
if Rails.version >= '6.0'
|
18
|
+
create_javascript_manifest file
|
19
|
+
return
|
20
|
+
end
|
17
21
|
say_status :missing, file, :red
|
18
22
|
return if options[:pretend]
|
19
23
|
raise Thor::Error, "JS file #{file} is required for ActiveScaffold"
|
20
24
|
end
|
21
25
|
original_js = File.binread(file)
|
22
26
|
if original_js.include?('require active_scaffold')
|
23
|
-
say_status('skipped',
|
27
|
+
say_status('skipped', "insert into #{file}", :yellow)
|
24
28
|
else
|
25
|
-
insert_into_file
|
29
|
+
insert_into_file file, after: %r{//= require +.*ujs['"]?\n} do
|
26
30
|
"//= require active_scaffold\n"
|
27
31
|
end
|
28
32
|
end
|
33
|
+
setup_jquery file, original_js
|
29
34
|
end
|
30
35
|
|
31
36
|
def add_to_stylesheet_manifest
|
@@ -35,11 +40,54 @@ module ActiveScaffold
|
|
35
40
|
if original_css =~ /require active_scaffold$/
|
36
41
|
say_status('skipped', 'insert into app/assets/stylesheets/application.css', :yellow)
|
37
42
|
else
|
38
|
-
insert_into_file 'app/assets/stylesheets/application.css', :
|
43
|
+
insert_into_file 'app/assets/stylesheets/application.css', before: %r{[ ]*\*/} do
|
39
44
|
" *= require active_scaffold\n"
|
40
45
|
end
|
41
46
|
end
|
42
47
|
end
|
48
|
+
|
49
|
+
protected
|
50
|
+
|
51
|
+
def create_javascript_manifest(file)
|
52
|
+
FileUtils.mkdir_p File.dirname(file)
|
53
|
+
File.open(file, 'w') do |f|
|
54
|
+
f << "// This is a manifest file that'll be compiled into application.js, which will include all the files
|
55
|
+
// listed below.
|
56
|
+
//
|
57
|
+
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, or any plugin's
|
58
|
+
// vendor/assets/javascripts directory can be referenced here using a relative path.
|
59
|
+
//
|
60
|
+
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
|
61
|
+
// compiled file. JavaScript code in this file should be added after the last require_* statement.
|
62
|
+
//
|
63
|
+
// Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
|
64
|
+
// about supported directives.
|
65
|
+
//
|
66
|
+
//= require active_scaffold
|
67
|
+
"
|
68
|
+
say_status('create', file)
|
69
|
+
end
|
70
|
+
insert_into_file 'app/views/layouts/application.html.erb', after: /javascript_pack_tag 'application'.*\n/ do
|
71
|
+
" <%= javascript_include_tag 'application', 'data-turbolinks-track': 'reload' %>\n"
|
72
|
+
end
|
73
|
+
append_to_file 'config/initializers/assets.rb' do
|
74
|
+
"Rails.application.config.assets.precompile += %w( application.js )\n"
|
75
|
+
end
|
76
|
+
setup_jquery file, where: 'active_scaffold'
|
77
|
+
end
|
78
|
+
|
79
|
+
def setup_jquery(file, original_js = nil, where: 'ujs')
|
80
|
+
original_js ||= File.binread(file)
|
81
|
+
if ActiveScaffold.js_framework == :jquery
|
82
|
+
unless original_js.include?('require jquery')
|
83
|
+
insert_into_file file, before: %r{//= require +.*#{where}['"]?\n} do
|
84
|
+
"//= require jquery\n"
|
85
|
+
end
|
86
|
+
end
|
87
|
+
else
|
88
|
+
say_status('missing', 'no jquery-rails gem, load jquery in your layout, or add jquery-rails to Gemfile and add //= require jquery to application.js', :red)
|
89
|
+
end
|
90
|
+
end
|
43
91
|
end
|
44
92
|
end
|
45
93
|
end
|
@@ -5,7 +5,7 @@ require 'test_helper'
|
|
5
5
|
class ActionColumnsTest < MiniTest::Test
|
6
6
|
def setup
|
7
7
|
@columns = ActiveScaffold::DataStructures::ActionColumns.new(%i[a b])
|
8
|
-
@columns.action = stub(:
|
8
|
+
@columns.action = stub(core: stub(model_id: 'model_stub'), user_settings_key: :"model_stub_active_scaffold/config/test")
|
9
9
|
end
|
10
10
|
|
11
11
|
def test_label
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class ActionViewRenderingTest < ActionController::TestCase
|
4
|
+
setup do
|
5
|
+
@controller = PeopleController.new
|
6
|
+
end
|
7
|
+
|
8
|
+
test 'render :super twice' do
|
9
|
+
get :index
|
10
|
+
assert_select '#controller', 1
|
11
|
+
assert_select '#app', 1
|
12
|
+
end
|
13
|
+
|
14
|
+
test 'render partial override with render :super twice' do
|
15
|
+
get :new
|
16
|
+
assert_select '#first_name_field', 1
|
17
|
+
assert_select '#controller_form', 1
|
18
|
+
assert_select '#app_form', 1
|
19
|
+
end
|
20
|
+
end
|
@@ -3,7 +3,7 @@ require 'test_helper'
|
|
3
3
|
module ModelStubs
|
4
4
|
class ModelStub < ActiveRecord::Base
|
5
5
|
self.abstract_class = true
|
6
|
-
def self.columns; @columns ||= [ColumnMock.new('foo', '')] end
|
6
|
+
def self.columns; @columns ||= [ColumnMock.new('foo', '', 'string')] end
|
7
7
|
|
8
8
|
def self.columns_hash; @hash ||= Hash[@columns.map { |c| [c.name, c] }] end
|
9
9
|
|
data/test/misc/tableless_test.rb
CHANGED
@@ -25,6 +25,10 @@ class TablelessTest < MiniTest::Test
|
|
25
25
|
|
26
26
|
def test_find_with_association
|
27
27
|
assert Person.new.files.empty?
|
28
|
+
@person = Person.new
|
29
|
+
@person.save(validate: false)
|
30
|
+
assert @person.files.empty?
|
31
|
+
assert_equal [], @person.files.to_a
|
28
32
|
end
|
29
33
|
|
30
34
|
def test_tableless_assoc_with_dependent
|
@@ -35,6 +39,10 @@ class TablelessTest < MiniTest::Test
|
|
35
39
|
|
36
40
|
def test_find_with_through_association
|
37
41
|
assert Building.new.files.empty?
|
42
|
+
@building = Building.new
|
43
|
+
@building.save(validate: false)
|
44
|
+
assert @building.files.empty?
|
45
|
+
assert_equal [], @building.files.to_a
|
38
46
|
end
|
39
47
|
|
40
48
|
def test_new
|
data/test/test_helper.rb
CHANGED
@@ -1,10 +1,10 @@
|
|
1
|
-
require 'simplecov' if
|
1
|
+
require 'simplecov' if ENV['COVERAGE']
|
2
2
|
|
3
3
|
ENV['RAILS_ENV'] = 'test'
|
4
4
|
require 'mock_app/config/environment'
|
5
5
|
require 'rails/test_help'
|
6
6
|
require 'minitest/autorun'
|
7
|
-
require 'mocha/
|
7
|
+
require 'mocha/minitest'
|
8
8
|
require 'cow_proxy'
|
9
9
|
|
10
10
|
require 'minitest/reporters'
|
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.6.
|
4
|
+
version: 3.6.3
|
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:
|
11
|
+
date: 2021-11-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -17,6 +17,9 @@ dependencies:
|
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: 4.2.0
|
20
|
+
- - "<"
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '6.2'
|
20
23
|
type: :runtime
|
21
24
|
prerelease: false
|
22
25
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -24,6 +27,9 @@ dependencies:
|
|
24
27
|
- - ">="
|
25
28
|
- !ruby/object:Gem::Version
|
26
29
|
version: 4.2.0
|
30
|
+
- - "<"
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '6.2'
|
27
33
|
- !ruby/object:Gem::Dependency
|
28
34
|
name: cow_proxy
|
29
35
|
requirement: !ruby/object:Gem::Requirement
|
@@ -224,6 +230,7 @@ files:
|
|
224
230
|
- lib/active_scaffold/bridges/ancestry/ancestry_bridge.rb
|
225
231
|
- lib/active_scaffold/bridges/bitfields.rb
|
226
232
|
- lib/active_scaffold/bridges/bitfields/bitfields_bridge.rb
|
233
|
+
- lib/active_scaffold/bridges/bitfields/list_ui.rb
|
227
234
|
- lib/active_scaffold/bridges/calendar_date_select.rb
|
228
235
|
- lib/active_scaffold/bridges/calendar_date_select/as_cds_bridge.rb
|
229
236
|
- lib/active_scaffold/bridges/cancan.rb
|
@@ -377,6 +384,7 @@ files:
|
|
377
384
|
- test/data_structures/standard_column_test.rb
|
378
385
|
- test/data_structures/validation_reflection_test.rb
|
379
386
|
- test/data_structures/virtual_column_test.rb
|
387
|
+
- test/extensions/action_view_rendering_test.rb
|
380
388
|
- test/extensions/active_record_test.rb
|
381
389
|
- test/extensions/routing_mapper_test.rb
|
382
390
|
- test/helpers/form_column_helpers_test.rb
|
@@ -404,6 +412,7 @@ files:
|
|
404
412
|
- test/mock_app/app/controllers/contacts_controller.rb
|
405
413
|
- test/mock_app/app/controllers/floors_controller.rb
|
406
414
|
- test/mock_app/app/controllers/people_controller.rb
|
415
|
+
- test/mock_app/app/controllers/roles_controller.rb
|
407
416
|
- test/mock_app/app/helpers/application_helper.rb
|
408
417
|
- test/mock_app/app/models/address.rb
|
409
418
|
- test/mock_app/app/models/building.rb
|
@@ -413,6 +422,11 @@ files:
|
|
413
422
|
- test/mock_app/app/models/floor.rb
|
414
423
|
- test/mock_app/app/models/person.rb
|
415
424
|
- test/mock_app/app/models/role.rb
|
425
|
+
- test/mock_app/app/views/active_scaffold_overrides/_form.html.erb
|
426
|
+
- test/mock_app/app/views/active_scaffold_overrides/list.html.erb
|
427
|
+
- test/mock_app/app/views/people/_first_name_form_column.html.erb
|
428
|
+
- test/mock_app/app/views/people/_form.html.erb
|
429
|
+
- test/mock_app/app/views/people/list.html.erb
|
416
430
|
- test/mock_app/config.ru
|
417
431
|
- test/mock_app/config/application.rb
|
418
432
|
- test/mock_app/config/boot.rb
|
@@ -457,11 +471,11 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
457
471
|
version: '2.3'
|
458
472
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
459
473
|
requirements:
|
460
|
-
- - "
|
474
|
+
- - ">="
|
461
475
|
- !ruby/object:Gem::Version
|
462
|
-
version:
|
476
|
+
version: '0'
|
463
477
|
requirements: []
|
464
|
-
rubygems_version: 3.0.
|
478
|
+
rubygems_version: 3.0.9
|
465
479
|
signing_key:
|
466
480
|
specification_version: 4
|
467
481
|
summary: Rails 4.x and 5.x versions of ActiveScaffold supporting prototype and jquery
|
@@ -498,6 +512,7 @@ test_files:
|
|
498
512
|
- test/data_structures/standard_column_test.rb
|
499
513
|
- test/data_structures/validation_reflection_test.rb
|
500
514
|
- test/data_structures/virtual_column_test.rb
|
515
|
+
- test/extensions/action_view_rendering_test.rb
|
501
516
|
- test/extensions/active_record_test.rb
|
502
517
|
- test/extensions/routing_mapper_test.rb
|
503
518
|
- test/helpers/form_column_helpers_test.rb
|
@@ -525,6 +540,7 @@ test_files:
|
|
525
540
|
- test/mock_app/app/controllers/contacts_controller.rb
|
526
541
|
- test/mock_app/app/controllers/floors_controller.rb
|
527
542
|
- test/mock_app/app/controllers/people_controller.rb
|
543
|
+
- test/mock_app/app/controllers/roles_controller.rb
|
528
544
|
- test/mock_app/app/helpers/application_helper.rb
|
529
545
|
- test/mock_app/app/models/address.rb
|
530
546
|
- test/mock_app/app/models/building.rb
|
@@ -534,6 +550,11 @@ test_files:
|
|
534
550
|
- test/mock_app/app/models/floor.rb
|
535
551
|
- test/mock_app/app/models/person.rb
|
536
552
|
- test/mock_app/app/models/role.rb
|
553
|
+
- test/mock_app/app/views/active_scaffold_overrides/_form.html.erb
|
554
|
+
- test/mock_app/app/views/active_scaffold_overrides/list.html.erb
|
555
|
+
- test/mock_app/app/views/people/_first_name_form_column.html.erb
|
556
|
+
- test/mock_app/app/views/people/_form.html.erb
|
557
|
+
- test/mock_app/app/views/people/list.html.erb
|
537
558
|
- test/mock_app/config.ru
|
538
559
|
- test/mock_app/config/application.rb
|
539
560
|
- test/mock_app/config/boot.rb
|