tessa 6.0.0.rc2 → 6.0.0.rc3

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 20d746d445cccc01d998f1d8bead8b92b8e0083e1858cd40ed2151785c1f4830
4
- data.tar.gz: aa0432076ee14f238af2bf5cffdc83a0f37055246a1524ae2a05cb48e5bb3ed4
3
+ metadata.gz: a8e21c3d74e92f753a5d6ae6b0e78adf670a512a029b4044c35b82a06f02b6b4
4
+ data.tar.gz: a653d63a20d3433b3c983b5b552d739dd2a75b77bb272f1f066ca06f07122f6b
5
5
  SHA512:
6
- metadata.gz: 386f143532a9e1a17b7149488d6d50d2affa444a3fc029653c5dca2218eef980df1963982cc64020b7aca85c7fbd7063e19a23fa0355cdebc4a0881230715585
7
- data.tar.gz: f504a6ae2e98ee85478bb5d89ddb950533c80aa5a881f7accb336dfd36049eea8b1336c5a9f602ff6b51a4085826d76104475e3af9fdb8e17fdb0b7160a177f6
6
+ metadata.gz: c1b13ee45b792918c844b31d23c888309be682e3df4b40533c5ac9ca51f9b8b39b2d96c836c19cd0d89776e697aa2b698db5d74d6496962c07b19da98d9aa13a
7
+ data.tar.gz: 81fbd95c45021c449ed445c6d9831c824095279d26dc249b475b2a3aca9acc238af86634a12efac47f9e057180fa5aad1d45a6cb4ece929273ab284ce11da355
@@ -17,27 +17,51 @@ module Tessa
17
17
 
18
18
  def hidden_fields_for(attribute_name)
19
19
  asset = object.public_send(attribute_name)
20
- unless asset&.key.present?
21
- return @builder.hidden_field("#{attribute_name}", value: nil)
20
+ if asset&.is_a?(String)
21
+ # This happens if the controller rejects the change with errors and re-renders the form.
22
+ # In this case our field value would be the signed upload ID.
23
+ return hidden_fileds_for_signed_id(attribute_name, asset)
22
24
  end
23
25
 
24
- @builder.hidden_field("#{attribute_name}",
25
- value: asset.key,
26
- data: {
27
- # These get read by the JS to populate the preview in Dropzone
28
- meta: meta_for_asset(asset)
26
+ if asset&.key.present?
27
+ @builder.hidden_field("#{attribute_name}", {
28
+ value: asset.key,
29
+ data: {
30
+ meta: meta_for_blob(asset).merge({
31
+ # this allows us to find the hidden HTML input to remove it if we remove the asset
32
+ "signedID" => blob.key,
33
+ })
34
+ }
29
35
  })
36
+ end
37
+
38
+ return @builder.hidden_field("#{attribute_name}", value: nil)
39
+ end
40
+
41
+ def hidden_fileds_for_signed_id(attribute_name, signed_id)
42
+ if blob = ActiveStorage::Blob.find_signed(signed_id)
43
+ return @builder.hidden_field("#{attribute_name}", {
44
+ value: signed_id,
45
+ data: {
46
+ meta: meta_for_blob(blob).merge({
47
+ 'signedID' => signed_id
48
+ })
49
+ }
50
+ })
51
+ end
52
+
53
+ # The form post sent some other string which was not a signed ID
54
+ return @builder.hidden_field("#{attribute_name}", value: nil)
30
55
  end
31
56
 
32
- def meta_for_asset(asset)
57
+ # These get read by the JS to populate the preview in Dropzone
58
+ def meta_for_blob(blob)
33
59
  {
34
- # this allows us to find the hidden HTML input to remove it if we remove the asset
35
- "signedID" => asset.key,
36
- "name" => asset.filename,
37
- "size" => asset.byte_size,
38
- "mimeType" => asset.content_type,
39
- "url" => asset.service_url(disposition: :inline, expires_in: 1.hour),
40
- }.to_json
60
+ "name" => blob.filename,
61
+ "size" => blob.byte_size,
62
+ "mimeType" => blob.content_type,
63
+ "url" => blob.service_url(disposition: :inline, expires_in: 1.hour),
64
+ }.as_json
41
65
  end
42
66
  end
43
67
  end
data/lib/tessa/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Tessa
2
- VERSION = "6.0.0.rc2"
2
+ VERSION = "6.0.0.rc3"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tessa
3
3
  version: !ruby/object:Gem::Version
4
- version: 6.0.0.rc2
4
+ version: 6.0.0.rc3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Justin Powell