worker-field-nested_has_many 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,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 684ca5b27cf9d28d4356549f8e81194d1de2e96e2a222d5a01e1058fc3ad8af6
4
+ data.tar.gz: d16141b7192c74d57f3c10e6f93e48c667c2738727ba1888424c620ab8cc49b1
5
+ SHA512:
6
+ metadata.gz: '08514a214257b5c70a140be6d46ed5335c96efc5729b6d81a71f69374aab5e05781f0a83df49985cce93cb600658a785b9c90285a4aa86d2a7b663348e396145'
7
+ data.tar.gz: 4d44b7515dbb46ffe3c1084063c465bd79df75d34079331df34fd316c7d77432cff383ab6d93ccd5ed822205ffdc74d0725f77600b151166582ad8e670c082de
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+ Gemfile.lock
@@ -0,0 +1 @@
1
+ ruby-2.5.3
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source "https://rubygems.org"
2
+
3
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2019 v baxter
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.
@@ -0,0 +1,17 @@
1
+ # Administrate::Field::NestedHasMany
2
+
3
+ A plugin for nested has_many forms in [Administrate].
4
+ This Gem is a specific custmized one form the original one available there
5
+ from the name administrate-field-nested_has_many
6
+
7
+ you can get the original one there
8
+ https://github.com/nickcharlton/administrate-field-nested_has_many
9
+
10
+ ```ruby
11
+ gem "administrate-field-nested_has_many"
12
+ ```
13
+
14
+ # Thanks
15
+
16
+ A huge thank you to all the person who work on the original one.
17
+ A huge thank you to Nick Charlton & Grayson Wright !!
@@ -0,0 +1,20 @@
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
+ ##
10
+ # Configure the test suite.
11
+ ##
12
+ require "rspec/core"
13
+ require "rspec/core/rake_task"
14
+
15
+ RSpec::Core::RakeTask.new
16
+
17
+ ##
18
+ # By default, just run the tests.
19
+ ##
20
+ task default: :spec
@@ -0,0 +1,53 @@
1
+ @import 'administrate/library/variables';
2
+ @import 'administrate/library/clearfix';
3
+ .container-flex{
4
+ display: flex;
5
+ flex-wrap: wrap;
6
+
7
+ }
8
+ .add_has_many{
9
+ position: absolute;
10
+ bottom: 0;
11
+ right: 0;
12
+ margin-bottom: 1rem;
13
+ }
14
+ .field-unit--nested{
15
+ width: 100%;
16
+ min-height: 100px;
17
+ padding-bottom: 4rem;
18
+ }
19
+ .field-unit--nested-has-many {
20
+ label {
21
+ display: block;
22
+ font-weight: 300;
23
+ margin: 0;
24
+ font-size: 12px;
25
+ }
26
+ legend > label{
27
+ font-weight: 700!important;
28
+ position: absolute!important;
29
+ top: -10px!important;
30
+ font-size: 1em;
31
+ }
32
+
33
+ .nested-fields {
34
+ @include administrate-clearfix;
35
+ width: 43%;
36
+ border: 1px solid #a8a8a83d;
37
+ margin: 1rem;
38
+ padding: 1rem;
39
+ display: flex;
40
+ flex-direction: column;
41
+ justify-content: space-between;
42
+ min-height: 300px;
43
+ .bibibibib{
44
+ .field-unit__label {
45
+ width: calc(15% - 1rem);
46
+ }
47
+ }
48
+ }
49
+
50
+ .remove_fields, .add_fields {
51
+ float: right;
52
+ }
53
+ }
@@ -0,0 +1,46 @@
1
+
2
+ <div class="nested-fields <%= field.attribute %>">
3
+ <div class="bibibibib">
4
+ <% field.nested_fields_for_builder(f).each do |attribute| -%>
5
+ <% if attribute.html_class.to_s != "boolean"%>
6
+ <div class="field-unit field-unit--<%= attribute.html_class %>">
7
+ <%= render_field attribute, f: f %>
8
+ </div>
9
+ <% else %>
10
+ <%= render_field attribute, f: f %>
11
+ <% end -%>
12
+ <% end -%>
13
+
14
+ </div>
15
+ <!-- <div class="button remove-field button remove-field__option_buton">
16
+ <%#= link_to(
17
+ t("add option"),
18
+ [:showproductoption,
19
+ # order_number: "toto",
20
+ # quotation_id: "#{page.resource.id}",
21
+ # user_id: "#{page.resource.user_id}"
22
+ ],
23
+ remote: :true,
24
+ :'data-dismiss' => "modal",
25
+ :'data-toggle' => "modal",
26
+ :'data-target' => "#exampleModal",
27
+ # method: :get,
28
+ ) %>
29
+
30
+ </div> -->
31
+ <!-- <div class="button remove-field button remove-field__option_buton" >
32
+ <%#= link_to showproductoption_path, remote: true,:'data-dismiss' =>'modal', :'data-toggle' => 'modal', :'data-target' => '#exampleModal' do%>
33
+ <div class="specialite">réseau</div>
34
+ <%# end %>
35
+ </div> -->
36
+ <% if field.attribute.to_s == "line_items"%>
37
+ <div class="button remove-field button remove-field__option_buton executer-button" >
38
+ <div class="specialite">Ajouter des options</div>
39
+ </div>
40
+ <% end %>
41
+ <!-- <a href='#' id='executer-button' class='btn btn-default'>Executer</a> -->
42
+ <div class="button remove-field">
43
+ <%= link_to_remove_association I18n.t("administrate.fields.nested_has_many.remove", resource: field.associated_class_name.titleize), f %>
44
+
45
+ </div>
46
+ </div>
@@ -0,0 +1,27 @@
1
+ <fieldset class="field-unit--nested <%= field.attribute %>">
2
+ <div class="container-flex">
3
+ <!-- <legend><%= f.label field.attribute %></legend> -->
4
+ <%= f.fields_for field.association_name do |nested_form| %>
5
+ <%= render(
6
+ partial: "fields/nested_has_many/fields",
7
+ locals: {
8
+ f: nested_form,
9
+ field: field,
10
+ },
11
+ ) %>
12
+ <% end %>
13
+ <div class = "add_has_many">
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 toto button_add_associated_#{field.associated_class_name}",
19
+ # class: "button toto button_add_associated_#{field.associated_class_name}",
20
+ # # id usefull for the JS inside New quotation
21
+ # id: "button_add_associated_#{field.associated_class_name}",
22
+ partial: "fields/nested_has_many/fields",
23
+ render_options: { locals: { field: field } },
24
+ ) %>
25
+ </div>
26
+ </div>
27
+ </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,45 @@
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
+
43
+ <% else %>
44
+ <%= t("administrate.fields.has_many.none", default: "–") %>
45
+ <% end %>
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "worker/field/nested_has_many"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -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,81 @@
1
+ require "administrate/field/has_many"
2
+ require "administrate/page/form"
3
+ require "rails"
4
+ require "administrate/engine"
5
+ require "cocoon"
6
+
7
+ module Administrate
8
+ module Field
9
+ class NestedHasMany < Administrate::Field::HasMany
10
+ class Engine < ::Rails::Engine
11
+ Administrate::Engine.add_javascript(
12
+ "administrate-field-nested_has_many/application",
13
+ )
14
+ Administrate::Engine.add_stylesheet(
15
+ "administrate-field-nested_has_many/application",
16
+ )
17
+ end
18
+
19
+ DEFAULT_ATTRIBUTES = %i(id _destroy).freeze
20
+
21
+ def nested_fields
22
+ associated_form.attributes.reject do |nested_field|
23
+ skipped_fields.include?(nested_field.attribute)
24
+ end
25
+ end
26
+
27
+ def nested_fields_for_builder(form_builder)
28
+ return nested_fields unless form_builder.index.is_a? Integer
29
+
30
+ nested_fields.each do |nested_field|
31
+ next if nested_field.resource.blank?
32
+
33
+ # inject current data into field
34
+ resource = nested_field.resource[form_builder.index]
35
+ nested_field.instance_variable_set(
36
+ "@data",
37
+ resource.send(nested_field.attribute),
38
+ )
39
+ end
40
+ end
41
+
42
+ def to_s
43
+ data
44
+ end
45
+
46
+ def self.dashboard_for_resource(resource)
47
+ "#{resource.to_s.classify}Dashboard".constantize
48
+ end
49
+
50
+ def self.associated_attributes(associated_resource)
51
+ DEFAULT_ATTRIBUTES +
52
+ dashboard_for_resource(associated_resource).new.permitted_attributes
53
+ end
54
+
55
+ def self.permitted_attribute(associated_resource, _options = nil)
56
+ {
57
+ "#{associated_resource}_attributes".to_sym =>
58
+ associated_attributes(associated_resource),
59
+ }
60
+ end
61
+
62
+ def associated_class_name
63
+ options.fetch(:class_name, attribute.to_s.singularize.camelcase)
64
+ end
65
+
66
+ def association_name
67
+ associated_class_name.underscore.pluralize
68
+ end
69
+
70
+ def associated_form
71
+ Administrate::Page::Form.new(associated_dashboard, data)
72
+ end
73
+
74
+ private
75
+
76
+ def skipped_fields
77
+ Array(options[:skip])
78
+ end
79
+ end
80
+ end
81
+ end
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "i18n/tasks"
4
+
5
+ RSpec.describe "I18n" do
6
+ let(:i18n) { I18n::Tasks::BaseTask.new }
7
+ let(:missing_keys) { i18n.missing_keys }
8
+ let(:unused_keys) { i18n.unused_keys }
9
+
10
+ it "does not have missing keys" do
11
+ expect(missing_keys).to be_empty,
12
+ "Missing #{missing_keys.leaves.count} i18n keys,
13
+ run `i18n-tasks missing' to show them"
14
+ end
15
+
16
+ it "does not have unused keys" do
17
+ expect(unused_keys).to be_empty,
18
+ "#{unused_keys.leaves.count} unused i18n keys,
19
+ run `i18n-tasks unused' to show them"
20
+ end
21
+
22
+ it "files are normalized" do
23
+ non_normalized = i18n.non_normalized_paths
24
+ message = "The following files need to be normalized:\n" \
25
+ "#{non_normalized.map { |path| " #{path}" }.join("\n")}\n" \
26
+ "Please run `i18n-tasks normalize` to fix"
27
+ expect(non_normalized).to be_empty, message
28
+ end
29
+ end
@@ -0,0 +1,14 @@
1
+ require "administrate/field/nested_has_many"
2
+
3
+ describe Administrate::Field::NestedHasMany do
4
+ describe "#to_partial_path" do
5
+ it "returns a partial based on the page being rendered" do
6
+ page = :show
7
+ field = Administrate::Field::NestedHasMany.new(:relation, "/a.jpg", page)
8
+
9
+ path = field.to_partial_path
10
+
11
+ expect(path).to eq("/fields/nested_has_many/#{page}")
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,26 @@
1
+ $:.push File.expand_path("../lib", __FILE__)
2
+
3
+ Gem::Specification.new do |gem|
4
+ gem.name = "worker-field-nested_has_many"
5
+ # gem.version = Worker::Field::NestedHasMany::VERSION
6
+ gem.version = "0.1.0"
7
+ gem.authors = ["v baxter"]
8
+ gem.email = ["vincent.viricel@gmail.com"]
9
+
10
+ gem.summary = "Custom Plugin -from original one - for nested has_many forms in Administrate"
11
+ gem.description = "Plugin for nested has_many forms in Administrate"
12
+ gem.homepage = "https://github.com/HHGB12/worker-field-nested_has_many"
13
+ gem.license = "MIT"
14
+
15
+ gem.require_paths = ["lib"]
16
+ gem.files = `git ls-files`.split("\n")
17
+ gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
+
19
+ gem.add_dependency "administrate", "> 0.8", "< 1"
20
+ gem.add_dependency "cocoon", "~> 1.2", ">= 1.2.11"
21
+
22
+ gem.add_development_dependency 'rake', '~> 10.0'
23
+ gem.add_development_dependency 'rspec', '~> 3.4'
24
+ gem.add_development_dependency 'i18n-tasks', '~> 0.9.28'
25
+
26
+ end
metadata ADDED
@@ -0,0 +1,150 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: worker-field-nested_has_many
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - v baxter
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2019-02-28 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.8'
20
+ - - "<"
21
+ - !ruby/object:Gem::Version
22
+ version: '1'
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - ">"
28
+ - !ruby/object:Gem::Version
29
+ version: '0.8'
30
+ - - "<"
31
+ - !ruby/object:Gem::Version
32
+ version: '1'
33
+ - !ruby/object:Gem::Dependency
34
+ name: cocoon
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: '1.2'
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ version: 1.2.11
43
+ type: :runtime
44
+ prerelease: false
45
+ version_requirements: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - "~>"
48
+ - !ruby/object:Gem::Version
49
+ version: '1.2'
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ version: 1.2.11
53
+ - !ruby/object:Gem::Dependency
54
+ name: rake
55
+ requirement: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - "~>"
58
+ - !ruby/object:Gem::Version
59
+ version: '10.0'
60
+ type: :development
61
+ prerelease: false
62
+ version_requirements: !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - "~>"
65
+ - !ruby/object:Gem::Version
66
+ version: '10.0'
67
+ - !ruby/object:Gem::Dependency
68
+ name: rspec
69
+ requirement: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - "~>"
72
+ - !ruby/object:Gem::Version
73
+ version: '3.4'
74
+ type: :development
75
+ prerelease: false
76
+ version_requirements: !ruby/object:Gem::Requirement
77
+ requirements:
78
+ - - "~>"
79
+ - !ruby/object:Gem::Version
80
+ version: '3.4'
81
+ - !ruby/object:Gem::Dependency
82
+ name: i18n-tasks
83
+ requirement: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - "~>"
86
+ - !ruby/object:Gem::Version
87
+ version: 0.9.28
88
+ type: :development
89
+ prerelease: false
90
+ version_requirements: !ruby/object:Gem::Requirement
91
+ requirements:
92
+ - - "~>"
93
+ - !ruby/object:Gem::Version
94
+ version: 0.9.28
95
+ description: Plugin for nested has_many forms in Administrate
96
+ email:
97
+ - vincent.viricel@gmail.com
98
+ executables: []
99
+ extensions: []
100
+ extra_rdoc_files: []
101
+ files:
102
+ - ".gitignore"
103
+ - ".ruby-version"
104
+ - Gemfile
105
+ - LICENSE.txt
106
+ - README.md
107
+ - Rakefile
108
+ - app/assets/javascripts/administrate-field-nested_has_many/application.js
109
+ - app/assets/stylesheets/administrate-field-nested_has_many/application.css
110
+ - app/assets/stylesheets/administrate-field-nested_has_many/base.scss
111
+ - app/views/fields/nested_has_many/_fields.html.erb
112
+ - app/views/fields/nested_has_many/_form.html.erb
113
+ - app/views/fields/nested_has_many/_index.html.erb
114
+ - app/views/fields/nested_has_many/_show.html.erb
115
+ - bin/console
116
+ - bin/setup
117
+ - config/i18n-tasks.yml
118
+ - config/locales/administrate-field-nested_has_many.en.yml
119
+ - config/locales/administrate-field-nested_has_many.ja.yml
120
+ - lib/worker/field/nested_has_many.rb
121
+ - spec/i18n_spec.rb
122
+ - spec/lib/worker/field/nested_has_many_spec.rb
123
+ - worker-field-nested_has_many.gemspec
124
+ homepage: https://github.com/HHGB12/worker-field-nested_has_many
125
+ licenses:
126
+ - MIT
127
+ metadata: {}
128
+ post_install_message:
129
+ rdoc_options: []
130
+ require_paths:
131
+ - lib
132
+ required_ruby_version: !ruby/object:Gem::Requirement
133
+ requirements:
134
+ - - ">="
135
+ - !ruby/object:Gem::Version
136
+ version: '0'
137
+ required_rubygems_version: !ruby/object:Gem::Requirement
138
+ requirements:
139
+ - - ">="
140
+ - !ruby/object:Gem::Version
141
+ version: '0'
142
+ requirements: []
143
+ rubyforge_project:
144
+ rubygems_version: 2.7.6
145
+ signing_key:
146
+ specification_version: 4
147
+ summary: Custom Plugin -from original one - for nested has_many forms in Administrate
148
+ test_files:
149
+ - spec/i18n_spec.rb
150
+ - spec/lib/worker/field/nested_has_many_spec.rb