activeadmin-ajax_filter 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 623bc73b23aeeffb17a649881dd93aac161501e7
4
+ data.tar.gz: 20c10cfbdf0e62cf2c4a9398e1b347c4607bf86f
5
+ SHA512:
6
+ metadata.gz: 332257481022b85e17431c08bd7dd30535c56ae3fec0bdbe4161583089bbe44643515e4bebe18741b59ae88c666c815af15219bb3e224abb375f817fbfff7468
7
+ data.tar.gz: 3d2a382207e390bdba1ecbf104e48751d4511414c254ce706bb3309ebf4553ca80fbee3f6ad580c4e05501691eb4ec72cb3fc4c9f632c03843449b85862a9117
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --require spec_helper
data/.travis.yml ADDED
@@ -0,0 +1,7 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.1.5
4
+ - 2.2.4
5
+ - 2.3.0
6
+ - ruby-head
7
+ before_install: gem install bundler -v 1.10.6
@@ -0,0 +1,13 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
4
+
5
+ We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, or religion.
6
+
7
+ Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
8
+
9
+ Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
10
+
11
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
12
+
13
+ This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in activeadmin-ajax_filter.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Alex Emelyanov
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,73 @@
1
+ # Activeadmin::AjaxFilter
2
+
3
+ This gem extends ActiveAdmin so that your can use filters with AJAX-powered input.
4
+
5
+ ## Prerequisites
6
+
7
+ This extension assumes that you're using [Active Admin](https://github.com/activeadmin/activeadmin) with [Ransack](https://github.com/activerecord-hackery/ransack)
8
+
9
+ ## Installation
10
+
11
+ Add this line to your application's Gemfile:
12
+
13
+ ```ruby
14
+ gem 'activeadmin-ajax_filter'
15
+ ```
16
+
17
+ And then execute:
18
+
19
+ $ bundle
20
+
21
+ Or install it yourself as:
22
+
23
+ $ gem install activeadmin-ajax_filter
24
+
25
+ ## Usage
26
+
27
+ Include this line in your JavaScript code (active_admin.js.coffee)
28
+
29
+ ```coffeescript
30
+ #= require activeadmin-ajax_filter
31
+ ```
32
+
33
+ Include this line in your CSS code (active_admin.scss)
34
+
35
+ ```scss
36
+ @import "activeadmin-ajax_filter";
37
+ ```
38
+
39
+ Include `ActiveAdmin::AjaxFilter` module to the ActiveAdmin relation resource for which you want to support filtering and add `ajax_select` filter to main resource. For example:
40
+
41
+ ```ruby
42
+ # Relation-resource
43
+ ActiveAdmin.register User do
44
+ include ActiveAdmin::AjaxFilter
45
+ ...
46
+
47
+ # Main resource
48
+ ActiveAdmin.register Invoice do
49
+ filter :user, as: :ajax_select, data: { search_fields: [:email, :customer_uid], limit: 7 }
50
+ ```
51
+
52
+ You can use next parameters in `data` hash:
53
+
54
+ * limit - count of the items which will be requested by AJAX, by default `5`
55
+ * value_field - value field for html select element, by default `id`
56
+ * search_fields - fields by which AJAX search will be performed, required parameter
57
+ * ransack - ransack query which will be applied, by default it's builded from `search_fields` with `or` and `contains` clauses, e.g.: `email_or_customer_uid_cont`
58
+
59
+ ## Development
60
+
61
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake false` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
62
+
63
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
64
+
65
+ ## Contributing
66
+
67
+ Bug reports and pull requests are welcome on GitHub at https://github.com/holyketzer/activeadmin-ajax_filter. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](contributor-covenant.org) code of conduct.
68
+
69
+
70
+ ## License
71
+
72
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
73
+
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,29 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'active_admin/ajax_filter/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = 'activeadmin-ajax_filter'
8
+ gem.version = ActiveAdmin::AjaxFilter::VERSION
9
+ gem.authors = ['Alex Emelyanov']
10
+ gem.email = ['aemelyanov@spbtv.com']
11
+
12
+ gem.summary = 'AJAX filters for ActiveAdmin'
13
+ gem.description = 'Allows to define filter by relation for ActiveAdmin resource pages using Ransacker to dynamicaly load items while user is typing symbols in filter'
14
+ gem.homepage = 'https://github.com/holyketzer/activeadmin-ajax_filter'
15
+ gem.license = 'MIT'
16
+
17
+ gem.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ gem.bindir = 'exe'
19
+ gem.executables = gem.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ gem.require_paths = ['lib']
21
+
22
+ gem.add_dependency 'activeadmin', '>= 1.0.0.pre1'
23
+ gem.add_dependency 'coffee-rails', '~> 4.1', '>= 4.1.0'
24
+ gem.add_development_dependency 'bundler', '~> 1.10'
25
+ gem.add_development_dependency 'rake', '~> 10.0'
26
+ gem.add_development_dependency 'rspec', '~> 3.3', '>= 3.3.0'
27
+ gem.add_development_dependency 'sqlite3', '~> 1.3', '>= 1.3.11'
28
+ gem.add_development_dependency 'temping', '~> 3.3', '>= 3.3.0'
29
+ end
@@ -0,0 +1,61 @@
1
+ $ ->
2
+ $('.filter_ajax_select select').each (_, select) ->
3
+ select = $(select)
4
+ valueField = select.data('value-field')
5
+ searchFields = select.data('search-fields').split(' ')
6
+
7
+ loadOptions = (q, callback) ->
8
+ $.ajax
9
+ url: 'users/filter'
10
+ type: 'GET'
11
+ dataType: 'json'
12
+ data:
13
+ q: q
14
+ limit: select.data('limit')
15
+ error: ->
16
+ callback()
17
+ success: (res) ->
18
+ callback(res)
19
+
20
+ select.selectize
21
+ valueField: valueField
22
+ labelField: searchFields[0]
23
+ searchField: searchFields
24
+ options: []
25
+ create: false
26
+ render:
27
+ option: (item, escape) ->
28
+ html = searchFields.map (field, index)->
29
+ value = escape(item[field])
30
+
31
+ if index == 0
32
+ klass = 'primary'
33
+ else
34
+ klass = 'secondary'
35
+
36
+ "<span class='#{klass}'>#{value}</span>"
37
+
38
+ "<div class='item'>#{html.join('')}</div>"
39
+
40
+ load: (query, callback) ->
41
+ if query.length
42
+ q = {}
43
+ q[select.data('ransack')] = query
44
+ loadOptions(q, callback)
45
+ else
46
+ callback()
47
+
48
+ onInitialize: ->
49
+ selectize = this
50
+ selectedValue = select.data('selected-value')
51
+ selectedRansack = "#{valueField}_eq"
52
+
53
+ if selectedValue
54
+ q = {}
55
+ q[selectedRansack] = selectedValue
56
+
57
+ loadOptions(q, (res)->
58
+ if res.length
59
+ selectize.addOption(res[0])
60
+ selectize.addItem(res[0][valueField])
61
+ )
@@ -0,0 +1,13 @@
1
+ .filter_ajax_select .selectize-dropdown {
2
+ .item {
3
+ border-bottom: light-gray 1px solid;
4
+ }
5
+
6
+ .primary {
7
+ font-weight: bold;
8
+ }
9
+
10
+ .primary, .secondary {
11
+ display: block;
12
+ }
13
+ }
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "activeadmin/ajax_filter"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,23 @@
1
+ require 'active_admin'
2
+ require 'active_admin/ajax_filter/engine'
3
+ require 'active_admin/ajax_filter/version'
4
+ require 'active_admin/inputs/filters/ajax_select_input'
5
+
6
+ module ActiveAdmin
7
+ module AjaxFilter
8
+ class << self
9
+ # @param [ActiveAdmin::DSL] dsl
10
+ # @return [void]
11
+ #
12
+ def included(dsl)
13
+ dsl.instance_eval do
14
+ collection_action :filter, method: :get do
15
+ scope = collection.ransack(params[:q]).result
16
+
17
+ render json: scope.order(:created_at).limit(params[:limit] || 10)
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,9 @@
1
+ require 'rails/engine'
2
+
3
+ module ActiveAdmin
4
+ module AjaxFilter
5
+ # Including an Engine tells Rails that this gem contains assets
6
+ class Engine < ::Rails::Engine
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,5 @@
1
+ module ActiveAdmin
2
+ module AjaxFilter
3
+ VERSION = '0.1.1'
4
+ end
5
+ end
@@ -0,0 +1,53 @@
1
+ module ActiveAdmin
2
+ module Inputs
3
+ module Filters
4
+ class AjaxSelectInput < SelectInput
5
+ DEFAULT_LIMIT = 5
6
+
7
+ def pluck_column
8
+ klass.reorder("#{method} asc").limit(collection_limit).uniq.pluck(method)
9
+ end
10
+
11
+ def collection_from_association
12
+ super.limit(collection_limit)
13
+ end
14
+
15
+ def input_html_options
16
+ super.merge(
17
+ 'data-limit' => collection_limit,
18
+ 'data-value-field' => value_field,
19
+ 'data-search-fields' => search_fields,
20
+ 'data-ransack' => ransack,
21
+ 'data-selected-value' => selected_value,
22
+ )
23
+ end
24
+
25
+ def ajax_data
26
+ options[:data] || {}
27
+ end
28
+
29
+ def collection_limit
30
+ ajax_data[:limit] || DEFAULT_LIMIT
31
+ end
32
+
33
+ def value_field
34
+ ajax_data[:value_field] || :id
35
+ end
36
+
37
+ def search_fields
38
+ ajax_data[:search_fields] || raise(ArgumentError, 'search_fields in required')
39
+ end
40
+
41
+ def ransack
42
+ ajax_data[:ransack] || "#{search_fields.join('_or_')}_cont"
43
+ end
44
+
45
+ def selected_value
46
+ if @object
47
+ @object.try(:send, input_name)
48
+ end
49
+ end
50
+ end
51
+ end
52
+ end
53
+ end
@@ -0,0 +1 @@
1
+ require 'active_admin/ajax_filter'
metadata ADDED
@@ -0,0 +1,185 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: activeadmin-ajax_filter
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Alex Emelyanov
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-02-01 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activeadmin
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 1.0.0.pre1
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 1.0.0.pre1
27
+ - !ruby/object:Gem::Dependency
28
+ name: coffee-rails
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '4.1'
34
+ - - ">="
35
+ - !ruby/object:Gem::Version
36
+ version: 4.1.0
37
+ type: :runtime
38
+ prerelease: false
39
+ version_requirements: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - "~>"
42
+ - !ruby/object:Gem::Version
43
+ version: '4.1'
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: 4.1.0
47
+ - !ruby/object:Gem::Dependency
48
+ name: bundler
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - "~>"
52
+ - !ruby/object:Gem::Version
53
+ version: '1.10'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - "~>"
59
+ - !ruby/object:Gem::Version
60
+ version: '1.10'
61
+ - !ruby/object:Gem::Dependency
62
+ name: rake
63
+ requirement: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - "~>"
66
+ - !ruby/object:Gem::Version
67
+ version: '10.0'
68
+ type: :development
69
+ prerelease: false
70
+ version_requirements: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - "~>"
73
+ - !ruby/object:Gem::Version
74
+ version: '10.0'
75
+ - !ruby/object:Gem::Dependency
76
+ name: rspec
77
+ requirement: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - "~>"
80
+ - !ruby/object:Gem::Version
81
+ version: '3.3'
82
+ - - ">="
83
+ - !ruby/object:Gem::Version
84
+ version: 3.3.0
85
+ type: :development
86
+ prerelease: false
87
+ version_requirements: !ruby/object:Gem::Requirement
88
+ requirements:
89
+ - - "~>"
90
+ - !ruby/object:Gem::Version
91
+ version: '3.3'
92
+ - - ">="
93
+ - !ruby/object:Gem::Version
94
+ version: 3.3.0
95
+ - !ruby/object:Gem::Dependency
96
+ name: sqlite3
97
+ requirement: !ruby/object:Gem::Requirement
98
+ requirements:
99
+ - - "~>"
100
+ - !ruby/object:Gem::Version
101
+ version: '1.3'
102
+ - - ">="
103
+ - !ruby/object:Gem::Version
104
+ version: 1.3.11
105
+ type: :development
106
+ prerelease: false
107
+ version_requirements: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - "~>"
110
+ - !ruby/object:Gem::Version
111
+ version: '1.3'
112
+ - - ">="
113
+ - !ruby/object:Gem::Version
114
+ version: 1.3.11
115
+ - !ruby/object:Gem::Dependency
116
+ name: temping
117
+ requirement: !ruby/object:Gem::Requirement
118
+ requirements:
119
+ - - "~>"
120
+ - !ruby/object:Gem::Version
121
+ version: '3.3'
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: 3.3.0
125
+ type: :development
126
+ prerelease: false
127
+ version_requirements: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - "~>"
130
+ - !ruby/object:Gem::Version
131
+ version: '3.3'
132
+ - - ">="
133
+ - !ruby/object:Gem::Version
134
+ version: 3.3.0
135
+ description: Allows to define filter by relation for ActiveAdmin resource pages using
136
+ Ransacker to dynamicaly load items while user is typing symbols in filter
137
+ email:
138
+ - aemelyanov@spbtv.com
139
+ executables: []
140
+ extensions: []
141
+ extra_rdoc_files: []
142
+ files:
143
+ - ".gitignore"
144
+ - ".rspec"
145
+ - ".travis.yml"
146
+ - CODE_OF_CONDUCT.md
147
+ - Gemfile
148
+ - LICENSE.txt
149
+ - README.md
150
+ - Rakefile
151
+ - activeadmin-ajax_filter.gemspec
152
+ - app/assets/javascripts/activeadmin-ajax_filter.js.coffee
153
+ - app/assets/stylesheets/activeadmin-ajax_filter.css
154
+ - bin/console
155
+ - bin/setup
156
+ - lib/active_admin/ajax_filter.rb
157
+ - lib/active_admin/ajax_filter/engine.rb
158
+ - lib/active_admin/ajax_filter/version.rb
159
+ - lib/active_admin/inputs/filters/ajax_select_input.rb
160
+ - lib/activeadmin-ajax_filter.rb
161
+ homepage: https://github.com/holyketzer/activeadmin-ajax_filter
162
+ licenses:
163
+ - MIT
164
+ metadata: {}
165
+ post_install_message:
166
+ rdoc_options: []
167
+ require_paths:
168
+ - lib
169
+ required_ruby_version: !ruby/object:Gem::Requirement
170
+ requirements:
171
+ - - ">="
172
+ - !ruby/object:Gem::Version
173
+ version: '0'
174
+ required_rubygems_version: !ruby/object:Gem::Requirement
175
+ requirements:
176
+ - - ">="
177
+ - !ruby/object:Gem::Version
178
+ version: '0'
179
+ requirements: []
180
+ rubyforge_project:
181
+ rubygems_version: 2.5.1
182
+ signing_key:
183
+ specification_version: 4
184
+ summary: AJAX filters for ActiveAdmin
185
+ test_files: []