trestle-active_storage 2.0.0 → 2.1.0
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/README.md +10 -1
- data/app/views/trestle/active_storage/_has_many_field.html.erb +35 -0
- data/app/views/trestle/active_storage/{_field.html.erb → _has_one_field.html.erb} +0 -0
- data/lib/trestle/active_storage/controller_concern.rb +18 -2
- data/lib/trestle/active_storage/field.rb +16 -6
- data/lib/trestle/active_storage/version.rb +1 -1
- metadata +6 -6
- data/config/routes.rb +0 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1dc007395a6923c10983c54ed4bd8b4f2073eaa230cdc60878a4b35e2d808a7a
|
4
|
+
data.tar.gz: 8fcb932920c938072708e39dd7a7712f8b07167af062b332ec80b2a3897036dc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a208efb0445661502d8cb641f0f10aab91aaceb312b60c9192083521e1f911a6002da14c847cba99f1099c57222585a5ee7e9990b80376027eef53fbd9b0b496
|
7
|
+
data.tar.gz: 95e5ac5377b3bbb0cd10cad88f156e97128b90f4c7df0d89ad937c9e068ce71901ab447b1f20a3a3c2af3f2b43827360de57ec9c833fcb1e3cb9aac808cf6197
|
data/README.md
CHANGED
@@ -23,6 +23,8 @@ Trestle.resource(:users) do
|
|
23
23
|
end
|
24
24
|
```
|
25
25
|
|
26
|
+
You can use the `active_storage_field` field type for both `has_one_attached` and `has_many_attached` attachments.
|
27
|
+
|
26
28
|
## Installation
|
27
29
|
|
28
30
|
These instructions assume you have a working Trestle application. To integrate trestle-active_storage, first add it to your application's Gemfile:
|
@@ -41,11 +43,18 @@ If you'd like to get up and running on Heroku, check out their [documentation on
|
|
41
43
|
|
42
44
|
## TODO / Wishlist
|
43
45
|
|
44
|
-
- [
|
46
|
+
- [x] Support for `has_many_attached` attachments
|
45
47
|
- [x] Support for Active Storage previews
|
46
48
|
- [ ] Preview of selected local file ([#1](https://github.com/richardvenneman/trestle-active_storage/issues/1))
|
47
49
|
- [ ] Integration tests
|
48
50
|
|
51
|
+
## Contributors
|
52
|
+
|
53
|
+
| <img src="https://avatars.githubusercontent.com/richardvenneman?s=100" width="100" alt="richard venneman" /><br />[<sub>Richard Venneman</sub>](https://www.cityspotters.com)<br />[💻](https://github.com/richardvenneman/trestle-active_storage/commits?author=richardvenneman) [📖](https://github.com/richardvenneman/trestle-active_storage/commits?author=richardvenneman) 👀 | <img src="https://avatars.githubusercontent.com/tachyons?s=100" width="100" alt="aboobacker mk" /><br />[<sub>Aboobacker MK</sub>](http://aboobacker.in/)<br />💡 | <img src="https://avatars.githubusercontent.com/PunkMaldito?s=100" width="100" alt="rafael porto" /><br />[<sub>Rafael Porto</sub>](http://euodeiovoce.com.br/)<br />[💻](https://github.com/richardvenneman/trestle-active_storage/commits?author=PunkMaldito) |
|
54
|
+
| :---: | :---: | :---: |
|
55
|
+
|
56
|
+
This project follows the [all-contributors](https://github.com/kentcdodds/all-contributors) specification.
|
57
|
+
|
49
58
|
## License
|
50
59
|
|
51
60
|
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
@@ -0,0 +1,35 @@
|
|
1
|
+
<div class='nested-fields-container'>
|
2
|
+
<%= builder.fields_for :images do %>
|
3
|
+
<div class="active-storage">
|
4
|
+
<% if attachments.attached? %>
|
5
|
+
<% attachments.each do |attachment| %>
|
6
|
+
<div class="active-storage__preview">
|
7
|
+
<% if attachment.previewable? %>
|
8
|
+
<%= link_to image_tag(main_app.url_for(attachment.preview(resize: "300x300>")), class: "active-storage__image"),
|
9
|
+
main_app.rails_blob_path(attachment, disposition: "attachment") %>
|
10
|
+
<% elsif attachment.variable? %>
|
11
|
+
<%= link_to image_tag(main_app.url_for(attachment.variant(resize: "300x300>")), class: "active-storage__image"),
|
12
|
+
main_app.rails_blob_path(attachment, disposition: "attachment") %>
|
13
|
+
<% else %>
|
14
|
+
<%= link_to main_app.rails_blob_path(attachment, disposition: "attachment"), class: "btn btn-info" do %>
|
15
|
+
<i class="fa fa-download"></i>
|
16
|
+
<span class="btn-label">Download <%= field_name %></span>
|
17
|
+
<% end %>
|
18
|
+
<% end %>
|
19
|
+
|
20
|
+
<div>
|
21
|
+
<small><%= attachment.blob.filename %></small>
|
22
|
+
<%= builder.check_box("delete_#{field_name}_#{attachment.blob_id}", label: "Delete this #{field_name.to_s.singularize}") %>
|
23
|
+
</div>
|
24
|
+
</div>
|
25
|
+
<hr>
|
26
|
+
<% end %>
|
27
|
+
<% end %>
|
28
|
+
</div>
|
29
|
+
|
30
|
+
<%= builder.raw_file_field(field_name, class: 'active-storage__field', multiple: true, direct_upload: true) %>
|
31
|
+
<% end %>
|
32
|
+
</div>
|
33
|
+
|
34
|
+
|
35
|
+
|
File without changes
|
@@ -13,13 +13,29 @@ module Trestle
|
|
13
13
|
self.instance = admin.find_instance(params)
|
14
14
|
|
15
15
|
admin.active_storage_fields.each do |field|
|
16
|
-
instance.
|
16
|
+
attachment = instance.send(field)
|
17
|
+
|
18
|
+
if attachment.respond_to?(:each)
|
19
|
+
attachment.each do |att|
|
20
|
+
instance.class.send(:attr_accessor, "delete_#{field}_#{att.blob_id}")
|
21
|
+
end
|
22
|
+
else
|
23
|
+
instance.class.send(:attr_accessor, "delete_#{field}")
|
24
|
+
end
|
17
25
|
end
|
18
26
|
end
|
19
27
|
|
20
28
|
def purge_attachments
|
21
29
|
admin.active_storage_fields.each do |field|
|
22
|
-
|
30
|
+
attachment = instance.send(field)
|
31
|
+
|
32
|
+
if attachment.respond_to?(:each)
|
33
|
+
attachment.each do |att|
|
34
|
+
att.purge if instance.try("delete_#{field}_#{att.blob_id}") == '1'
|
35
|
+
end
|
36
|
+
else
|
37
|
+
instance.send(field).purge if instance.try("delete_#{field}") == '1'
|
38
|
+
end
|
23
39
|
end
|
24
40
|
end
|
25
41
|
end
|
@@ -5,12 +5,22 @@ module Trestle
|
|
5
5
|
instance = builder.object
|
6
6
|
attachment = instance.send(name)
|
7
7
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
8
|
+
rendering_options = {}.tap do |hash|
|
9
|
+
hash[:locals] = {}.tap do |locals|
|
10
|
+
locals[:builder] = builder
|
11
|
+
locals[:field_name] = name
|
12
|
+
|
13
|
+
if attachment.respond_to?(:each)
|
14
|
+
hash[:partial] = 'trestle/active_storage/has_many_field'
|
15
|
+
locals[:attachments] = attachment
|
16
|
+
else
|
17
|
+
hash[:partial] = 'trestle/active_storage/has_one_field'
|
18
|
+
locals[:attachment] = attachment
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
@template.render rendering_options
|
14
24
|
end
|
15
25
|
end
|
16
26
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: trestle-active_storage
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Richard Venneman
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-10-
|
11
|
+
date: 2018-10-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -16,7 +16,7 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 5.2
|
19
|
+
version: '5.2'
|
20
20
|
- - "<"
|
21
21
|
- !ruby/object:Gem::Version
|
22
22
|
version: '6'
|
@@ -26,7 +26,7 @@ dependencies:
|
|
26
26
|
requirements:
|
27
27
|
- - ">="
|
28
28
|
- !ruby/object:Gem::Version
|
29
|
-
version: 5.2
|
29
|
+
version: '5.2'
|
30
30
|
- - "<"
|
31
31
|
- !ruby/object:Gem::Version
|
32
32
|
version: '6'
|
@@ -55,9 +55,9 @@ files:
|
|
55
55
|
- README.md
|
56
56
|
- Rakefile
|
57
57
|
- app/assets/javascripts/trestle/active_storage_fields.js
|
58
|
-
- app/views/trestle/active_storage/
|
58
|
+
- app/views/trestle/active_storage/_has_many_field.html.erb
|
59
|
+
- app/views/trestle/active_storage/_has_one_field.html.erb
|
59
60
|
- config/initializers/trestle.rb
|
60
|
-
- config/routes.rb
|
61
61
|
- lib/tasks/trestle/active_storage_tasks.rake
|
62
62
|
- lib/trestle/active_storage.rb
|
63
63
|
- lib/trestle/active_storage/builder.rb
|
data/config/routes.rb
DELETED