rs-activeadmin-searchable_select 4.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.actrc +20 -0
- data/.claude/commands/fix-tests.md +203 -0
- data/.github/workflows/ci.yml +170 -0
- data/.github/workflows/npm-publish.yml +47 -0
- data/.gitignore +27 -0
- data/.npmignore +58 -0
- data/.rspec +2 -0
- data/.rubocop.yml +67 -0
- data/.yardopts +2 -0
- data/AGENTS.md +39 -0
- data/Appraisals +15 -0
- data/CHANGELOG.md +24 -0
- data/CLAUDE.md +104 -0
- data/Gemfile +11 -0
- data/Gemfile.lock +366 -0
- data/LICENSE.txt +25 -0
- data/README.md +439 -0
- data/Rakefile +4 -0
- data/bin/rspec +17 -0
- data/config/database.yml +16 -0
- data/config.ru +28 -0
- data/docs/activeadmin-4-detailed-reference.md +932 -0
- data/docs/activeadmin-4-gem-migration-guide.md +313 -0
- data/docs/combustion.md +213 -0
- data/docs/for-next-session.md +199 -0
- data/docs/guide-update-your-app.md +213 -0
- data/docs/propshaft-readme.md +121 -0
- data/docs/propshaft-upgrade.md +267 -0
- data/docs/rails-7-asset-pipeline.md +279 -0
- data/docs/setup-activeadmin-app.md +552 -0
- data/docs/setup-activeadmin-gem.md +535 -0
- data/docs/upload-system.md +225 -0
- data/gemfiles/rails_7.x_active_admin_4.x.gemfile +11 -0
- data/gemfiles/rails_7.x_active_admin_4.x.gemfile.lock +371 -0
- data/gemfiles/rails_8.x_active_admin_4.x.gemfile +11 -0
- data/gemfiles/rails_8.x_active_admin_4.x.gemfile.lock +366 -0
- data/lefthook.yml +17 -0
- data/lib/activeadmin/inputs/filters/searchable_select_input.rb +13 -0
- data/lib/activeadmin/inputs/searchable_select_input.rb +11 -0
- data/lib/activeadmin/searchable_select/engine.rb +17 -0
- data/lib/activeadmin/searchable_select/option_collection.rb +119 -0
- data/lib/activeadmin/searchable_select/resource_dsl_extension.rb +56 -0
- data/lib/activeadmin/searchable_select/resource_extension.rb +10 -0
- data/lib/activeadmin/searchable_select/select_input_extension.rb +159 -0
- data/lib/activeadmin/searchable_select/version.rb +5 -0
- data/lib/activeadmin/searchable_select.rb +20 -0
- data/lib/activeadmin-searchable_select.rb +4 -0
- data/lib/generators/active_admin/searchable_select/install/install_generator.rb +217 -0
- data/package-lock.json +18 -0
- data/package.json +45 -0
- data/rs-activeadmin-searchable_select.gemspec +38 -0
- data/sonar-project.properties +25 -0
- data/spec/features/ajax_params_spec.rb +31 -0
- data/spec/features/end_to_end_spec.rb +227 -0
- data/spec/features/filter_input_spec.rb +137 -0
- data/spec/features/form_input_spec.rb +122 -0
- data/spec/features/inline_ajax_setting_spec.rb +26 -0
- data/spec/features/input_errors_spec.rb +76 -0
- data/spec/features/input_html_options_spec.rb +30 -0
- data/spec/features/options_dsl_spec.rb +220 -0
- data/spec/features/production_build_spec.rb +108 -0
- data/spec/internal/app/admin/categories.rb +26 -0
- data/spec/internal/app/admin/dashboard.rb +29 -0
- data/spec/internal/app/admin/option_types.rb +19 -0
- data/spec/internal/app/admin/option_values.rb +30 -0
- data/spec/internal/app/admin/posts.rb +27 -0
- data/spec/internal/app/admin/products.rb +22 -0
- data/spec/internal/app/admin/rgb_colors.rb +25 -0
- data/spec/internal/app/admin/tag_names.rb +21 -0
- data/spec/internal/app/admin/test_ajax_params_category.rb +10 -0
- data/spec/internal/app/admin/test_ajax_params_post.rb +20 -0
- data/spec/internal/app/admin/test_form_post_class.rb +7 -0
- data/spec/internal/app/admin/test_form_post_custom.rb +11 -0
- data/spec/internal/app/admin/test_form_post_resource.rb +11 -0
- data/spec/internal/app/admin/test_form_post_resource_custom.rb +12 -0
- data/spec/internal/app/admin/test_inline_ajax_post.rb +9 -0
- data/spec/internal/app/admin/test_input_html_post.rb +11 -0
- data/spec/internal/app/admin/test_posts_display_text.rb +9 -0
- data/spec/internal/app/admin/test_posts_filter.rb +9 -0
- data/spec/internal/app/admin/test_posts_named.rb +9 -0
- data/spec/internal/app/admin/test_posts_pagination.rb +9 -0
- data/spec/internal/app/admin/test_posts_payload_lambda.rb +11 -0
- data/spec/internal/app/admin/test_posts_payload_proc.rb +9 -0
- data/spec/internal/app/admin/test_posts_scope_lambda.rb +8 -0
- data/spec/internal/app/admin/test_posts_scope_params.rb +8 -0
- data/spec/internal/app/admin/test_posts_scope_user.rb +8 -0
- data/spec/internal/app/admin/test_posts_text_attr.rb +5 -0
- data/spec/internal/app/admin/users.rb +23 -0
- data/spec/internal/app/admin/variants.rb +31 -0
- data/spec/internal/app/assets/config/manifest.js +1 -0
- data/spec/internal/app/assets/javascripts/active_admin.js +2 -0
- data/spec/internal/app/assets/javascripts/searchable_select_test.js +2 -0
- data/spec/internal/app/controllers/application_controller.rb +5 -0
- data/spec/internal/app/css/active_admin_source.css +81 -0
- data/spec/internal/app/js/active_admin.js +17 -0
- data/spec/internal/app/models/article.rb +12 -0
- data/spec/internal/app/models/category.rb +12 -0
- data/spec/internal/app/models/internal/tag_name.rb +14 -0
- data/spec/internal/app/models/internal_tag_name.rb +11 -0
- data/spec/internal/app/models/option_type.rb +12 -0
- data/spec/internal/app/models/option_value.rb +4 -0
- data/spec/internal/app/models/post.rb +15 -0
- data/spec/internal/app/models/product.rb +12 -0
- data/spec/internal/app/models/rgb_color.rb +16 -0
- data/spec/internal/app/models/user.rb +12 -0
- data/spec/internal/app/models/variant.rb +12 -0
- data/spec/internal/build_activeadmin_css.js +115 -0
- data/spec/internal/config/database.yml +7 -0
- data/spec/internal/config/environment.rb +48 -0
- data/spec/internal/config/initializers/active_admin.rb +53 -0
- data/spec/internal/config/initializers/assets.rb +9 -0
- data/spec/internal/config/initializers/searchable_select.rb +6 -0
- data/spec/internal/config/routes.rb +4 -0
- data/spec/internal/config.ru +4 -0
- data/spec/internal/db/schema.rb +63 -0
- data/spec/internal/db/seeds.rb +88 -0
- data/spec/internal/esbuild.config.js +30 -0
- data/spec/internal/inject-jquery.js +4 -0
- data/spec/internal/log/.gitignore +1 -0
- data/spec/internal/package/LICENSE.txt +25 -0
- data/spec/internal/package/README.md +439 -0
- data/spec/internal/package/package.json +45 -0
- data/spec/internal/package/src/index.js +1 -0
- data/spec/internal/package/src/searchable_select/init.js +1 -0
- data/spec/internal/package/src/searchable_select.css +1 -0
- data/spec/internal/package/src/searchable_select.scss +1 -0
- data/spec/internal/package-lock.json +1385 -0
- data/spec/internal/package.json +26 -0
- data/spec/internal/public/favicon.ico +0 -0
- data/spec/internal/spec/internal/app/css/active_admin_source.css +38 -0
- data/spec/internal/spec/internal/log/test.log +0 -0
- data/spec/internal/tailwind-active_admin.config.js +53 -0
- data/spec/rails_helper.rb +86 -0
- data/spec/spec_helper.rb +137 -0
- data/spec/support/active_admin_helpers.rb +17 -0
- data/spec/support/capybara.rb +8 -0
- data/spec/support/models.rb +88 -0
- data/spec/support/pluck_polyfill.rb +12 -0
- data/spec/support/reset_settings.rb +5 -0
- data/src/index.js +77 -0
- data/src/searchable_select/init.js +58 -0
- data/src/searchable_select.css +5 -0
- data/src/searchable_select.css.map +1 -0
- metadata +405 -0
@@ -0,0 +1,159 @@
|
|
1
|
+
module ActiveAdmin
|
2
|
+
module SearchableSelect
|
3
|
+
# Mixin for searchable select inputs.
|
4
|
+
#
|
5
|
+
# Supports the same options as inputs of type `:select`.
|
6
|
+
#
|
7
|
+
# Adds support for an `ajax` option to fetch options data from a
|
8
|
+
# JSON endpoint. Pass either `true` to use defaults or a hash
|
9
|
+
# containing some of the following options:
|
10
|
+
#
|
11
|
+
# - `resource`: ActiveRecord model class of ActiveAdmin resource
|
12
|
+
# which provides the collection action to fetch options
|
13
|
+
# from. By default the resource is auto detected via the name
|
14
|
+
# of the input attribute.
|
15
|
+
#
|
16
|
+
# - `collection_name`: Name passed to the
|
17
|
+
# `searchable_select_options` method that defines the collection
|
18
|
+
# action to fetch options from.
|
19
|
+
#
|
20
|
+
# - `params`: Hash of query parameters that shall be passed to the
|
21
|
+
# options endpoint.
|
22
|
+
#
|
23
|
+
# - `path_params`: Hash of parameters, which would be passed to the
|
24
|
+
# dynamic collection path generation for the resource.
|
25
|
+
# e.g `admin_articles_path(path_params)`
|
26
|
+
#
|
27
|
+
# If the `ajax` option is present, the `collection` option is
|
28
|
+
# ignored.
|
29
|
+
module SelectInputExtension
|
30
|
+
# @api private
|
31
|
+
def to_html
|
32
|
+
super
|
33
|
+
rescue RuntimeError => e
|
34
|
+
# In development/test, display the error message
|
35
|
+
raise e unless Rails.env.development? || Rails.env.test?
|
36
|
+
|
37
|
+
template.content_tag(:div, e.message, class: 'searchable-select-error')
|
38
|
+
end
|
39
|
+
|
40
|
+
# @api private
|
41
|
+
def input_html_options
|
42
|
+
super.tap do |options|
|
43
|
+
options[:class] = [options[:class], 'searchable-select-input'].compact.join(' ')
|
44
|
+
options['data-ajax-url'] = ajax_url if ajax? && !SearchableSelect.inline_ajax_options
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
# @api private
|
49
|
+
def collection_from_options
|
50
|
+
return super unless options[:ajax]
|
51
|
+
|
52
|
+
if SearchableSelect.inline_ajax_options
|
53
|
+
all_options_collection
|
54
|
+
else
|
55
|
+
selected_value_collection
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
private
|
60
|
+
|
61
|
+
def ajax?
|
62
|
+
options[:ajax].present?
|
63
|
+
end
|
64
|
+
|
65
|
+
def ajax_url
|
66
|
+
return unless options[:ajax]
|
67
|
+
|
68
|
+
[ajax_resource.route_collection_path(path_params),
|
69
|
+
'/',
|
70
|
+
option_collection.collection_action_name,
|
71
|
+
'?',
|
72
|
+
ajax_params.to_query].join
|
73
|
+
end
|
74
|
+
|
75
|
+
def all_options_collection
|
76
|
+
option_collection_scope.all.map do |record|
|
77
|
+
option_for_record(record)
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
def selected_value_collection
|
82
|
+
selected_records.collect { |s| option_for_record(s) }
|
83
|
+
end
|
84
|
+
|
85
|
+
def option_for_record(record)
|
86
|
+
[option_collection.display_text(record), record.id]
|
87
|
+
end
|
88
|
+
|
89
|
+
def selected_records
|
90
|
+
@selected_records ||=
|
91
|
+
if selected_values
|
92
|
+
option_collection_scope.where(id: selected_values)
|
93
|
+
else
|
94
|
+
[]
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
def selected_values
|
99
|
+
@object&.send(input_name)
|
100
|
+
end
|
101
|
+
|
102
|
+
def option_collection_scope
|
103
|
+
option_collection.scope(template, path_params.merge(ajax_params))
|
104
|
+
end
|
105
|
+
|
106
|
+
def option_collection
|
107
|
+
ajax_resource
|
108
|
+
.searchable_select_option_collections
|
109
|
+
.fetch(ajax_option_collection_name) do
|
110
|
+
raise("No option collection named '#{ajax_option_collection_name}' " \
|
111
|
+
"defined in '#{ajax_resource_class.name}' admin.")
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
def ajax_resource
|
116
|
+
@ajax_resource ||=
|
117
|
+
template.active_admin_namespace.resource_for(ajax_resource_class) ||
|
118
|
+
raise("No admin found for '#{ajax_resource_class.name}' to fetch " \
|
119
|
+
'options for searchable select input from.')
|
120
|
+
end
|
121
|
+
|
122
|
+
def ajax_resource_class
|
123
|
+
ajax_options.fetch(:resource) do
|
124
|
+
raise_cannot_auto_detect_resource unless reflection
|
125
|
+
reflection.klass
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
def raise_cannot_auto_detect_resource
|
130
|
+
raise('Cannot auto detect resource to fetch options for searchable select input from. ' \
|
131
|
+
"Explicitly pass class of an ActiveAdmin resource:\n\n " \
|
132
|
+
"f.input(:custom_category,\n " \
|
133
|
+
"type: :searchable_select,\n " \
|
134
|
+
"ajax: {\n " \
|
135
|
+
"resource: Category\n " \
|
136
|
+
"})\n")
|
137
|
+
end
|
138
|
+
|
139
|
+
def ajax_option_collection_name
|
140
|
+
ajax_options.fetch(:collection_name, :all)
|
141
|
+
end
|
142
|
+
|
143
|
+
def ajax_params
|
144
|
+
ajax_options.fetch(:params, {})
|
145
|
+
end
|
146
|
+
|
147
|
+
def path_params
|
148
|
+
ajax_options.fetch(:path_params, {})
|
149
|
+
end
|
150
|
+
|
151
|
+
def ajax_options
|
152
|
+
# ActiveAdmin 4 may transform ajax hash to boolean
|
153
|
+
return {} if options[:ajax] == true || options[:ajax].nil?
|
154
|
+
|
155
|
+
options[:ajax]
|
156
|
+
end
|
157
|
+
end
|
158
|
+
end
|
159
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'activeadmin/searchable_select/engine'
|
2
|
+
require 'activeadmin/searchable_select/option_collection'
|
3
|
+
require 'activeadmin/searchable_select/resource_extension'
|
4
|
+
require 'activeadmin/searchable_select/resource_dsl_extension'
|
5
|
+
require 'activeadmin/searchable_select/select_input_extension'
|
6
|
+
require 'activeadmin/searchable_select/version'
|
7
|
+
|
8
|
+
ActiveAdmin::Resource.include ActiveAdmin::SearchableSelect::ResourceExtension
|
9
|
+
ActiveAdmin::ResourceDSL.include ActiveAdmin::SearchableSelect::ResourceDSLExtension
|
10
|
+
|
11
|
+
module ActiveAdmin
|
12
|
+
# Global settings for searchable selects
|
13
|
+
module SearchableSelect
|
14
|
+
# Statically render all options into searchable selects with
|
15
|
+
# `ajax` option set to true. This can be used to ease ui driven
|
16
|
+
# integration testing.
|
17
|
+
mattr_accessor :inline_ajax_options
|
18
|
+
self.inline_ajax_options = false
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,217 @@
|
|
1
|
+
require 'rails/generators'
|
2
|
+
|
3
|
+
module ActiveAdmin
|
4
|
+
module SearchableSelect
|
5
|
+
module Generators
|
6
|
+
class InstallGenerator < Rails::Generators::Base
|
7
|
+
source_root File.expand_path('templates', __dir__)
|
8
|
+
|
9
|
+
desc 'Installs ActiveAdmin Searchable Select for ActiveAdmin 4.x'
|
10
|
+
|
11
|
+
class_option :bundler,
|
12
|
+
type: :string,
|
13
|
+
default: 'esbuild',
|
14
|
+
desc: 'JavaScript bundler to use (esbuild, importmap, webpack)',
|
15
|
+
enum: %w[esbuild importmap webpack]
|
16
|
+
|
17
|
+
def install_npm_package
|
18
|
+
return unless options[:bundler] != 'importmap'
|
19
|
+
|
20
|
+
say 'Installing @codevise/activeadmin-searchable_select npm package...', :green
|
21
|
+
run 'npm install @codevise/activeadmin-searchable_select jquery select2'
|
22
|
+
end
|
23
|
+
|
24
|
+
def setup_javascript
|
25
|
+
case options[:bundler]
|
26
|
+
when 'esbuild'
|
27
|
+
setup_esbuild
|
28
|
+
when 'importmap'
|
29
|
+
setup_importmap
|
30
|
+
when 'webpack'
|
31
|
+
setup_webpack
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def setup_stylesheets
|
36
|
+
if File.exist?('app/assets/stylesheets/active_admin.css')
|
37
|
+
say 'Adding Select2 styles to active_admin.css...', :green
|
38
|
+
prepend_to_file 'app/assets/stylesheets/active_admin.css' do
|
39
|
+
<<~CSS
|
40
|
+
@import url('https://cdn.jsdelivr.net/npm/select2@4.1.0-rc.0/dist/css/select2.min.css');
|
41
|
+
|
42
|
+
CSS
|
43
|
+
end
|
44
|
+
elsif File.exist?('app/assets/stylesheets/active_admin.scss')
|
45
|
+
say 'Adding Select2 styles to active_admin.scss...', :green
|
46
|
+
prepend_to_file 'app/assets/stylesheets/active_admin.scss' do
|
47
|
+
<<~SCSS
|
48
|
+
@import url('https://cdn.jsdelivr.net/npm/select2@4.1.0-rc.0/dist/css/select2.min.css');
|
49
|
+
|
50
|
+
SCSS
|
51
|
+
end
|
52
|
+
else
|
53
|
+
say 'Please manually add Select2 styles to your ActiveAdmin stylesheet', :yellow
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def show_post_install_message
|
58
|
+
say "\n✅ ActiveAdmin Searchable Select has been installed!", :green
|
59
|
+
|
60
|
+
case options[:bundler]
|
61
|
+
when 'esbuild'
|
62
|
+
say "\nMake sure to rebuild your JavaScript:", :yellow
|
63
|
+
say ' npm run build', :cyan
|
64
|
+
say "\nFor development with watch mode:", :yellow
|
65
|
+
say ' npm run build -- --watch', :cyan
|
66
|
+
when 'importmap'
|
67
|
+
say "\nRestart your Rails server to load the new pins.", :yellow
|
68
|
+
when 'webpack'
|
69
|
+
say "\nRecompile your webpack bundles:", :yellow
|
70
|
+
say ' bin/webpack', :cyan
|
71
|
+
end
|
72
|
+
|
73
|
+
say "\n📚 Usage example:", :green
|
74
|
+
say <<~RUBY
|
75
|
+
|
76
|
+
# In your ActiveAdmin resource:
|
77
|
+
ActiveAdmin.register User do
|
78
|
+
searchable_select_options(
|
79
|
+
scope: User.all,
|
80
|
+
text_attribute: :name
|
81
|
+
)
|
82
|
+
end
|
83
|
+
|
84
|
+
ActiveAdmin.register Post do
|
85
|
+
form do |f|
|
86
|
+
f.inputs do
|
87
|
+
f.input :user, as: :searchable_select, ajax: true
|
88
|
+
end
|
89
|
+
f.actions
|
90
|
+
end
|
91
|
+
end
|
92
|
+
RUBY
|
93
|
+
end
|
94
|
+
|
95
|
+
PACKAGE_JSON_FILE = 'package.json'.freeze
|
96
|
+
|
97
|
+
private
|
98
|
+
|
99
|
+
def setup_esbuild
|
100
|
+
say 'Setting up for esbuild...', :green
|
101
|
+
|
102
|
+
# Check if app/javascript/active_admin.js exists
|
103
|
+
js_file = 'app/javascript/active_admin.js'
|
104
|
+
|
105
|
+
if File.exist?(js_file)
|
106
|
+
say "Adding searchable_select to #{js_file}...", :green
|
107
|
+
append_to_file js_file do
|
108
|
+
<<~JS
|
109
|
+
|
110
|
+
// ActiveAdmin Searchable Select
|
111
|
+
import '@codevise/activeadmin-searchable_select';
|
112
|
+
JS
|
113
|
+
end
|
114
|
+
else
|
115
|
+
say "Creating #{js_file}...", :green
|
116
|
+
create_file js_file do
|
117
|
+
<<~JS
|
118
|
+
import "@activeadmin/activeadmin";
|
119
|
+
|
120
|
+
// ActiveAdmin Searchable Select#{' '}
|
121
|
+
import $ from 'jquery';
|
122
|
+
import select2 from 'select2';
|
123
|
+
|
124
|
+
// Critical: Initialize select2 on jQuery for production builds
|
125
|
+
select2($);
|
126
|
+
|
127
|
+
// Ensure jQuery is globally available
|
128
|
+
window.$ = window.jQuery = $;
|
129
|
+
|
130
|
+
// Import the searchable select functionality
|
131
|
+
import '@codevise/activeadmin-searchable_select';
|
132
|
+
JS
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
# Update package.json scripts if needed
|
137
|
+
return unless File.exist?(PACKAGE_JSON_FILE)
|
138
|
+
|
139
|
+
package_json = JSON.parse(File.read(PACKAGE_JSON_FILE))
|
140
|
+
|
141
|
+
return if package_json['scripts'] && package_json['scripts']['build']
|
142
|
+
|
143
|
+
say 'Adding build script to package.json...', :green
|
144
|
+
package_json['scripts'] ||= {}
|
145
|
+
package_json['scripts']['build'] =
|
146
|
+
'esbuild app/javascript/*.* --bundle --sourcemap --format=esm ' \
|
147
|
+
'--outdir=app/assets/builds --public-path=/assets'
|
148
|
+
|
149
|
+
File.write(PACKAGE_JSON_FILE, JSON.pretty_generate(package_json))
|
150
|
+
end
|
151
|
+
|
152
|
+
def setup_importmap
|
153
|
+
say 'Setting up for importmap...', :green
|
154
|
+
|
155
|
+
# Add pins to importmap.rb
|
156
|
+
if File.exist?('config/importmap.rb')
|
157
|
+
say 'Adding pins to config/importmap.rb...', :green
|
158
|
+
append_to_file 'config/importmap.rb' do
|
159
|
+
<<~RUBY
|
160
|
+
|
161
|
+
# ActiveAdmin Searchable Select
|
162
|
+
pin "jquery", to: "https://cdn.jsdelivr.net/npm/jquery@3.7.1/dist/jquery.min.js"
|
163
|
+
pin "select2", to: "https://cdn.jsdelivr.net/npm/select2@4.1.0-rc.0/dist/js/select2.min.js"
|
164
|
+
pin "activeadmin-searchable_select", to: "activeadmin-searchable_select.js"
|
165
|
+
RUBY
|
166
|
+
end
|
167
|
+
end
|
168
|
+
|
169
|
+
# Copy the vendor JavaScript file
|
170
|
+
say 'Copying vendor JavaScript file...', :green
|
171
|
+
copy_file '../../../../vendor/assets/javascripts/activeadmin-searchable_select.js',
|
172
|
+
'app/assets/javascripts/activeadmin-searchable_select.js'
|
173
|
+
|
174
|
+
# Update application.js
|
175
|
+
js_file = 'app/javascript/application.js'
|
176
|
+
return unless File.exist?(js_file)
|
177
|
+
|
178
|
+
say "Adding imports to #{js_file}...", :green
|
179
|
+
append_to_file js_file do
|
180
|
+
<<~JS
|
181
|
+
|
182
|
+
// ActiveAdmin Searchable Select
|
183
|
+
import "jquery"
|
184
|
+
import "select2"
|
185
|
+
import "activeadmin-searchable_select"
|
186
|
+
JS
|
187
|
+
end
|
188
|
+
end
|
189
|
+
|
190
|
+
def setup_webpack
|
191
|
+
say 'Setting up for webpack...', :green
|
192
|
+
|
193
|
+
js_file = 'app/javascript/packs/active_admin.js'
|
194
|
+
|
195
|
+
if File.exist?(js_file)
|
196
|
+
say "Adding searchable_select to #{js_file}...", :green
|
197
|
+
append_to_file js_file do
|
198
|
+
<<~JS
|
199
|
+
|
200
|
+
// ActiveAdmin Searchable Select
|
201
|
+
import $ from 'jquery';
|
202
|
+
import select2 from 'select2';
|
203
|
+
select2($);
|
204
|
+
window.$ = window.jQuery = $;
|
205
|
+
|
206
|
+
import '@codevise/activeadmin-searchable_select';
|
207
|
+
JS
|
208
|
+
end
|
209
|
+
else
|
210
|
+
say 'Please manually add the searchable_select import ' \
|
211
|
+
'to your ActiveAdmin JavaScript pack', :yellow
|
212
|
+
end
|
213
|
+
end
|
214
|
+
end
|
215
|
+
end
|
216
|
+
end
|
217
|
+
end
|
data/package-lock.json
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
{
|
2
|
+
"name": "@codevise/activeadmin-searchable_select",
|
3
|
+
"version": "4.0.2",
|
4
|
+
"lockfileVersion": 1,
|
5
|
+
"requires": true,
|
6
|
+
"dependencies": {
|
7
|
+
"jquery": {
|
8
|
+
"version": "3.7.0",
|
9
|
+
"resolved": "https://registry.npmjs.org/jquery/-/jquery-3.7.0.tgz",
|
10
|
+
"integrity": "sha512-umpJ0/k8X0MvD1ds0P9SfowREz2LenHsQaxSohMZ5OMNEU2r0tf8pdeEFTHMFxWVxKNyU9rTtK3CWzUCTKJUeQ=="
|
11
|
+
},
|
12
|
+
"select2": {
|
13
|
+
"version": "4.0.13",
|
14
|
+
"resolved": "https://registry.npmjs.org/select2/-/select2-4.0.13.tgz",
|
15
|
+
"integrity": "sha512-1JeB87s6oN/TDxQQYCvS5EFoQyvV6eYMZZ0AeA4tdFDYWN3BAGZ8npr17UBFddU0lgAt3H0yjX3X6/ekOj1yjw=="
|
16
|
+
}
|
17
|
+
}
|
18
|
+
}
|
data/package.json
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
{
|
2
|
+
"name": "@rocket-sensei/activeadmin-searchable_select",
|
3
|
+
"version": "4.0.5",
|
4
|
+
"description": "Use searchable selects based on Select2 in Active Admin forms and filters.",
|
5
|
+
"main": "src/index.js",
|
6
|
+
"module": "src/index.js",
|
7
|
+
"style": "src/searchable_select.scss",
|
8
|
+
"exports": {
|
9
|
+
".": {
|
10
|
+
"import": "./src/index.js",
|
11
|
+
"require": "./src/index.js",
|
12
|
+
"default": "./src/index.js"
|
13
|
+
},
|
14
|
+
"./css": "./src/searchable_select.css",
|
15
|
+
"./style": "./src/searchable_select.css",
|
16
|
+
"./scss": "./src/searchable_select.scss"
|
17
|
+
},
|
18
|
+
"repository": {
|
19
|
+
"type": "git",
|
20
|
+
"url": "git+https://github.com/glebtv/activeadmin-searchable_select.git"
|
21
|
+
},
|
22
|
+
"author": "Codevise Solutions Ltd <info@codevise.de>",
|
23
|
+
"license": "MIT",
|
24
|
+
"private": false,
|
25
|
+
"bugs": {
|
26
|
+
"url": "https://github.com/glebtv/activeadmin-searchable_select/issues"
|
27
|
+
},
|
28
|
+
"homepage": "https://github.com/glebtv/activeadmin-searchable_select#readme",
|
29
|
+
"keywords": [
|
30
|
+
"select2",
|
31
|
+
"active",
|
32
|
+
"admin",
|
33
|
+
"searchable",
|
34
|
+
"select",
|
35
|
+
"activeadmin",
|
36
|
+
"rails"
|
37
|
+
],
|
38
|
+
"peerDependencies": {
|
39
|
+
"jquery": ">= 3.0, < 5",
|
40
|
+
"select2": "^4.0.0 || ^4.1.0-rc.0"
|
41
|
+
},
|
42
|
+
"files": [
|
43
|
+
"src/**/*"
|
44
|
+
]
|
45
|
+
}
|
@@ -0,0 +1,38 @@
|
|
1
|
+
lib = File.expand_path('lib', __dir__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
require 'activeadmin/searchable_select/version'
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = 'rs-activeadmin-searchable_select'
|
7
|
+
spec.version = ActiveAdmin::SearchableSelect::VERSION
|
8
|
+
spec.summary = 'Use searchable selects based on Select2 in Active Admin forms and filters.'
|
9
|
+
spec.license = 'MIT'
|
10
|
+
spec.authors = ['Rocket Sensei']
|
11
|
+
spec.email = 'glebtv@gmail.com'
|
12
|
+
spec.homepage = 'https://github.com/glebtv/activeadmin-searchable_select'
|
13
|
+
|
14
|
+
spec.files = `git ls-files -z`.split("\x0")
|
15
|
+
spec.require_paths = ['lib']
|
16
|
+
|
17
|
+
spec.required_ruby_version = ['>= 2.1', '< 4']
|
18
|
+
|
19
|
+
spec.add_development_dependency 'appraisal', '~> 2.2'
|
20
|
+
spec.add_development_dependency 'bundler', ['>= 1.5', '< 3']
|
21
|
+
spec.add_development_dependency 'combustion', '~> 1.5'
|
22
|
+
spec.add_development_dependency 'database_cleaner-active_record', '~> 2.1'
|
23
|
+
spec.add_development_dependency 'rake'
|
24
|
+
spec.add_development_dependency 'rspec-rails', '~> 6.0'
|
25
|
+
spec.add_development_dependency 'sqlite3', '~> 2.1'
|
26
|
+
|
27
|
+
spec.add_development_dependency 'capybara', '~> 3.39'
|
28
|
+
spec.add_development_dependency 'capybara-playwright-driver', '~> 0.5'
|
29
|
+
spec.add_development_dependency 'puma', '~> 6.0'
|
30
|
+
|
31
|
+
spec.add_development_dependency 'propshaft'
|
32
|
+
spec.add_development_dependency 'rails'
|
33
|
+
spec.add_development_dependency 'rubocop', '~> 1.50.0'
|
34
|
+
spec.add_development_dependency 'semmy', '~> 1.0'
|
35
|
+
|
36
|
+
spec.add_dependency 'activeadmin', '~> 4.0.0.beta'
|
37
|
+
spec.metadata['rubygems_mfa_required'] = 'true'
|
38
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# SonarQube project configuration
|
2
|
+
sonar.projectKey=glebtv_activeadmin-searchable_select
|
3
|
+
sonar.projectName=activeadmin-searchable_select
|
4
|
+
sonar.projectVersion=0.5.0
|
5
|
+
|
6
|
+
# Source code directories
|
7
|
+
sonar.sources=lib,app
|
8
|
+
sonar.tests=spec
|
9
|
+
|
10
|
+
# Language
|
11
|
+
sonar.language=ruby
|
12
|
+
|
13
|
+
# Encoding
|
14
|
+
sonar.sourceEncoding=UTF-8
|
15
|
+
|
16
|
+
# Ruby specific settings
|
17
|
+
sonar.ruby.file.suffixes=.rb,.rake
|
18
|
+
sonar.ruby.coverage.reportPaths=coverage/coverage.xml
|
19
|
+
|
20
|
+
# Exclusions
|
21
|
+
sonar.exclusions=spec/**/*,vendor/**/*,coverage/**/*,tmp/**/*,*.gemspec,gemfiles/**/*,Appraisals
|
22
|
+
sonar.test.exclusions=spec/internal/app/assets/builds/**/*,spec/internal/public/**/*,spec/internal/node_modules/**/*
|
23
|
+
|
24
|
+
# Coverage exclusions (files that don't need coverage)
|
25
|
+
sonar.coverage.exclusions=spec/**/*,vendor/**/*,spec/internal/**/*,**/*_spec.rb
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'rails_helper'
|
2
|
+
|
3
|
+
require 'support/models'
|
4
|
+
require 'support/capybara'
|
5
|
+
|
6
|
+
RSpec.describe 'ajax params', type: :request do
|
7
|
+
# Using static TestAjaxParamsPost and TestAjaxParamsCategory admins
|
8
|
+
|
9
|
+
it 'passes parameters when rendering selected item' do
|
10
|
+
user = User.create
|
11
|
+
category = Category.create(name: 'Travel', created_by: user)
|
12
|
+
post = Post.create(category: category)
|
13
|
+
|
14
|
+
ApplicationController.current_user = user
|
15
|
+
get "/admin/test_ajax_params_posts/#{post.id}/edit"
|
16
|
+
|
17
|
+
expect(response.body).to have_selector('.searchable-select-input option[selected]',
|
18
|
+
text: 'Travel')
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'includes parameters in ajax url' do
|
22
|
+
user = User.create
|
23
|
+
|
24
|
+
ApplicationController.current_user = user
|
25
|
+
get '/admin/test_ajax_params_posts/new'
|
26
|
+
|
27
|
+
url_matcher = "?created_by=#{user.id}"
|
28
|
+
expect(response.body).to have_selector('.searchable-select-input' \
|
29
|
+
"[data-ajax-url*='#{url_matcher}']")
|
30
|
+
end
|
31
|
+
end
|