administrate-field-active_storage 0.2.2 → 0.3.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6840d701a76b3fa5a311bb907ae5d4d78be0d16614b90d77ab7a43ad9e7dad62
4
- data.tar.gz: ae7ad5a5636a73896296e1e5a1568aab403005e669b9f4f5a862ae3b27de20bd
3
+ metadata.gz: fc5923a984b8ef1046ab8657f3de54cbd68c5c50bc90b9f0aba62d36ed0c0a1b
4
+ data.tar.gz: d383f74c54bfd179912f66d612d4ad19c0b4f4da5baf1facd14c1df10d2c2c9f
5
5
  SHA512:
6
- metadata.gz: 87639eb9518a224dd5d23b500fd6372fdf96f30288ae93e4c8ffdfad0e4605eae0f02877febc85be1e79a89f7213572cf78b2f0612e560fcfe4ffdc387a676a4
7
- data.tar.gz: 790bae3270fda0dc76594ee80414a9de7b84633aef1aca19ee60a759d272ed3f5762ff7e5b2a336fe5509e547d45f3e8345002ef2f0d99b4d2ebe56715205374
6
+ metadata.gz: a7686831282ed9ffaf94c01cdab6e3f029a7ba93736896982d8255db70bc28f93402f2a9a0f17b820b17258eadbf2f9a294e2e07cc8fd5164dd5d979eb6ad9cb
7
+ data.tar.gz: e479ad715183dd81c20b58aec5796f9a06949537729a25e320ea8f0a83b9a056d05cc36b7186da561468fce878284e33dcb8314af33cc38149a18ce34dd22bcd
data/README.md CHANGED
@@ -95,53 +95,53 @@ Your `routes.rb` file must point to a controller action with method `delete` whi
95
95
  end
96
96
  ```
97
97
 
98
- ### url_only
99
- Only the following needs to change in order for the field to be url_only
100
- ```ruby
101
- class ModelDashboard < Administrate::BaseDashboard
102
- ATTRIBUTE_TYPES = {
103
- attachments: Field::ActiveStorage.with_options({url_only: true}),
104
- # ...
105
- }
106
- # ...
107
- end
108
- ```
98
+ ## Options
109
99
 
110
- ### show_in_index
111
- 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
112
- ```ruby
113
- class ModelDashboard < Administrate::BaseDashboard
114
- ATTRIBUTE_TYPES = {
115
- attachments: Field::ActiveStorage.with_options({show_in_index: true}),
116
- # ...
117
- }
118
- # ...
119
- end
120
- ```
100
+ Various options can be passed to `Administrate::Field::ActiveStorage#with_options`
101
+ as illustrated below:
121
102
 
122
- ### show_preview_size
123
- Supply the size of the image preview inside the show page. Check out the [mini_magic#resize_to_limit](https://github.com/janko/image_processing/blob/master/doc/minimagick.md#methods) documentation
124
- ```ruby
103
+ ```rb
125
104
  class ModelDashboard < Administrate::BaseDashboard
126
105
  ATTRIBUTE_TYPES = {
127
- attachments: Field::ActiveStorage.with_options({show_preview_size: [150, 200]}),
106
+ attachments: Field::ActiveStorage.with_options(index_display_preview: false),
128
107
  # ...
129
108
  }
130
109
  # ...
131
110
  end
132
111
  ```
133
112
 
113
+ ### show_display_preview
114
+
115
+ Display attachment preview.
116
+
117
+ Defaults to `true`.
118
+
119
+ ### index_display_preview
120
+
121
+ Displays the first attachment (which is the only attachment in case of `has_one`)
122
+ in the `index` action.
123
+
124
+ Defaults to `true`.
125
+
126
+ ### index_preview_size and show_preview_size
127
+
128
+ Indicate the size of the image preview for the `index` and `show` actions, respectively.
129
+ Refer to [mini_magic#resize_to_limit](https://github.com/janko/image_processing/blob/master/doc/minimagick.md#methods)
130
+ for documentation.
131
+
132
+ Default to `[150, 150]` and `[800, 800]`, respectively.
133
+
134
+ ### index_display_count
135
+
136
+ Displays the number of attachments in the `index` action.
137
+
138
+ Defaults to `true` if number of attachments is not 1.
139
+
134
140
  ### direct_upload
135
- If you want to upload directly from the browser to the cloud you can use direct_upload
136
- ```ruby
137
- class ModelDashboard < Administrate::BaseDashboard
138
- ATTRIBUTE_TYPES = {
139
- attachments: Field::ActiveStorage.with_options({direct_upload: true}),
140
- # ...
141
- }
142
- # ...
143
- end
144
- ```
141
+
142
+ Enables direct upload from the browser to the cloud.
143
+
144
+ Defaults to `false`.
145
145
 
146
146
  Don't forget to include [ActiveStorage JavaScript](https://edgeguides.rubyonrails.org/active_storage_overview.html#direct-uploads). You can use `rails generate administrate:assets:javascripts` to be able to customize Administrate JavaScripts in your application.
147
147
 
@@ -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.2.2"
5
+ gem.version = "0.3.0"
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"
@@ -20,11 +20,12 @@ By default, the input is a text field for the image's URL.
20
20
  </div>
21
21
 
22
22
  <div class="field-unit__field">
23
- <% if field.data.present? && field.attached? %>
23
+ <% if field.attached? %>
24
24
  <%= render partial: 'fields/active_storage/items', locals: { field: field, removable: field.destroyable? } %>
25
- <br />
26
- Add:
27
25
  <% end %>
28
26
 
29
- <%= f.file_field field.attribute, multiple: field.many?, direct_upload: field.direct? %>
27
+ <div>
28
+ <%= field.can_add_attachment? ? "Add:" : "Replace:" %>
29
+ <%= f.file_field field.attribute, multiple: field.many?, direct_upload: field.direct? %>
30
+ </div>
30
31
  </div>
@@ -14,19 +14,25 @@ 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 %>
17
+
18
+ <% if field.attached? %>
19
+ <style> <%# figure out a way to remove this %>
18
20
  td img {
19
- max-height: unset !important;
21
+ max-height: unset !important;
20
22
  }
21
- </style>
22
- <%
23
- attachments = Array(field.many? ? field.attachments : field.data)
24
- %>
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: [250, 250] } %>
23
+ </style>
24
+ <% if field.index_display_preview? %>
25
+ <%= render partial: 'fields/active_storage/preview',
26
+ locals: {
27
+ field: field,
28
+ attachment: field.attachments[0],
29
+ size: field.index_preview_size
30
+ } %>
31
+ <% end %>
32
+
33
+ <% if field.index_display_count? %>
34
+ <div class="attachments-count">
35
+ <%= pluralize(field.attachments.count, 'Attachment') %>
36
+ </div>
28
37
  <% end %>
29
- <%= pluralize(attachments.count, 'Attached file') %>
30
- <% else %>
31
- 0 Attached files
32
38
  <% end %>
@@ -19,37 +19,23 @@ controlled via a boolean local variable.
19
19
  - `removable`:
20
20
  A boolean used to control the display of a `Remove` link which
21
21
  is used to destroy a single attachment. Defaults to `false`
22
+ - `size`:
23
+ [x, y]
24
+ Maximum size of the ActiveStorage preview.
22
25
  %>
23
26
 
24
27
  <%
25
28
  # By default we don't allow attachment removal
26
29
  removable = local_assigns.fetch(:removable, false)
27
- image_size = local_assigns.fetch(:image_size, [1920, 1080])
28
30
  %>
29
31
 
30
- <% if attachment.image? and attachment.variable? and !field.url_only? %>
31
- <%= link_to(field.blob_url(attachment), title: attachment.filename) do %>
32
- <%= image_tag(field.variant(attachment, resize_to_limit: image_size)) %>
33
- <% end %>
34
- <% elsif attachment.image? and !field.url_only? %>
35
- <%= link_to(field.blob_url(attachment), title: attachment.filename) do %>
36
- <%= image_tag(field.url(attachment)) %>
37
- <% end %>
38
- <% elsif attachment.video? and attachment.previewable? and !field.url_only? %> <%# if ffmpeg is installed %>
39
- <%= video_tag(field.url(attachment), poster: field.preview(attachment, resize_to_limit: image_size), controls: true, autobuffer: true, style: "width: 100%; height: auto;") %>
40
- <% elsif attachment.video? and !field.url_only? %>
41
- <%= video_tag(field.url(attachment), controls: true, autobuffer: true, style: "width: 100%; height: auto;") %>
42
- <% elsif attachment.audio? and !field.url_only? %>
43
- <%= audio_tag(field.url(attachment), autoplay: false, controls: true) %>
44
- <% else %>
45
- <%= link_to(field.blob_url(attachment), title: attachment.filename) do %>
46
- <% if attachment.previewable? and !field.url_only? %>
47
- <%= image_tag(field.preview(attachment, resize_to_limit: [595, 842])) %>
48
- <% else %>
49
- <%= attachment.filename %>
50
- <% end %>
51
- <% end %>
52
- <% end %>
32
+ <div>
33
+ <%= render partial: 'fields/active_storage/preview', locals: local_assigns %>
34
+ </div>
35
+
36
+ <div>
37
+ <%= link_to 'Download', field.blob_url(attachment), title: attachment.filename %>
38
+ </div>
53
39
 
54
40
  <% if removable %>
55
41
  <%= link_to 'Remove', field.destroy_path(field, attachment), method: :delete, class: 'remove-attachment-link' %>
@@ -9,17 +9,22 @@ This partial renders one or more attachments
9
9
  An instance of [Administrate::Field::Image].
10
10
  A wrapper around the image url pulled from the database.
11
11
  - `removable`:
12
- A boolean used to control the display of a `Remove` link which
12
+ A boolean used to control the display of a `Remove` link which
13
13
  is used to destroy a single attachment. Defaults to `false`
14
14
  %>
15
15
 
16
- <%
17
- attachments = Array(field.many? ? field.attachments : field.data)
16
+ <%
18
17
  removable = local_assigns.fetch(:removable, false)
19
18
  %>
20
19
 
21
- <% attachments.each do |attachment| %>
20
+ <% field.attachments.each do |attachment| %>
22
21
  <div class="attachments-listing">
23
- <%= render partial: 'fields/active_storage/item', locals: { field: field, attachment: attachment, removable: removable, image_size: field.show_preview_size } %>
22
+ <%= render partial: 'fields/active_storage/item',
23
+ locals: {
24
+ field: field,
25
+ attachment: attachment,
26
+ removable: removable,
27
+ size: field.show_preview_size
28
+ } %>
24
29
  </div>
25
30
  <% end %>
@@ -0,0 +1,25 @@
1
+ <div style="width: <%=size[0]%>px; height: auto; overflow: hidden;">
2
+ <% if attachment.image? %>
3
+ <% if attachment.variable? %>
4
+ <%= image_tag(field.variant(attachment, resize_to_limit: size)) %>
5
+ <% else %>
6
+ <%= image_tag(field.url(attachment)) %>
7
+ <% end %>
8
+ <% elsif attachment.video? %>
9
+ <% if attachment.previewable? %>
10
+ <%= video_tag(field.url(attachment),
11
+ poster: field.preview(attachment, resize_to_limit: size),
12
+ controls: true,
13
+ autobuffer: true,
14
+ style: "object-fit: contain; width: 100%; height: 100%;") %>
15
+ <% else %>
16
+ <%= video_tag(field.url(attachment), controls: true, autobuffer: true, style: style) %>
17
+ <% end %>
18
+ <% elsif attachment.audio? %>
19
+ <%= audio_tag(field.url(attachment), autoplay: false, controls: true) %>
20
+ <% elsif attachment.previewable? %>
21
+ <%= image_tag(field.preview(attachment, resize_to_limit: size)) %>
22
+ <% else %>
23
+ <%= attachment.filename %>
24
+ <% end %>
25
+ </div>
@@ -17,4 +17,6 @@ By default, the attribute is rendered as an image tag.
17
17
 
18
18
  <% if field.attached? %>
19
19
  <%= render partial: 'fields/active_storage/items', locals: { field: field } %>
20
+ <% else %>
21
+ No attachment
20
22
  <% end %>
@@ -7,20 +7,28 @@ module Administrate
7
7
  class Engine < ::Rails::Engine
8
8
  end
9
9
 
10
- def url_only?
11
- options.fetch(:url_only, false)
12
- end
13
-
14
10
  def destroyable?
15
11
  options.key?(:destroy_path)
16
12
  end
17
13
 
18
- def show_in_index?
19
- options.fetch(:show_in_index, false)
14
+ def index_display_preview?
15
+ options.fetch(:index_display_preview, true)
16
+ end
17
+
18
+ def index_preview_size
19
+ options.fetch(:index_preview_size, [150, 150])
20
+ end
21
+
22
+ def index_display_count?
23
+ options.fetch(:index_display_count) { attachments.count != 1 }
24
+ end
25
+
26
+ def show_display_preview?
27
+ options.fetch(:show_display_preview, true)
20
28
  end
21
29
 
22
30
  def show_preview_size
23
- options.fetch(:show_preview_size, [1080, 1920])
31
+ options.fetch(:show_preview_size, [800, 800])
24
32
  end
25
33
 
26
34
  def many?
@@ -65,7 +73,14 @@ module Administrate
65
73
  Rails.application.routes.url_helpers.send(destroy_path_helper, {:record_id => record_id, :attachment_id => attachment_id})
66
74
  end
67
75
 
68
- delegate :attached?, to: :data
76
+ def can_add_attachment?
77
+ many? || attachments.empty?
78
+ end
79
+
80
+ def attached?
81
+ data.present? && data.attached?
82
+ end
83
+
69
84
  delegate :attachments, to: :data
70
85
  end
71
86
  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.2.2
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Hamad AlGhanim
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-03-06 00:00:00.000000000 Z
11
+ date: 2020-04-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: administrate
@@ -71,6 +71,7 @@ files:
71
71
  - app/views/fields/active_storage/_index.html.erb
72
72
  - app/views/fields/active_storage/_item.html.erb
73
73
  - app/views/fields/active_storage/_items.html.erb
74
+ - app/views/fields/active_storage/_preview.html.erb
74
75
  - app/views/fields/active_storage/_show.html.erb
75
76
  - contribute.md
76
77
  - example-project/.gitignore