administrate-field-has_many_with_fields 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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: a494e09edf468634d11ab409298ab1d543812cd0e9517be2a398491bd4b2ce25
4
+ data.tar.gz: 1077b6614a81a81cd5403a082960e083de4c1263519ddd9845e8abcdb83ae966
5
+ SHA512:
6
+ metadata.gz: 4d584b998f37f0eeccbd089aad7e2dbaac35369594ce475d7b8a981e516ca5958c893060577af82227b3141ecebdb41a7091d4a7311f30e6e39916a18cf66557
7
+ data.tar.gz: 13fa01d3fce970a945e12bae5f78a9f05e40310dc125f87aa86496723e8c6537144ff643a097c32b9b66f90d7a561198440a95ee7983d9524fccc0b309a844e8
data/Gemfile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in administrate-field-has_many_with_fields.gemspec
6
+ gemspec
7
+
8
+ gem "rake", "~> 13.0"
9
+
10
+ gem "rspec", "~> 3.0"
11
+
12
+ gem "factory_bot"
data/Gemfile.lock ADDED
@@ -0,0 +1,153 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ administrate-field-has_many_with_fields (0.1.0)
5
+ administrate
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ actionpack (5.1.7)
11
+ actionview (= 5.1.7)
12
+ activesupport (= 5.1.7)
13
+ rack (~> 2.0)
14
+ rack-test (>= 0.6.3)
15
+ rails-dom-testing (~> 2.0)
16
+ rails-html-sanitizer (~> 1.0, >= 1.0.2)
17
+ actionview (5.1.7)
18
+ activesupport (= 5.1.7)
19
+ builder (~> 3.1)
20
+ erubi (~> 1.4)
21
+ rails-dom-testing (~> 2.0)
22
+ rails-html-sanitizer (~> 1.0, >= 1.0.3)
23
+ activemodel (5.1.7)
24
+ activesupport (= 5.1.7)
25
+ activerecord (5.1.7)
26
+ activemodel (= 5.1.7)
27
+ activesupport (= 5.1.7)
28
+ arel (~> 8.0)
29
+ activesupport (5.1.7)
30
+ concurrent-ruby (~> 1.0, >= 1.0.2)
31
+ i18n (>= 0.7, < 2)
32
+ minitest (~> 5.1)
33
+ tzinfo (~> 1.1)
34
+ administrate (0.8.1)
35
+ actionpack (>= 4.2, < 5.2)
36
+ actionview (>= 4.2, < 5.2)
37
+ activerecord (>= 4.2, < 5.2)
38
+ autoprefixer-rails (>= 6.0)
39
+ datetime_picker_rails (~> 0.0.7)
40
+ jquery-rails (>= 4.0)
41
+ kaminari (>= 1.0)
42
+ momentjs-rails (~> 2.8)
43
+ sass-rails (~> 5.0)
44
+ selectize-rails (~> 0.6)
45
+ arel (8.0.0)
46
+ autoprefixer-rails (10.4.2.0)
47
+ execjs (~> 2)
48
+ builder (3.2.4)
49
+ concurrent-ruby (1.1.9)
50
+ crass (1.0.6)
51
+ datetime_picker_rails (0.0.7)
52
+ momentjs-rails (>= 2.8.1)
53
+ diff-lcs (1.5.0)
54
+ erubi (1.10.0)
55
+ execjs (2.8.1)
56
+ factory_bot (6.2.1)
57
+ activesupport (>= 5.0.0)
58
+ ffi (1.15.5)
59
+ i18n (1.10.0)
60
+ concurrent-ruby (~> 1.0)
61
+ jquery-rails (4.4.0)
62
+ rails-dom-testing (>= 1, < 3)
63
+ railties (>= 4.2.0)
64
+ thor (>= 0.14, < 2.0)
65
+ kaminari (1.2.2)
66
+ activesupport (>= 4.1.0)
67
+ kaminari-actionview (= 1.2.2)
68
+ kaminari-activerecord (= 1.2.2)
69
+ kaminari-core (= 1.2.2)
70
+ kaminari-actionview (1.2.2)
71
+ actionview
72
+ kaminari-core (= 1.2.2)
73
+ kaminari-activerecord (1.2.2)
74
+ activerecord
75
+ kaminari-core (= 1.2.2)
76
+ kaminari-core (1.2.2)
77
+ loofah (2.15.0)
78
+ crass (~> 1.0.2)
79
+ nokogiri (>= 1.5.9)
80
+ method_source (1.0.0)
81
+ minitest (5.15.0)
82
+ momentjs-rails (2.29.1.1)
83
+ railties (>= 3.1)
84
+ nokogiri (1.12.5-x86_64-darwin)
85
+ racc (~> 1.4)
86
+ racc (1.6.0)
87
+ rack (2.2.3)
88
+ rack-test (1.1.0)
89
+ rack (>= 1.0, < 3)
90
+ rails-dom-testing (2.0.3)
91
+ activesupport (>= 4.2.0)
92
+ nokogiri (>= 1.6)
93
+ rails-html-sanitizer (1.4.2)
94
+ loofah (~> 2.3)
95
+ railties (5.1.7)
96
+ actionpack (= 5.1.7)
97
+ activesupport (= 5.1.7)
98
+ method_source
99
+ rake (>= 0.8.7)
100
+ thor (>= 0.18.1, < 2.0)
101
+ rake (13.0.6)
102
+ rb-fsevent (0.11.1)
103
+ rb-inotify (0.10.1)
104
+ ffi (~> 1.0)
105
+ rspec (3.11.0)
106
+ rspec-core (~> 3.11.0)
107
+ rspec-expectations (~> 3.11.0)
108
+ rspec-mocks (~> 3.11.0)
109
+ rspec-core (3.11.0)
110
+ rspec-support (~> 3.11.0)
111
+ rspec-expectations (3.11.0)
112
+ diff-lcs (>= 1.2.0, < 2.0)
113
+ rspec-support (~> 3.11.0)
114
+ rspec-mocks (3.11.0)
115
+ diff-lcs (>= 1.2.0, < 2.0)
116
+ rspec-support (~> 3.11.0)
117
+ rspec-support (3.11.0)
118
+ sass (3.7.4)
119
+ sass-listen (~> 4.0.0)
120
+ sass-listen (4.0.0)
121
+ rb-fsevent (~> 0.9, >= 0.9.4)
122
+ rb-inotify (~> 0.9, >= 0.9.7)
123
+ sass-rails (5.0.7)
124
+ railties (>= 4.0.0, < 6)
125
+ sass (~> 3.1)
126
+ sprockets (>= 2.8, < 4.0)
127
+ sprockets-rails (>= 2.0, < 4.0)
128
+ tilt (>= 1.1, < 3)
129
+ selectize-rails (0.12.6)
130
+ sprockets (3.7.2)
131
+ concurrent-ruby (~> 1.0)
132
+ rack (> 1, < 3)
133
+ sprockets-rails (3.2.2)
134
+ actionpack (>= 4.0)
135
+ activesupport (>= 4.0)
136
+ sprockets (>= 3.0.0)
137
+ thor (1.2.1)
138
+ thread_safe (0.3.6)
139
+ tilt (2.0.10)
140
+ tzinfo (1.2.9)
141
+ thread_safe (~> 0.1)
142
+
143
+ PLATFORMS
144
+ x86_64-darwin-14
145
+
146
+ DEPENDENCIES
147
+ administrate-field-has_many_with_fields!
148
+ factory_bot
149
+ rake (~> 13.0)
150
+ rspec (~> 3.0)
151
+
152
+ BUNDLED WITH
153
+ 2.3.8
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2022 James Newman
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,39 @@
1
+ # Administrate::Field::HasManyWithFields
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
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'administrate-field-has_many_with_fields'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle install
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install administrate-field-has_many_with_fields
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
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.
30
+
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).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/administrate-field-has_many_with_fields.
36
+
37
+ ## License
38
+
39
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ task default: :spec
@@ -0,0 +1,34 @@
1
+ <%#
2
+ # HasMany Show Partial
3
+ This partial renders a has_many relationship,
4
+ to be displayed on a resource's show page.
5
+ By default, the relationship is rendered
6
+ as a table of the first few associated resources.
7
+ The columns of the table are taken
8
+ from the associated resource class's dashboard.
9
+ ## Local variables:
10
+ - `field`:
11
+ An instance of [Administrate::Field::HasMany][1].
12
+ Contains methods to help display a table of associated resources.
13
+ [1]: http://www.rubydoc.info/gems/administrate/Administrate/Field/HasMany
14
+ %>
15
+
16
+ <% page ||= Administrate::Page::Show.new("#{field.resource.class.name}Dashboard".constantize.new, field.resource) %>
17
+
18
+ <% if field.resources.any? %>
19
+ <% order = field.order_from_params(params.fetch(field.name, {})) %>
20
+ <% page_number = params.fetch(field.name, {}).fetch(:page, nil) %>
21
+ <%= render(
22
+ "collection",
23
+ collection_presenter: field.associated_collection(order),
24
+ collection_field_name: field.name,
25
+ page: page,
26
+ resources: field.resources(page_number, order),
27
+ table_title: field.name,
28
+ ) %>
29
+ <% if field.more_than_limit? %>
30
+ <%= paginate field.resources(page_number), param_name: "#{field.name}[page]" %>
31
+ <% end %>
32
+ <% else %>
33
+ <%= t("administrate.fields.has_many.none", default: "–") %>
34
+ <% end %>
@@ -0,0 +1,9 @@
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
@@ -0,0 +1,85 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "administrate/order"
4
+ require "administrate/field/has_many"
5
+ # require_relative "has_many_with_fields/version"
6
+
7
+ require "administrate/field/base"
8
+ require "rails"
9
+
10
+ module Administrate
11
+ module Field
12
+ class HasManyWithFields < Administrate::Field::HasMany
13
+ class Engine < ::Rails::Engine
14
+ end
15
+
16
+ def associated_collection(order = self.override_order)
17
+ CollectionWithFields.new(
18
+ associated_dashboard,
19
+ order: order,
20
+ fields: options[:fields],
21
+ )
22
+ end
23
+
24
+ def override_order
25
+ @order ||= Administrate::Order.new(sort_by, direction)
26
+ end
27
+ end
28
+ end
29
+ end
30
+
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
+ class CollectionWithFields < Administrate::Page::Collection
71
+ def attributes_for(resource)
72
+ selected_attribute_names.map do |attr_name|
73
+ attribute_field(dashboard, resource, attr_name, :index)
74
+ end
75
+ end
76
+
77
+ def attribute_types
78
+ dashboard.attribute_types_for(attribute_names)
79
+ dashboard.attribute_types_for(selected_attribute_names)
80
+ end
81
+
82
+ def selected_attribute_names
83
+ Array(options[:fields] || attribute_names)
84
+ end
85
+ end
metadata ADDED
@@ -0,0 +1,70 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: administrate-field-has_many_with_fields
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - James Newman
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2022-03-20 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'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ description:
28
+ email:
29
+ - jamesmnewman1@gmail.com
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - Gemfile
35
+ - Gemfile.lock
36
+ - LICENSE.txt
37
+ - README.md
38
+ - Rakefile
39
+ - app/views/fields/has_many_with_fields/_show.html.erb
40
+ - lib/administrate/field/has_many_with_fields.rb
41
+ - lib/administrate/field/has_many_with_fields/version.rb
42
+ homepage: https://github.com/jnewman12/administrate-field-has_many_with_fields
43
+ licenses:
44
+ - MIT
45
+ metadata:
46
+ allowed_push_host: https://rubygems.org
47
+ homepage_uri: https://github.com/jnewman12/administrate-field-has_many_with_fields
48
+ source_code_uri: https://github.com/jnewman12/administrate-field-has_many_with_fields
49
+ post_install_message:
50
+ rdoc_options: []
51
+ require_paths:
52
+ - lib
53
+ required_ruby_version: !ruby/object:Gem::Requirement
54
+ requirements:
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ version: 2.5.0
58
+ required_rubygems_version: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ version: '0'
63
+ requirements: []
64
+ rubyforge_project:
65
+ rubygems_version: 2.7.6
66
+ signing_key:
67
+ specification_version: 4
68
+ summary: Administrate has_many field extension to only use certain fields in a has_many
69
+ collection
70
+ test_files: []