para 0.11.1 → 0.11.3

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: f8200df9f27fa2f27d322ee3458aca86afe26c70629be160848bb12629586057
4
- data.tar.gz: 6a931b1665e21f17304bc1f918cb32b686796accadd3184532d4b47230414c46
3
+ metadata.gz: 9ecad01c0560b48fbe495db67c73c5f3275096b45b4a99a9c9bc0075a39d111e
4
+ data.tar.gz: aedd600ea37ee165dccf2d8ac8452b316999a10de5092c5dea3ab72c1ef0d4a9
5
5
  SHA512:
6
- metadata.gz: 27faad84e404aea146d51ece49a8d5091f1dc3f201a44c16841733c28ecfdc8aab1560f080887216949db150d0c19e1e5ced913cdb2cace01462608b735c77f9
7
- data.tar.gz: 0b11a0c0239a54e99408d15deb17c0ff4174be9719dd0fa592faebce81affa2b69f9e68fd3697160d31db2f8b12fe50c2519e8f622e787cdd5e02c00573425b3
6
+ metadata.gz: ff73f38e195cb79654b75b8e0e145873e540f8b351b887dfeb871548fb73f73f698dc641f62116fbc820e7909db80a22fb933e990625ede8de89aa133d0436a9
7
+ data.tar.gz: 74b34f00a147194d45060346895a46581eda59cd5d6a27f2963093557ba4331b570c866c8a98acc70395c89422ce5485a040373ec6167955ff41e649a9841ac7
@@ -17,7 +17,7 @@ module Para
17
17
 
18
18
  attachment_reflections = original.class.reflections.select do |name, reflection|
19
19
  name.to_s.match(ATTACHMENTS_RELATION_REGEX) &&
20
- reflection.options[:class_name] == "ActiveStorage::Attachment"
20
+ reflection.options[:class_name] == 'ActiveStorage::Attachment'
21
21
  end
22
22
 
23
23
  attachment_reflections.each do |name, reflection|
@@ -26,16 +26,27 @@ module Para
26
26
 
27
27
  if reflection.collection?
28
28
  association_target.each do |attachment|
29
- clone_attachment(name, attachment)
29
+ clone_attachment_if_needed(name, attachment)
30
30
  end
31
31
  else
32
- clone_attachment(name, association_target)
32
+ clone_attachment_if_needed(name, association_target)
33
33
  end
34
34
  end
35
35
  end
36
36
 
37
+ def clone_attachment_if_needed(name, attachment)
38
+ return if attachment.nil?
39
+
40
+ store_key = store_key_for(attachment)
41
+
42
+ # If the attachment has already been cloned, we don't need to clone it again
43
+ return if dictionary[store_key]&.key?(attachment)
44
+
45
+ clone_attachment(name, attachment)
46
+ end
47
+
37
48
  def clone_attachment(name, original_attachment)
38
- association_name = name.gsub(ATTACHMENTS_RELATION_REGEX, "")
49
+ association_name = name.gsub(ATTACHMENTS_RELATION_REGEX, '')
39
50
  original_blob = original_attachment.blob
40
51
 
41
52
  # Handle missing file in storage service by bypassing the attachment cloning
@@ -45,7 +56,7 @@ module Para
45
56
  attachment_target = clone.send(association_name)
46
57
 
47
58
  cloned_blob = ActiveStorage::Blob.create_and_upload!(
48
- io: tempfile,
59
+ io: tempfile,
49
60
  filename: original_blob.filename,
50
61
  content_type: original_blob.content_type
51
62
  )
@@ -67,10 +78,10 @@ module Para
67
78
  # doesn't always return the same, so for now we still handle the Rails 5.2 case.
68
79
  def find_cloned_attachment(attachment_target, original_blob)
69
80
  attachments = if attachment_target.attachments.any?
70
- attachment_target.attachments
71
- else
72
- [attachment_target.attachment]
73
- end
81
+ attachment_target.attachments
82
+ else
83
+ [attachment_target.attachment]
84
+ end
74
85
 
75
86
  attachment = attachments.find do |att|
76
87
  att.blob.checksum == original_blob.checksum
@@ -81,11 +92,15 @@ module Para
81
92
  # simulates what the deep_cloneable gem does when it clones a resource
82
93
  #
83
94
  def store_cloned(source, clone)
84
- store_key = source.class.name.tableize.to_sym
95
+ store_key = store_key_for(source)
85
96
 
86
97
  dictionary[store_key] ||= {}
87
98
  dictionary[store_key][source] = clone
88
99
  end
100
+
101
+ def store_key_for(attachment)
102
+ attachment.class.name.tableize.to_sym
103
+ end
89
104
  end
90
105
  end
91
106
  end
@@ -1,14 +1,14 @@
1
1
  module Para
2
2
  module Inputs
3
3
  class NestedBaseInput < SimpleForm::Inputs::Base
4
- GLOBAL_NESTED_FIELD_KEY = "para.nested_field.parent"
4
+ GLOBAL_NESTED_FIELD_KEY = 'para.nested_field.parent'
5
5
 
6
6
  private
7
7
 
8
8
  def dom_identifier
9
9
  @dom_identifier ||= begin
10
10
  name = attribute_name
11
- id = @builder.object.id || "_new_#{ parent_nested_field&.attribute_name }_"
11
+ id = @builder.object.id || "_new_#{parent_nested_field&.attribute_name}_"
12
12
  time = (Time.now.to_f * 1000).to_i
13
13
  random = (rand * 1000).to_i
14
14
  [name, id, time, random].join('-')
@@ -22,7 +22,7 @@ module Para
22
22
  def subclasses
23
23
  options.fetch(:subclasses, [])
24
24
  end
25
-
25
+
26
26
  def add_button_label
27
27
  options.fetch(:add_button_label) { I18n.t('para.form.nested.add') }
28
28
  end
@@ -39,13 +39,13 @@ module Para
39
39
  @parent_nested_field = RequestStore.store[GLOBAL_NESTED_FIELD_KEY]
40
40
  RequestStore.store[GLOBAL_NESTED_FIELD_KEY] = self
41
41
 
42
- block.call.tap do
43
- RequestStore.store[GLOBAL_NESTED_FIELD_KEY] = @parent_nested_field
44
- end
42
+ block.call
43
+ ensure
44
+ RequestStore.store[GLOBAL_NESTED_FIELD_KEY] = @parent_nested_field
45
45
  end
46
46
 
47
- def parent_nested_field
48
- @parent_nested_field || RequestStore.store[GLOBAL_NESTED_FIELD_KEY]
47
+ def parent_nested_field(fallback_to_self: true)
48
+ @parent_nested_field || (RequestStore.store[GLOBAL_NESTED_FIELD_KEY] if fallback_to_self)
49
49
  end
50
50
  end
51
51
  end
@@ -4,7 +4,7 @@ module Para
4
4
  attr_reader :resource
5
5
 
6
6
  def input(_wrapper_options = nil)
7
- input_html_options[:class] << "nested-many"
7
+ input_html_options[:class] << 'nested-many'
8
8
 
9
9
  orderable = options.fetch(:orderable, model.orderable?)
10
10
  add_button = options.fetch(:add_button, true)
@@ -40,6 +40,15 @@ module Para
40
40
  end
41
41
  end
42
42
 
43
+ protected
44
+
45
+ def render_partial?
46
+ options[:render_partial] ||
47
+ object.errors.any? ||
48
+ (object.persisted? && uncollapsed?) ||
49
+ parent_nested_field(fallback_to_self: false)&.render_partial?
50
+ end
51
+
43
52
  private
44
53
 
45
54
  def parent_model
@@ -58,10 +67,6 @@ module Para
58
67
  inset? && Para.config.uncollapse_inset_nested_fields
59
68
  end
60
69
 
61
- def render_partial?
62
- options[:render_partial] || object.errors.any? || (object.persisted? && uncollapsed?)
63
- end
64
-
65
70
  def remote_partial_params
66
71
  @remote_partial_params ||= options.fetch(:remote_partial_params, {}).merge(
67
72
  namespace: :nested_form
data/lib/para/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Para
4
- VERSION = '0.11.1'
4
+ VERSION = '0.11.3'
5
5
  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.11.1
4
+ version: 0.11.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Valentin Ballestrino
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-01-10 00:00:00.000000000 Z
11
+ date: 2023-10-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: active_decorator
@@ -862,7 +862,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
862
862
  - !ruby/object:Gem::Version
863
863
  version: '0'
864
864
  requirements: []
865
- rubygems_version: 3.4.2
865
+ rubygems_version: 3.4.8
866
866
  signing_key:
867
867
  specification_version: 4
868
868
  summary: Rails admin engine