activeadmin-searchable_select 1.0.0 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/CHANGELOG.md +9 -0
- data/Gemfile +4 -0
- data/activeadmin-searchable_select.gemspec +0 -2
- data/app/assets/javascripts/active_admin/searchable_select.js +3 -0
- data/app/assets/javascripts/active_admin/searchable_select/init.js +46 -0
- data/gemfiles/rails_4.2_active_admin_1.0.0.pre4.gemfile +1 -0
- data/gemfiles/rails_5.1_active_admin_1.0.gemfile +1 -0
- data/gemfiles/rails_5.1_active_admin_1.1.gemfile +1 -0
- data/lib/activeadmin/searchable_select/version.rb +1 -1
- data/spec/features/end_to_end_spec.rb +31 -24
- data/spec/internal/app/assets/stylesheets/active_admin.scss +2 -0
- metadata +5 -5
- data/app/assets/javascripts/active_admin/searchable_select.js.coffee +0 -3
- data/app/assets/javascripts/active_admin/searchable_select/init.js.coffee +0 -29
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 8e5f2ce9146eca37e95d909b912c1ef5afe9fc511ac736b3d118e81c05c937a4
|
4
|
+
data.tar.gz: 206673047e75f7a79c369c2a5a4a4532b5f336cc4035b817d313775095f227e9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 80c69cf8baa62dac91cbf3f0ff073d5b967f87b5966d547cddc984790e63d99754e5e78acb999512f92bee49e996e3b7edb4272dd32356ea101b1ada17b6fc72
|
7
|
+
data.tar.gz: 931f1f0653de38ef169d0664ebf69396dc4819ee2c3eafd4f33a63ca476b658aaa60c9888903919d1f2ed5c43c5c153b7473e7cef2aaa4533dbbc42852268d9f
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,14 @@
|
|
1
1
|
# CHANGELOG
|
2
2
|
|
3
|
+
### Version 1.0.1
|
4
|
+
|
5
|
+
2018-01-19
|
6
|
+
|
7
|
+
[Compare changes](https://github.com/codevise/activeadmin-searchable_select/compare/v1.0.0...v1.0.1)
|
8
|
+
|
9
|
+
- Use zero based pagination parameter
|
10
|
+
([#2](https://github.com/codevise/activeadmin-searchable_select/pull/2))
|
11
|
+
|
3
12
|
### Version 1.0.0
|
4
13
|
|
5
14
|
2017-10-23
|
data/Gemfile
CHANGED
@@ -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
|
+
}());
|
@@ -24,35 +24,42 @@ RSpec.describe 'end to end', type: :feature, js: true do
|
|
24
24
|
end
|
25
25
|
|
26
26
|
describe 'index page with searchable select filter' do
|
27
|
-
before(:each) do
|
28
|
-
music_category = Category.create(name: 'Music')
|
29
|
-
travel_category = Category.create(name: 'Travel')
|
30
|
-
|
31
|
-
Post.create(title: 'Best songs',
|
32
|
-
category: music_category)
|
33
|
-
Post.create(title: 'Best places',
|
34
|
-
category: travel_category)
|
35
|
-
end
|
36
|
-
|
37
27
|
it 'loads filter input options' do
|
28
|
+
Category.create(name: 'Music')
|
29
|
+
Category.create(name: 'Travel')
|
30
|
+
|
38
31
|
visit '/admin/posts'
|
39
32
|
|
40
33
|
expand_select_box
|
34
|
+
wait_for_ajax
|
41
35
|
|
42
36
|
expect(select_box_items).to eq(%w(Music Travel))
|
43
37
|
end
|
44
38
|
|
45
39
|
it 'allows filtering options by term' do
|
40
|
+
Category.create(name: 'Music')
|
41
|
+
Category.create(name: 'Travel')
|
42
|
+
|
46
43
|
visit '/admin/posts'
|
47
44
|
|
48
45
|
expand_select_box
|
49
|
-
|
50
|
-
wait_for_ajax
|
51
|
-
enter_search_term('T')
|
52
|
-
end
|
46
|
+
enter_search_term('T')
|
47
|
+
wait_for_ajax
|
53
48
|
|
54
49
|
expect(select_box_items).to eq(%w(Travel))
|
55
50
|
end
|
51
|
+
|
52
|
+
it 'loads more items when scrolling down' do
|
53
|
+
15.times { |i| Category.create(name: "Category #{i}") }
|
54
|
+
visit '/admin/posts'
|
55
|
+
|
56
|
+
expand_select_box
|
57
|
+
wait_for_ajax
|
58
|
+
scroll_select_box_list
|
59
|
+
wait_for_ajax
|
60
|
+
|
61
|
+
expect(select_box_items.size).to eq(15)
|
62
|
+
end
|
56
63
|
end
|
57
64
|
|
58
65
|
def expand_select_box
|
@@ -63,21 +70,21 @@ RSpec.describe 'end to end', type: :feature, js: true do
|
|
63
70
|
find('.select2-dropdown input').send_keys(term)
|
64
71
|
end
|
65
72
|
|
73
|
+
def scroll_select_box_list
|
74
|
+
page.execute_script '$(".select2-container ul").scrollTop(1000)'
|
75
|
+
end
|
76
|
+
|
66
77
|
def select_box_items
|
67
78
|
all('.select2-dropdown li').map(&:text)
|
68
79
|
end
|
69
80
|
|
70
|
-
def wait_for_ajax
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
yield
|
76
|
-
|
77
|
-
sleep(0.5) until finished_all_ajax_requests?(count)
|
81
|
+
def wait_for_ajax
|
82
|
+
Timeout.timeout(Capybara.default_max_wait_time) do
|
83
|
+
loop until finished_all_ajax_requests?
|
84
|
+
end
|
78
85
|
end
|
79
86
|
|
80
|
-
def finished_all_ajax_requests?
|
81
|
-
page.evaluate_script('
|
87
|
+
def finished_all_ajax_requests?
|
88
|
+
page.evaluate_script('jQuery.active').zero?
|
82
89
|
end
|
83
90
|
end
|
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.0.
|
4
|
+
version: 1.0.1
|
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:
|
11
|
+
date: 2018-01-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -244,8 +244,8 @@ files:
|
|
244
244
|
- README.md
|
245
245
|
- Rakefile
|
246
246
|
- activeadmin-searchable_select.gemspec
|
247
|
-
- app/assets/javascripts/active_admin/searchable_select.js
|
248
|
-
- app/assets/javascripts/active_admin/searchable_select/init.js
|
247
|
+
- app/assets/javascripts/active_admin/searchable_select.js
|
248
|
+
- app/assets/javascripts/active_admin/searchable_select/init.js
|
249
249
|
- app/assets/stylesheets/active_admin/searchable_select.scss
|
250
250
|
- bin/rspec
|
251
251
|
- gemfiles/rails_4.2_active_admin_1.0.0.pre4.gemfile
|
@@ -304,7 +304,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
304
304
|
version: '0'
|
305
305
|
requirements: []
|
306
306
|
rubyforge_project:
|
307
|
-
rubygems_version: 2.
|
307
|
+
rubygems_version: 2.7.0
|
308
308
|
signing_key:
|
309
309
|
specification_version: 4
|
310
310
|
summary: Use searchable selects based on Select2 in Active Admin forms and filters.
|
@@ -1,29 +0,0 @@
|
|
1
|
-
'use strict';
|
2
|
-
|
3
|
-
initSearchableSelects = (inputs, extra = {}) ->
|
4
|
-
inputs.each ->
|
5
|
-
item = $(this)
|
6
|
-
# reading from data allows <input data-searchable_select='{"tags": ['some']}'>
|
7
|
-
# to be passed to select2
|
8
|
-
options = $.extend(extra, item.data('searchableSelect'))
|
9
|
-
url = item.data('ajaxUrl');
|
10
|
-
|
11
|
-
if url
|
12
|
-
$.extend(
|
13
|
-
options,
|
14
|
-
ajax: {
|
15
|
-
url: url,
|
16
|
-
dataType: 'json'
|
17
|
-
}
|
18
|
-
)
|
19
|
-
|
20
|
-
item.select2(options)
|
21
|
-
|
22
|
-
$(document).on 'has_many_add:after', '.has_many_container', (e, fieldset) ->
|
23
|
-
initSearchableSelects(fieldset.find('.searchable-select-input'))
|
24
|
-
|
25
|
-
$(document).on 'page:load turbolinks:load', ->
|
26
|
-
initSearchableSelects($(".searchable-select-input"), placeholder: "")
|
27
|
-
return
|
28
|
-
|
29
|
-
$(-> initSearchableSelects($(".searchable-select-input")))
|