tessa 6.0.0.rc2 → 6.0.0.rc4

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: 20d746d445cccc01d998f1d8bead8b92b8e0083e1858cd40ed2151785c1f4830
4
- data.tar.gz: aa0432076ee14f238af2bf5cffdc83a0f37055246a1524ae2a05cb48e5bb3ed4
3
+ metadata.gz: 465985ee1e3fe7c0c2e014f24d4db97207bb2554f1127ab8c1cf98ed96e62f5d
4
+ data.tar.gz: 9096cc877ca2105f2dfe93500379487474d8ba384f102a7e54c92c9dad45bb3c
5
5
  SHA512:
6
- metadata.gz: 386f143532a9e1a17b7149488d6d50d2affa444a3fc029653c5dca2218eef980df1963982cc64020b7aca85c7fbd7063e19a23fa0355cdebc4a0881230715585
7
- data.tar.gz: f504a6ae2e98ee85478bb5d89ddb950533c80aa5a881f7accb336dfd36049eea8b1336c5a9f602ff6b51a4085826d76104475e3af9fdb8e17fdb0b7160a177f6
6
+ metadata.gz: 88a2d4528b06fd940b3e7637e71df7b8cdf9e759331637a7b2b93c8c626f3114e6025c5fa8b90d5610e2172118ab06a3f8913e1927779e69bbdd8a14a9bd5a27
7
+ data.tar.gz: 52254393104522de42429250ff2adcd43c542816878c0f0fe6853f578078b5391648dd1da73dc321b24e8b003047246a616df0fe15005bfa95bb91e2aaf63e3d
@@ -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" => asset.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.rc4"
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.rc4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Justin Powell
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2023-05-08 00:00:00.000000000 Z
12
+ date: 2023-05-12 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake