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 +4 -4
- data/lib/tessa/simple_form/asset_input.rb +39 -15
- data/lib/tessa/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a8e21c3d74e92f753a5d6ae6b0e78adf670a512a029b4044c35b82a06f02b6b4
|
4
|
+
data.tar.gz: a653d63a20d3433b3c983b5b552d739dd2a75b77bb272f1f066ca06f07122f6b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
|
21
|
-
|
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
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
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
|
-
|
57
|
+
# These get read by the JS to populate the preview in Dropzone
|
58
|
+
def meta_for_blob(blob)
|
33
59
|
{
|
34
|
-
|
35
|
-
"
|
36
|
-
"
|
37
|
-
"
|
38
|
-
|
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