administrate-field-has_many_with_fields 0.1.0 → 0.1.1

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a494e09edf468634d11ab409298ab1d543812cd0e9517be2a398491bd4b2ce25
4
- data.tar.gz: 1077b6614a81a81cd5403a082960e083de4c1263519ddd9845e8abcdb83ae966
3
+ metadata.gz: 3d49fef5b3d0f3a3d6ba60dd9193f86810cef395ebcafe1ce9bf59784bec6d6d
4
+ data.tar.gz: c3fa10616982c245a1120805294d9f2029e8c8ee65edcf9ccf971385107be3c0
5
5
  SHA512:
6
- metadata.gz: 4d584b998f37f0eeccbd089aad7e2dbaac35369594ce475d7b8a981e516ca5958c893060577af82227b3141ecebdb41a7091d4a7311f30e6e39916a18cf66557
7
- data.tar.gz: 13fa01d3fce970a945e12bae5f78a9f05e40310dc125f87aa86496723e8c6537144ff643a097c32b9b66f90d7a561198440a95ee7983d9524fccc0b309a844e8
6
+ metadata.gz: 691bc71229177dc6237d28a7dd0e979e8f4018f1c41abe871e8d475101436f3e7d81ff61ca179b00d36afa99d2913b6d21b137290780bea63bfb657a3f6f2c7d
7
+ data.tar.gz: 3c56b2fdbeaa5100470a082a7c7d839bcd06f5c5f5afcd479de6af690b7a4117bac41c6da74f15abb6a84eb8a0f1f8938f03de4fdabbb9679eab525eb89cdaca
data/Gemfile CHANGED
@@ -8,5 +8,3 @@ gemspec
8
8
  gem "rake", "~> 13.0"
9
9
 
10
10
  gem "rspec", "~> 3.0"
11
-
12
- gem "factory_bot"
data/Gemfile.lock CHANGED
@@ -53,8 +53,6 @@ GEM
53
53
  diff-lcs (1.5.0)
54
54
  erubi (1.10.0)
55
55
  execjs (2.8.1)
56
- factory_bot (6.2.1)
57
- activesupport (>= 5.0.0)
58
56
  ffi (1.15.5)
59
57
  i18n (1.10.0)
60
58
  concurrent-ruby (~> 1.0)
@@ -145,7 +143,6 @@ PLATFORMS
145
143
 
146
144
  DEPENDENCIES
147
145
  administrate-field-has_many_with_fields!
148
- factory_bot
149
146
  rake (~> 13.0)
150
147
  rspec (~> 3.0)
151
148
 
data/README.md CHANGED
@@ -1,8 +1,6 @@
1
1
  # Administrate::Field::HasManyWithFields
2
2
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/administrate/field/has_many_with_fields`. To experiment with that code, run `bin/console` for an interactive prompt.
4
-
5
- TODO: Delete this and the text above, and describe your gem
3
+ An administrate plug-in designed to allow you to only show certain fields when rendering a `has_many` relationship instead of rendering entire collection's dashboard. Extends the `Administrate::Field::HasMany` field.
6
4
 
7
5
  ## Installation
8
6
 
@@ -22,17 +20,40 @@ Or install it yourself as:
22
20
 
23
21
  ## Usage
24
22
 
25
- TODO: Write usage instructions here
23
+ Turn the standard `has_many` relationship in your administrate dashboard from this
26
24
 
27
- ## Development
25
+ ```ruby
26
+ class UserDashboard < Administrate::BaseDashboard
27
+ # ATTRIBUTE_TYPES
28
+ # a hash that describes the type of each of the model's fields.
29
+ #
30
+ # Each different type represents an Administrate::Field object,
31
+ # which determines how the attribute is displayed
32
+ # on pages throughout the dashboard.
33
+ ATTRIBUTE_TYPES = {
34
+ posts: Field::HasMany,
35
+ # ...
36
+ }
37
+ ```
28
38
 
29
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
39
+ into this
30
40
 
31
- 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 the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
41
+ ```ruby
42
+ class UserDashboard < Administrate::BaseDashboard
43
+ # ATTRIBUTE_TYPES
44
+ # a hash that describes the type of each of the model's fields.
45
+ #
46
+ # Each different type represents an Administrate::Field object,
47
+ # which determines how the attribute is displayed
48
+ # on pages throughout the dashboard.
49
+ ATTRIBUTE_TYPES = {
50
+ posts: Field::HasManyWithFields.with_options(fields: [:id, :attr_1, :attr_2, :method_1]),
51
+ # ...
52
+ }
53
+ ```
32
54
 
33
- ## Contributing
55
+ The standard administrate `with_options` method (limit, class_name, etc) still works because this inherits from `Administrate::Field::HasMany`. The `fields` array also works with both model attributes and model methods.
34
56
 
35
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/administrate-field-has_many_with_fields.
36
57
 
37
58
  ## License
38
59
 
@@ -0,0 +1,25 @@
1
+ <%#
2
+ # HasMany Form Partial
3
+ This partial renders an input element for has_many relationships.
4
+ By default, the input is a collection select box
5
+ that displays all possible records to associate with.
6
+ The collection select box supports multiple inputs,
7
+ and is augmented with [Selectize].
8
+ ## Local variables:
9
+ - `f`:
10
+ A Rails form generator, used to help create the appropriate input fields.
11
+ - `field`:
12
+ An instance of [Administrate::Field::HasMany][1].
13
+ Contains helper methods for displaying a collection select box.
14
+ [1]: http://www.rubydoc.info/gems/administrate/Administrate/Field/HasMany
15
+ [Selectize]: http://brianreavis.github.io/selectize.js
16
+ %>
17
+
18
+ <div class="field-unit__label">
19
+ <%= f.label field.attribute, for: "#{f.object_name}_#{field.attribute_key}" %>
20
+ </div>
21
+ <div class="field-unit__field">
22
+ <%= f.select(field.attribute_key, nil, {}, multiple: true) do %>
23
+ <%= options_for_select(field.associated_resource_options, field.selected_options) %>
24
+ <% end %>
25
+ </div>
@@ -0,0 +1,14 @@
1
+ <%#
2
+ # HasMany Index Partial
3
+ This partial renders a has_many relationship,
4
+ to be displayed on a resource's index page.
5
+ By default, the relationship is rendered
6
+ as a count of how many objects are associated through the relationship.
7
+ ## Local variables:
8
+ - `field`:
9
+ An instance of [Administrate::Field::HasMany][1].
10
+ A wrapper around the has_many relationship pulled from the database.
11
+ [1]: http://www.rubydoc.info/gems/administrate/Administrate/Field/HasMany
12
+ %>
13
+
14
+ <%= pluralize(field.data.size, t("activerecord.models.#{field.attribute.to_s.singularize}", default: field.attribute.to_s.humanize.downcase.singularize, count: field.data.size)) %>
@@ -1,9 +1,5 @@
1
- # frozen_string_literal: true
2
-
3
1
  require "administrate/order"
4
2
  require "administrate/field/has_many"
5
- # require_relative "has_many_with_fields/version"
6
-
7
3
  require "administrate/field/base"
8
4
  require "rails"
9
5
 
@@ -28,45 +24,6 @@ module Administrate
28
24
  end
29
25
  end
30
26
 
31
-
32
-
33
- # module Administrate
34
- # module Field
35
- # # module HasManyWithFields
36
- # class HasManyWithFields < Administrate::Field::HasMany
37
- # class Error < StandardError; end
38
-
39
- # def associated_collection(order = self.override_order)
40
- # CollectionWithFields.new(
41
- # associated_dashboard,
42
- # order: order,
43
- # fields: options[:fields],
44
- # )
45
- # end
46
-
47
- # def override_order
48
- # @order ||= Administrate::Order.new(sort_by, direction)
49
- # end
50
- # end
51
- # end
52
- # end
53
-
54
-
55
-
56
- # class HasManyWithFields < Administrate::Field::HasMany
57
- # def associated_collection(order = self.override_order)
58
- # CollectionWithFields.new(
59
- # associated_dashboard,
60
- # order: order,
61
- # fields: options[:fields],
62
- # )
63
- # end
64
-
65
- # def override_order
66
- # @order ||= Administrate::Order.new(sort_by, direction)
67
- # end
68
- # end
69
-
70
27
  class CollectionWithFields < Administrate::Page::Collection
71
28
  def attributes_for(resource)
72
29
  selected_attribute_names.map do |attr_name|
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: administrate-field-has_many_with_fields
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Newman
@@ -36,9 +36,10 @@ files:
36
36
  - LICENSE.txt
37
37
  - README.md
38
38
  - Rakefile
39
+ - app/views/fields/has_many_with_fields/_form.html.erb
40
+ - app/views/fields/has_many_with_fields/_index.html.erb
39
41
  - app/views/fields/has_many_with_fields/_show.html.erb
40
42
  - lib/administrate/field/has_many_with_fields.rb
41
- - lib/administrate/field/has_many_with_fields/version.rb
42
43
  homepage: https://github.com/jnewman12/administrate-field-has_many_with_fields
43
44
  licenses:
44
45
  - MIT
@@ -1,9 +0,0 @@
1
- # # frozen_string_literal: true
2
-
3
- # module Administrate
4
- # module Field
5
- # class HasManyWithFields
6
- # VERSION = "0.1.0"
7
- # end
8
- # end
9
- # end