administrate-field-active_storage 1.0.1 → 1.0.3

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: fb8203ad81a8b3db6fcce553c35464064d3d91953b695b28bd7f85125f1f710a
4
- data.tar.gz: 8a07735ef1388e626757526398d54b13e758aa6c726a73fc648a3d8ccd0e5a76
3
+ metadata.gz: 12fb995471a84f218352f4c630c6de6088c1eec7b975671f42125a1f91fe05d5
4
+ data.tar.gz: 797c67a7742599097b761314a457f1f53f3153aeb5c6aa72c4556cfd0a86d449
5
5
  SHA512:
6
- metadata.gz: 651a2d4e9462ecf1bc6c1dfa2a4f9e1400777362232ca39ecbff2030816d626ffd0693b51de05c3c3bc554373222437b9c07ec2d5ac8543dd117c36a068de308
7
- data.tar.gz: 2d7afc572bfb5713ce971496af0580303e27802338974c4eb3210674d89fea13d3fe3878c0422cd4ddc9a6efa32d541d0b80f694855f8984d046171f0d9abbb0
6
+ metadata.gz: 3d285fd017385d5ce56a18a2ef464b5ec5d981fa065fe8a59706db2b7716676d81fbff44909a4b1543cfb70821c2368057184d0095bf6aaaafcf3e9139ad1b8e
7
+ data.tar.gz: 6ccbf0a5119607bda9110ace878002ba9a8fd40ae39573c112c96f14cc69c0fa54855ddf28bc5ce7e437776532a85f2d3f5c44cea8373b4a695176cd78000493
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- administrate-field-active_storage (0.4.1)
4
+ administrate-field-active_storage (1.0.2)
5
5
  administrate (>= 0.2.2)
6
6
  rails (>= 7.0)
7
7
 
@@ -67,12 +67,12 @@ GEM
67
67
  i18n (>= 1.6, < 2)
68
68
  minitest (>= 5.1)
69
69
  tzinfo (~> 2.0)
70
- administrate (0.19.0)
71
- actionpack (>= 5.0)
72
- actionview (>= 5.0)
73
- activerecord (>= 5.0)
74
- jquery-rails (>= 4.0)
75
- kaminari (>= 1.0)
70
+ administrate (0.20.1)
71
+ actionpack (>= 6.0, < 8.0)
72
+ actionview (>= 6.0, < 8.0)
73
+ activerecord (>= 6.0, < 8.0)
74
+ jquery-rails (~> 4.6.0)
75
+ kaminari (~> 1.2.2)
76
76
  sassc-rails (~> 2.1)
77
77
  selectize-rails (~> 0.6)
78
78
  ast (2.4.2)
@@ -121,23 +121,25 @@ GEM
121
121
  net-imap
122
122
  net-pop
123
123
  net-smtp
124
- marcel (1.0.2)
124
+ marcel (1.0.4)
125
125
  method_source (1.0.0)
126
126
  mini_mime (1.1.5)
127
- mini_portile2 (2.8.5)
128
127
  minitest (5.15.0)
129
- net-imap (0.4.5)
128
+ net-imap (0.4.11)
130
129
  date
131
130
  net-protocol
132
131
  net-pop (0.1.2)
133
132
  net-protocol
134
133
  net-protocol (0.2.2)
135
134
  timeout
136
- net-smtp (0.4.0)
135
+ net-smtp (0.5.0)
137
136
  net-protocol
138
- nio4r (2.6.0)
139
- nokogiri (1.13.3)
140
- mini_portile2 (~> 2.8.0)
137
+ nio4r (2.7.3)
138
+ nokogiri (1.13.3-arm64-darwin)
139
+ racc (~> 1.4)
140
+ nokogiri (1.13.3-x86_64-darwin)
141
+ racc (~> 1.4)
142
+ nokogiri (1.13.3-x86_64-linux)
141
143
  racc (~> 1.4)
142
144
  parser (3.0.3.2)
143
145
  ast (~> 2.4.1)
@@ -192,7 +194,9 @@ GEM
192
194
  actionpack (>= 5.2)
193
195
  activesupport (>= 5.2)
194
196
  sprockets (>= 3.0.0)
195
- sqlite3 (1.4.2)
197
+ sqlite3 (1.7.3-arm64-darwin)
198
+ sqlite3 (1.7.3-x86_64-darwin)
199
+ sqlite3 (1.7.3-x86_64-linux)
196
200
  terminal-table (3.0.2)
197
201
  unicode-display_width (>= 1.1.1, < 3)
198
202
  thor (1.1.0)
@@ -208,6 +212,7 @@ GEM
208
212
 
209
213
  PLATFORMS
210
214
  arm64-darwin-21
215
+ arm64-darwin-22
211
216
  x86_64-darwin-20
212
217
  x86_64-linux
213
218
 
data/README.md CHANGED
@@ -60,7 +60,9 @@ class ModelDashboard < Administrate::BaseDashboard
60
60
  ```
61
61
  I know it is not ideal, if you have a workaround please submit a PR.
62
62
 
63
- Note: Rails 6 introduced a new config to determine the behavior on updates to `has_many_attached`. Setting `Rails.application.config.active_storage.replace_on_assign_to_many` to `true` will overwrite any existing values (purging the old ones), and setting it to `false` will append the new values.
63
+ Note: Rails 6 introduced a new config to determine the behavior on updates to `has_many_attached`. Setting `Rails.application.config.active_storage.replace_on_assign_to_many` to `true` will overwrite any existing values (purging the old ones), and setting it to `false` will append the new values. Please note that this configuation was [deprecated with Rails 7.1](https://github.com/rails/rails/blob/v7.0.2.3/activestorage/lib/active_storage/attached/model.rb#L150)
64
+ >config.active_storage.replace_on_assign_to_many is deprecated and will be removed in Rails 7.1. Make sure that your code works well with config.active_storage.replace_on_assign_to_many set to true before upgrading. To append new attachables to the Active Storage association, prefer using attach. Using association setter would result in purging the existing attached attachments and replacing them with new ones.
65
+
64
66
 
65
67
  ### Prevent N+1 queries
66
68
  In order to prevent N+1 queries from active storage you have to modify your admin model controller, below an example for a model called `User` and with attached avatars
@@ -182,6 +184,10 @@ in the `index` action.
182
184
 
183
185
  Defaults to `true`.
184
186
 
187
+ ### index_preview_only
188
+
189
+ If true, will show only the preview in the `index` action, and not the filename or destroy link (if set).
190
+
185
191
  ### index_preview_size and show_preview_size
186
192
 
187
193
  Indicate the size of the image preview for the `index` and `show` actions, respectively.
@@ -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 = "1.0.1"
5
+ gem.version = "1.0.3"
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"
@@ -16,25 +16,14 @@ By default, the attribute is rendered as an image tag.
16
16
  %>
17
17
 
18
18
  <% if field.attached? %>
19
- <% if field.index_display_preview? %>
20
- <% if field.many? %>
21
- <%= render partial: 'fields/active_storage/items',
22
- locals: {
23
- field: field,
24
- variant: field.index_preview_variant,
25
- size: field.index_preview_size
26
- } %>
27
- <% else %>
28
- <%= render partial: 'fields/active_storage/item',
29
- locals: {
30
- field: field,
31
- attachment: field.data,
32
- variant: field.index_preview_variant,
33
- size: field.index_preview_size
34
- } %>
35
- <% end %>
36
- <% end %>
37
-
19
+ <%= render partial: "fields/active_storage/items",
20
+ locals: {
21
+ field: field,
22
+ variant: field.index_preview_variant,
23
+ size: field.index_preview_size,
24
+ display_preview: field.index_display_preview?,
25
+ preview_only: field.index_preview_only?
26
+ } %>
38
27
  <% if field.index_display_count? %>
39
28
  <div class="attachments-count">
40
29
  <%= pluralize(field.attachments.count,
@@ -19,13 +19,18 @@ controlled via a boolean local variable.
19
19
  - `size`:
20
20
  [x, y]
21
21
  Maximum size of the ActiveStorage preview.
22
+ - `preview_only`:
23
+ If true, show only the previous and not the name or destroy link
22
24
  %>
23
- <% if field.show_display_preview? && attachment.persisted? %>
25
+ <% preview_only = local_assigns.fetch(:preview_only, false)
26
+ display_preview = local_assigns.fetch(:display_preview, field.show_display_preview?) %>
27
+ <% if display_preview && attachment.persisted? %>
24
28
  <div>
25
29
  <%= render partial: 'fields/active_storage/preview', locals: local_assigns %>
26
30
  </div>
27
31
  <% end %>
28
32
 
33
+ <% unless preview_only %>
29
34
  <% if attachment.persisted? %>
30
35
  <div>
31
36
  <%= link_to attachment.filename, field.blob_url(attachment), title: attachment.filename %>
@@ -40,3 +45,4 @@ controlled via a boolean local variable.
40
45
  </div>
41
46
  <hr>
42
47
  <% end %>
48
+ <% end %>
@@ -17,6 +17,8 @@ This partial renders one or more attachments
17
17
  <%
18
18
  variant = local_assigns.fetch(:variant, field.show_preview_variant)
19
19
  size = local_assigns.fetch(:size, field.show_preview_size)
20
+ display_preview = local_assigns.fetch(:display_preview, field.show_display_preview?)
21
+ preview_only = local_assigns.fetch(:preview_only, false)
20
22
  %>
21
23
 
22
24
  <% field.attachments.each do |attachment| %>
@@ -26,7 +28,9 @@ This partial renders one or more attachments
26
28
  field: field,
27
29
  attachment: attachment,
28
30
  variant: variant,
29
- size: size
31
+ size: size,
32
+ display_preview: display_preview,
33
+ preview_only: preview_only
30
34
  } %>
31
35
  </div>
32
36
  <% end %>
@@ -20,6 +20,10 @@ module Administrate
20
20
  options.fetch(:index_preview_variant, nil)
21
21
  end
22
22
 
23
+ def index_preview_only?
24
+ options.fetch(:index_preview_only, false)
25
+ end
26
+
23
27
  def index_display_count?
24
28
  options.fetch(:index_display_count) { attached? && attachments.count != 1 }
25
29
  end
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ..
3
3
  specs:
4
- administrate-field-active_storage (0.4.1)
4
+ administrate-field-active_storage (1.0.2)
5
5
  administrate (>= 0.2.2)
6
6
  rails (>= 7.0)
7
7
 
@@ -84,18 +84,16 @@ GEM
84
84
  tzinfo (~> 2.0)
85
85
  addressable (2.8.0)
86
86
  public_suffix (>= 2.0.2, < 5.0)
87
- administrate (0.16.0)
88
- actionpack (>= 5.0)
89
- actionview (>= 5.0)
90
- activerecord (>= 5.0)
91
- datetime_picker_rails (~> 0.0.7)
92
- jquery-rails (>= 4.0)
93
- kaminari (>= 1.0)
94
- momentjs-rails (~> 2.8)
87
+ administrate (0.20.1)
88
+ actionpack (>= 6.0, < 8.0)
89
+ actionview (>= 6.0, < 8.0)
90
+ activerecord (>= 6.0, < 8.0)
91
+ jquery-rails (~> 4.6.0)
92
+ kaminari (~> 1.2.2)
95
93
  sassc-rails (~> 2.1)
96
94
  selectize-rails (~> 0.6)
97
95
  base64 (0.2.0)
98
- bigdecimal (3.1.4)
96
+ bigdecimal (3.1.8)
99
97
  bindex (0.8.1)
100
98
  builder (3.2.4)
101
99
  byebug (11.1.3)
@@ -109,28 +107,25 @@ GEM
109
107
  regexp_parser (>= 1.5, < 3.0)
110
108
  xpath (~> 3.2)
111
109
  childprocess (4.1.0)
112
- concurrent-ruby (1.2.2)
110
+ concurrent-ruby (1.2.3)
113
111
  connection_pool (2.4.1)
114
112
  crass (1.0.6)
115
113
  date (3.3.4)
116
- datetime_picker_rails (0.0.7)
117
- momentjs-rails (>= 2.8.1)
118
- drb (2.2.0)
119
- ruby2_keywords
114
+ drb (2.2.1)
120
115
  erubi (1.12.0)
121
- ffi (1.15.4)
116
+ ffi (1.16.3)
122
117
  globalid (1.2.1)
123
118
  activesupport (>= 6.1)
124
- i18n (1.14.1)
119
+ i18n (1.14.5)
125
120
  concurrent-ruby (~> 1.0)
126
121
  image_processing (1.12.2)
127
122
  mini_magick (>= 4.9.5, < 5)
128
123
  ruby-vips (>= 2.0.17, < 3)
129
- io-console (0.6.0)
130
- irb (1.9.0)
131
- rdoc
132
- reline (>= 0.3.8)
133
- jquery-rails (4.4.0)
124
+ io-console (0.7.2)
125
+ irb (1.13.1)
126
+ rdoc (>= 4.0.0)
127
+ reline (>= 0.4.2)
128
+ jquery-rails (4.6.0)
134
129
  rails-dom-testing (>= 1, < 3)
135
130
  railties (>= 4.2.0)
136
131
  thor (>= 0.14, < 2.0)
@@ -158,9 +153,7 @@ GEM
158
153
  matrix (0.4.2)
159
154
  mini_magick (4.12.0)
160
155
  mini_mime (1.1.5)
161
- minitest (5.20.0)
162
- momentjs-rails (2.29.1)
163
- railties (>= 3.1)
156
+ minitest (5.23.0)
164
157
  mutex_m (0.2.0)
165
158
  net-imap (0.4.5)
166
159
  date
@@ -172,28 +165,28 @@ GEM
172
165
  net-smtp (0.4.0)
173
166
  net-protocol
174
167
  nio4r (2.6.0)
175
- nokogiri (1.15.5-arm64-darwin)
168
+ nokogiri (1.16.5-arm64-darwin)
176
169
  racc (~> 1.4)
177
- nokogiri (1.15.5-x86_64-darwin)
170
+ nokogiri (1.16.5-x86_64-darwin)
178
171
  racc (~> 1.4)
179
- nokogiri (1.15.5-x86_64-linux)
172
+ nokogiri (1.16.5-x86_64-linux)
180
173
  racc (~> 1.4)
181
- psych (5.1.1.1)
174
+ psych (5.1.2)
182
175
  stringio
183
176
  public_suffix (4.0.6)
184
177
  puma (5.6.4)
185
178
  nio4r (~> 2.0)
186
179
  racc (1.7.3)
187
- rack (2.2.8)
180
+ rack (3.0.11)
188
181
  rack-mini-profiler (2.3.3)
189
182
  rack (>= 1.2.0)
190
- rack-session (1.0.1)
191
- rack (< 3)
183
+ rack-session (2.0.0)
184
+ rack (>= 3.0.0)
192
185
  rack-test (2.1.0)
193
186
  rack (>= 1.3)
194
- rackup (1.0.0)
195
- rack (< 3)
196
- webrick
187
+ rackup (2.1.0)
188
+ rack (>= 3)
189
+ webrick (~> 1.8)
197
190
  rails (7.1.2)
198
191
  actioncable (= 7.1.2)
199
192
  actionmailbox (= 7.1.2)
@@ -223,16 +216,15 @@ GEM
223
216
  rake (>= 12.2)
224
217
  thor (~> 1.0, >= 1.2.2)
225
218
  zeitwerk (~> 2.6)
226
- rake (13.1.0)
227
- rdoc (6.6.0)
219
+ rake (13.2.1)
220
+ rdoc (6.6.3.1)
228
221
  psych (>= 4.0.0)
229
222
  regexp_parser (2.2.0)
230
- reline (0.4.0)
223
+ reline (0.5.7)
231
224
  io-console (~> 0.5)
232
225
  rexml (3.2.5)
233
226
  ruby-vips (2.2.0)
234
227
  ffi (~> 1.12)
235
- ruby2_keywords (0.0.5)
236
228
  rubyzip (2.3.2)
237
229
  sass-rails (6.0.0)
238
230
  sassc-rails (~> 2.1, >= 2.1.1)
@@ -249,17 +241,19 @@ GEM
249
241
  childprocess (>= 0.5, < 5.0)
250
242
  rexml (~> 3.2, >= 3.2.5)
251
243
  rubyzip (>= 1.2.2)
252
- sprockets (4.0.2)
244
+ sprockets (4.2.1)
253
245
  concurrent-ruby (~> 1.0)
254
- rack (> 1, < 3)
246
+ rack (>= 2.2.4, < 4)
255
247
  sprockets-rails (3.4.2)
256
248
  actionpack (>= 5.2)
257
249
  activesupport (>= 5.2)
258
250
  sprockets (>= 3.0.0)
259
- sqlite3 (1.4.2)
260
- stringio (3.0.9)
261
- thor (1.3.0)
262
- tilt (2.0.10)
251
+ sqlite3 (1.7.3-arm64-darwin)
252
+ sqlite3 (1.7.3-x86_64-darwin)
253
+ sqlite3 (1.7.3-x86_64-linux)
254
+ stringio (3.1.0)
255
+ thor (1.3.1)
256
+ tilt (2.3.0)
263
257
  timeout (0.4.1)
264
258
  tzinfo (2.0.6)
265
259
  concurrent-ruby (~> 1.0)
@@ -274,7 +268,7 @@ GEM
274
268
  websocket-extensions (0.1.5)
275
269
  xpath (3.2.0)
276
270
  nokogiri (~> 1.8)
277
- zeitwerk (2.6.12)
271
+ zeitwerk (2.6.14)
278
272
 
279
273
  PLATFORMS
280
274
  arm64-darwin-23
@@ -42,5 +42,11 @@ module Admin
42
42
 
43
43
  # See https://administrate-prototype.herokuapp.com/customizing_controller_actions
44
44
  # for more information
45
+
46
+ def destroy_other_image
47
+ other_image = requested_resource.other_images.find(params[:attachment_id])
48
+ other_image.purge
49
+ redirect_back(fallback_location: requested_resource)
50
+ end
45
51
  end
46
52
  end
@@ -10,6 +10,11 @@ class PostDashboard < Administrate::BaseDashboard
10
10
  ATTRIBUTE_TYPES = {
11
11
  id: Field::Number,
12
12
  cover_image: Field::ActiveStorage,
13
+ other_images: Field::ActiveStorage.with_options(
14
+ destroy_url: proc do |namespace, resource, attachment|
15
+ [:other_image_admin_post, { id: resource.id, attachment_id: attachment.id }]
16
+ end
17
+ ),
13
18
  title: Field::String,
14
19
  created_at: Field::DateTime,
15
20
  updated_at: Field::DateTime,
@@ -24,6 +29,7 @@ class PostDashboard < Administrate::BaseDashboard
24
29
  id
25
30
  title
26
31
  cover_image
32
+ other_images
27
33
  created_at
28
34
  ].freeze
29
35
 
@@ -33,6 +39,7 @@ class PostDashboard < Administrate::BaseDashboard
33
39
  id
34
40
  title
35
41
  cover_image
42
+ other_images
36
43
  created_at
37
44
  updated_at
38
45
  ].freeze
@@ -43,6 +50,7 @@ class PostDashboard < Administrate::BaseDashboard
43
50
  FORM_ATTRIBUTES = %i[
44
51
  title
45
52
  cover_image
53
+ other_images
46
54
  ].freeze
47
55
 
48
56
  # COLLECTION_FILTERS
@@ -63,4 +71,8 @@ class PostDashboard < Administrate::BaseDashboard
63
71
  # def display_resource(post)
64
72
  # "Post ##{post.id}"
65
73
  # end
74
+
75
+ def permitted_attributes(action = nil)
76
+ super + [:other_images => []]
77
+ end
66
78
  end
@@ -1,5 +1,6 @@
1
1
  class Post < ApplicationRecord
2
2
  has_one_attached :cover_image
3
+ has_many_attached :other_images
3
4
 
4
5
  validates :title, presence: true
5
6
  end
@@ -2,7 +2,9 @@ Rails.application.routes.draw do
2
2
  # For details on the DSL available within this file, see https://guides.rubyonrails.org/routing.html
3
3
 
4
4
  namespace :admin do
5
- resources :posts
5
+ resources :posts do
6
+ delete :other_image, on: :member, action: :destroy_other_image
7
+ end
6
8
 
7
9
  root to: "posts#index"
8
10
  end
@@ -10,7 +10,7 @@
10
10
  #
11
11
  # It's strongly recommended that you check this file into your version control system.
12
12
 
13
- ActiveRecord::Schema.define(version: 2023_11_17_224946) do
13
+ ActiveRecord::Schema[7.1].define(version: 2023_11_17_224946) do
14
14
  create_table "active_storage_attachments", force: :cascade do |t|
15
15
  t.string "name", null: false
16
16
  t.string "record_type", null: false
@@ -40,9 +40,9 @@ ActiveRecord::Schema.define(version: 2023_11_17_224946) do
40
40
  end
41
41
 
42
42
  create_table "posts", force: :cascade do |t|
43
- t.string "title"
44
43
  t.datetime "created_at", null: false
45
44
  t.datetime "updated_at", null: false
45
+ t.string "title"
46
46
  end
47
47
 
48
48
  add_foreign_key "active_storage_attachments", "active_storage_blobs", column: "blob_id"
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: 1.0.1
4
+ version: 1.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Hamad AlGhanim
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-12-29 00:00:00.000000000 Z
11
+ date: 2024-05-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: administrate