para 0.8.12 → 0.9.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9cd266c603b5629183643836cce701deb33e3322af0a98f021fb48f6922127c6
4
- data.tar.gz: 36ff9796de7371559684be64fdb6f402acd5267997e94fb9f739e294d508a6d3
3
+ metadata.gz: 36e1d56aa604b3827cc9e483a65deb72827424890f9125ee83cb43ca5d7e34ed
4
+ data.tar.gz: bf514778435313e925dbd1222bd85393f842416ac7a58833a21d02d45edc4eb9
5
5
  SHA512:
6
- metadata.gz: ddab0a864ddf77239b958c1d03fc5a67c69bfbf551893c45fd000c8b2970f14d865e01b71c786935d0dd27907149c090335ec13413365805f29f25658bb5949e
7
- data.tar.gz: f288a5bd00b8bea61093546d9d5ce9ff649c18165564f3fa5876cedfe856f486604ef6ad46b1b57155dc62c21859e4de24936f65169428386da5b42f5b64044b
6
+ metadata.gz: eb0433062dd44b4b6f4b1278604e94cc751c586bee5196118cab5d7feaba6fe011df5e0900410ce1f2a65e78e88723e6e7cee8d22c82864dce99a52d2866d95c
7
+ data.tar.gz: 1d4fabf4b0160ae3e7fdbc238a8c047a93c7d1c69a8d07c89d4f1f565ba61d1cf452f17baa4db52e8180036bcae99df775d714fabc876208bd36d518ff6f927e
@@ -5,7 +5,7 @@ class Para.NestedManyField
5
5
  @initializeOrderable()
6
6
  @initializeCocoon()
7
7
 
8
- @$field.on 'shown.bs.collapse', $.proxy(@collapseShown, this)
8
+ @$field.on 'shown.bs.collapse', @stoppingPropagation(@collapseShown)
9
9
 
10
10
  initializeOrderable: ->
11
11
  @orderable = @$field.hasClass('orderable')
@@ -21,11 +21,17 @@ class Para.NestedManyField
21
21
  $(el).find('.resource-position-field').val(i)
22
22
 
23
23
  initializeCocoon: ->
24
- @$fieldsList.on 'cocoon:after-insert', $.proxy(@afterInsertField, this)
25
- @$fieldsList.on 'cocoon:before-remove', $.proxy(@beforeRemoveField, this)
26
- @$fieldsList.on 'cocoon:after-remove', $.proxy(@afterRemoveField, this)
24
+ @$fieldsList.on 'cocoon:after-insert', @afterInsertField
25
+ @$fieldsList.on 'cocoon:before-remove', @beforeRemoveField
26
+ @$fieldsList.on 'cocoon:after-remove', @afterRemoveField
27
27
 
28
- afterInsertField: (e, $element) ->
28
+ stoppingPropagation: (callback) =>
29
+ (e, args...) =>
30
+ e.stopPropagation()
31
+ callback(e, args...)
32
+
33
+
34
+ afterInsertField: (e, $element) =>
29
35
  if ($collapsible = $element.find('[data-open-on-insert="true"]')).length
30
36
  @openInsertedField($collapsible)
31
37
 
@@ -36,21 +42,21 @@ class Para.NestedManyField
36
42
 
37
43
  $element.simpleForm()
38
44
 
39
- beforeRemoveField: (e, $element) ->
45
+ beforeRemoveField: (e, $element) =>
40
46
  $nextEl = $element.next()
41
47
  # Remove attributes mappings field for new records since it will try to
42
48
  # create an empty nested resource otherwise
43
49
  $nextEl.remove() if $nextEl.is('[data-attributes-mappings]') and not $element.is('[data-persisted]')
44
50
 
45
51
  # When a sub field is removed, update every sub field position
46
- afterRemoveField: ->
52
+ afterRemoveField: =>
47
53
  @handleOrderingUpdated();
48
54
 
49
55
  openInsertedField: ($field) ->
50
56
  $target = $($field.attr('href'))
51
57
  $target.collapse('show')
52
58
 
53
- collapseShown: (e) ->
59
+ collapseShown: (e) =>
54
60
  $target = $(e.target)
55
61
 
56
62
  if $target.is("[data-rendered]") or $target.data("rendered")
@@ -5,6 +5,7 @@ module Para
5
5
  @model = params[:model_name].constantize
6
6
  @object = params[:id] ? @model.find(params[:id]) : @model.new
7
7
  @object_name = params[:object_name]
8
+ @builder_options = params[:builder_options]&.permit! || {}
8
9
 
9
10
  render layout: false
10
11
  end
@@ -5,8 +5,10 @@ module Para
5
5
  #
6
6
  def admin_component_sections
7
7
  @admin_component_sections ||= begin
8
- Para::ComponentSection.ordered.includes(:components).tap do |sections|
9
- sections.flat_map(&:components).each(&method(:decorate))
8
+ sections = Para::ComponentSection.ordered.includes(:components, :parent_component)
9
+
10
+ sections.tap do |loaded_sections|
11
+ loaded_sections.flat_map(&:components).each(&method(:decorate))
10
12
  end
11
13
  end
12
14
  end
@@ -23,5 +25,11 @@ module Para
23
25
  config = Para.components.component_configuration_for(component.identifier)
24
26
  !config.shown_if || instance_exec(&config.shown_if)
25
27
  end
28
+
29
+ def current_component_or_parent?(component)
30
+ return false unless @component
31
+
32
+ @component == component || @component.parent_component == component
33
+ end
26
34
  end
27
35
  end
@@ -19,9 +19,13 @@ module Para
19
19
  attributes = model_field_mappings(model).fields
20
20
  relation = options.fetch(:relation, model.name.to_s.underscore.pluralize)
21
21
  allow_adding_resource = options.fetch(:addable, true)
22
+ force_list = options.fetch(:force_list, false)
22
23
 
23
- partial = :list
24
- partial = :tree if model.respond_to?(:roots) && can?(:tree, model)
24
+ partial = if !force_list && model.respond_to?(:roots) && can?(:tree, model)
25
+ :tree
26
+ else
27
+ :list
28
+ end
25
29
 
26
30
  render(
27
31
  partial: find_partial_for(relation, partial),
@@ -1,6 +1,15 @@
1
1
  - nested_form = nil
2
2
 
3
- - para_form_for(@object, url: "") do |form|
3
+ -# Initialize an unredered form builder that will only be used to create the nested fields
4
+ -# by using the yielded block form builder argument.
5
+ -#
6
+ -# The form's object name is set through the provided :object_name param to ensure that
7
+ -# the form inputs are named correctly in the loading form.
8
+ -#
9
+ -# Builder options allow to customize the options passed to the form builder to customize
10
+ -# the rendered partials.
11
+ -#
12
+ - para_form_for(@object, @builder_options.merge(url: "")) do |form|
4
13
  - form.object_name = @object_name
5
14
  - nested_form = capture do
6
15
  = render(partial: find_partial_for(@model, :remote_nested_form), locals: { form: form, model: @model, object: @object, object_name: @object_name })
@@ -1 +1 @@
1
- = render partial: find_partial_for(model, :fields), locals: { form: form }
1
+ = render partial: find_partial_for(model, form.nested_fields_partial_name), locals: { form: form }
@@ -15,7 +15,7 @@
15
15
  %ul.component-section-list-items.collapse.in{ id: "collapse-section-#{index}" }
16
16
  - component_section.components.each do |component|
17
17
  - if can?(:manage, component) && show_component?(component)
18
- %li.component-item{ class: (@component == component) && 'active' }
18
+ %li.component-item{ class: ('active' if current_component_or_parent?(component)) }
19
19
  = link_to component.main_navigation_name, component.path
20
20
 
21
21
  - else
@@ -2,6 +2,7 @@
2
2
  .fields-list{ id: dom_identifier }
3
3
  = form.simple_fields_for attribute_name, resources, nested_attribute_name: attribute_name, orderable: orderable, track_attribute_mappings: render_partial do |nested_form|
4
4
  = render partial: find_partial_for(model, 'nested_many/container', partial_dir: 'inputs'), locals: { form: nested_form, model: nested_form.object.class, subclass: subclass, nested_locals: nested_locals, inset: inset, uncollapsed: uncollapsed, render_partial: render_partial, remote_partial_params: remote_partial_params }
5
+
5
6
  -# Add button
6
7
  - if add_button
7
8
  - if subclass
@@ -6,7 +6,7 @@
6
6
  = render partial: find_partial_for(model, 'nested_one/container', partial_dir: 'inputs'), locals: { nested_form: nested_form, form: form, model: nested_form.object.class, subclass: subclass, nested_locals: nested_locals }
7
7
 
8
8
  - else
9
- = render partial: find_partial_for(model, :fields), locals: { form: nested_form, parent: form.object }.merge(nested_locals)
9
+ = render partial: find_partial_for(model, form.nested_fields_partial_name), locals: { form: nested_form, parent: form.object }.merge(nested_locals)
10
10
 
11
11
  - if defined?(subclass) && subclass
12
- = render partial: 'para/inputs/nested_one/add_with_subclasses', locals: { form: form, model: model, dom_identifier: dom_identifier, nested_locals: nested_locals, attribute_name: attribute_name, subclasses: subclasses, add_button_label: add_button_label, add_button_class: add_button_class, subclass: subclass }
12
+ = render partial: 'para/inputs/nested_one/add_with_subclasses', locals: { form: form, model: model, dom_identifier: dom_identifier, nested_locals: nested_locals, attribute_name: attribute_name, subclasses: subclasses, add_button_label: add_button_label, add_button_class: add_button_class, subclass: subclass }
@@ -14,7 +14,7 @@
14
14
  .panel-collapse.form-inputs.collapse{ id: form.nested_resource_dom_id, class: ('in' if uncollapsed && form.object.persisted?), data: { rendered: render_partial, render_path: @component.path(remote_partial_params), id: form.object.id, :"object-name" => form.object_name, :"model-name" => model.name } }
15
15
  .panel-body{ data: { :"nested-form-container" => true } }
16
16
  - if render_partial
17
- = render partial: find_partial_for(model, :fields), locals: { form: form }.merge(nested_locals)
17
+ = render partial: find_partial_for(model, form.nested_fields_partial_name), locals: { form: form }.merge(nested_locals)
18
18
  - else
19
19
  = fa_icon "spinner spin"
20
20
 
@@ -6,4 +6,4 @@
6
6
  %i.fa.fa-angle-up
7
7
 
8
8
  .panel-body.panel-collapse.form-inputs.collapse{ id: nested_form.nested_resource_dom_id }
9
- = render partial: find_partial_for(model, :fields), locals: { form: nested_form, parent: nested_form.object }.merge(nested_locals)
9
+ = render partial: find_partial_for(model, form.nested_fields_partial_name), locals: { form: nested_form, parent: nested_form.object }.merge(nested_locals)
@@ -13,14 +13,14 @@ en:
13
13
  error: "Could not delete %{model}"
14
14
  clone:
15
15
  success: "%{model} cloned"
16
- error: "Could not clone %{model}"
17
-
16
+ error: "Could not clone %{model}"
17
+
18
18
  jobs:
19
19
  para/importer/base:
20
20
  progressing: "The file is being imported, please wait a few moments ..."
21
21
  success: "The import of the file was successfully completed"
22
22
  success_with_errors: |
23
- The import of the file was done, but some lines
23
+ The import of the file was done, but some lines
24
24
  were not taken into account due to errors :
25
25
  other_errors: "<br>And <b>%{count}</b> others errors ..."
26
26
  error: "The selected file contains errors and could not be imported"
@@ -40,9 +40,6 @@ en:
40
40
  confirmation:
41
41
  shared:
42
42
  destroy: 'Are you sure that you want to delete %{model} ?'
43
-
44
- component:
45
- none_created: "No components yet ..."
46
43
 
47
44
  component:
48
45
  create: "Create a component"
@@ -146,7 +143,7 @@ en:
146
143
  type: "Type"
147
144
  model_type: "Resource"
148
145
  namespaced: "Only list component's resources"
149
-
146
+
150
147
  activemodel:
151
148
  models:
152
149
  settings_rails/form:
@@ -76,6 +76,14 @@ module Para
76
76
  nested? && options[:parent_builder].object
77
77
  end
78
78
 
79
+ # Returns the partial name to be looked up for rendering used inside the nested
80
+ # fields partials, for the nested fields container and the remote nested fields
81
+ # partial.
82
+ #
83
+ def nested_fields_partial_name
84
+ :fields
85
+ end
86
+
79
87
  private
80
88
 
81
89
  def default_resource_name
@@ -3,7 +3,7 @@ module Para
3
3
  class NestedManyInput < NestedBaseInput
4
4
  attr_reader :resource
5
5
 
6
- def input(wrapper_options = nil)
6
+ def input(_wrapper_options = nil)
7
7
  input_html_options[:class] << "nested-many"
8
8
 
9
9
  orderable = options.fetch(:orderable, model.orderable?)
@@ -40,6 +40,8 @@ module Para
40
40
  end
41
41
  end
42
42
 
43
+ private
44
+
43
45
  def parent_model
44
46
  @parent_model ||= @builder.object.class
45
47
  end
@@ -92,9 +92,9 @@ module Para
92
92
  end
93
93
 
94
94
  content_tag(:th, options) do
95
- if (sort = options.delete(:sort))
95
+ if search && (sort = options.delete(:sort))
96
96
  view.sort_link(search, *sort, label, hide_indicator: true)
97
- elsif searchable?(field_name)
97
+ elsif search && searchable?(field_name)
98
98
  view.sort_link(search, field_name, label, hide_indicator: true)
99
99
  else
100
100
  label
data/lib/para/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Para
2
- VERSION = '0.8.12'
2
+ VERSION = '0.9.2'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: para
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.12
4
+ version: 0.9.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Valentin Ballestrino
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-12-14 00:00:00.000000000 Z
11
+ date: 2021-02-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -19,7 +19,7 @@ dependencies:
19
19
  version: '4.0'
20
20
  - - "<="
21
21
  - !ruby/object:Gem::Version
22
- version: '6.0'
22
+ version: '7.0'
23
23
  type: :runtime
24
24
  prerelease: false
25
25
  version_requirements: !ruby/object:Gem::Requirement
@@ -29,7 +29,7 @@ dependencies:
29
29
  version: '4.0'
30
30
  - - "<="
31
31
  - !ruby/object:Gem::Version
32
- version: '6.0'
32
+ version: '7.0'
33
33
  - !ruby/object:Gem::Dependency
34
34
  name: rails-i18n
35
35
  requirement: !ruby/object:Gem::Requirement
@@ -152,16 +152,22 @@ dependencies:
152
152
  name: paperclip
153
153
  requirement: !ruby/object:Gem::Requirement
154
154
  requirements:
155
- - - "~>"
155
+ - - ">="
156
156
  - !ruby/object:Gem::Version
157
157
  version: '4.2'
158
+ - - "<"
159
+ - !ruby/object:Gem::Version
160
+ version: '7.0'
158
161
  type: :runtime
159
162
  prerelease: false
160
163
  version_requirements: !ruby/object:Gem::Requirement
161
164
  requirements:
162
- - - "~>"
165
+ - - ">="
163
166
  - !ruby/object:Gem::Version
164
167
  version: '4.2'
168
+ - - "<"
169
+ - !ruby/object:Gem::Version
170
+ version: '7.0'
165
171
  - !ruby/object:Gem::Dependency
166
172
  name: cancancan
167
173
  requirement: !ruby/object:Gem::Requirement
@@ -334,16 +340,22 @@ dependencies:
334
340
  name: bootstrap-sass
335
341
  requirement: !ruby/object:Gem::Requirement
336
342
  requirements:
337
- - - "~>"
343
+ - - ">="
344
+ - !ruby/object:Gem::Version
345
+ version: '3.3'
346
+ - - "<"
338
347
  - !ruby/object:Gem::Version
339
- version: 3.3.0
348
+ version: '3.5'
340
349
  type: :runtime
341
350
  prerelease: false
342
351
  version_requirements: !ruby/object:Gem::Requirement
343
352
  requirements:
344
- - - "~>"
353
+ - - ">="
354
+ - !ruby/object:Gem::Version
355
+ version: '3.3'
356
+ - - "<"
345
357
  - !ruby/object:Gem::Version
346
- version: 3.3.0
358
+ version: '3.5'
347
359
  - !ruby/object:Gem::Dependency
348
360
  name: font-awesome-rails
349
361
  requirement: !ruby/object:Gem::Requirement