activeadmin-searchable_select 1.6.0 → 1.8.0

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
  SHA256:
3
- metadata.gz: 86f2b11107d464955292c9d5a51629757ff3fb213aafdeb9302b948f421796ee
4
- data.tar.gz: 961efac5444a994afac0b8a13437bbd96ec8effedbbc6356b606a9d23bc80849
3
+ metadata.gz: 7cfe9f36cf136d370ead8ce6227d00057850a5d4f6ee9520cbed52da1c15a3d8
4
+ data.tar.gz: d5043ace26e5abc0b5a4ee3c58b2fad8243b9cb8c78de93be0013f6c4116b163
5
5
  SHA512:
6
- metadata.gz: 79b204c1f6af56e2d39c4ee658cfde5af5ca31733ed3d2eb657ab78a8de66511b9e7387dd5fa64a457768095c67858e64f3fd598058ef1458fceba0575880522
7
- data.tar.gz: 9bcbd53a3504788a0c18ce8f701efefcc2f0495625eedf277a30c738c5083d4b3a4602fdd95c05ca904ad8b0034e551ea1706a46f077805c5b0146f0121ee2fc
6
+ metadata.gz: 912517731c734da5286389411fc658c3de99d336b538b8f9c8e6b28640185bcd3b718d7220c3b91d4a1d70f398b0e43bfe606c61403cd66807d441f89eda668d
7
+ data.tar.gz: 4491ef833bf6b70a2b66008de0507b22ca05dd0d9ff620b76127ec284fd4961c8eb868856ff2f472001d85b904a1e0114509d996c013ff66a81a2f27c8592ee5
@@ -23,6 +23,8 @@ jobs:
23
23
  include:
24
24
  - ruby-version: '3.0'
25
25
  gemfile: gemfiles/rails_6.x_active_admin_2.x.gemfile
26
+ - ruby-version: '3.0'
27
+ gemfile: gemfiles/rails_6.x_active_admin_3.x.gemfile
26
28
 
27
29
  env:
28
30
  BUNDLE_GEMFILE: ${{ matrix.gemfile }}
data/Appraisals CHANGED
@@ -16,4 +16,9 @@ end
16
16
  appraise 'rails-6.x-active-admin-2.x' do
17
17
  gem 'rails', '~> 6.1'
18
18
  gem 'activeadmin', '~> 2.0'
19
- end
19
+ end
20
+
21
+ appraise 'rails-6.x-active-admin-3.x' do
22
+ gem 'rails', '~> 6.1'
23
+ gem 'activeadmin', '~> 3.0'
24
+ end
data/CHANGELOG.md CHANGED
@@ -1,14 +1,16 @@
1
1
  # CHANGELOG
2
2
 
3
- ### Version 1.6.0
3
+ ### Version 1.8.0
4
4
 
5
- 2022-04-05
5
+ 2023-08-17
6
6
 
7
- [Compare changes](https://github.com/codevise/activeadmin-searchable_select/compare/1-5-stable...v1.6.0)
7
+ [Compare changes](https://github.com/codevise/activeadmin-searchable_select/compare/1-7-stable...v1.8.0)
8
8
 
9
- - Add option to pass path params for nested resource fetching
10
- ([#39](https://github.com/codevise/activeadmin-searchable_select/pull/39))
9
+ - Update webdrivers to fix specs for Chrome 115
10
+ ([#47](https://github.com/codevise/activeadmin-searchable_select/pull/47))
11
+ - Add support for Active Admin 3.0
12
+ ([#45](https://github.com/codevise/activeadmin-searchable_select/pull/45))
11
13
 
12
14
  See
13
- [1-5-stable branch](https://github.com/codevise/activeadmin-searchable_select/blob/1-5-stable/CHANGELOG.md)
15
+ [1-7-stable branch](https://github.com/codevise/activeadmin-searchable_select/blob/1-7-stable/CHANGELOG.md)
14
16
  for previous changes.
data/README.md CHANGED
@@ -1,7 +1,9 @@
1
1
  # ActiveAdmin Searchable Select
2
2
 
3
3
  [![Gem Version](https://badge.fury.io/rb/activeadmin-searchable_select.svg)](http://badge.fury.io/rb/activeadmin-searchable_select)
4
- [![Build Status](https://github.com/codevise/activeadmin-searchable_select.svg?branch=master)](https://github.com/codevise/activeadmin-searchable_select/actions)
4
+ [![NPM Version](https://badge.fury.io/js/@codevise%2Factiveadmin-searchable_select.svg)](https://badge.fury.io/js/@codevise%2Factiveadmin-searchable_select)
5
+ [![npm](https://img.shields.io/npm/dm/@codevise/activeadmin-searchable_select)](https://www.npmjs.com/package/@codevise/activeadmin-searchable_select)
6
+ [![Build Status](https://github.com/codevise/activeadmin-searchable_select/actions/workflows/tests.yml/badge.svg)](https://github.com/codevise/activeadmin-searchable_select/actions)
5
7
 
6
8
  Searchable select boxes (via [Select2](https://select2.org/)) for
7
9
  ActiveAdmin forms and filters. Extends the ActiveAdmin resource DSL to
@@ -15,6 +17,7 @@ Add `activeadmin-searchable_select` to your Gemfile:
15
17
  gem 'activeadmin-searchable_select'
16
18
  ```
17
19
 
20
+ ##### Using assets via Sprockets
18
21
  Import stylesheets and require javascripts:
19
22
 
20
23
  ```scss
@@ -27,6 +30,39 @@ Import stylesheets and require javascripts:
27
30
  //= require active_admin/searchable_select
28
31
  ```
29
32
 
33
+ ##### Using assets via Webpacker (or any other assets bundler) as a NPM module (Yarn package)
34
+
35
+ Execute:
36
+
37
+ $ npm i @codevise/activeadmin-searchable_select
38
+
39
+ Or
40
+
41
+ $ yarn add @codevise/activeadmin-searchable_select
42
+
43
+ Or add manually to `package.json`:
44
+
45
+ ```json
46
+ "dependencies": {
47
+ "@codevise/activeadmin-searchable_select": "1.6.0"
48
+ }
49
+ ```
50
+ and execute:
51
+
52
+ $ yarn
53
+
54
+ Add the following line into `app/javascript/active_admin.js`:
55
+
56
+ ```javascript
57
+ import '@codevise/activeadmin-searchable_select';
58
+ ```
59
+
60
+ Add the following line into `app/javascript/stylesheets/active_admin.scss`:
61
+
62
+ ```css
63
+ @import '@codevise/activeadmin-searchable_select';
64
+ ```
65
+
30
66
  ## Usage
31
67
 
32
68
  ### Making Select Boxes Searchable
@@ -26,8 +26,8 @@ Gem::Specification.new do |spec|
26
26
 
27
27
  spec.add_development_dependency 'capybara', '~> 3.9'
28
28
  spec.add_development_dependency 'puma', '~> 5.0'
29
- spec.add_development_dependency 'selenium-webdriver', '~> 3.6'
30
- spec.add_development_dependency 'webdrivers', '~> 4.0'
29
+ spec.add_development_dependency 'selenium-webdriver', '~> 4.1'
30
+ spec.add_development_dependency 'webdrivers', '= 5.3.0'
31
31
 
32
32
  spec.add_development_dependency 'coffee-rails'
33
33
  spec.add_development_dependency 'rails'
@@ -35,7 +35,7 @@ Gem::Specification.new do |spec|
35
35
  spec.add_development_dependency 'semmy', '~> 1.0'
36
36
  spec.add_development_dependency 'sprockets', '~> 3.7'
37
37
 
38
- spec.add_runtime_dependency 'activeadmin', ['>= 1.x', '< 3']
38
+ spec.add_runtime_dependency 'activeadmin', ['>= 1.x', '< 4']
39
39
  spec.add_runtime_dependency 'jquery-rails', ['>= 3.0', '< 5']
40
40
  spec.add_runtime_dependency 'select2-rails', '~> 4.0'
41
41
  end
@@ -0,0 +1,2 @@
1
+ import 'select2';
2
+ import './searchable_select/init';
@@ -0,0 +1,9 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "sass-rails"
6
+ gem "rails", "~> 6.1"
7
+ gem "activeadmin", "~> 3.0"
8
+
9
+ gemspec path: "../"
@@ -84,7 +84,7 @@ module ActiveAdmin
84
84
  end
85
85
 
86
86
  def option_collection_scope
87
- option_collection.scope(template, ajax_params)
87
+ option_collection.scope(template, path_params.merge(ajax_params))
88
88
  end
89
89
 
90
90
  def option_collection
@@ -1,5 +1,5 @@
1
1
  module ActiveAdmin
2
2
  module SearchableSelect
3
- VERSION = '1.6.0'.freeze
3
+ VERSION = '1.8.0'.freeze
4
4
  end
5
5
  end
data/package.json ADDED
@@ -0,0 +1,38 @@
1
+ {
2
+ "name": "@codevise/activeadmin-searchable_select",
3
+ "version": "1.7.0",
4
+ "description": "Use searchable selects based on Select2 in Active Admin forms and filters.",
5
+ "main": "src/searchable_select.js",
6
+ "style": "src/searchable_select.scss",
7
+ "repository": "git@github.com:codevise/activeadmin-searchable_select.git",
8
+ "author": "Codevise Solutions Ltd <info@codevise.de>",
9
+ "license": "MIT",
10
+ "private": false,
11
+ "repository": {
12
+ "type": "git",
13
+ "url": "git+https://github.com/codevise/activeadmin-searchable_select.git"
14
+ },
15
+ "bugs": {
16
+ "url": "https://github.com/codevise/activeadmin-searchable_select/issues"
17
+ },
18
+ "homepage": "https://github.com/codevise/activeadmin-searchable_select#readme",
19
+ "keywords": [
20
+ "select2",
21
+ "active",
22
+ "admin",
23
+ "searchable",
24
+ "select"
25
+ ],
26
+ "dependencies": {
27
+ "jquery": ">= 3.0, < 5",
28
+ "select2": "~> 4.0"
29
+ },
30
+ "files": [
31
+ "src/**/*"
32
+ ],
33
+ "scripts": {
34
+ "prepare_javascripts_src": "rm -rf src && cp -R app/assets/javascripts/active_admin/ src && mv src/searchable_select_pack.js src/searchable_select.js",
35
+ "prepare_stylesheets_src": "cp -R app/assets/stylesheets/active_admin/* src",
36
+ "prepublishOnly": "npm run prepare_javascripts_src && npm run prepare_stylesheets_src"
37
+ }
38
+ }
@@ -180,6 +180,22 @@ RSpec.describe 'end to end', type: :feature, js: true do
180
180
  expect(select_box_items.size).to eq(15)
181
181
  end
182
182
  end
183
+
184
+ describe 'edit page with searchable select filter' do
185
+ it 'preselects item' do
186
+ option_type = OptionType.create(name: 'Color')
187
+ ot = OptionType.create(name: 'Size')
188
+ option_value = OptionValue.create(value: 'Black', option_type: option_type)
189
+ OptionValue.create(value: 'Orange', option_type: option_type)
190
+ OptionValue.create(value: 'M', option_type: ot)
191
+ product = Product.create(name: 'Cap', option_type: option_type)
192
+ variant = Variant.create(product: product, option_value: option_value)
193
+
194
+ visit "/admin/products/#{product.id}/variants/#{variant.id}/edit"
195
+
196
+ expect(select_box_selected_item_text).to eq('Black')
197
+ end
198
+ end
183
199
  end
184
200
 
185
201
  def expand_select_box
@@ -198,6 +214,10 @@ RSpec.describe 'end to end', type: :feature, js: true do
198
214
  all('.select2-dropdown li').map(&:text)
199
215
  end
200
216
 
217
+ def select_box_selected_item_text
218
+ find('.select2-selection').text
219
+ end
220
+
201
221
  def wait_for_ajax
202
222
  Timeout.timeout(Capybara.default_max_wait_time) do
203
223
  sleep 0.1
@@ -4,6 +4,10 @@ class User < ActiveRecord::Base; end
4
4
 
5
5
  class Category < ActiveRecord::Base
6
6
  belongs_to :created_by, class_name: 'User'
7
+
8
+ def self.ransackable_attributes(_auth_object = nil)
9
+ ['name']
10
+ end
7
11
  end
8
12
 
9
13
  class Post < ActiveRecord::Base
@@ -11,6 +15,10 @@ class Post < ActiveRecord::Base
11
15
  belongs_to :user
12
16
 
13
17
  scope(:published, -> { where(published: true) })
18
+
19
+ def self.ransackable_attributes(_auth_object = nil)
20
+ %w(category_id title)
21
+ end
14
22
  end
15
23
 
16
24
  module RGB
@@ -24,6 +32,10 @@ module Internal
24
32
  class TagName < ActiveRecord::Base
25
33
  self.table_name = :internal_tag_names
26
34
  belongs_to :color, class_name: 'RGB::Color', foreign_key: :color_id
35
+
36
+ def self.ransackable_attributes(_auth_object = nil)
37
+ ['color_id']
38
+ end
27
39
  end
28
40
  end
29
41
 
@@ -31,6 +43,10 @@ class OptionType < ActiveRecord::Base; end
31
43
 
32
44
  class OptionValue < ActiveRecord::Base
33
45
  belongs_to :option_type
46
+
47
+ def self.ransackable_attributes(_auth_object = nil)
48
+ ['value']
49
+ end
34
50
  end
35
51
 
36
52
  class Product < ActiveRecord::Base
@@ -0,0 +1,46 @@
1
+ (function() {
2
+ function initSearchableSelects(inputs, extra) {
3
+ inputs.each(function() {
4
+ var item = $(this);
5
+
6
+ // reading from data allows <input data-searchable_select='{"tags": ['some']}'>
7
+ // to be passed to select2
8
+ var options = $.extend(extra || {}, item.data('searchableSelect'));
9
+ var url = item.data('ajaxUrl');
10
+
11
+ if (url) {
12
+ $.extend(options, {
13
+ ajax: {
14
+ url: url,
15
+ dataType: 'json',
16
+
17
+ data: function (params) {
18
+ return {
19
+ term: params.term,
20
+ page: pageParamWithBaseZero(params)
21
+ };
22
+ }
23
+ }
24
+ });
25
+ }
26
+
27
+ item.select2(options);
28
+ });
29
+ }
30
+
31
+ function pageParamWithBaseZero(params) {
32
+ return params.page ? params.page - 1 : undefined;
33
+ }
34
+
35
+ $(document).on('has_many_add:after', '.has_many_container', function(e, fieldset) {
36
+ initSearchableSelects(fieldset.find('.searchable-select-input'));
37
+ });
38
+
39
+ $(document).on('page:load turbolinks:load', function() {
40
+ initSearchableSelects($(".searchable-select-input"), {placeholder: ""});
41
+ });
42
+
43
+ $(function() {
44
+ initSearchableSelects($(".searchable-select-input"));
45
+ });
46
+ }());
@@ -0,0 +1,2 @@
1
+ import 'select2';
2
+ import './searchable_select/init';
@@ -0,0 +1,5 @@
1
+ @import "select2";
2
+
3
+ .searchable_select.input .select2-container {
4
+ min-width: 30%;
5
+ }
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activeadmin-searchable_select
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.6.0
4
+ version: 1.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Codevise Solutions Ltd
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-04-05 00:00:00.000000000 Z
11
+ date: 2023-08-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -148,28 +148,28 @@ dependencies:
148
148
  requirements:
149
149
  - - "~>"
150
150
  - !ruby/object:Gem::Version
151
- version: '3.6'
151
+ version: '4.1'
152
152
  type: :development
153
153
  prerelease: false
154
154
  version_requirements: !ruby/object:Gem::Requirement
155
155
  requirements:
156
156
  - - "~>"
157
157
  - !ruby/object:Gem::Version
158
- version: '3.6'
158
+ version: '4.1'
159
159
  - !ruby/object:Gem::Dependency
160
160
  name: webdrivers
161
161
  requirement: !ruby/object:Gem::Requirement
162
162
  requirements:
163
- - - "~>"
163
+ - - '='
164
164
  - !ruby/object:Gem::Version
165
- version: '4.0'
165
+ version: 5.3.0
166
166
  type: :development
167
167
  prerelease: false
168
168
  version_requirements: !ruby/object:Gem::Requirement
169
169
  requirements:
170
- - - "~>"
170
+ - - '='
171
171
  - !ruby/object:Gem::Version
172
- version: '4.0'
172
+ version: 5.3.0
173
173
  - !ruby/object:Gem::Dependency
174
174
  name: coffee-rails
175
175
  requirement: !ruby/object:Gem::Requirement
@@ -249,7 +249,7 @@ dependencies:
249
249
  version: 1.x
250
250
  - - "<"
251
251
  - !ruby/object:Gem::Version
252
- version: '3'
252
+ version: '4'
253
253
  type: :runtime
254
254
  prerelease: false
255
255
  version_requirements: !ruby/object:Gem::Requirement
@@ -259,7 +259,7 @@ dependencies:
259
259
  version: 1.x
260
260
  - - "<"
261
261
  - !ruby/object:Gem::Version
262
- version: '3'
262
+ version: '4'
263
263
  - !ruby/object:Gem::Dependency
264
264
  name: jquery-rails
265
265
  requirement: !ruby/object:Gem::Requirement
@@ -314,12 +314,14 @@ files:
314
314
  - activeadmin-searchable_select.gemspec
315
315
  - app/assets/javascripts/active_admin/searchable_select.js
316
316
  - app/assets/javascripts/active_admin/searchable_select/init.js
317
+ - app/assets/javascripts/active_admin/searchable_select_pack.js
317
318
  - app/assets/stylesheets/active_admin/searchable_select.scss
318
319
  - bin/rspec
319
320
  - gemfiles/rails_5.1_active_admin_1.x.gemfile
320
321
  - gemfiles/rails_5.x_active_admin_1.x.gemfile
321
322
  - gemfiles/rails_5.x_active_admin_2.x.gemfile
322
323
  - gemfiles/rails_6.x_active_admin_2.x.gemfile
324
+ - gemfiles/rails_6.x_active_admin_3.x.gemfile
323
325
  - lib/activeadmin-searchable_select.rb
324
326
  - lib/activeadmin/inputs/filters/searchable_select_input.rb
325
327
  - lib/activeadmin/inputs/searchable_select_input.rb
@@ -330,6 +332,7 @@ files:
330
332
  - lib/activeadmin/searchable_select/resource_extension.rb
331
333
  - lib/activeadmin/searchable_select/select_input_extension.rb
332
334
  - lib/activeadmin/searchable_select/version.rb
335
+ - package.json
333
336
  - spec/features/ajax_params_spec.rb
334
337
  - spec/features/end_to_end_spec.rb
335
338
  - spec/features/filter_input_spec.rb
@@ -353,6 +356,9 @@ files:
353
356
  - spec/support/models.rb
354
357
  - spec/support/pluck_polyfill.rb
355
358
  - spec/support/reset_settings.rb
359
+ - src/searchable_select.js
360
+ - src/searchable_select.scss
361
+ - src/searchable_select/init.js
356
362
  homepage: https://github.com/codevise/activeadmin-searchable_select
357
363
  licenses:
358
364
  - MIT
@@ -375,7 +381,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
375
381
  - !ruby/object:Gem::Version
376
382
  version: '0'
377
383
  requirements: []
378
- rubygems_version: 3.0.8
384
+ rubygems_version: 3.2.3
379
385
  signing_key:
380
386
  specification_version: 4
381
387
  summary: Use searchable selects based on Select2 in Active Admin forms and filters.