administrate-field-belongs_to_search 0.1.2

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: 41209459176c92826ff7ae2539c7b52643fa10bb
4
+ data.tar.gz: b5f6cb2068cb07d1059b6a7f66a88b6b0b2be228
5
+ SHA512:
6
+ metadata.gz: d5733597a1a50f44b4280bf8f2289063eecc10357d14216130c532305ad24bdebdd52d6f5df44824a48acb7237d6c4197a9b706875fac57cbaeb70f21f6de42d
7
+ data.tar.gz: a7e3631147fedfc2534410d85d83e9cadf35d8053a3c6f76949616bc3caa745c6637013f8345f125196ee1e2acdeaa797acd42ca6e1f90d40d7e6e85e5b1c054
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/.rubocop.yml ADDED
@@ -0,0 +1,31 @@
1
+ Rails:
2
+ Enabled: true
3
+
4
+ Metrics/LineLength:
5
+ Max: 120
6
+ Metrics/MethodLength:
7
+ Max: 20
8
+ Metrics/ClassLength:
9
+ Max: 220
10
+
11
+ Metrics/AbcSize:
12
+ Max: 35
13
+
14
+ Documentation:
15
+ Enabled: false
16
+
17
+ Style/FrozenStringLiteralComment:
18
+ Enabled: false
19
+
20
+ # allow multiline `expect { ... }.to do_something`
21
+ Style/BlockDelimiters:
22
+ Exclude:
23
+ - 'spec/**/*'
24
+
25
+ # specs tend to get long
26
+ Metrics/BlockLength:
27
+ Exclude:
28
+ - 'spec/**/*'
29
+
30
+ Style/TrailingCommaInLiteral:
31
+ EnforcedStyleForMultiline: comma
data/.travis.yml ADDED
@@ -0,0 +1,6 @@
1
+ before_install:
2
+ - rvm install 2.2.2
3
+ install: bundle install
4
+ script:
5
+ - bundle exec rubocop
6
+ - bundle exec rake
data/CHANGELOG.md ADDED
@@ -0,0 +1,15 @@
1
+ # Changelog
2
+
3
+ ## Upcoming release
4
+
5
+ ## 0.1.2
6
+
7
+ * Re-push unbroken 0.1.1
8
+
9
+ ## 0.1.1
10
+
11
+ * Fix broken Rails dependency (klaseskilson)
12
+
13
+ ## 0.1.0
14
+
15
+ Initial release
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License
2
+
3
+ Copyright (c) 2017 Fishbrain AB.
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,58 @@
1
+ # Administrate::Field::BelongsToSearch
2
+
3
+ [![Build Status](https://travis-ci.org/fishbrain/administrate-field-belongs_to_search.svg?branch=master)](https://travis-ci.org/fishbrain/administrate-field-belongs_to_search)
4
+
5
+ A plugin to search through `belongs_to` associations in [thoughtbot's Administrate](https://github.com/thoughtbot/administrate) Rails engine.
6
+
7
+ ## Usage
8
+
9
+ Add it to your `Gemfile`:
10
+
11
+ ```ruby
12
+ gem 'administrate-field-belongs_to_search', '~> 0.1.2'
13
+ ```
14
+
15
+ Run bundler to install:
16
+
17
+ ```sh
18
+ bundle install
19
+ ```
20
+
21
+ Add it to your Administrate dashboard, for instance:
22
+
23
+ ```ruby
24
+ class PostDashboard < Administrate::BaseDashboard
25
+ ATTRIBUTE_TYPES = {
26
+ author: Field::BelongsToSearch.with_options(class_name: 'User')
27
+ }
28
+ # ...
29
+ ```
30
+
31
+ With this, you should be good to go!
32
+
33
+ ## Develop and contribute
34
+
35
+ Fork and clone the repo. Install dependencies and run test using:
36
+
37
+ ```sh
38
+ bundle install
39
+ bundle exec rake
40
+ ```
41
+
42
+ Then, implement your feature/fix, [write a good commit message](http://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html)
43
+ and submit a pull request to this repository. If you only have some feedback or are unsure about how to do something, you're welcome to
44
+ submit an [issue](https://github.com/fishbrain/administrate-field-belongs_to_search/issues/new).
45
+
46
+ ## License
47
+
48
+ This plugin is Copyright © 2017 Fishbrain AB. It is licensed under the MIT license. See [LICENSE](LICENSE) for details.
49
+
50
+ ========
51
+
52
+ ![Fishbrain AB](http://i.imgur.com/wOMiqE8.png)
53
+
54
+ This plugin is maintained by [Fishbrain AB](https://fishbrain.com).
55
+
56
+ At Fishbrain, we're passionate about the outdoors and conservation. Together, we work to bring you the best app for fishing, hands down.
57
+
58
+ If you love working with amazing and talented people in tight-knit teams, [join us](https://fishbrain.com/jobs/)!
data/Rakefile ADDED
@@ -0,0 +1,22 @@
1
+ #!/usr/bin/env rake
2
+
3
+ begin
4
+ require 'bundler/setup'
5
+ rescue LoadError
6
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
7
+ end
8
+
9
+ require 'bundler/gem_tasks'
10
+
11
+ ##
12
+ # Configure the test suite.
13
+ ##
14
+ require 'rspec/core'
15
+ require 'rspec/core/rake_task'
16
+
17
+ RSpec::Core::RakeTask.new
18
+
19
+ ##
20
+ # By default, just run the tests.
21
+ ##
22
+ task default: :spec
@@ -0,0 +1,33 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+
5
+ Gem::Specification.new do |gem|
6
+ gem.name = 'administrate-field-belongs_to_search'
7
+ gem.version = '0.1.2'.freeze
8
+ gem.authors = ['Klas Eskilson']
9
+ gem.email = ['klas.eskilson@gmail.com']
10
+ gem.homepage = 'https://github.com/fishbrain/administrate-field-belongs_to_search'
11
+ gem.summary = 'Plugin that adds search capabilities to belongs_to associations for Administrate'
12
+ gem.license = 'MIT'
13
+
14
+ gem.require_paths = %w(lib)
15
+ gem.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(spec)/}) }
16
+ gem.test_files = `git ls-files -z -- {spec}/*`.split("\x0")
17
+
18
+ gem.add_dependency 'administrate', '~> 0.3'
19
+ gem.add_dependency 'rails', '>= 4.2', '< 5.1'
20
+ gem.add_dependency 'selectize-rails', '~> 0.6'
21
+
22
+ gem.add_development_dependency 'coveralls', '~> 0'
23
+ gem.add_development_dependency 'factory_girl', '~> 4.8'
24
+ gem.add_development_dependency 'rake', '~> 12.0'
25
+ gem.add_development_dependency 'rspec', '~> 3.4'
26
+ gem.add_development_dependency 'rubocop', '~> 0'
27
+ gem.add_development_dependency 'simplecov', '~> 0'
28
+ gem.add_development_dependency 'sqlite3', '~> 1.3'
29
+
30
+ gem.description = <<-DESCRIPTION
31
+ Add support to search through (potentially large) belongs_to associations in your Administrate dashboards.
32
+ DESCRIPTION
33
+ end
@@ -0,0 +1,28 @@
1
+ // belongs_to form
2
+ $(function() {
3
+ $(".field-unit--belongs-to-search select").each(function initializeSelectize(index, element) {
4
+ var $element = $(element);
5
+ $element.selectize({
6
+ valueField: 'id',
7
+ labelField: 'dashboard_display_name',
8
+ searchField: 'dashboard_display_name',
9
+ create: false,
10
+ searchUrl: $element.data('url') + '?search=',
11
+
12
+ load: function(query, callback) {
13
+ if (!query.length) return callback();
14
+ var searchUrl = this.settings.searchUrl;
15
+ $.ajax({
16
+ url: searchUrl + encodeURIComponent(query),
17
+ type: 'GET',
18
+ error: function() {
19
+ callback();
20
+ },
21
+ success: function(res) {
22
+ callback(res.resources);
23
+ }
24
+ });
25
+ },
26
+ });
27
+ });
28
+ });
@@ -0,0 +1,23 @@
1
+ # ## Index
2
+ #
3
+ # This view is the template for the index page.
4
+ #
5
+ # ## Local variables:
6
+ #
7
+ # - `page`:
8
+ # An instance of [Administrate::Page::Collection][1].
9
+ # Contains helper methods to help display a table,
10
+ # and knows which attributes should be displayed in the resource's table.
11
+ # - `resources`:
12
+ # An instance of `ActiveRecord::Relation` containing the resources
13
+ # that match the user's search criteria.
14
+ # By default, these resources are passed to the table partial to be displayed.
15
+ # - `search_term`:
16
+ # A string containing the term the user has searched for, if any.
17
+ #
18
+ # [1]: http://www.rubydoc.info/gems/administrate/Administrate/Page/Collection
19
+
20
+ json.resources resources do |resource|
21
+ json.id resource.id
22
+ json.dashboard_display_name @_dashboard.display_resource(resource)
23
+ end
@@ -0,0 +1,27 @@
1
+ <%#
2
+ # BelongsToSearch Form Partial
3
+
4
+ This partial renders an search input element for belongs_to relationships.
5
+ By default, the input is a collection select box
6
+ that displays all possible records to associate with.
7
+
8
+ ## Local variables:
9
+
10
+ - `f`:
11
+ A Rails form generator, used to help create the appropriate input fields.
12
+ - `field`:
13
+ An instance of [BelongsToWithSearchField].
14
+ Contains helper methods for displaying a collection select box.
15
+ %>
16
+
17
+ <div class="field-unit__label">
18
+ <%= f.label field.permitted_attribute %>
19
+ </div>
20
+ <div class="field-unit__field">
21
+ <%= f.select(field.permitted_attribute,
22
+ nil,
23
+ {},
24
+ 'data-url': polymorphic_url([namespace, field.associated_class], format: :json)) do %>
25
+ <%= options_for_select(field.associated_resource_options, field.selected_option) %>
26
+ <% end %>
27
+ </div>
@@ -0,0 +1,21 @@
1
+ <%#
2
+ # BelongsToSearch Index Partial
3
+
4
+ This partial renders a belongs_to relationship,
5
+ to be displayed on a resource's index page.
6
+
7
+ By default, the relationship is rendered as a link to the associated object.
8
+
9
+ ## Local variables:
10
+
11
+ - `field`:
12
+ An instance of Administrate::Field::BelongsToSearch.
13
+ A wrapper around the belongs_to relationship pulled from the database.
14
+ %>
15
+
16
+ <% if field.data %>
17
+ <%= link_to(
18
+ field.display_associated_resource,
19
+ [namespace, field.data],
20
+ ) %>
21
+ <% end %>
@@ -0,0 +1,21 @@
1
+ <%#
2
+ # BelongsToSearch Show Partial
3
+
4
+ This partial renders a belongs_to relationship,
5
+ to be displayed on a resource's show page.
6
+
7
+ By default, the relationship is rendered as a link to the associated object.
8
+
9
+ ## Local variables:
10
+
11
+ - `field`:
12
+ An instance of Administrate::Field::BelongsToSearch.
13
+ A wrapper around the belongs_to relationship pulled from the database.
14
+ %>
15
+
16
+ <% if field.data %>
17
+ <%= link_to(
18
+ field.display_associated_resource,
19
+ [namespace, field.data],
20
+ ) %>
21
+ <% end %>
@@ -0,0 +1,25 @@
1
+ require 'administrate/field/belongs_to'
2
+ require 'rails'
3
+
4
+ module Administrate
5
+ module Field
6
+ class BelongsToSearch < Administrate::Field::BelongsTo
7
+ class Engine < ::Rails::Engine
8
+ config.assets.precompile << 'belongs_to_search.js' if config.respond_to? :assets
9
+ Administrate::Engine.add_javascript 'belongs_to_search.js' if defined?(Administrate::Engine)
10
+ end
11
+
12
+ def associated_resource_options
13
+ if data.nil?
14
+ []
15
+ else
16
+ [[display_candidate_resource(data), data.id]]
17
+ end
18
+ end
19
+
20
+ def associated_class
21
+ super
22
+ end
23
+ end
24
+ end
25
+ end
metadata ADDED
@@ -0,0 +1,207 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: administrate-field-belongs_to_search
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.2
5
+ platform: ruby
6
+ authors:
7
+ - Klas Eskilson
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-02-02 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: administrate
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0.3'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rails
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '4.2'
34
+ - - "<"
35
+ - !ruby/object:Gem::Version
36
+ version: '5.1'
37
+ type: :runtime
38
+ prerelease: false
39
+ version_requirements: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ version: '4.2'
44
+ - - "<"
45
+ - !ruby/object:Gem::Version
46
+ version: '5.1'
47
+ - !ruby/object:Gem::Dependency
48
+ name: selectize-rails
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - "~>"
52
+ - !ruby/object:Gem::Version
53
+ version: '0.6'
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - "~>"
59
+ - !ruby/object:Gem::Version
60
+ version: '0.6'
61
+ - !ruby/object:Gem::Dependency
62
+ name: coveralls
63
+ requirement: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - "~>"
66
+ - !ruby/object:Gem::Version
67
+ version: '0'
68
+ type: :development
69
+ prerelease: false
70
+ version_requirements: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - "~>"
73
+ - !ruby/object:Gem::Version
74
+ version: '0'
75
+ - !ruby/object:Gem::Dependency
76
+ name: factory_girl
77
+ requirement: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - "~>"
80
+ - !ruby/object:Gem::Version
81
+ version: '4.8'
82
+ type: :development
83
+ prerelease: false
84
+ version_requirements: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - "~>"
87
+ - !ruby/object:Gem::Version
88
+ version: '4.8'
89
+ - !ruby/object:Gem::Dependency
90
+ name: rake
91
+ requirement: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - "~>"
94
+ - !ruby/object:Gem::Version
95
+ version: '12.0'
96
+ type: :development
97
+ prerelease: false
98
+ version_requirements: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - "~>"
101
+ - !ruby/object:Gem::Version
102
+ version: '12.0'
103
+ - !ruby/object:Gem::Dependency
104
+ name: rspec
105
+ requirement: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - "~>"
108
+ - !ruby/object:Gem::Version
109
+ version: '3.4'
110
+ type: :development
111
+ prerelease: false
112
+ version_requirements: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - "~>"
115
+ - !ruby/object:Gem::Version
116
+ version: '3.4'
117
+ - !ruby/object:Gem::Dependency
118
+ name: rubocop
119
+ requirement: !ruby/object:Gem::Requirement
120
+ requirements:
121
+ - - "~>"
122
+ - !ruby/object:Gem::Version
123
+ version: '0'
124
+ type: :development
125
+ prerelease: false
126
+ version_requirements: !ruby/object:Gem::Requirement
127
+ requirements:
128
+ - - "~>"
129
+ - !ruby/object:Gem::Version
130
+ version: '0'
131
+ - !ruby/object:Gem::Dependency
132
+ name: simplecov
133
+ requirement: !ruby/object:Gem::Requirement
134
+ requirements:
135
+ - - "~>"
136
+ - !ruby/object:Gem::Version
137
+ version: '0'
138
+ type: :development
139
+ prerelease: false
140
+ version_requirements: !ruby/object:Gem::Requirement
141
+ requirements:
142
+ - - "~>"
143
+ - !ruby/object:Gem::Version
144
+ version: '0'
145
+ - !ruby/object:Gem::Dependency
146
+ name: sqlite3
147
+ requirement: !ruby/object:Gem::Requirement
148
+ requirements:
149
+ - - "~>"
150
+ - !ruby/object:Gem::Version
151
+ version: '1.3'
152
+ type: :development
153
+ prerelease: false
154
+ version_requirements: !ruby/object:Gem::Requirement
155
+ requirements:
156
+ - - "~>"
157
+ - !ruby/object:Gem::Version
158
+ version: '1.3'
159
+ description: |
160
+ Add support to search through (potentially large) belongs_to associations in your Administrate dashboards.
161
+ email:
162
+ - klas.eskilson@gmail.com
163
+ executables: []
164
+ extensions: []
165
+ extra_rdoc_files: []
166
+ files:
167
+ - ".gitignore"
168
+ - ".rspec"
169
+ - ".rubocop.yml"
170
+ - ".travis.yml"
171
+ - CHANGELOG.md
172
+ - Gemfile
173
+ - LICENSE
174
+ - README.md
175
+ - Rakefile
176
+ - administrate-field-belongs_to_search.gemspec
177
+ - app/assets/javascripts/belongs_to_search.js
178
+ - app/views/administrate/application/index.json.jbuilder
179
+ - app/views/fields/belongs_to_search/_form.html.erb
180
+ - app/views/fields/belongs_to_search/_index.html.erb
181
+ - app/views/fields/belongs_to_search/_show.html.erb
182
+ - lib/administrate/field/belongs_to_search.rb
183
+ homepage: https://github.com/fishbrain/administrate-field-belongs_to_search
184
+ licenses:
185
+ - MIT
186
+ metadata: {}
187
+ post_install_message:
188
+ rdoc_options: []
189
+ require_paths:
190
+ - lib
191
+ required_ruby_version: !ruby/object:Gem::Requirement
192
+ requirements:
193
+ - - ">="
194
+ - !ruby/object:Gem::Version
195
+ version: '0'
196
+ required_rubygems_version: !ruby/object:Gem::Requirement
197
+ requirements:
198
+ - - ">="
199
+ - !ruby/object:Gem::Version
200
+ version: '0'
201
+ requirements: []
202
+ rubyforge_project:
203
+ rubygems_version: 2.4.5.1
204
+ signing_key:
205
+ specification_version: 4
206
+ summary: Plugin that adds search capabilities to belongs_to associations for Administrate
207
+ test_files: []