trestle-active_storage 2.0.0 → 3.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +25 -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} +1 -1
- data/lib/trestle/active_storage.rb +7 -6
- data/lib/trestle/active_storage/controller_concern.rb +18 -2
- data/lib/trestle/active_storage/engine.rb +4 -1
- data/lib/trestle/active_storage/field.rb +16 -6
- data/lib/trestle/active_storage/version.rb +1 -1
- metadata +17 -12
- 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: cb04373f55898190ff541b714e60a76339a9973d6c685e0361d81372e3ac51f7
|
4
|
+
data.tar.gz: 7c21f06234ffa638875cf25053ab5cc4748a2b754ae7c26177dc989f279725b5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1f64a0a1b8b7f3c473fc52c0bc8750f7b30ae37781298963e00a66b9162422d6234eb09d3f5164b4349150854b8d622da4c2aaa770b25d1d7305e7d818844b5a
|
7
|
+
data.tar.gz: d6b98ed4b70d17116d477ba9bcb77ffc56de015918c3bf0de9acb4ddf843e56db6187999d25d591521c4dfabf32a30b323a534729c47c4d48ed0bcef641fb15d
|
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,33 @@ 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
|
+
Thanks goes out to these wonderful people ([emoji key](https://allcontributors.org/docs/en/emoji-key)):
|
54
|
+
<!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section -->
|
55
|
+
<!-- prettier-ignore-start -->
|
56
|
+
<!-- markdownlint-disable -->
|
57
|
+
<table>
|
58
|
+
<tr>
|
59
|
+
<td align="center"><a href="https://www.cityspotters.com"><img src="https://avatars1.githubusercontent.com/u/75705?v=4" width="100px;" alt=""/><br /><sub><b>Richard Venneman</b></sub></a><br /><a href="#ideas-richardvenneman" title="Ideas, Planning, & Feedback">🤔</a> <a href="https://github.com/richardvenneman/trestle-active_storage/commits?author=richardvenneman" title="Code">💻</a> <a href="https://github.com/richardvenneman/trestle-active_storage/commits?author=richardvenneman" title="Documentation">📖</a> <a href="#question-richardvenneman" title="Answering Questions">💬</a> <a href="https://github.com/richardvenneman/trestle-active_storage/pulls?q=is%3Apr+reviewed-by%3Arichardvenneman" title="Reviewed Pull Requests">👀</a></td>
|
60
|
+
<td align="center"><a href="http://aboobacker.in"><img src="https://avatars1.githubusercontent.com/u/3112976?v=4" width="100px;" alt=""/><br /><sub><b>Aboobacker MK</b></sub></a><br /><a href="#ideas-tachyons" title="Ideas, Planning, & Feedback">🤔</a></td>
|
61
|
+
<td align="center"><a href="http://euodeiovoce.com.br"><img src="https://avatars2.githubusercontent.com/u/1027961?v=4" width="100px;" alt=""/><br /><sub><b>Rafael Porto</b></sub></a><br /><a href="https://github.com/richardvenneman/trestle-active_storage/commits?author=PunkMaldito" title="Code">💻</a></td>
|
62
|
+
<td align="center"><a href="https://github.com/hoenth"><img src="https://avatars2.githubusercontent.com/u/62977?v=4" width="100px;" alt=""/><br /><sub><b>Tom Hoen</b></sub></a><br /><a href="https://github.com/richardvenneman/trestle-active_storage/issues?q=author%3Ahoenth" title="Bug reports">🐛</a> <a href="https://github.com/richardvenneman/trestle-active_storage/commits?author=hoenth" title="Code">💻</a></td>
|
63
|
+
<td align="center"><a href="https://github.com/basharabdullah"><img src="https://avatars3.githubusercontent.com/u/167290?v=4" width="100px;" alt=""/><br /><sub><b>Bashar Abdullah</b></sub></a><br /><a href="https://github.com/richardvenneman/trestle-active_storage/issues?q=author%3Abasharabdullah" title="Bug reports">🐛</a></td>
|
64
|
+
<td align="center"><a href="https://github.com/McRipper"><img src="https://avatars2.githubusercontent.com/u/58031?v=4" width="100px;" alt=""/><br /><sub><b>Emanuele Barban</b></sub></a><br /><a href="https://github.com/richardvenneman/trestle-active_storage/commits?author=McRipper" title="Code">💻</a></td>
|
65
|
+
</tr>
|
66
|
+
</table>
|
67
|
+
|
68
|
+
<!-- markdownlint-enable -->
|
69
|
+
<!-- prettier-ignore-end -->
|
70
|
+
<!-- ALL-CONTRIBUTORS-LIST:END -->
|
71
|
+
This project follows the [all-contributors](https://github.com/kentcdodds/all-contributors) specification.
|
72
|
+
|
49
73
|
## License
|
50
74
|
|
51
75
|
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 field_name do %>
|
3
|
+
<div class="active-storage">
|
4
|
+
<% if attachments.attached? && builder.object.persisted? %>
|
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
|
+
|
@@ -1,5 +1,5 @@
|
|
1
1
|
<div class="active-storage">
|
2
|
-
<% if attachment.attached? %>
|
2
|
+
<% if attachment.attached? && builder.object.persisted? %>
|
3
3
|
<div class="active-storage__preview">
|
4
4
|
<% if attachment.previewable? %>
|
5
5
|
<%= link_to image_tag(main_app.url_for(attachment.preview(resize: "300x300>")), class: "active-storage__image"),
|
@@ -1,14 +1,15 @@
|
|
1
|
-
|
1
|
+
require_relative 'active_storage/version'
|
2
|
+
|
2
3
|
require 'trestle'
|
3
4
|
|
4
5
|
module Trestle
|
5
6
|
module ActiveStorage
|
6
|
-
extend ActiveSupport::Autoload
|
7
7
|
|
8
|
-
|
9
|
-
|
10
|
-
|
8
|
+
require_relative "active_storage/builder"
|
9
|
+
require_relative "active_storage/resource"
|
10
|
+
require_relative "active_storage/controller_concern"
|
11
|
+
|
11
12
|
end
|
12
13
|
end
|
13
14
|
|
14
|
-
|
15
|
+
require_relative 'active_storage/engine' if defined?(Rails)
|
@@ -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
|
@@ -3,10 +3,13 @@ module Trestle
|
|
3
3
|
class Engine < Rails::Engine
|
4
4
|
config.assets.precompile << 'activestorage.js' << 'trestle/active_storage_fields.js'
|
5
5
|
|
6
|
+
config.to_prepare do
|
7
|
+
Trestle::ResourceController.send(:include, Trestle::ActiveStorage::ControllerConcern)
|
8
|
+
end
|
9
|
+
|
6
10
|
initializer :extensions do
|
7
11
|
Trestle::Resource.send(:include, Trestle::ActiveStorage::Resource)
|
8
12
|
Trestle::Resource::Builder.send(:include, Trestle::ActiveStorage::Builder)
|
9
|
-
Trestle::Resource::Controller.send(:include, Trestle::ActiveStorage::ControllerConcern)
|
10
13
|
end
|
11
14
|
end
|
12
15
|
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:
|
4
|
+
version: 3.0.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:
|
11
|
+
date: 2020-06-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -16,34 +16,40 @@ 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
|
-
version: '
|
22
|
+
version: '7'
|
23
23
|
type: :runtime
|
24
24
|
prerelease: false
|
25
25
|
version_requirements: !ruby/object:Gem::Requirement
|
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
|
-
version: '
|
32
|
+
version: '7'
|
33
33
|
- !ruby/object:Gem::Dependency
|
34
34
|
name: trestle
|
35
35
|
requirement: !ruby/object:Gem::Requirement
|
36
36
|
requirements:
|
37
37
|
- - "~>"
|
38
38
|
- !ruby/object:Gem::Version
|
39
|
-
version:
|
39
|
+
version: 0.9.0
|
40
|
+
- - ">="
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
version: 0.9.3
|
40
43
|
type: :runtime
|
41
44
|
prerelease: false
|
42
45
|
version_requirements: !ruby/object:Gem::Requirement
|
43
46
|
requirements:
|
44
47
|
- - "~>"
|
45
48
|
- !ruby/object:Gem::Version
|
46
|
-
version:
|
49
|
+
version: 0.9.0
|
50
|
+
- - ">="
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: 0.9.3
|
47
53
|
description: ActiveStorage integration plugin for the Trestle admin framework.
|
48
54
|
email:
|
49
55
|
- richardvenneman@me.com
|
@@ -55,9 +61,9 @@ files:
|
|
55
61
|
- README.md
|
56
62
|
- Rakefile
|
57
63
|
- app/assets/javascripts/trestle/active_storage_fields.js
|
58
|
-
- app/views/trestle/active_storage/
|
64
|
+
- app/views/trestle/active_storage/_has_many_field.html.erb
|
65
|
+
- app/views/trestle/active_storage/_has_one_field.html.erb
|
59
66
|
- config/initializers/trestle.rb
|
60
|
-
- config/routes.rb
|
61
67
|
- lib/tasks/trestle/active_storage_tasks.rake
|
62
68
|
- lib/trestle/active_storage.rb
|
63
69
|
- lib/trestle/active_storage/builder.rb
|
@@ -85,8 +91,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
85
91
|
- !ruby/object:Gem::Version
|
86
92
|
version: '0'
|
87
93
|
requirements: []
|
88
|
-
|
89
|
-
rubygems_version: 2.7.3
|
94
|
+
rubygems_version: 3.1.2
|
90
95
|
signing_key:
|
91
96
|
specification_version: 4
|
92
97
|
summary: ActiveStorage integration plugin for the Trestle admin framework
|
data/config/routes.rb
DELETED