formstrap 0.1.2 → 0.1.3

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: 40f3e1c17b291e264dbe5dc51b0b478c6ca4b92d33a0ecc1f758cc4a9d48510a
4
- data.tar.gz: 271fd64f522260f1845475094be4a6abf4c7a8e527dc36cbf43ffe1e8f00007b
3
+ metadata.gz: a7107b5857d9ac041c0adfb899049c93cbda09ecb46b0740a848cc3d7ebb881e
4
+ data.tar.gz: 56f553925e6d00e5ca9e2c22ea02596a64023739304eef1af6f1a35e058046a3
5
5
  SHA512:
6
- metadata.gz: a164e51245520da0e05bb9c6ddb899791f113f00b5b76a50e48e4c1e4ebc4a551c35586814c3697e087ae0050b2d5f2b2ed104b2ce340368fb5ddb7c2d845e66
7
- data.tar.gz: 801723b921f1f07c8de24799b75532fa9a3cc591e8d98f13c116b4dea4013cf6fc4795d0859d64f34546fd771943190880a1cb8537b2934c79829e4e300a81bb
6
+ metadata.gz: 30d0714a40e7de9ea0572ba8892c53d909d9f627e09a4a1eee04bc938ed6cf35423312186f0803dd2d04170209ac3dbc9c494d87f94fdb2ce801488bf90687aa
7
+ data.tar.gz: da87804184cae4b9234232b37750c9f6e21ab87e9426320ae78bdeeac583b944cfe30fd23f045e10474c43b194736f8cdf6591ab6627d29f35b66b782778cbe8
@@ -3,14 +3,11 @@ class Formstrap::MediaController < FormstrapController
3
3
  layout false
4
4
 
5
5
  def index
6
- @blobs =
7
- ActiveStorage::Blob
8
- .not_attached_to_variant
9
- .by_mimetypes_string(media_params[:mimetype])
10
- .order(created_at: :desc)
11
- .group(:id)
12
- .all
13
- @blobs = paginate(@blobs)
6
+ blobs = ActiveStorage::Blob
7
+ blobs = filter(blobs)
8
+ blobs = sort(blobs)
9
+ blobs = blobs.group(:id)
10
+ @blobs = paginate(blobs)
14
11
  @mimetypes = media_params[:mimetype]
15
12
 
16
13
  respond_to do |format|
@@ -51,14 +48,41 @@ class Formstrap::MediaController < FormstrapController
51
48
 
52
49
  private
53
50
 
51
+ def filter(blobs)
52
+ blobs = filter_unattached(blobs)
53
+ blobs = filter_by_mimetype(blobs, media_params[:mimetype]) if media_params[:mimetype].present?
54
+ blobs = filter_excluded_models(blobs, media_params[:exclude_models]) if media_params[:exclude_models].present?
55
+ blobs
56
+ end
57
+
58
+ def filter_unattached(blobs)
59
+ blobs.not_attached_to_variant
60
+ end
61
+
62
+ def filter_by_mimetype(blobs, mimetype)
63
+ blobs.by_mimetypes_string(mimetype)
64
+ end
65
+
66
+ def filter_excluded_models(blobs, model_names = [])
67
+ blobs.not_attached_to(model_names)
68
+ end
69
+
70
+ def sort(blobs)
71
+ blobs.order(created_at: :desc)
72
+ end
73
+
54
74
  def media_params
55
75
  params.permit(
56
- :min,
57
76
  :max,
58
- :name,
59
77
  :mimetype,
78
+ :min,
79
+ :name,
80
+ :page,
81
+ :page_start,
82
+ :per_page,
60
83
  ids: [],
61
- files: []
84
+ files: [],
85
+ exclude_models: []
62
86
  )
63
87
  end
64
88
 
@@ -15,6 +15,7 @@
15
15
  # * +wrapper+ - Hash with all options for the surrounding html tag
16
16
  # * +width+ - Width of the thumbnail
17
17
  # * +height+ - Height of the thumbnail
18
+ # * +exclude_models+ - Array of model names to exclude from selection (e.g. ["User", "Company"])
18
19
  #
19
20
  # ==== References
20
21
  # https://headmin.dev/docs/forms/media
@@ -35,12 +36,12 @@
35
36
 
36
37
  <!-- Render previews for attachments -->
37
38
  <%= form.fields_for(media.nested_attribute, media.association_object) do |ff| %>
38
- <%= render "formstrap/media/item", media.item_options.merge(form: ff, url: formstrap_media_path(name: media.name, ids: media.blob_ids, min: media.min, max: media.max, mimetype: media.accept)) %>
39
+ <%= render "formstrap/media/item", media.item_options.merge(form: ff, url: formstrap_media_path(name: media.name, ids: media.blob_ids, min: media.min, max: media.max, mimetype: media.accept, exclude_models: media.exclude_models)) %>
39
40
  <% end %>
40
41
 
41
42
  <!-- Placeholder -->
42
43
  <div class="<%= "d-none" if media.attachments.any? %>" data-media-target="placeholder">
43
- <a href="<%= formstrap_media_path(name: media.name, ids: media.blob_ids, min: media.min, max: media.max, mimetype: media.accept) %>" data-turbo-frame="remote_modal" data-media-target="modalButton">
44
+ <a href="<%= formstrap_media_path(name: media.name, ids: media.blob_ids, min: media.min, max: media.max, mimetype: media.accept, exclude_models: media.exclude_models) %>" data-turbo-frame="remote_modal" data-media-target="modalButton">
44
45
  <%= render "formstrap/shared/thumbnail", media.thumbnail_options %>
45
46
  </a>
46
47
  </div>
@@ -50,7 +51,7 @@
50
51
  <% association_object = ActiveStorage::Attachment.new %>
51
52
  <template data-media-target="template" data-template-id-regex="<%= association_object.object_id %>">
52
53
  <%= form.fields_for(media.nested_attribute, ActiveStorage::Attachment.new, child_index: association_object.object_id) do |ff| %>
53
- <%= render "formstrap/media/item", media.item_options.merge(form: ff, url: formstrap_media_path(name: media.name, ids: media.blob_ids, min: media.min, max: media.max, mimetype: media.accept)) %>
54
+ <%= render "formstrap/media/item", media.item_options.merge(form: ff, url: formstrap_media_path(name: media.name, ids: media.blob_ids, min: media.min, max: media.max, mimetype: media.accept, exclude_models: media.exclude_models)) %>
54
55
  <% end %>
55
56
  </template>
56
57
 
@@ -1,3 +1,3 @@
1
1
  module Formstrap
2
- VERSION = "0.1.2"
2
+ VERSION = "0.1.3"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: formstrap
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jef Vlamings
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-04-24 00:00:00.000000000 Z
11
+ date: 2024-01-11 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: An extensive Bootstrap form library to power your Ruby On Rails application.
14
14
  email:
@@ -219,7 +219,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
219
219
  - !ruby/object:Gem::Version
220
220
  version: '0'
221
221
  requirements: []
222
- rubygems_version: 3.3.3
222
+ rubygems_version: 3.4.22
223
223
  signing_key:
224
224
  specification_version: 4
225
225
  summary: Bootstrap-powered Form Helpers