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,220 @@
|
|
1
|
+
require 'rails_helper'
|
2
|
+
|
3
|
+
require 'support/models'
|
4
|
+
require 'support/pluck_polyfill'
|
5
|
+
|
6
|
+
RSpec.describe 'searchable_select_options dsl', type: :request do
|
7
|
+
describe 'with text_attribute option' do
|
8
|
+
# Using static TestPostTextAttr admin
|
9
|
+
describe 'creates JSON endpoint that' do
|
10
|
+
it 'returns options for searchable select' do
|
11
|
+
Post.create!(title: 'A post')
|
12
|
+
|
13
|
+
get '/admin/test_post_text_attrs/all_options'
|
14
|
+
|
15
|
+
expect(json_response).to match(results: [a_hash_including(text: 'A post',
|
16
|
+
id: kind_of(Numeric))],
|
17
|
+
pagination: { more: false })
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'supports filtering via term parameter' do
|
21
|
+
Post.create!(title: 'A post')
|
22
|
+
Post.create!(title: 'Other post')
|
23
|
+
Post.create!(title: 'Not matched')
|
24
|
+
|
25
|
+
get '/admin/test_post_text_attrs/all_options?term=post'
|
26
|
+
titles = json_response[:results].pluck(:text)
|
27
|
+
|
28
|
+
expect(titles).to eq(['A post', 'Other post'])
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
describe 'with separate filter option' do
|
34
|
+
# Using static TestPostFilter admin
|
35
|
+
describe 'creates JSON endpoint that' do
|
36
|
+
it 'returns options for searchable select' do
|
37
|
+
Post.create!(title: 'A post')
|
38
|
+
|
39
|
+
get '/admin/test_post_filters/all_options'
|
40
|
+
|
41
|
+
expect(json_response).to match(results: [a_hash_including(text: 'A post',
|
42
|
+
id: kind_of(Numeric))],
|
43
|
+
pagination: { more: false })
|
44
|
+
end
|
45
|
+
|
46
|
+
it 'supports filtering via term parameter' do
|
47
|
+
Post.create!(title: 'Post')
|
48
|
+
Post.create!(title: 'Not matched')
|
49
|
+
|
50
|
+
get '/admin/test_post_filters/all_options?term=Post'
|
51
|
+
titles = json_response[:results].pluck(:text)
|
52
|
+
|
53
|
+
expect(titles).to eq(['Post'])
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
describe 'with separate display_text option' do
|
59
|
+
# Using static TestPostDisplayText admin
|
60
|
+
describe 'creates JSON endpoint that' do
|
61
|
+
it 'returns options for searchable select' do
|
62
|
+
Post.create!(title: 'A post')
|
63
|
+
|
64
|
+
get '/admin/test_post_display_texts/all_options'
|
65
|
+
|
66
|
+
expect(json_response).to match(results: [a_hash_including(text: 'A POST',
|
67
|
+
id: kind_of(Numeric))],
|
68
|
+
pagination: { more: false })
|
69
|
+
end
|
70
|
+
|
71
|
+
it 'supports filtering via term parameter' do
|
72
|
+
Post.create!(title: 'A post')
|
73
|
+
Post.create!(title: 'Not matched')
|
74
|
+
|
75
|
+
get '/admin/test_post_display_texts/all_options?term=post'
|
76
|
+
titles = json_response[:results].pluck(:text)
|
77
|
+
|
78
|
+
expect(titles).to eq(['A POST'])
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
describe 'pagination' do
|
84
|
+
# Using static TestPostPagination admin
|
85
|
+
it 'limits results and indicates that more results are available' do
|
86
|
+
Post.create!(title: 'A post')
|
87
|
+
Post.create!(title: 'Other post')
|
88
|
+
Post.create!(title: 'Yet another post')
|
89
|
+
|
90
|
+
get '/admin/test_post_paginations/all_options'
|
91
|
+
|
92
|
+
expect(json_response[:results].size).to eq(2)
|
93
|
+
expect(json_response[:pagination][:more]).to eq(true)
|
94
|
+
end
|
95
|
+
|
96
|
+
it 'allows passing page param' do
|
97
|
+
Post.create!(title: 'A post')
|
98
|
+
Post.create!(title: 'Other post')
|
99
|
+
Post.create!(title: 'Yet another post')
|
100
|
+
|
101
|
+
get '/admin/test_post_paginations/all_options?page=1'
|
102
|
+
|
103
|
+
expect(json_response[:results].size).to eq(1)
|
104
|
+
expect(json_response[:pagination][:more]).to eq(false)
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
describe 'with additional_payload' do
|
109
|
+
context 'as lambda' do
|
110
|
+
# Using static TestPostPayloadLambda admin
|
111
|
+
let!(:post) { Post.create!(title: 'A post', published: false) }
|
112
|
+
|
113
|
+
subject { get '/admin/test_post_payload_lambdas/all_options' }
|
114
|
+
|
115
|
+
it 'returns options with our additional attribute' do
|
116
|
+
subject
|
117
|
+
expect(json_response).to match(
|
118
|
+
results: [{ text: 'A post', id: post.id, published: false }],
|
119
|
+
pagination: { more: false }
|
120
|
+
)
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
context 'as Proc' do
|
125
|
+
# Using static TestPostPayloadProc admin
|
126
|
+
let!(:post) { Post.create!(title: 'A post', published: false) }
|
127
|
+
|
128
|
+
subject { get '/admin/test_post_payload_procs/all_options' }
|
129
|
+
|
130
|
+
it 'returns options with our additional attribute' do
|
131
|
+
subject
|
132
|
+
expect(json_response).to match(
|
133
|
+
results: [{ text: 'A post', id: post.id, published: false }],
|
134
|
+
pagination: { more: false }
|
135
|
+
)
|
136
|
+
end
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
140
|
+
it 'allows passing lambda as scope' do
|
141
|
+
# Using static TestPostScopeLambda admin
|
142
|
+
Post.create!(title: 'Draft')
|
143
|
+
Post.create!(title: 'Published post', published: true)
|
144
|
+
|
145
|
+
get '/admin/test_post_scope_lambdas/all_options'
|
146
|
+
titles = json_response[:results].pluck(:text)
|
147
|
+
|
148
|
+
expect(titles).to eq(['Published post'])
|
149
|
+
end
|
150
|
+
|
151
|
+
it 'allows passing lambda as scope that uses view helpers' do
|
152
|
+
# Using static TestPostScopeUser admin
|
153
|
+
user = User.create!
|
154
|
+
Post.create!(title: 'By current user', user: user)
|
155
|
+
Post.create!(title: 'By other user', user: User.create!)
|
156
|
+
|
157
|
+
ApplicationController.current_user = user
|
158
|
+
get '/admin/test_post_scope_users/all_options'
|
159
|
+
titles = json_response[:results].pluck(:text)
|
160
|
+
|
161
|
+
expect(titles).to eq(['By current user'])
|
162
|
+
end
|
163
|
+
|
164
|
+
it 'allows passing lambda that takes params argument' do
|
165
|
+
# Using static TestPostScopeParams admin
|
166
|
+
user = User.create!
|
167
|
+
Post.create!(title: 'By given user', user: user)
|
168
|
+
Post.create!(title: 'By other user', user: User.create!)
|
169
|
+
|
170
|
+
get "/admin/test_post_scope_params/all_options?user=#{user.id}"
|
171
|
+
titles = json_response[:results].pluck(:text)
|
172
|
+
|
173
|
+
expect(titles).to eq(['By given user'])
|
174
|
+
end
|
175
|
+
|
176
|
+
it 'allows passing name prefix for collection action' do
|
177
|
+
# Using static TestPostNamed admin
|
178
|
+
Post.create!(title: 'A post')
|
179
|
+
|
180
|
+
get '/admin/test_post_nameds/some_options'
|
181
|
+
|
182
|
+
expect(json_response).to include(results: array_including(a_hash_including(text: 'A post')))
|
183
|
+
end
|
184
|
+
|
185
|
+
it 'fails with helpful message if scope option is missing' do
|
186
|
+
expect do
|
187
|
+
ActiveAdminHelpers.setup do
|
188
|
+
ActiveAdmin.register(Post) do
|
189
|
+
searchable_select_options(text_attribute: :title)
|
190
|
+
end
|
191
|
+
end
|
192
|
+
end.to raise_error(/Missing option: scope/)
|
193
|
+
end
|
194
|
+
|
195
|
+
it 'fails with helpful message if display_text are missing' do
|
196
|
+
expect do
|
197
|
+
ActiveAdminHelpers.setup do
|
198
|
+
ActiveAdmin.register(Post) do
|
199
|
+
searchable_select_options(scope: Post,
|
200
|
+
filter: ->(_term, scope) { scope })
|
201
|
+
end
|
202
|
+
end
|
203
|
+
end.to raise_error(/Missing option: display_text/)
|
204
|
+
end
|
205
|
+
|
206
|
+
it 'fails with helpful message if filter option is missing' do
|
207
|
+
expect do
|
208
|
+
ActiveAdminHelpers.setup do
|
209
|
+
ActiveAdmin.register(Post) do
|
210
|
+
searchable_select_options(scope: Post,
|
211
|
+
display_text: ->(_term, scope) { scope })
|
212
|
+
end
|
213
|
+
end
|
214
|
+
end.to raise_error(/Missing option: filter/)
|
215
|
+
end
|
216
|
+
|
217
|
+
def json_response
|
218
|
+
JSON.parse(response.body).with_indifferent_access
|
219
|
+
end
|
220
|
+
end
|
@@ -0,0 +1,108 @@
|
|
1
|
+
require 'rails_helper'
|
2
|
+
require 'support/models'
|
3
|
+
require 'support/capybara'
|
4
|
+
require 'support/active_admin_helpers'
|
5
|
+
|
6
|
+
RSpec.describe 'production build compatibility', type: :feature do
|
7
|
+
# Using static admin files configured with searchable_select
|
8
|
+
|
9
|
+
describe 'select2 initialization', js: true do
|
10
|
+
it 'initializes select2 on searchable select inputs' do
|
11
|
+
visit '/admin/posts'
|
12
|
+
|
13
|
+
# Check that the searchable-select-input class is present
|
14
|
+
expect(page).to have_css('.searchable-select-input')
|
15
|
+
|
16
|
+
# Check that Select2 container is created
|
17
|
+
expect(page).to have_css('.select2-container', wait: 5)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
describe 'basic functionality without JavaScript', js: false do
|
22
|
+
it 'renders searchable select as a regular select' do
|
23
|
+
Category.create(name: 'Books')
|
24
|
+
Category.create(name: 'Movies')
|
25
|
+
|
26
|
+
visit '/admin/posts/new'
|
27
|
+
|
28
|
+
# Should have a select input with the searchable-select-input class
|
29
|
+
expect(page).to have_css('select.searchable-select-input')
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
describe 'ajax functionality', js: true do
|
34
|
+
it 'loads options via ajax when clicked' do
|
35
|
+
Category.create(name: 'Technology')
|
36
|
+
Category.create(name: 'Science')
|
37
|
+
|
38
|
+
visit '/admin/posts'
|
39
|
+
|
40
|
+
# Open the filter select - click the first select2 container
|
41
|
+
find('.select2-container', match: :first).click
|
42
|
+
|
43
|
+
# Wait for ajax to load options
|
44
|
+
expect(page).to have_css('.select2-results__option', text: 'Technology', wait: 5)
|
45
|
+
expect(page).to have_css('.select2-results__option', text: 'Science')
|
46
|
+
end
|
47
|
+
|
48
|
+
it 'filters options based on search term' do
|
49
|
+
Category.create(name: 'Ruby Programming')
|
50
|
+
Category.create(name: 'Python Programming')
|
51
|
+
Category.create(name: 'JavaScript')
|
52
|
+
|
53
|
+
visit '/admin/posts'
|
54
|
+
|
55
|
+
# Open the filter select - click the first select2 container
|
56
|
+
find('.select2-container', match: :first).click
|
57
|
+
|
58
|
+
# Type in search box
|
59
|
+
find('.select2-search__field').set('Ruby')
|
60
|
+
|
61
|
+
# Should only show matching option
|
62
|
+
expect(page).to have_css('.select2-results__option', text: 'Ruby Programming', wait: 5)
|
63
|
+
expect(page).not_to have_css('.select2-results__option', text: 'Python Programming')
|
64
|
+
expect(page).not_to have_css('.select2-results__option', text: 'JavaScript')
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
describe 'form submission', js: true do
|
69
|
+
it 'submits selected value correctly' do
|
70
|
+
category = Category.create(name: 'Test Category')
|
71
|
+
|
72
|
+
visit '/admin/posts/new'
|
73
|
+
|
74
|
+
fill_in 'Title', with: 'Test Post'
|
75
|
+
|
76
|
+
# Wait for Select2 to initialize and select category using Select2
|
77
|
+
sleep 0.5 # Allow time for Select2 to initialize
|
78
|
+
within '#post_category_input' do
|
79
|
+
find('.select2-container').click
|
80
|
+
end
|
81
|
+
find('.select2-results__option', text: 'Test Category').click
|
82
|
+
|
83
|
+
click_button 'Create Post'
|
84
|
+
|
85
|
+
# Verify the post was created with the correct category
|
86
|
+
post = Post.last
|
87
|
+
expect(post).to be_present
|
88
|
+
expect(post.title).to eq('Test Post')
|
89
|
+
expect(post.category).to eq(category)
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
describe 'preselected values', js: true do
|
94
|
+
it 'shows preselected value when editing' do
|
95
|
+
category = Category.create(name: 'Selected Category')
|
96
|
+
post = Post.create(title: 'Test', category: category)
|
97
|
+
|
98
|
+
visit "/admin/posts/#{post.id}/edit"
|
99
|
+
|
100
|
+
# Check that the selected value is displayed
|
101
|
+
within '#post_category_input' do
|
102
|
+
within '.select2-container' do
|
103
|
+
expect(page).to have_content('Selected Category')
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
ActiveAdmin.register Category do
|
2
|
+
permit_params :name, :description, :created_at, :updated_at
|
3
|
+
|
4
|
+
searchable_select_options(scope: Category, text_attribute: :name)
|
5
|
+
searchable_select_options(name: 'custom', scope: Category, text_attribute: :name)
|
6
|
+
|
7
|
+
index do
|
8
|
+
selectable_column
|
9
|
+
id_column
|
10
|
+
column :name
|
11
|
+
column :description
|
12
|
+
column :created_at
|
13
|
+
actions
|
14
|
+
end
|
15
|
+
|
16
|
+
filter :name
|
17
|
+
filter :description
|
18
|
+
|
19
|
+
form do |f|
|
20
|
+
f.inputs do
|
21
|
+
f.input :name
|
22
|
+
f.input :description
|
23
|
+
end
|
24
|
+
f.actions
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
ActiveAdmin.register_page 'Dashboard' do
|
2
|
+
menu priority: 1, label: proc { I18n.t('active_admin.dashboard') }
|
3
|
+
|
4
|
+
content title: proc { I18n.t('active_admin.dashboard') } do
|
5
|
+
div class: 'blank_slate_container', id: 'dashboard_default_message' do
|
6
|
+
span class: 'blank_slate' do
|
7
|
+
span 'Welcome to ActiveAdmin Searchable Select Test App'
|
8
|
+
small 'This is a test application for manually testing the searchable select functionality'
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
panel 'Info' do
|
13
|
+
ul do
|
14
|
+
li "Posts: #{Post.count}"
|
15
|
+
li "Categories: #{Category.count}"
|
16
|
+
li "Users: #{User.count}"
|
17
|
+
li "RGB Colors: #{RgbColor.count}"
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
panel 'Recent Posts' do
|
22
|
+
ul do
|
23
|
+
Post.limit(5).map do |post|
|
24
|
+
li link_to(post.title, admin_post_path(post))
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
ActiveAdmin.register OptionValue do
|
2
|
+
belongs_to :option_type
|
3
|
+
|
4
|
+
permit_params :value, :option_type_id
|
5
|
+
|
6
|
+
searchable_select_options(scope: lambda do |params|
|
7
|
+
OptionValue.where(
|
8
|
+
option_type_id: params[:option_type_id]
|
9
|
+
)
|
10
|
+
end,
|
11
|
+
text_attribute: :value)
|
12
|
+
|
13
|
+
index do
|
14
|
+
selectable_column
|
15
|
+
id_column
|
16
|
+
column :value
|
17
|
+
column :option_type
|
18
|
+
actions
|
19
|
+
end
|
20
|
+
|
21
|
+
filter :value
|
22
|
+
|
23
|
+
form do |f|
|
24
|
+
f.inputs do
|
25
|
+
f.input :value
|
26
|
+
f.input :option_type
|
27
|
+
end
|
28
|
+
f.actions
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
ActiveAdmin.register Post do
|
2
|
+
permit_params :title, :body, :category_id, :user_id, :created_at, :updated_at
|
3
|
+
|
4
|
+
index do
|
5
|
+
selectable_column
|
6
|
+
id_column
|
7
|
+
column :title
|
8
|
+
column :category
|
9
|
+
column :user
|
10
|
+
column :created_at
|
11
|
+
actions
|
12
|
+
end
|
13
|
+
|
14
|
+
filter :title
|
15
|
+
filter :category, as: :searchable_select, ajax: true
|
16
|
+
filter :user, as: :searchable_select, ajax: true
|
17
|
+
|
18
|
+
form do |f|
|
19
|
+
f.inputs do
|
20
|
+
f.input :title
|
21
|
+
f.input :body
|
22
|
+
f.input :category, as: :searchable_select, ajax: true
|
23
|
+
f.input :user, as: :searchable_select, ajax: true
|
24
|
+
end
|
25
|
+
f.actions
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
ActiveAdmin.register Product do
|
2
|
+
permit_params :name, :option_type_id
|
3
|
+
|
4
|
+
index do
|
5
|
+
selectable_column
|
6
|
+
id_column
|
7
|
+
column :name
|
8
|
+
column :option_type
|
9
|
+
actions
|
10
|
+
end
|
11
|
+
|
12
|
+
filter :name
|
13
|
+
filter :option_type
|
14
|
+
|
15
|
+
form do |f|
|
16
|
+
f.inputs do
|
17
|
+
f.input :name
|
18
|
+
f.input :option_type
|
19
|
+
end
|
20
|
+
f.actions
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
ActiveAdmin.register RgbColor do
|
2
|
+
permit_params :code, :description
|
3
|
+
|
4
|
+
searchable_select_options(scope: RgbColor.all,
|
5
|
+
text_attribute: :display_name)
|
6
|
+
|
7
|
+
index do
|
8
|
+
selectable_column
|
9
|
+
id_column
|
10
|
+
column :code
|
11
|
+
column :description
|
12
|
+
actions
|
13
|
+
end
|
14
|
+
|
15
|
+
filter :code
|
16
|
+
filter :description
|
17
|
+
|
18
|
+
form do |f|
|
19
|
+
f.inputs do
|
20
|
+
f.input :code
|
21
|
+
f.input :description
|
22
|
+
end
|
23
|
+
f.actions
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
ActiveAdmin.register Internal::TagName, as: 'Tag Name' do
|
2
|
+
permit_params :name, :color_id
|
3
|
+
|
4
|
+
index do
|
5
|
+
selectable_column
|
6
|
+
id_column
|
7
|
+
column :name
|
8
|
+
column :color
|
9
|
+
actions
|
10
|
+
end
|
11
|
+
|
12
|
+
filter :color, as: :searchable_select, ajax: { resource: RgbColor }
|
13
|
+
|
14
|
+
form do |f|
|
15
|
+
f.inputs do
|
16
|
+
f.input :name
|
17
|
+
f.input :color, as: :searchable_select, ajax: { resource: RgbColor }
|
18
|
+
end
|
19
|
+
f.actions
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
# Admin for testing ajax params with custom scope
|
2
|
+
ActiveAdmin.register Category, as: 'TestAjaxParamsCategory' do
|
3
|
+
menu false
|
4
|
+
searchable_select_options(
|
5
|
+
scope: lambda do |params|
|
6
|
+
Category.where(created_by_id: params[:created_by])
|
7
|
+
end,
|
8
|
+
text_attribute: :name
|
9
|
+
)
|
10
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# Admin for testing ajax params with form
|
2
|
+
ActiveAdmin.register Post, as: 'TestAjaxParamsPost' do
|
3
|
+
menu false
|
4
|
+
controller do
|
5
|
+
def current_user
|
6
|
+
ApplicationController.current_user
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
form do |f|
|
11
|
+
f.input(:category,
|
12
|
+
as: :searchable_select,
|
13
|
+
ajax: {
|
14
|
+
resource: 'TestAjaxParamsCategory',
|
15
|
+
params: {
|
16
|
+
created_by: current_user.id
|
17
|
+
}
|
18
|
+
})
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
# Admin for testing form input with resource and custom collection name
|
2
|
+
ActiveAdmin.register Post, as: 'TestFormPostResourceCustom' do
|
3
|
+
menu false
|
4
|
+
form do |f|
|
5
|
+
f.input(:category_id,
|
6
|
+
as: :searchable_select,
|
7
|
+
ajax: {
|
8
|
+
resource: Category,
|
9
|
+
collection_name: 'custom'
|
10
|
+
})
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
# Admin for testing input_html options
|
2
|
+
ActiveAdmin.register Post, as: 'TestInputHtmlPost' do
|
3
|
+
menu false
|
4
|
+
permit_params :title, :category_id
|
5
|
+
|
6
|
+
form do |f|
|
7
|
+
f.input :title
|
8
|
+
f.input :category, as: :searchable_select, input_html: { class: 'custom-class' },
|
9
|
+
ajax: { resource: Category }
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
# Admin for testing searchable_select_options with display_text option
|
2
|
+
ActiveAdmin.register Post, as: 'TestPostDisplayText' do
|
3
|
+
menu false
|
4
|
+
searchable_select_options(
|
5
|
+
scope: Post,
|
6
|
+
display_text: ->(record) { record.title.upcase },
|
7
|
+
text_attribute: :title
|
8
|
+
)
|
9
|
+
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
# Admin for testing searchable_select_options with filter option
|
2
|
+
ActiveAdmin.register Post, as: 'TestPostFilter' do
|
3
|
+
menu false
|
4
|
+
searchable_select_options(
|
5
|
+
scope: Post,
|
6
|
+
filter: ->(term, scope) { scope.where(title: term) },
|
7
|
+
text_attribute: :title
|
8
|
+
)
|
9
|
+
end
|