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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: e45366aab36050f1bacd26cf7c7e083f73366337
4
- data.tar.gz: 41b977d5f33c903293d2cccccfcabf2de910c71a
2
+ SHA256:
3
+ metadata.gz: 8e5f2ce9146eca37e95d909b912c1ef5afe9fc511ac736b3d118e81c05c937a4
4
+ data.tar.gz: 206673047e75f7a79c369c2a5a4a4532b5f336cc4035b817d313775095f227e9
5
5
  SHA512:
6
- metadata.gz: 48d3f353accca041a2bc5d533cc8574d6f895f7b04fca7354b5d10e6fc73c3ae276b555ed031ea8226bcfc0a68f70c49657f737df9c51fb0f6f316700d34c2a4
7
- data.tar.gz: 1114951d8895a4a25a1e56162d099c9fc60592241ec79b9ee8c573fed3db93e427b3137f41d555c3a658eef3f0df6cecf2a3f4034e8102a8a4280cfa97336a8e
6
+ metadata.gz: 80c69cf8baa62dac91cbf3f0ff073d5b967f87b5966d547cddc984790e63d99754e5e78acb999512f92bee49e996e3b7edb4272dd32356ea101b1ada17b6fc72
7
+ data.tar.gz: 931f1f0653de38ef169d0664ebf69396dc4819ee2c3eafd4f33a63ca476b658aaa60c9888903919d1f2ed5c43c5c153b7473e7cef2aaa4533dbbc42852268d9f
@@ -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
@@ -1,3 +1,7 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
+ # Required for select2-rails to work with Active Admin 1.1
4
+ # see https://github.com/activeadmin/activeadmin/issues/5226
5
+ gem 'sass-rails'
6
+
3
7
  gemspec
@@ -1,5 +1,3 @@
1
- # -*- encoding: utf-8 -*-
2
-
3
1
  lib = File.expand_path('../lib', __FILE__)
4
2
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
3
  require 'activeadmin/searchable_select/version'
@@ -0,0 +1,3 @@
1
+ //= require select2
2
+
3
+ //= require_tree ./searchable_select
@@ -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
+ }());
@@ -2,6 +2,7 @@
2
2
 
3
3
  source "https://rubygems.org"
4
4
 
5
+ gem "sass-rails"
5
6
  gem "rails", "~> 4.2"
6
7
  gem "activeadmin", "1.0.0.pre4"
7
8
  gem "jquery-ui-rails", "~> 5.0"
@@ -2,6 +2,7 @@
2
2
 
3
3
  source "https://rubygems.org"
4
4
 
5
+ gem "sass-rails"
5
6
  gem "rails", "~> 5.1"
6
7
  gem "activeadmin", "~> 1.0"
7
8
 
@@ -2,6 +2,7 @@
2
2
 
3
3
  source "https://rubygems.org"
4
4
 
5
+ gem "sass-rails"
5
6
  gem "rails", "~> 5.1"
6
7
  gem "activeadmin", "~> 1.1"
7
8
 
@@ -1,5 +1,5 @@
1
1
  module ActiveAdmin
2
2
  module SearchableSelect
3
- VERSION = '1.0.0'.freeze
3
+ VERSION = '1.0.1'.freeze
4
4
  end
5
5
  end
@@ -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 do
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(count = 1)
71
- page.execute_script 'window._ajaxCalls = 0'
72
- page.execute_script 'window._ajaxCompleteCounter = function() { window._ajaxCalls += 1; }'
73
- page.execute_script '$(document).ajaxComplete(window._ajaxCompleteCounter)'
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?(count)
81
- page.evaluate_script('window._ajaxCalls') == count
87
+ def finished_all_ajax_requests?
88
+ page.evaluate_script('jQuery.active').zero?
82
89
  end
83
90
  end
@@ -1,2 +1,4 @@
1
1
  @import "active_admin/mixins";
2
2
  @import "active_admin/base";
3
+
4
+ @import "active_admin/searchable_select";
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.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: 2017-10-23 00:00:00.000000000 Z
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.coffee
248
- - app/assets/javascripts/active_admin/searchable_select/init.js.coffee
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.6.8
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,3 +0,0 @@
1
- #= require select2
2
-
3
- #= require_tree ./searchable_select
@@ -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")))