administrate-field-active_storage 0.0.2 → 0.1.0

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
  SHA1:
3
- metadata.gz: 36e2931ef3866e05ff79f6580d2e82d9255bf32a
4
- data.tar.gz: e756ee6745311cfc2fda588a222ec4f4ce5656a1
3
+ metadata.gz: 3cce01035ebb6d8d270b4703123e5da7d74d3dd7
4
+ data.tar.gz: 73e0994b8b94bd8951d83cb1f5e8f18b3da372dc
5
5
  SHA512:
6
- metadata.gz: ec287997ada87ecba73e4aba1f812be8005fe2340c6b37a2edf7b7177cb15a0dccdfc91a46b0b530548e83258754d88837ec18ec873b19fda999fd8f82c14b9f
7
- data.tar.gz: 9b43814703a5281d9de9a0f2a7a16878e5b75c995c9f33cd93816ea70414ffb3b68757d55ef191ea5aa819f6c2f374921ac06460223cb3ff428b0fdec4d990ff
6
+ metadata.gz: d6e1b6db8cf2ecf429006e34664ff801978150da69448abf772b2bcdaf88fa49778b1dc6819ae5108e03626271269820a60d9020634f1913fcba0c4b37eadb09
7
+ data.tar.gz: a1f3d6cdb212cd5b1c36999d890ac1cda80ae4eb3f1df31b9a9ff4887decd92ce10cdbfb2ae27b04e8fd83c10e68184af710edcb64baea8eb243dccfa5ab8510
data/README.md CHANGED
@@ -1,11 +1,11 @@
1
1
  # Administrate::Field::ActiveStorage
2
2
  ![rails](https://img.shields.io/badge/rails-%3E%3D5.2.0-red.svg)
3
3
  ## Things To Know:
4
- - currently the gem only works for `has_one_attached` support for `has_many_attached` will be added in a future release.
5
4
  - to preview pdf files you need to install `mupdf` or `Poppler`.
6
5
  - to preview video files you need to install `ffmpeg`.
7
6
 
8
7
  ## How To Use:
8
+
9
9
  Add `administrate-field-active_storage` to your Gemfile:
10
10
 
11
11
  ```ruby
@@ -18,7 +18,7 @@ Install:
18
18
  $ bundle install
19
19
  ```
20
20
 
21
- Use:
21
+ ### `has_one_attached`:
22
22
  assuming your modelname is `Model` and field name is `attachment`
23
23
  ```ruby
24
24
  class ModelDashboard < Administrate::BaseDashboard
@@ -30,6 +30,29 @@ class ModelDashboard < Administrate::BaseDashboard
30
30
  Then add `:attachment` to `FORM_ATTRIBUTES` and `SHOW_PAGE_ATTRIBUTES`.
31
31
  currently adding `:attachment` `COLLECTION_ATTRIBUTES` will work but will probably look too big.
32
32
 
33
+ ### `has_many_attached`:
34
+ assuming your modelname is `Model` and field name is `attachments`
35
+ the processs is identical the only issue is that the form field isn't being permitted, in order to permit it we apply the following method to the dashboard:
36
+
37
+ ```ruby
38
+ class ModelDashboard < Administrate::BaseDashboard
39
+ ATTRIBUTE_TYPES = {
40
+ attachments: Field::ActiveStorage,
41
+ }
42
+
43
+ # ...
44
+ FORM_ATTRIBUTES = {
45
+ #...
46
+ :attachments
47
+ }
48
+
49
+ # permitted for has_many_attached
50
+ def permitted_attributes
51
+ super + [:attachments => []]
52
+ end
53
+ ```
54
+ i know it is not ideal, if you have a workaround please submit a PR
55
+
33
56
  ## Things To Do:
34
57
 
35
58
  - [x] upload single file
@@ -39,8 +62,9 @@ currently adding `:attachment` `COLLECTION_ATTRIBUTES` will work but will probab
39
62
  - [x] download link to other files
40
63
  - [x] preview videos
41
64
  - [x] preview pdfs
65
+ - [x] upload multiple files
66
+ - [ ] find a way to delete attachments
42
67
  - [ ] preview office files as pictures
43
- - [ ] upload multiple files
44
68
 
45
69
  ## Contribution guide:
46
70
  1. contributers are welcome (code, suggestions, and bugs).
@@ -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.0.2"
5
+ gem.version = "0.1.0"
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"
@@ -19,5 +19,5 @@ By default, the input is a text field for the image's URL.
19
19
  <%= f.label field.attribute %>
20
20
  </div>
21
21
  <div class="field-unit__field">
22
- <%= f.file_field field.attribute %>
22
+ <%= f.file_field field.attribute, multiple: field.many? %>
23
23
  </div>
@@ -14,18 +14,12 @@ 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
- <% if field.image? %>
18
- <%= image_tag(field.url) %>
19
- <% elsif field.video? and field.previewable?%> <%# if ffmpeg is installed %>
20
- <%= video_tag(field.url, poster: field.preview(resize: "1920x1080>"), controls: true, autobuffer: true, style: "width: 100%; height: auto;") %>
21
- <% elsif field.video? %>
22
- <%= video_tag(field.url, controls: true, autobuffer: true, style: "width: 100%; height: auto;") %>
23
- <% elsif field.audio? %>
24
- <%= audio_tag(field.url, autoplay: true, controls: true) %>
25
- <% elsif field.previewable? %>
26
- <%= image_tag(field.preview(resize: "595x842>")) %>
27
- <br/>
28
- Download: <%= link_to(field.filename, field.blob_url) %>
29
- <% else %>
30
- <%= link_to(field.filename, field.blob_url) %>
17
+ <% if field.attached? %>
18
+ <% if field.many? %>
19
+ <% field.attachments.each do |attachment| %>
20
+ <%= render :partial => 'item', :field => field, :attachment => attachment %>
21
+ <% end %>
22
+ <% else %>
23
+ <%= render :partial => 'item', :field => field, :attachment => field.data %>
24
+ <% end %>
31
25
  <% end %>
@@ -0,0 +1,15 @@
1
+ <% if attachment.image? %>
2
+ <%= image_tag(field.url(attachment)) %>
3
+ <% elsif attachment.video? and attachment.previewable? %> <%# if ffmpeg is installed %>
4
+ <%= video_tag(field.url(attachment), poster: field.preview(attachment, resize: "1920x1080>"), controls: true, autobuffer: true, style: "width: 100%; height: auto;") %>
5
+ <% elsif attachment.video? %>
6
+ <%= video_tag(field.url(attachment), controls: true, autobuffer: true, style: "width: 100%; height: auto;") %>
7
+ <% elsif attachment.audio? %>
8
+ <%= audio_tag(field.url(attachment), autoplay: true, controls: true) %>
9
+ <% elsif attachment.previewable? %>
10
+ <%= image_tag(field.preview(attachment, resize: "595x842>")) %>
11
+ <br/>
12
+ Download: <%= link_to(attachment.filename, field.blob_url(attachment)) %>
13
+ <% else %>
14
+ <%= link_to(attachment.filename, field.blob_url(attachment)) %>
15
+ <% end %>
@@ -14,17 +14,12 @@ 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
- <% if field.image? %>
19
- <%= image_tag(field.url) %>
20
- <% elsif field.video? %>
21
- <%= video_tag(field.url, poster: field.preview(resize: "1920x1080>"), controls: true, autobuffer: true, style: "width: 100%; height: auto;") %>
22
- <% elsif field.audio? %>
23
- <%= audio_tag(field.url, autoplay: true, controls: true) %>
24
- <% elsif field.previewable? %>
25
- <%= image_tag(field.preview(resize: "595x842>")) %>
26
- <br/>
27
- Download: <%= link_to(field.filename, field.blob_url) %>
28
- <% else %>
29
- <%= link_to(field.filename, field.blob_url) %>
30
- <% end %>
17
+ <% if field.attached? %>
18
+ <% if field.many? %>
19
+ <% field.attachments.each do |attachment| %>
20
+ <%= render :partial => 'fields/active_storage/item', locals: { field: field, attachment: attachment } %>
21
+ <% end %>
22
+ <% else %>
23
+ <%= render :partial => 'fields/active_storage/item', locals: { field: field, attachment: field.data } %>
24
+ <% end %>
25
+ <% end %>
@@ -9,29 +9,27 @@ module Administrate
9
9
  # currently we are using Rails.application.routes.url_helpers
10
10
  # without including the namespace because it runs into an
11
11
  # exception
12
+ def many?
13
+ # find a way to use instance_of
14
+ data.class.name == "ActiveStorage::Attached::Many"
15
+ end
16
+ # work around since calling data.preview(options)
17
+ # returns "/images/<ActiveStorage::Preview>" which isnt the url
12
18
 
13
- def url
14
- Rails.application.routes.url_helpers.rails_blob_path(data, only_path: true)
19
+ def preview(attachment, options)
20
+ Rails.application.routes.url_helpers.rails_representation_path(attachment.preview(options), only_path: true)
15
21
  end
16
22
 
17
- def blob_url
18
- Rails.application.routes.url_helpers.rails_blob_path(data, disposition: :attachment, only_path: true)
23
+ def url(attachment)
24
+ Rails.application.routes.url_helpers.rails_blob_path(attachment, only_path: true)
19
25
  end
20
26
 
21
- # work around since calling data.preview(options)
22
- # returns "/images/<ActiveStorage::Preview>" which isnt the url
23
-
24
- def preview(options)
25
- Rails.application.routes.url_helpers.rails_representation_path(data.preview(options), only_path: true)
27
+ def blob_url(attachment)
28
+ Rails.application.routes.url_helpers.rails_blob_path(attachment, disposition: :attachment, only_path: true)
26
29
  end
27
30
 
28
- delegate :filename, to: :data
29
- delegate :previewable?, to: :data
30
- delegate :image?, to: :data
31
- delegate :video?, to: :data
32
- delegate :audio?, to: :data
33
- delegate :audio?, to: :data
34
-
31
+ delegate :attached?, to: :data
32
+ delegate :attachments, to: :data
35
33
  end
36
34
  end
37
35
  end
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.0.2
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Hamad AlGhanim
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-07-06 00:00:00.000000000 Z
11
+ date: 2018-07-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: administrate
@@ -60,7 +60,6 @@ extensions: []
60
60
  extra_rdoc_files: []
61
61
  files:
62
62
  - ".gitignore"
63
- - CHANGELOG.md
64
63
  - Gemfile
65
64
  - LICENSE
66
65
  - README.md
@@ -68,6 +67,7 @@ files:
68
67
  - administrate-field-active_storage.gemspec
69
68
  - app/views/fields/active_storage/_form.html.erb
70
69
  - app/views/fields/active_storage/_index.html.erb
70
+ - app/views/fields/active_storage/_item.html.erb
71
71
  - app/views/fields/active_storage/_show.html.erb
72
72
  - contribute.md
73
73
  - lib/administrate/field/active_storage.rb
@@ -1,18 +0,0 @@
1
- # CHANGELOG
2
-
3
- ## 1.1.0 (2017-03-24)
4
-
5
- * Don't crash if image is nil/blank ([#9][])
6
- * Remove Explicit Dependency on Rails ([#11][])
7
- * Adds this CHANGELOG ([#12][])
8
-
9
- [#9]: https://github.com/thoughtbot/administrate-field-image/pull/9
10
- [#11]: https://github.com/thoughtbot/administrate-field-image/pull/11
11
- [#12]: https://github.com/thoughtbot/administrate-field-image/pull/12
12
-
13
- ## 1.0.0 (2017-01-16)
14
-
15
- * Extraction from [administrate][].
16
- * Rails 5 support.
17
-
18
- [administrate]: https://github.com/thoughtbot/administrate