administrate-field-active_storage 0.1.6 → 0.1.7
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 +22 -0
- data/administrate-field-active_storage.gemspec +1 -1
- data/app/views/fields/active_storage/_index.html.erb +8 -0
- data/app/views/fields/active_storage/_item.html.erb +3 -2
- data/app/views/fields/active_storage/_items.html.erb +1 -1
- data/example-project/Gemfile +1 -0
- data/example-project/Gemfile.lock +3 -1
- data/example-project/app/dashboards/user_dashboard.rb +5 -5
- data/lib/administrate/field/active_storage.rb +18 -6
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: '09680d84898084c57e5074d113530d27fb7d7ae1'
|
4
|
+
data.tar.gz: 4da191e3ba06952160837bb122ad242e1cfc8ef9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1ab9acf4c492cf3c344fb96cd66d6eb800616269226761ccb1e1fc4981f9340b1615c8cb8fb5ee82bca8d1ce3b141937e35f3ea5a7669acd899045be426cc900
|
7
|
+
data.tar.gz: 43e86708e5ed5baba482887db772f51d30b6faee422d88d6ffea5e7648d25d37e0aa46594682eab9522dc6aa5d7817347e50fe7fa57bba86c53aa3e008f984f4
|
data/README.md
CHANGED
@@ -87,6 +87,28 @@ class ModelDashboard < Administrate::BaseDashboard
|
|
87
87
|
end
|
88
88
|
```
|
89
89
|
|
90
|
+
### show_in_index
|
91
|
+
This will preview thumbnails in the index page and if you're using `has_many` it will show the first one as a thumbnail and a count of the total attached files
|
92
|
+
```ruby
|
93
|
+
class ModelDashboard < Administrate::BaseDashboard
|
94
|
+
ATTRIBUTE_TYPES = {
|
95
|
+
attachments: Field::ActiveStorage.with_options({show_in_index: true}),
|
96
|
+
# ...
|
97
|
+
}
|
98
|
+
# ...
|
99
|
+
end
|
100
|
+
```
|
101
|
+
|
102
|
+
## show_preview_size
|
103
|
+
Supply the size of the image preview inside the show page check out the mini_magic documentation for resize
|
104
|
+
```ruby
|
105
|
+
class ModelDashboard < Administrate::BaseDashboard
|
106
|
+
ATTRIBUTE_TYPES = {
|
107
|
+
attachments: Field::ActiveStorage.with_options({show_preview_size: '150x200>'}),
|
108
|
+
# ...
|
109
|
+
}
|
110
|
+
# ...
|
111
|
+
end
|
90
112
|
### direct_upload
|
91
113
|
If you want to upload directly from the browser to the cloud you can use direct_upload
|
92
114
|
```ruby
|
@@ -2,7 +2,7 @@ $:.push File.expand_path("../lib", __FILE__)
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |gem|
|
4
4
|
gem.name = "administrate-field-active_storage"
|
5
|
-
gem.version = "0.1.
|
5
|
+
gem.version = "0.1.7"
|
6
6
|
gem.authors = ["Hamad AlGhanim"]
|
7
7
|
gem.email = ["hamadyalghanim@gmail.com"]
|
8
8
|
gem.homepage = "https://github.com/Dreamersoul/administrate-field-active_storage"
|
@@ -14,10 +14,18 @@ By default, the attribute is rendered as an image tag.
|
|
14
14
|
|
15
15
|
[1]: http://www.rubydoc.info/gems/administrate/Administrate/Field/Image
|
16
16
|
%>
|
17
|
+
<style> <%# figure out a way to remove this %>
|
18
|
+
td img {
|
19
|
+
max-height: unset !important;
|
20
|
+
}
|
21
|
+
</style>
|
17
22
|
<%
|
18
23
|
attachments = Array(field.many? ? field.attachments : field.data)
|
19
24
|
%>
|
20
25
|
<% if field.attached? %>
|
26
|
+
<% if field.show_in_index? %>
|
27
|
+
<%= render partial: 'fields/active_storage/item', locals: { field: field, attachment: attachments[0], image_size: "250x250>" } %>
|
28
|
+
<% end %>
|
21
29
|
<%= pluralize(attachments.count, 'Attached file') %>
|
22
30
|
<% else %>
|
23
31
|
0 Attached files
|
@@ -24,12 +24,13 @@ controlled via a boolean local variable.
|
|
24
24
|
<%
|
25
25
|
# By default we don't allow attachment removal
|
26
26
|
removable = local_assigns.fetch(:removable, false)
|
27
|
+
image_size = local_assigns.fetch(:image_size, "1920x1080>")
|
27
28
|
%>
|
28
29
|
|
29
30
|
<% if attachment.image? and !field.url_only? %>
|
30
|
-
<%= image_tag(field.
|
31
|
+
<%= image_tag(field.variant(attachment, resize: image_size)) %>
|
31
32
|
<% elsif attachment.video? and attachment.previewable? and !field.url_only? %> <%# if ffmpeg is installed %>
|
32
|
-
<%= video_tag(field.url(attachment), poster: field.preview(attachment, resize:
|
33
|
+
<%= video_tag(field.url(attachment), poster: field.preview(attachment, resize: image_size), controls: true, autobuffer: true, style: "width: 100%; height: auto;") %>
|
33
34
|
<% elsif attachment.video? and !field.url_only? %>
|
34
35
|
<%= video_tag(field.url(attachment), controls: true, autobuffer: true, style: "width: 100%; height: auto;") %>
|
35
36
|
<% elsif attachment.audio? and !field.url_only? %>
|
@@ -20,6 +20,6 @@ This partial renders one or more attachments
|
|
20
20
|
|
21
21
|
<% attachments.each do |attachment| %>
|
22
22
|
<div class="attachments-listing">
|
23
|
-
<%= render partial: 'fields/active_storage/item', locals: { field: field, attachment: attachment, removable: removable } %>
|
23
|
+
<%= render partial: 'fields/active_storage/item', locals: { field: field, attachment: attachment, removable: removable, image_size: field.show_preview_size } %>
|
24
24
|
</div>
|
25
25
|
<% end %>
|
data/example-project/Gemfile
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: ..
|
3
3
|
specs:
|
4
|
-
administrate-field-active_storage (0.1.
|
4
|
+
administrate-field-active_storage (0.1.6)
|
5
5
|
administrate (>= 0.2.0.rc1)
|
6
6
|
rails (>= 5.2)
|
7
7
|
|
@@ -136,6 +136,7 @@ GEM
|
|
136
136
|
mimemagic (~> 0.3.2)
|
137
137
|
method_source (0.9.2)
|
138
138
|
mimemagic (0.3.3)
|
139
|
+
mini_magick (4.9.3)
|
139
140
|
mini_mime (1.0.1)
|
140
141
|
mini_portile2 (2.4.0)
|
141
142
|
minitest (5.11.3)
|
@@ -244,6 +245,7 @@ DEPENDENCIES
|
|
244
245
|
coffee-rails (~> 4.2)
|
245
246
|
jbuilder (~> 2.5)
|
246
247
|
listen (>= 3.0.5, < 3.2)
|
248
|
+
mini_magick
|
247
249
|
puma (~> 3.11)
|
248
250
|
rails (~> 5.2.0)
|
249
251
|
sass-rails (~> 5.0)
|
@@ -10,9 +10,9 @@ class UserDashboard < Administrate::BaseDashboard
|
|
10
10
|
ATTRIBUTE_TYPES = {
|
11
11
|
id: Field::Number,
|
12
12
|
name: Field::String,
|
13
|
-
avatars: Field::ActiveStorage.with_options({:destroy_path => :custom_active_record_remove_path}),
|
13
|
+
avatars: Field::ActiveStorage.with_options({:destroy_path => :custom_active_record_remove_path, :show_in_index => true}),
|
14
14
|
created_at: Field::DateTime,
|
15
|
-
updated_at: Field::DateTime
|
15
|
+
updated_at: Field::DateTime
|
16
16
|
}.freeze
|
17
17
|
|
18
18
|
# COLLECTION_ATTRIBUTES
|
@@ -23,7 +23,7 @@ class UserDashboard < Administrate::BaseDashboard
|
|
23
23
|
COLLECTION_ATTRIBUTES = [
|
24
24
|
:id,
|
25
25
|
:name,
|
26
|
-
:avatars
|
26
|
+
:avatars
|
27
27
|
].freeze
|
28
28
|
|
29
29
|
# SHOW_PAGE_ATTRIBUTES
|
@@ -33,7 +33,7 @@ class UserDashboard < Administrate::BaseDashboard
|
|
33
33
|
:name,
|
34
34
|
:avatars,
|
35
35
|
:created_at,
|
36
|
-
:updated_at
|
36
|
+
:updated_at
|
37
37
|
].freeze
|
38
38
|
|
39
39
|
# FORM_ATTRIBUTES
|
@@ -41,7 +41,7 @@ class UserDashboard < Administrate::BaseDashboard
|
|
41
41
|
# on the model's form (`new` and `edit`) pages.
|
42
42
|
FORM_ATTRIBUTES = [
|
43
43
|
:name,
|
44
|
-
:avatars
|
44
|
+
:avatars
|
45
45
|
].freeze
|
46
46
|
|
47
47
|
# Overwrite this method to customize how users are displayed
|
@@ -1,5 +1,5 @@
|
|
1
|
-
require
|
2
|
-
require
|
1
|
+
require 'administrate/field/base'
|
2
|
+
require 'rails'
|
3
3
|
|
4
4
|
module Administrate
|
5
5
|
module Field
|
@@ -15,9 +15,17 @@ module Administrate
|
|
15
15
|
options.key?(:destroy_path)
|
16
16
|
end
|
17
17
|
|
18
|
+
def show_in_index?
|
19
|
+
options.key?(:destroy_path)
|
20
|
+
end
|
21
|
+
|
22
|
+
def show_preview_size
|
23
|
+
options.fetch(:show_preview_size, "1080x1920>")
|
24
|
+
end
|
25
|
+
|
18
26
|
def many?
|
19
27
|
# find a way to use instance_of
|
20
|
-
data.class.name ==
|
28
|
+
data.class.name == 'ActiveStorage::Attached::Many'
|
21
29
|
end
|
22
30
|
|
23
31
|
def direct?
|
@@ -28,7 +36,7 @@ module Administrate
|
|
28
36
|
# options.fetch(:destroy_path, false).present?
|
29
37
|
# end
|
30
38
|
|
31
|
-
# currently we are using Rails.application.routes.url_helpers
|
39
|
+
# currently we are using Rails.application.routes.url_helpers
|
32
40
|
# without including the namespace because it runs into an
|
33
41
|
# exception
|
34
42
|
|
@@ -38,10 +46,14 @@ module Administrate
|
|
38
46
|
Rails.application.routes.url_helpers.rails_representation_path(attachment.preview(options), only_path: true)
|
39
47
|
end
|
40
48
|
|
49
|
+
def variant(attachment, options)
|
50
|
+
Rails.application.routes.url_helpers.rails_representation_path(attachment.variant(combine_options: options), only_path: true)
|
51
|
+
end
|
52
|
+
|
41
53
|
def url(attachment)
|
42
54
|
Rails.application.routes.url_helpers.rails_blob_path(attachment, only_path: true)
|
43
55
|
end
|
44
|
-
|
56
|
+
|
45
57
|
def blob_url(attachment)
|
46
58
|
Rails.application.routes.url_helpers.rails_blob_path(attachment, disposition: :attachment, only_path: true)
|
47
59
|
end
|
@@ -52,7 +64,7 @@ module Administrate
|
|
52
64
|
attachment_id = attachment.id
|
53
65
|
Rails.application.routes.url_helpers.send(destroy_path_helper, {:record_id => record_id, :attachment_id => attachment_id})
|
54
66
|
end
|
55
|
-
|
67
|
+
|
56
68
|
delegate :attached?, to: :data
|
57
69
|
delegate :attachments, to: :data
|
58
70
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: administrate-field-active_storage
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Hamad AlGhanim
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-06-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: administrate
|