viniBaxter-spa-nested_has_many 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (104) hide show
  1. checksums.yaml +7 -0
  2. data/.DS_Store +0 -0
  3. data/.circleci/config.yml +29 -0
  4. data/.gitignore +4 -0
  5. data/.ruby-version +1 -0
  6. data/Appraisals +13 -0
  7. data/CHANGELOG.md +57 -0
  8. data/Gemfile +5 -0
  9. data/README.md +38 -0
  10. data/Rakefile +24 -0
  11. data/app/assets/javascripts/administrate-field-nested_has_many/application.js +1 -0
  12. data/app/assets/stylesheets/administrate-field-nested_has_many/application.css +3 -0
  13. data/app/assets/stylesheets/administrate-field-nested_has_many/base.scss +14 -0
  14. data/app/views/fields/nested_has_many/_fields.html.erb +9 -0
  15. data/app/views/fields/nested_has_many/_form.html.erb +23 -0
  16. data/app/views/fields/nested_has_many/_index.html.erb +19 -0
  17. data/app/views/fields/nested_has_many/_show.html.erb +9 -0
  18. data/app/views/fields/nested_has_many/_show_current.html.erb +44 -0
  19. data/app/views/fields/nested_has_many/_show_old.html.erb +36 -0
  20. data/bin/rails +13 -0
  21. data/config/i18n-tasks.yml +8 -0
  22. data/config/locales/administrate-field-nested_has_many.en.yml +7 -0
  23. data/config/locales/administrate-field-nested_has_many.ja.yml +7 -0
  24. data/config/locales/administrate-field-nested_has_many.pt.yml +7 -0
  25. data/config/locales/administrate-field-nested_has_many.ru.yml +7 -0
  26. data/gemfiles/administrate_0.10.gemfile +8 -0
  27. data/gemfiles/administrate_0.10.gemfile.lock +214 -0
  28. data/gemfiles/administrate_0.13.gemfile +8 -0
  29. data/gemfiles/administrate_0.13.gemfile.lock +207 -0
  30. data/gemfiles/administrate_master.gemfile +8 -0
  31. data/gemfiles/administrate_master.gemfile.lock +219 -0
  32. data/lib/viniBaxter/spa/nested_has_many.rb +90 -0
  33. data/spec/dummy/.gitignore +3 -0
  34. data/spec/dummy/Rakefile +6 -0
  35. data/spec/dummy/app/assets/config/manifest.js +7 -0
  36. data/spec/dummy/app/assets/images/.keep +0 -0
  37. data/spec/dummy/app/assets/javascripts/application.js +14 -0
  38. data/spec/dummy/app/assets/javascripts/channels/.keep +0 -0
  39. data/spec/dummy/app/assets/stylesheets/application.css +15 -0
  40. data/spec/dummy/app/controllers/admin/application_controller.rb +21 -0
  41. data/spec/dummy/app/controllers/admin/foo/students_controller.rb +21 -0
  42. data/spec/dummy/app/controllers/admin/schools_controller.rb +21 -0
  43. data/spec/dummy/app/controllers/application_controller.rb +2 -0
  44. data/spec/dummy/app/controllers/concerns/.keep +0 -0
  45. data/spec/dummy/app/dashboards/foo/student_dashboard.rb +51 -0
  46. data/spec/dummy/app/dashboards/school_dashboard.rb +52 -0
  47. data/spec/dummy/app/helpers/application_helper.rb +2 -0
  48. data/spec/dummy/app/mailers/application_mailer.rb +4 -0
  49. data/spec/dummy/app/models/application_record.rb +3 -0
  50. data/spec/dummy/app/models/concerns/.keep +0 -0
  51. data/spec/dummy/app/models/foo/student.rb +3 -0
  52. data/spec/dummy/app/models/school.rb +4 -0
  53. data/spec/dummy/app/views/layouts/application.html.erb +15 -0
  54. data/spec/dummy/app/views/layouts/mailer.html.erb +13 -0
  55. data/spec/dummy/app/views/layouts/mailer.text.erb +1 -0
  56. data/spec/dummy/bin/bundle +3 -0
  57. data/spec/dummy/bin/rails +4 -0
  58. data/spec/dummy/bin/rake +4 -0
  59. data/spec/dummy/bin/setup +36 -0
  60. data/spec/dummy/bin/update +31 -0
  61. data/spec/dummy/bin/yarn +11 -0
  62. data/spec/dummy/config.ru +5 -0
  63. data/spec/dummy/config/application.rb +18 -0
  64. data/spec/dummy/config/boot.rb +5 -0
  65. data/spec/dummy/config/cable.yml +10 -0
  66. data/spec/dummy/config/database.yml +12 -0
  67. data/spec/dummy/config/environment.rb +5 -0
  68. data/spec/dummy/config/environments/development.rb +53 -0
  69. data/spec/dummy/config/environments/test.rb +36 -0
  70. data/spec/dummy/config/initializers/application_controller_renderer.rb +8 -0
  71. data/spec/dummy/config/initializers/assets.rb +14 -0
  72. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  73. data/spec/dummy/config/initializers/content_security_policy.rb +25 -0
  74. data/spec/dummy/config/initializers/cookies_serializer.rb +5 -0
  75. data/spec/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  76. data/spec/dummy/config/initializers/inflections.rb +16 -0
  77. data/spec/dummy/config/initializers/mime_types.rb +4 -0
  78. data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
  79. data/spec/dummy/config/locales/en.yml +33 -0
  80. data/spec/dummy/config/puma.rb +34 -0
  81. data/spec/dummy/config/routes.rb +9 -0
  82. data/spec/dummy/config/spring.rb +6 -0
  83. data/spec/dummy/config/storage.yml +34 -0
  84. data/spec/dummy/db/migrate/20180907104642_create_schools.rb +9 -0
  85. data/spec/dummy/db/migrate/20180907104703_create_students.rb +10 -0
  86. data/spec/dummy/db/schema.rb +29 -0
  87. data/spec/dummy/lib/assets/.keep +0 -0
  88. data/spec/dummy/package.json +5 -0
  89. data/spec/dummy/public/404.html +67 -0
  90. data/spec/dummy/public/422.html +67 -0
  91. data/spec/dummy/public/500.html +66 -0
  92. data/spec/dummy/public/apple-touch-icon-precomposed.png +0 -0
  93. data/spec/dummy/public/apple-touch-icon.png +0 -0
  94. data/spec/dummy/public/favicon.ico +0 -0
  95. data/spec/dummy/storage/.keep +0 -0
  96. data/spec/factories.rb +9 -0
  97. data/spec/features/has_many_spec.rb +41 -0
  98. data/spec/features/landing_spec.rb +10 -0
  99. data/spec/i18n_spec.rb +29 -0
  100. data/spec/lib/administrate/field/nested_has_many_spec.rb +14 -0
  101. data/spec/rails_helper.rb +67 -0
  102. data/spec/spec_helper.rb +96 -0
  103. data/viniBaxter-spa-nested_has_many.gemspec +29 -0
  104. metadata +368 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 721ebd4afc34f7626e1a8ef929ce195b10365cf1d96ef9c9c67f3a81f45dad3a
4
+ data.tar.gz: e34b61c7b8eda105effa3b194e7b068c30d7d4d6db48fdfb9fb711e0c8e3cd08
5
+ SHA512:
6
+ metadata.gz: f8a32948b74b4a3c018b18fe1b067fcc2e34ec00770fb7891a8c6032599d3484a565f19eafe278da01892fcbec438699b271d37e8d170659962a6960aa0161d6
7
+ data.tar.gz: 0ccaf7de4dc2c0aa9241bc67e37746304fb676f2674c6fbb4e0307bfcbb68348a87453689ef04602eda780797023278bbc9124d22eb520df2cb5bdc95db784e4
data/.DS_Store ADDED
Binary file
@@ -0,0 +1,29 @@
1
+ ---
2
+ version: 2
3
+ jobs:
4
+ build:
5
+ working_directory: ~/administrate-field-nested_has_many
6
+ docker:
7
+ - image: circleci/ruby:2.7.0-node-browsers
8
+ environment:
9
+ PGHOST: localhost
10
+ PGUSER: administrate-field-nested_has_many
11
+ PGPASSWORD: administrate-field-nested_has_many
12
+ RAILS_ENV: test
13
+ - image: postgres:11
14
+ environment:
15
+ POSTGRES_USER: administrate-field-nested_has_many
16
+ POSTGRES_DB: administrate-field-nested_has_many_test
17
+ POSTGRES_PASSWORD: administrate-field-nested_has_many
18
+ steps:
19
+ - checkout
20
+
21
+ - run: bundle install
22
+ - run: bundle exec appraisal install
23
+
24
+ - run: dockerize -wait tcp://localhost:5432 -timeout 1m
25
+
26
+ - run: bundle exec rake db:setup
27
+
28
+ - run: bundle exec rake
29
+ - run: bundle exec appraisal rake
data/.gitignore ADDED
@@ -0,0 +1,4 @@
1
+ Gemfile.lock
2
+ gemfiles/.bundle
3
+ pkg/
4
+ .rspec
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ ruby-2.6.3
data/Appraisals ADDED
@@ -0,0 +1,13 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ appraise "administrate-0.10" do
4
+ gem "administrate", "0.10.0"
5
+ end
6
+
7
+ appraise "administrate-0.13" do
8
+ gem "administrate", "0.13.0"
9
+ end
10
+
11
+ appraise "administrate-master" do
12
+ gem "administrate", git: "https://github.com/thoughtbot/administrate", branch: "master"
13
+ end
data/CHANGELOG.md ADDED
@@ -0,0 +1,57 @@
1
+ # CHANGELOG
2
+
3
+ ## 1.2.0
4
+
5
+ * Add support for namespaced models ([#24][])
6
+ * Add missing accepts nested attributes to School.
7
+ * Explicitly import administrate and field JS/CSS.
8
+ * Add ru locale ([#26][]).
9
+ * Add pt locale ([#25][]).
10
+ * Add Circle CI.
11
+ * Upgrade Ruby to 2.6.3.
12
+ * Add a dummy test app ([#19][]).
13
+
14
+ [#24]: https://github.com/nickcharlton/administrate-field-nested_has_many/pull/24
15
+ [#26]: https://github.com/nickcharlton/administrate-field-nested_has_many/pull/26
16
+ [#25]: https://github.com/nickcharlton/administrate-field-nested_has_many/pull/25
17
+ [#19]: https://github.com/nickcharlton/administrate-field-nested_has_many/pull/19
18
+
19
+ ## 1.1.0
20
+
21
+ * Add a `.ruby-version` file.
22
+ * Adjust to upstream administrate changes.
23
+ * Add Japanese locale.
24
+
25
+ ## 1.0.0
26
+
27
+ * Add `rake` for testing and release tools ([#16][]).
28
+ * Fixes for `administrate` 0.9.0 ([#11][]).
29
+ * Ensure current data is injected into nested fields ([#10][]).
30
+ * Remove direct dependency on Rails ([#10][]).
31
+ * Add i18n support ([#10][]).
32
+ * Make styling more consistent with `has_one` form ([#10][]).
33
+ * Add missing Gemfile and missing dependency on RSpec ([#15][]).
34
+ * Update gem location and authors ([#14][]).
35
+ * Avoid circular dependencies by not including the full library in the Gemspec
36
+ ([#13][]).
37
+
38
+ [#16]: https://github.com/nickcharlton/administrate-field-nested_has_many/pull/16
39
+ [#15]: https://github.com/nickcharlton/administrate-field-nested_has_many/pull/15
40
+ [#14]: https://github.com/nickcharlton/administrate-field-nested_has_many/pull/14
41
+ [#13]: https://github.com/nickcharlton/administrate-field-nested_has_many/pull/13
42
+ [#11]: https://github.com/nickcharlton/administrate-field-nested_has_many/pull/11
43
+ [#10]: https://github.com/nickcharlton/administrate-field-nested_has_many/pull/10
44
+
45
+ ## 0.1.0
46
+
47
+ * Updates for changes in `administrate` 0.2.1.
48
+ * Import JavaScript automatically.
49
+
50
+ ## 0.0.2
51
+
52
+ * Add missing import for `cocoon`.
53
+ * Note stop gap fix for missing JavaScript imports.
54
+
55
+ ## 0.0.1
56
+
57
+ * Initial Release.
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ source "https://rubygems.org"
2
+
3
+ gem "pg"
4
+
5
+ gemspec
data/README.md ADDED
@@ -0,0 +1,38 @@
1
+ # Administrate::Field::NestedHasMany
2
+
3
+ A plugin for nested has_many forms in [Administrate].
4
+
5
+ ## Usage
6
+
7
+ Add to your `Gemfile`:
8
+
9
+ ```ruby
10
+ gem "administrate-field-nested_has_many"
11
+ ```
12
+
13
+ Run:
14
+
15
+ ```bash
16
+ $ bundle install
17
+ ```
18
+
19
+ Add to your `FooDashboard`:
20
+
21
+ ```ruby
22
+ ATTRIBUTE_TYPES = {
23
+ bars: Field::NestedHasMany.with_options(skip: :foo),
24
+ }
25
+ ```
26
+
27
+ The `skip` option takes a single symbol or list of symbols.
28
+ It will prevent the nested form from displaying the fields for those attributes.
29
+
30
+ If a `Customer` `has_many :orders`,
31
+ and you want to render `orders` as a nested form on the customer edit page,
32
+ then it is generally necessary to add `skip: :customer` to the options
33
+ for the `NestedHasMany` field.
34
+ Otherwise, Administrate will try to render a field
35
+ for the order's `:customer` attribute,
36
+ which breaks the nested form logic.
37
+
38
+ [Administrate]: https://github.com/thoughtbot/administrate
data/Rakefile ADDED
@@ -0,0 +1,24 @@
1
+ begin
2
+ require "bundler/setup"
3
+ rescue LoadError
4
+ puts "You must `gem install bundler` and `bundle install` to run rake tasks"
5
+ end
6
+
7
+ require "bundler/gem_tasks"
8
+
9
+ require File.expand_path("../spec/dummy/config/application", __FILE__)
10
+
11
+ Rails.application.load_tasks
12
+
13
+ ##
14
+ # Configure the test suite.
15
+ ##
16
+ require "rspec/core"
17
+ require "rspec/core/rake_task"
18
+
19
+ RSpec::Core::RakeTask.new
20
+
21
+ ##
22
+ # By default, just run the tests.
23
+ ##
24
+ task default: :spec
@@ -0,0 +1,3 @@
1
+ /*
2
+ *= require_tree .
3
+ */
@@ -0,0 +1,14 @@
1
+ @import 'administrate/library/variables';
2
+ @import 'administrate/library/clearfix';
3
+
4
+ .field-unit--nested-has-many {
5
+ .nested-fields {
6
+ @include administrate-clearfix;
7
+ margin-bottom: $base-spacing;
8
+ padding-bottom: $base-spacing;
9
+ }
10
+
11
+ .remove_fields, .add_fields {
12
+ float: right;
13
+ }
14
+ }
@@ -0,0 +1,9 @@
1
+ <div class="nested-fields">
2
+ <% field.nested_fields_for_builder(f).each do |attribute| -%>
3
+ <div class="field-unit field-unit--<%= attribute.html_class %>">
4
+ <%= render_field attribute, f: f %>
5
+ </div>
6
+ <% end -%>
7
+
8
+ <%= link_to_remove_association I18n.t("administrate.fields.nested_has_many.remove", resource: field.associated_class_name.titleize), f %>
9
+ </div>
@@ -0,0 +1,23 @@
1
+ <fieldset class="field-unit--nested">
2
+ <legend><%= f.label field.attribute %></legend>
3
+ <%= f.fields_for field.association_name do |nested_form| %>
4
+ <%= render(
5
+ partial: "fields/nested_has_many/fields",
6
+ locals: {
7
+ f: nested_form,
8
+ field: field,
9
+ },
10
+ ) %>
11
+ <% end %>
12
+
13
+ <div>
14
+ <%= link_to_add_association(
15
+ I18n.t("administrate.fields.nested_has_many.add", resource: field.associated_class_name.titleize),
16
+ f,
17
+ field.association_name,
18
+ class: 'button',
19
+ partial: "fields/nested_has_many/fields",
20
+ render_options: { locals: { field: field } },
21
+ ) %>
22
+ </div>
23
+ </fieldset>
@@ -0,0 +1,19 @@
1
+ <%#
2
+ # HasMany Index Partial
3
+
4
+ This partial renders a has_many relationship,
5
+ to be displayed on a resource's index page.
6
+
7
+ By default, the relationship is rendered
8
+ as a count of how many objects are associated through the relationship.
9
+
10
+ ## Local variables:
11
+
12
+ - `field`:
13
+ An instance of [Administrate::Field::HasMany][1].
14
+ A wrapper around the has_many relationship pulled from the database.
15
+
16
+ [1]: http://www.rubydoc.info/gems/administrate/Administrate/Field/HasMany
17
+ %>
18
+
19
+ <%= pluralize(field.data.size, field.attribute.to_s.humanize.downcase) %>
@@ -0,0 +1,9 @@
1
+ <%
2
+ current = Gem::Version.new(Administrate::VERSION)
3
+ v0_10 = Gem::Version.new("0.10")
4
+ %>
5
+ <% if current <= v0_10 %>
6
+ <%= render "fields/nested_has_many/show_old", **local_assigns %>
7
+ <% else %>
8
+ <%= render "fields/nested_has_many/show_current", **local_assigns %>
9
+ <% end %>
@@ -0,0 +1,44 @@
1
+ <%#
2
+ # HasMany Show Partial
3
+
4
+ This partial renders a has_many relationship,
5
+ to be displayed on a resource's show page.
6
+
7
+ By default, the relationship is rendered
8
+ as a table of the first few associated resources.
9
+ The columns of the table are taken
10
+ from the associated resource class's dashboard.
11
+
12
+ ## Local variables:
13
+
14
+ - `field`:
15
+ An instance of [Administrate::Field::HasMany][1].
16
+ Contains methods to help display a table of associated resources.
17
+
18
+ [1]: http://www.rubydoc.info/gems/administrate/Administrate/Field/HasMany
19
+ %>
20
+
21
+ <% if field.resources.any? %>
22
+ <% order = field.order_from_params(params.fetch(field.name, {})) %>
23
+ <% page_number = params.fetch(field.name, {}).fetch(:page, nil) %>
24
+ <%= render(
25
+ "collection",
26
+ collection_presenter: field.associated_collection(order),
27
+ collection_field_name: field.name,
28
+ page: page,
29
+ resources: field.resources(page_number, order),
30
+ table_title: field.name,
31
+ ) %>
32
+
33
+ <% if field.more_than_limit? %>
34
+ <span>
35
+ <%= t(
36
+ 'administrate.fields.has_many.more',
37
+ count: field.limit,
38
+ total_count: field.data.count,
39
+ ) %>
40
+ </span>
41
+ <% end %>
42
+ <% else %>
43
+ <%= t("administrate.fields.has_many.none", default: "–") %>
44
+ <% end %>
@@ -0,0 +1,36 @@
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
+ <% if field.resources.any? %>
17
+ <%= render(
18
+ "collection",
19
+ collection_presenter: field.associated_collection,
20
+ resources: field.resources,
21
+ table_title: field.name
22
+ ) %>
23
+
24
+ <% if field.more_than_limit? %>
25
+ <span>
26
+ <%= t(
27
+ 'administrate.fields.has_many.more',
28
+ count: field.limit,
29
+ total_count: field.data.count,
30
+ ) %>
31
+ </span>
32
+ <% end %>
33
+
34
+ <% else %>
35
+ <%= t("administrate.fields.has_many.none", default: "–") %>
36
+ <% end %>
data/bin/rails ADDED
@@ -0,0 +1,13 @@
1
+ #!/usr/bin/env ruby
2
+ # This command will automatically be run when you run "rails" with Rails gems
3
+ # installed from the root of your application.
4
+
5
+ ENGINE_ROOT = File.expand_path('..', __dir__)
6
+ APP_PATH = File.expand_path('../spec/dummy/config/application', __dir__)
7
+
8
+ # Set up gems listed in the Gemfile.
9
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__)
10
+ require 'bundler/setup' if File.exist?(ENV['BUNDLE_GEMFILE'])
11
+
12
+ require 'rails/all'
13
+ require 'rails/engine/commands'
@@ -0,0 +1,8 @@
1
+ base_locale: en
2
+
3
+ data:
4
+ read:
5
+ - config/locales/administrate-field-nested_has_many.%{locale}.yml
6
+
7
+ ignore:
8
+ - 'administrate.fields.has_many.*'
@@ -0,0 +1,7 @@
1
+ ---
2
+ en:
3
+ administrate:
4
+ fields:
5
+ nested_has_many:
6
+ add: Add %{resource}
7
+ remove: Remove %{resource}
@@ -0,0 +1,7 @@
1
+ ---
2
+ ja:
3
+ administrate:
4
+ fields:
5
+ nested_has_many:
6
+ add: "%{resource}を追加"
7
+ remove: "%{resource}を削除"
@@ -0,0 +1,7 @@
1
+ ---
2
+ pt:
3
+ administrate:
4
+ fields:
5
+ nested_has_many:
6
+ add: Adicionar %{resource}
7
+ remove: Remover %{resource}
@@ -0,0 +1,7 @@
1
+ ---
2
+ ru:
3
+ administrate:
4
+ fields:
5
+ nested_has_many:
6
+ add: Добавить %{resource}
7
+ remove: Удалить %{resource}
@@ -0,0 +1,8 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "pg"
6
+ gem "administrate", "0.10.0"
7
+
8
+ gemspec path: "../"