viniBaxter-field-active_storage 3.0.0 → 5.0.0

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: cf204eba65b788fa8dfafb4018022b53aac17b95cbcd323db23e36621ca51de6
4
- data.tar.gz: 931a03b59d0588bc86118e34c645591f508d44ae94a1c6f111214d7c8e448d4c
3
+ metadata.gz: 02ca7e5e0d9df80466d7fe23019426fd67cdf9aecf4f8efd2c342dd91dd526f1
4
+ data.tar.gz: 93a22307a3e075c421df8a8318d696d58d87cf57c4922b186231cfc841d1d532
5
5
  SHA512:
6
- metadata.gz: 8bb96dca40f733b1841fc641954cfdb7d0e4ed17bef59c0a21b1ef0fc88d7e927380eb10faa0304966339f14821fdbf55d0f9655f215d94ff00c6951ae0ec67e
7
- data.tar.gz: '0360729623eab04bbbdaa179d8686bb5a70a3c0f95d4d710ff25b0de693827cdfab398eaef9777dc1fafa76c9e4ce5589d19d3b9298f2fdb08f537c7012ba41a'
6
+ metadata.gz: 435b45f51374a33a9f7ffbcc22730f9180230af34a7dc2c4c69a2618ac34848deae460932fb72e06d26c5fad79fee26210d2d6916c0e842701615f1c2e238acb
7
+ data.tar.gz: fe40c830c6b1c3d1adb47c7ec376644964bf002156f83327bff67c7058750cfc69cda12d0e56d7522e7eb333fc5ae612f938d66ea3e5d21c971c89bb7b7baab7
@@ -0,0 +1,24 @@
1
+ <div class="">
2
+ <div
3
+ class="dropzone dropzone-default dz-clickable"
4
+ data-controller="dropzonegem"
5
+ data-dropzonegem-max-file-size="<%= field.drop_max_file_size? %>"
6
+ data-dropzonegem-max-files="<%= field.drop_max_file? %>"
7
+ data-dropzonegem-accepted-files="<%= field.drop_accepted_files? %>"
8
+ data-dropzonegem-add-remove-links="hello">
9
+ <%= f.file_field field.attribute, multiple: field.many?, direct_upload: field.direct?, data: { target: 'dropzonegem.inputdropzonegem' } %>
10
+ <div class="dropzone-msg dz-message needsclick text-gray-600">
11
+ <h3 class="dropzone-msg-title">Drag & Drop here to upload or click here to browse</h3>
12
+ <span class="dropzone-msg-desc text-sm">
13
+ <%= field.drop_max_file_size? %>
14
+ MB par fichier. Les fichiers autorisés :
15
+ <%= field.drop_accepted_files? %>. Un maximum de
16
+ <%= field.drop_max_file? %> fichiers autorisés.
17
+ </span>
18
+ </div>
19
+ <div id="tpl" style='display:none'>
20
+ <%= render partial: 'fields/active_storage/dropjs_template'%>
21
+ </div>
22
+ <%#= render 'ulFordropjs' %>
23
+ </div>
24
+ </div>
@@ -0,0 +1,73 @@
1
+ <div class="list-group list-group-flush pt-4 my-n3 dz-image-preview dz-processing dz-success dz-complete">
2
+ <div class="dz-preview dz-file-preview bibi">
3
+ <div class="list-group-item">
4
+ <div class="row align-items-center">
5
+ <div class="col-auto">
6
+ <!-- Avatar -->
7
+ <%
8
+ # By default we don't allow attachment removal
9
+ removable = local_assigns.fetch(:removable, false)
10
+ image_size = local_assigns.fetch(:image_size, [1920, 1080])
11
+ %>
12
+ <% if attachment.image? and attachment.variable? and !field.url_only? %>
13
+ <%= link_to(field.blob_url(attachment), title: attachment.filename, class:'avatar') do %>
14
+ <%= image_tag(field.variant(attachment, resize_to_limit: image_size),class:'avatar-img rounded delete_on_click') %>
15
+ <% end %>
16
+ <% elsif attachment.image? and !field.url_only? %>
17
+ <%= link_to(field.blob_url(attachment), title: attachment.filename) do %>
18
+ <%= image_tag(field.url(attachment)) %>
19
+ <% end %>
20
+ <% elsif attachment.video? and attachment.previewable? and !field.url_only? %> <%# if ffmpeg is installed %>
21
+ <%= video_tag(field.url(attachment), poster: field.preview(attachment, resize_to_limit: image_size), controls: true, autobuffer: true, style: "width: 100%; height: auto;") %>
22
+ <% elsif attachment.video? and !field.url_only? %>
23
+ <%= video_tag(field.url(attachment), controls: true, autobuffer: true, style: "width: 100%; height: auto;") %>
24
+ <% elsif attachment.audio? and !field.url_only? %>
25
+ <%= audio_tag(field.url(attachment), autoplay: false, controls: true) %>
26
+ <% else %>
27
+ <%= link_to(field.blob_url(attachment), title: attachment.filename) do %>
28
+ <% if attachment.previewable? and !field.url_only? %>
29
+ <%= image_tag(field.preview(attachment, resize_to_limit: [595, 842])) %>
30
+ <% else %>
31
+ <%= attachment.filename %>
32
+ <% end %>
33
+ <% end %>
34
+ <% end %>
35
+ </div>
36
+ <div class="col ml-n2">
37
+ <!-- Title -->
38
+ <h4 class="font-weight-normal mb-1">
39
+ <a href="#!">
40
+ <div class="dz-filename"><span data-dz-name=""><%= attachment.filename %></span></div>
41
+ </a>
42
+ </h4>
43
+ <div class="dz-error-message"><span data-dz-errormessage=""></span></div>
44
+ <!-- Text -->
45
+ <small class="text-muted">
46
+ <div class="dz-size" data-dz-size=""><strong><%= attachment.byte_size.fdiv(1000).round(1) %></strong> KB</div>
47
+ </small>
48
+ </div>
49
+ <div class="col-auto">
50
+ <!-- Dropdown -->
51
+ <div class="dropdown">
52
+ <a href="#" class="dropdown-ellipses dropdown-toggle" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
53
+ <i class="fe fe-more-vertical"></i>
54
+ </a>
55
+ <div class="dropdown-menu dropdown-menu-right">
56
+ <a href="#!" class="dropdown-item">
57
+ Action
58
+ </a>
59
+ <%= link_to 'Remove file', field.destroy_path(field, attachment), method: :delete, class: 'dropdown-item dz-remove delete_on_click' %>
60
+ <a href="#!" class="dropdown-item">
61
+ Another action
62
+ </a>
63
+ <a href="#!" class="dropdown-item">
64
+ Something else here
65
+ </a>
66
+ </div>
67
+ </div>
68
+ </div>
69
+ </div>
70
+ <!-- / .row -->
71
+ </div>
72
+ </div>
73
+ </div>
@@ -0,0 +1,54 @@
1
+ <div class='list-group list-group-flush pt-4 my-n3'>
2
+ <div class="dz-preview dz-file-preview bibi">
3
+ <div class="list-group-item">
4
+ <div class="row align-items-center">
5
+ <div class="col-auto">
6
+ <!-- Avatar -->
7
+ <a href="#!" class="avatar">
8
+ <img data-dz-thumbnail data-dz-remove class="avatar-img rounded delete_on_click" />
9
+ </a>
10
+ </div>
11
+ <div class="col ml-n2">
12
+ <!-- Title -->
13
+ <h4 class="font-weight-normal mb-1">
14
+ <a href="#!">
15
+ <div class="dz-filename"><span data-dz-name></span></div>
16
+ </a>
17
+ </h4>
18
+ <div class="dz-progress">
19
+ <span
20
+ class="dz-upload"
21
+ data-dz-uploadprogress>
22
+ </span>
23
+ </div>
24
+ <div class="dz-error-message"><span data-dz-errormessage ></span></div>
25
+ <!-- Text -->
26
+ <small class="text-muted">
27
+ <div class="dz-size" data-dz-size></div>
28
+ </small>
29
+ </div>
30
+ <div class="col-auto">
31
+ <!-- Dropdown -->
32
+ <div class="dropdown">
33
+ <a href="#" class="dropdown-ellipses dropdown-toggle" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
34
+ <i class="fe fe-more-vertical"></i>
35
+ </a>
36
+ <div class="dropdown-menu dropdown-menu-right">
37
+ <a href="#!" class="dropdown-item">
38
+ Action
39
+ </a>
40
+ <a href="#!" class="dropdown-item dz-remove delete_on_click" data-dz-remove>Remove file</a>
41
+ <a href="#!" class="dropdown-item">
42
+ Another action
43
+ </a>
44
+ <a href="#!" class="dropdown-item">
45
+ Something else here
46
+ </a>
47
+ </div>
48
+ </div>
49
+ </div>
50
+ </div>
51
+ <!-- / .row -->
52
+ </div>
53
+ </div>
54
+ </div>
@@ -14,17 +14,24 @@ By default, the input is a text field for the image's URL.
14
14
 
15
15
  [1]: http://www.rubydoc.info/gems/administrate/Administrate/Field/Image
16
16
  %>
17
-
18
17
  <div class="field-unit__label">
19
18
  <%= f.label field.attribute %>
20
19
  </div>
21
-
22
20
  <div class="field-unit__field">
23
- <% if field.data.present? && field.attached? %>
24
- <%= render partial: 'fields/active_storage/items', locals: { field: field, removable: field.destroyable? } %>
25
- <br />
26
- Add:
21
+ <% if field.drop_js? %>
22
+ <!-- Form dropJS -->
23
+ <%= render partial: 'fields/active_storage/dropjs_items', locals: { f: f, field: field, removable: field.destroyable? } %>
24
+ <%else %>
25
+ <!-- Form if no dropJS -->
26
+ <%= f.file_field field.attribute, multiple: field.many?, direct_upload: field.direct? %>
27
+ <%end %>
28
+ <!-- show previous images recorded -->
29
+ <% if field.attached? %>
30
+ <% if !field.drop_js? %>
31
+ <%= render partial: 'fields/active_storage/items', locals: { field: field, removable: field.destroyable? } %>
32
+ <%= field.can_add_attachment? ? "Add:" : "Replace:" %>
33
+ <%else %>
34
+ <%= render partial: 'fields/active_storage/items', locals: { field: field, removable: field.destroyable? } %>
35
+ <%end %>
27
36
  <% end %>
28
-
29
- <%= f.file_field field.attribute, multiple: field.many?, direct_upload: field.direct? %>
30
37
  </div>
@@ -14,19 +14,29 @@ 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 %>
18
- td img {
19
- max-height: unset !important;
20
- }
17
+ <style>
18
+ <%# figure out a way to remove this %>
19
+ td img {
20
+ max-height: unset !important;
21
+ }
21
22
  </style>
22
23
  <%
23
24
  attachments = Array(field.many? ? field.attachments : field.data)
24
25
  %>
25
26
  <% if field.attached? %>
26
27
  <% if field.show_in_index? %>
27
- <%= render partial: 'fields/active_storage/item', locals: { field: field, attachment: attachments[0], image_size: [50, 50] } %>
28
+ <%= render partial: 'fields/active_storage/item',
29
+ locals: {
30
+ field: field,
31
+ attachment: attachments[0],
32
+ image_size: [50, 50]
33
+ } %>
34
+ <% end %>
35
+ <% if field.index_display_count? %>
36
+ <div class="attachments-count">
37
+ <%= pluralize(field.attachments.count, 'Attachment') %>
38
+ </div>
28
39
  <% end %>
29
- <% pluralize(attachments.count, 'Attached file') %>
30
40
  <% else %>
31
- 0 Attached files
41
+ 0 Attached files
32
42
  <% end %>
@@ -12,14 +12,42 @@ This partial renders one or more attachments
12
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
-
16
15
  <%
17
16
  attachments = Array(field.many? ? field.attachments : field.data)
18
17
  removable = local_assigns.fetch(:removable, false)
19
18
  %>
20
-
21
- <% attachments.each do |attachment| %>
22
- <div class="attachments-listing">
23
- <%= render partial: 'fields/active_storage/item', locals: { field: field, attachment: attachment, removable: removable, image_size: field.show_preview_size } %>
19
+ <!-- On edit if no dropJS -->
20
+ <% if !field.drop_js? %>
21
+ <% attachments.each do |attachment| %>
22
+ <div class="attachments-listing">
23
+ <%= render partial: 'fields/active_storage/item', locals: { field: field, attachment: attachment, removable: removable, image_size: field.show_preview_size } %>
24
+ </div>
25
+ <% end %>
26
+ <%else %>
27
+ <!-- On edit if dropJS -->
28
+ <div class="mt-5 col-12 ">
29
+ <div class="row">
30
+ <div class="col-12">
31
+ <div class="card card light-shadow card-fill">
32
+ <div class="card-header">
33
+ <!-- Title -->
34
+ <h4 class="card-header-title">
35
+ Latest Uploads
36
+ </h4>
37
+ </div>
38
+ <div class="card-body">
39
+ <div class="already-downloaded dropzone">
40
+ <div class="row">
41
+ <% attachments.each do |attachment| %>
42
+ <div class="col-6">
43
+ <%= render partial: 'fields/active_storage/dropjs_list_edit', locals: { field: field, attachment: attachment, removable: removable, image_size: field.show_preview_size }%>
44
+ </div>
45
+ <% end %>
46
+ </div>
47
+ </div>
48
+ </div>
49
+ </div>
50
+ </div>
51
+ </div>
24
52
  </div>
25
53
  <% end %>
@@ -0,0 +1,9 @@
1
+ <%
2
+ attachments = Array(field.many? ? field.attachments : field.data)
3
+ removable = local_assigns.fetch(:removable, false)
4
+ %>
5
+ <% attachments.each do |attachment| %>
6
+ <div class="attachments-listing">
7
+ <%= render partial: 'fields/active_storage/item', locals: { field: field, attachment: attachment, removable: removable, image_size: field.show_preview_size } %>
8
+ </div>
9
+ <% end %>
@@ -14,7 +14,10 @@ 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
-
18
17
  <% if field.attached? %>
19
- <%= render partial: 'fields/active_storage/items', locals: { field: field } %>
18
+ <% if field.show_drop_js_on_show? %>
19
+ <%= render partial: 'fields/active_storage/items', locals: { field: field } %>
20
+ <%else %>
21
+ <%= render partial: 'fields/active_storage/items_on_show', locals: { field: field } %>
22
+ <% end %>
20
23
  <% end %>
@@ -19,19 +19,44 @@ module Administrate
19
19
  options.fetch(:show_in_index, false)
20
20
  end
21
21
 
22
+ def index_display_count?
23
+ options.fetch(:index_display_count) { attachments.present? && attachments.count != 1 }
24
+ end
25
+
22
26
  def show_preview_size
23
27
  options.fetch(:show_preview_size, [1080, 1920])
24
28
  end
25
29
 
26
30
  def many?
27
31
  # find a way to use instance_of
28
- data.class.name == 'ActiveStorage::Attached::Many'
32
+ # data.class.name == 'ActiveStorage::Attached::Many'
33
+ data.is_a? ::ActiveStorage::Attached::Many
29
34
  end
30
35
 
31
36
  def direct?
32
37
  options.fetch(:direct_upload, false)
33
38
  end
34
39
 
40
+ def drop_js?
41
+ options.fetch(:drop_js, false)
42
+ end
43
+
44
+ def show_drop_js_on_show?
45
+ options.fetch(:show_drop_js_on_show, false)
46
+ end
47
+
48
+ def drop_max_file?
49
+ options.fetch(:drop_max_file, many? == true ? 10 : 1)
50
+ end
51
+
52
+ def drop_max_file_size?
53
+ options.fetch(:drop_max_file_size, 10)
54
+ end
55
+
56
+ def drop_accepted_files?
57
+ options.fetch(:drop_accepted_files, ".jpeg,.jpg,.png,.gif,.svg")
58
+ end
59
+
35
60
  # def destroy_path?
36
61
  # options.fetch(:destroy_path, false).present?
37
62
  # end
@@ -58,6 +83,10 @@ module Administrate
58
83
  Rails.application.routes.url_helpers.rails_blob_path(attachment, disposition: :attachment, only_path: true)
59
84
  end
60
85
 
86
+ def can_add_attachment?
87
+ many? || attachments.blank?
88
+ end
89
+
61
90
  def destroy_path(field, attachment)
62
91
  destroy_path_helper = options.fetch(:destroy_path)
63
92
  record_id = field.data.record.id
@@ -65,8 +94,15 @@ module Administrate
65
94
  Rails.application.routes.url_helpers.send(destroy_path_helper, {:record_id => record_id, :attachment_id => attachment_id})
66
95
  end
67
96
 
68
- delegate :attached?, to: :data
69
- delegate :attachments, to: :data
97
+ # delegate :attached?, to: :data
98
+ # delegate :attachments, to: :data
99
+ def attached?
100
+ data.present? && data.attached?
101
+ end
102
+
103
+ def attachments
104
+ data.attachments if attached?
105
+ end
70
106
  end
71
107
  end
72
108
  end
@@ -2,7 +2,7 @@ $:.push File.expand_path("../lib", __FILE__)
2
2
 
3
3
  Gem::Specification.new do |gem|
4
4
  gem.name = "viniBaxter-field-active_storage"
5
- gem.version = "3.0.0"
5
+ gem.version = "5.0.0"
6
6
  gem.authors = ["viny baxter"]
7
7
  gem.email = ["vincent.viricel@gmail.com"]
8
8
  gem.homepage = "https://github.com/Dreamersoul/administrate-field-active_storage"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: viniBaxter-field-active_storage
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.0
4
+ version: 5.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - viny baxter
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-05-07 00:00:00.000000000 Z
11
+ date: 2020-05-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: administrate
@@ -66,10 +66,14 @@ files:
66
66
  - README.md
67
67
  - Rakefile
68
68
  - _config.yml
69
+ - app/views/fields/active_storage/_dropjs_items.html.erb
70
+ - app/views/fields/active_storage/_dropjs_list_edit.html.erb
71
+ - app/views/fields/active_storage/_dropjs_template.html.erb
69
72
  - app/views/fields/active_storage/_form.html.erb
70
73
  - app/views/fields/active_storage/_index.html.erb
71
74
  - app/views/fields/active_storage/_item.html.erb
72
75
  - app/views/fields/active_storage/_items.html.erb
76
+ - app/views/fields/active_storage/_items_on_show.html.erb
73
77
  - app/views/fields/active_storage/_show.html.erb
74
78
  - contribute.md
75
79
  - lib/viniBaxter/field/active_storage.rb