formstrap 0.1.1 → 0.1.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: 5afd41f3d2d060b685fc6357bca9761bf8c48e4a1b84d7749ea74ead04ebe31a
4
- data.tar.gz: 103a7f552523b866e29460eb42ba1007e0ab558a1818eba5a6728500b07ac820
3
+ metadata.gz: a7107b5857d9ac041c0adfb899049c93cbda09ecb46b0740a848cc3d7ebb881e
4
+ data.tar.gz: 56f553925e6d00e5ca9e2c22ea02596a64023739304eef1af6f1a35e058046a3
5
5
  SHA512:
6
- metadata.gz: 5e90e2f3c3e5589459b4f48c1c8ee73a5720a0dbbb00fc543e70ef59d8045111b41b20c973fd80708404b05a074b4ef81d3a9d7e8206b3c1bd3c358b8b4e531b
7
- data.tar.gz: debe1ba9cefa1bfd484bb50df731c0b0fe555fe89e06140ec311e0e722ab93771fae0c1d9220aded9810b83c14e3869cf2336686c9169333262526aa295227ec
6
+ metadata.gz: 30d0714a40e7de9ea0572ba8892c53d909d9f627e09a4a1eee04bc938ed6cf35423312186f0803dd2d04170209ac3dbc9c494d87f94fdb2ce801488bf90687aa
7
+ data.tar.gz: da87804184cae4b9234232b37750c9f6e21ab87e9426320ae78bdeeac583b944cfe30fd23f045e10474c43b194736f8cdf6591ab6627d29f35b66b782778cbe8
@@ -31,7 +31,7 @@ export default class extends Controller {
31
31
  const ids = this.activeIds()
32
32
 
33
33
  this.modalButtonTargets.forEach((button) => {
34
- const sourceLocation = location.protocol + '//' + location.host
34
+ const sourceLocation = window.location.protocol + '//' + window.location.host
35
35
  const url = new URL(button.getAttribute('href'), sourceLocation)
36
36
 
37
37
  // Remove all ids[]
@@ -10974,7 +10974,7 @@ var media_controller_default = class extends Controller {
10974
10974
  syncIds() {
10975
10975
  const ids = this.activeIds();
10976
10976
  this.modalButtonTargets.forEach((button) => {
10977
- const sourceLocation = location.protocol + "//" + location.host;
10977
+ const sourceLocation = window.location.protocol + "//" + window.location.host;
10978
10978
  const url = new URL(button.getAttribute("href"), sourceLocation);
10979
10979
  url.searchParams.delete("ids[]");
10980
10980
  ids.forEach((id) => {
@@ -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
 
@@ -152,13 +152,7 @@ module Formstrap
152
152
  end
153
153
 
154
154
  def render_input(name, attribute, options)
155
- # ToDo: Find a way to import the host of the application
156
- renderer = ApplicationController.renderer.new(
157
- http_host: "headmin.test",
158
- https: true
159
- )
160
-
161
- renderer.render(template: "formstrap/_#{name}", locals: {form: self, attribute: attribute, **options})
155
+ @template.render("formstrap/#{name}", form: self, attribute: attribute, **options)
162
156
  end
163
157
 
164
158
  def method_missing(name, *args, &block)
@@ -1,3 +1,3 @@
1
1
  module Formstrap
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.3"
3
3
  end
data/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@frontierdotbe/formstrap",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "Bootstrap-powered Form Helpers",
5
5
  "module": "app/assets/javascripts/formstrap.js",
6
6
  "main": "app/assets/javascripts/formstrap.js",
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.1
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