active_admin_relationship_filters 0.1.0

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.
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in active_admin_relationship_filters.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Matt Brewer
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,68 @@
1
+ # ActiveAdminRelationshipFilters
2
+
3
+ This gem provides a few more filter options to ActiveAdmin allowing you to easily traverse relationships or filter on a HABTM.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'active_admin_relationship_filters'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install active_admin_relationship_filters
18
+
19
+ ## Usage
20
+
21
+ ### Multilevel Filter
22
+
23
+ Given the following scenario:
24
+
25
+ class Customer < ActiveRecord::Base
26
+ belongs_to :customer_type
27
+ end
28
+
29
+ class CustomerType < ActiveRecord::Base
30
+ has_many :customers
31
+ belongs_to :region
32
+ end
33
+
34
+ class Region < ActiveRecord::Base
35
+ has_many :customer_types, dependent: :destroy
36
+ end
37
+
38
+ ActiveAdmin.register Customer do
39
+ filter :customer_type_region_id, as: :multilevel, collection: proc { Region.all }, label: "Region"
40
+ end
41
+
42
+ The above configuration would allow me to select one `Region` from a dropdown to filter my listing of `Customer` records by, respective to an attribute on another model (`CustomerType`)
43
+
44
+ ### HABTM Filter
45
+
46
+ Given the following scenario:
47
+
48
+ class View < ActiveRecord::Base
49
+ has_and_belongs_to_many :items
50
+ end
51
+
52
+ class Item < ActiveRecord::Base
53
+ has_and_belongs_to_many :views
54
+ end
55
+
56
+ ActiveRecord.register Item do
57
+ filter :views_id, as: :habtm, collection: proc { View.all }
58
+ end
59
+
60
+ The above configuration would allow me to select one `View` from a dropdown to filter my listing of `Item` records by, for a HABTM relationship, while ActiveAdmin only supports belongs_to by default.
61
+
62
+ ## Contributing
63
+
64
+ 1. Fork it
65
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
66
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
67
+ 4. Push to the branch (`git push origin my-new-feature`)
68
+ 5. Create new Pull Request
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
@@ -0,0 +1,20 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/active_admin_relationship_filters/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["Matt Brewer"]
6
+ gem.email = ["matt.brewer@me.com"]
7
+ gem.description = %q{Provides a few more filter options to ActiveAdmin allowing you to easily traverse relationships or filter on a HABTM}
8
+ gem.summary = %q{Provides a few more filter options to ActiveAdmin allowing you to easily traverse relationships or filter on a HABTM}
9
+ gem.homepage = ""
10
+
11
+ gem.files = `git ls-files`.split($\)
12
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
13
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
14
+ gem.name = "active_admin_relationship_filters"
15
+ gem.require_paths = ["lib"]
16
+ gem.version = ActiveAdminRelationshipFilters::VERSION
17
+
18
+ gem.add_dependency "activeadmin", ">= 0.5"
19
+
20
+ end
@@ -0,0 +1,12 @@
1
+ require "active_admin_relationship_filters/version"
2
+ require 'active_admin'
3
+ require 'active_admin_relationship_filters/filters/filter_base'
4
+
5
+ module ActiveAdminRelationshipFilters
6
+
7
+ ::ActiveAdmin::Event.subscribe ::ActiveAdmin::Application::BeforeLoadEvent do |app|
8
+ require 'active_admin_relationship_filters/filters/filter_habtm_input'
9
+ require 'active_admin_relationship_filters/filters/filter_multilevel_input'
10
+ end
11
+
12
+ end
@@ -0,0 +1,11 @@
1
+ module ActiveAdmin
2
+ module Inputs
3
+ module FilterBase
4
+
5
+ def wrapper_html_options
6
+ { :class => "filter_form_field #{as}", id: "filter_#{input_name}" }
7
+ end
8
+
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,31 @@
1
+ module ActiveAdmin
2
+ module Inputs
3
+ class FilterHabtmInput < FilterSelectInput
4
+ include FilterBase
5
+
6
+ def to_html
7
+ input_wrapping do
8
+ label_html <<
9
+ (options[:group_by] ? grouped_select_html : select_html)
10
+ end
11
+ end
12
+
13
+ def input_name
14
+ name = super.sub("_ids_eq", "")
15
+ "#{name}s_id_in"
16
+ end
17
+
18
+ def input_options
19
+ super.merge(:include_blank => I18n.t('active_admin.any'))
20
+ end
21
+
22
+ def method
23
+ super.to_s.sub(/_id$/,'').to_sym
24
+ end
25
+
26
+ def extra_input_html_options
27
+ {}
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,31 @@
1
+ module ActiveAdmin
2
+ module Inputs
3
+ class FilterMultilevelInput < FilterSelectInput
4
+ include FilterBase
5
+
6
+ def to_html
7
+ input_wrapping do
8
+ label_html <<
9
+ (options[:group_by] ? grouped_select_html : select_html)
10
+ end
11
+ end
12
+
13
+ def input_name
14
+ name = super.sub("_eq", "")
15
+ "#{name}_id_eq"
16
+ end
17
+
18
+ def input_options
19
+ super.merge(:include_blank => I18n.t('active_admin.any'))
20
+ end
21
+
22
+ def method
23
+ super.to_s.sub(/_id$/,'').to_sym
24
+ end
25
+
26
+ def extra_input_html_options
27
+ {}
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,3 @@
1
+ module ActiveAdminRelationshipFilters
2
+ VERSION = "0.1.0"
3
+ end
metadata ADDED
@@ -0,0 +1,74 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: active_admin_relationship_filters
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Matt Brewer
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-10-16 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: activeadmin
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0.5'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0.5'
30
+ description: Provides a few more filter options to ActiveAdmin allowing you to easily
31
+ traverse relationships or filter on a HABTM
32
+ email:
33
+ - matt.brewer@me.com
34
+ executables: []
35
+ extensions: []
36
+ extra_rdoc_files: []
37
+ files:
38
+ - .gitignore
39
+ - Gemfile
40
+ - LICENSE
41
+ - README.md
42
+ - Rakefile
43
+ - active_admin_relationship_filters.gemspec
44
+ - lib/active_admin_relationship_filters.rb
45
+ - lib/active_admin_relationship_filters/filters/filter_base.rb
46
+ - lib/active_admin_relationship_filters/filters/filter_habtm_input.rb
47
+ - lib/active_admin_relationship_filters/filters/filter_multilevel_input.rb
48
+ - lib/active_admin_relationship_filters/version.rb
49
+ homepage: ''
50
+ licenses: []
51
+ post_install_message:
52
+ rdoc_options: []
53
+ require_paths:
54
+ - lib
55
+ required_ruby_version: !ruby/object:Gem::Requirement
56
+ none: false
57
+ requirements:
58
+ - - ! '>='
59
+ - !ruby/object:Gem::Version
60
+ version: '0'
61
+ required_rubygems_version: !ruby/object:Gem::Requirement
62
+ none: false
63
+ requirements:
64
+ - - ! '>='
65
+ - !ruby/object:Gem::Version
66
+ version: '0'
67
+ requirements: []
68
+ rubyforge_project:
69
+ rubygems_version: 1.8.24
70
+ signing_key:
71
+ specification_version: 3
72
+ summary: Provides a few more filter options to ActiveAdmin allowing you to easily
73
+ traverse relationships or filter on a HABTM
74
+ test_files: []