administrate-field-active_storage 0.3.1 → 0.3.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1ea48021b9c4480f394cc61655e5e0a51c8ee6f9723f97902902642668a9ea88
4
- data.tar.gz: b9691a2f4b65e00a559dbd5ec52e73b1bac589e98403a6f135fdcd0f09953bff
3
+ metadata.gz: e3930e26efcb0aa795b6606100a6dd6e8da523f80e7f201def1aa5ab79219217
4
+ data.tar.gz: '0286fd8dcca57e38402f283fef4971b62cb88d909d4a6d00255aaffa3581286e'
5
5
  SHA512:
6
- metadata.gz: c5409c4400e684e023b287144b7415f51a77d6800df33c17eeb6f805de5381900e1d4947413e3d64939e85fd2009c8ff6ebeecbcde864017fc2c99f11c668650
7
- data.tar.gz: cf96c0b3b886a87fbe4774c2b2e3658d56c64375b34eebcb1d2ff3240dafb9ccf0a96debab40b3ce675b7869b6dd5cc6d0cc114f11368bcea27da35f5e8e3c23
6
+ metadata.gz: 2942162811a236a3adc02f9607a2d941f002e40b422b3a39c83a148666390542eb15235ae3a6f65d906b3a2075b19e7946e4278091af55ce254ad423886ae923
7
+ data.tar.gz: 4e7800b780d17f2bf6ee6faa0d0b11a1e22e1456397d46d8e38a04d619be800ae7fc2778364c23f1041ef1e42c34276b11db8ca58fd34906db5822d42a99ccb1
data/.gitignore CHANGED
@@ -9,3 +9,4 @@
9
9
  /tmp/
10
10
  *.gem
11
11
  .DS_Store
12
+ .vscode/settings.json
@@ -1 +1 @@
1
- 2.6.3
1
+ 2.6.5
data/README.md CHANGED
@@ -11,7 +11,7 @@ Add `administrate-field-active_storage` and `mini_magick` to your Gemfile (rails
11
11
 
12
12
  ```ruby
13
13
  gem 'administrate-field-active_storage'
14
- gem 'mini_magick'
14
+ gem "image_processing"
15
15
  ```
16
16
 
17
17
  for rails 5.x use the following
@@ -102,7 +102,33 @@ module Admin
102
102
  end
103
103
  end
104
104
  ```
105
+ For `has_one_attached` cases, you will use:
105
106
 
107
+ ```rb
108
+ # routes.rb
109
+ ...
110
+ namespace :admin do
111
+ ...
112
+ resources :users do
113
+ delete :avatar, on: :member, action: :destroy_avatar
114
+ end
115
+ end
116
+
117
+ # app/controllers/admin/users_controller.rb
118
+ module Admin
119
+ class UsersController < ApplicationController
120
+
121
+ # For illustrative purposes only.
122
+ #
123
+ # **SECURITY NOTICE**: first verify whether current user is authorized to perform the action.
124
+ def destroy_avatar
125
+ avatar = requested_resource.avatar
126
+ avatar.purge
127
+ redirect_back(fallback_location: requested_resource)
128
+ end
129
+ end
130
+ end
131
+ ```
106
132
  This route can be customized with `destroy_url`. The option expects a `proc` receiving 3 arguments:
107
133
  the Administrate `namespace`, the `resource`, and the `attachment`. The proc can return anything
108
134
  accepted by `link_to`:
@@ -125,8 +151,6 @@ class UserDashboard < Administrate::BaseDashboard
125
151
  end
126
152
  ```
127
153
 
128
- To disable this feature, set `destroy_url` to `nil`.
129
-
130
154
  ## Options
131
155
 
132
156
  Various options can be passed to `Administrate::Field::ActiveStorage#with_options`
@@ -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.3.1"
5
+ gem.version = "0.3.6"
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"
@@ -25,7 +25,7 @@ By default, the attribute is rendered as an image tag.
25
25
  <%= render partial: 'fields/active_storage/preview',
26
26
  locals: {
27
27
  field: field,
28
- attachment: field.attachments[0],
28
+ attachment: field.data,
29
29
  size: field.index_preview_size
30
30
  } %>
31
31
  <% end %>
@@ -23,19 +23,20 @@ controlled via a boolean local variable.
23
23
  [x, y]
24
24
  Maximum size of the ActiveStorage preview.
25
25
  %>
26
+ <% if field.show_display_preview? %>
27
+ <div>
28
+ <%= render partial: 'fields/active_storage/preview', locals: local_assigns %>
29
+ </div>
30
+ <% end %>
26
31
 
27
32
  <div>
28
- <%= render partial: 'fields/active_storage/preview', locals: local_assigns %>
29
- </div>
30
-
31
- <div>
32
- <%= link_to 'Download', field.blob_url(attachment), title: attachment.filename %>
33
+ <%= link_to attachment.filename, field.blob_url(attachment), title: attachment.filename %>
33
34
  </div>
34
35
 
35
36
  <% if field.destroy_url.present? %>
36
37
  <% destroy_url = field.destroy_url.call(namespace, field.data.record, attachment) %>
37
38
  <div>
38
- <%= link_to 'Remove', destroy_url, method: :delete, class: 'remove-attachment-link' %>
39
+ <%= link_to 'Remove', destroy_url, method: :delete, class: 'remove-attachment-link', data: { confirm: t("administrate.actions.confirm") } %>
39
40
  </div>
40
41
  <hr>
41
42
  <% end %>
@@ -13,7 +13,7 @@
13
13
  autobuffer: true,
14
14
  style: "object-fit: contain; width: 100%; height: 100%;") %>
15
15
  <% else %>
16
- <%= video_tag(field.url(attachment), controls: true, autobuffer: true, style: style) %>
16
+ <%= video_tag(field.url(attachment), controls: true, autobuffer: true, style: "object-fit: contain; width: 100%; height: 100%;") %>
17
17
  <% end %>
18
18
  <% elsif attachment.audio? %>
19
19
  <%= audio_tag(field.url(attachment), autoplay: false, controls: true) %>
@@ -11,3 +11,5 @@
11
11
  - Daniel Tinoco [@0urobor0s](https://github.com/0urobor0s)
12
12
  - Matthew Hui [@mhui](https://github.com/mhui)
13
13
  - Sébastien Dubois [@sedubois](https://github.com/sedubois)
14
+ - Jazzy Gasper [@jazzygasper](https://github.com/jazzygasper)
15
+ - David Ma [@taikon](https://github.com/taikon)
@@ -16,7 +16,7 @@ module Administrate
16
16
  end
17
17
 
18
18
  def index_display_count?
19
- options.fetch(:index_display_count) { attachments.present? && attachments.count != 1 }
19
+ options.fetch(:index_display_count) { attached? && attachments.count != 1 }
20
20
  end
21
21
 
22
22
  def show_display_preview?
@@ -36,13 +36,7 @@ module Administrate
36
36
  end
37
37
 
38
38
  def destroy_url
39
- options.fetch(:destroy_url) do
40
- proc do |namespace, record, attachment|
41
- options = [attachment.name, namespace, record]
42
- options << { attachment_id: attachment.id } if many?
43
- options
44
- end
45
- end
39
+ options.fetch(:destroy_url, nil)
46
40
  end
47
41
 
48
42
  # currently we are using Rails.application.routes.url_helpers
@@ -56,7 +50,7 @@ module Administrate
56
50
  end
57
51
 
58
52
  def variant(attachment, options)
59
- Rails.application.routes.url_helpers.rails_representation_path(attachment.variant(combine_options: options), only_path: true)
53
+ Rails.application.routes.url_helpers.rails_representation_path(attachment.variant(options), only_path: true)
60
54
  end
61
55
 
62
56
  def url(attachment)
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.3.1
4
+ version: 0.3.6
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-04-14 00:00:00.000000000 Z
11
+ date: 2020-11-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: administrate