effective_assets 1.10.0 → 1.11.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/MIT-LICENSE +1 -1
- data/app/assets/config/effective_assets_manifest.js +2 -0
- data/app/assets/javascripts/effective/snippets/{effective_asset.js.coffee.erb → effective_asset.js.coffee} +1 -1
- data/app/controllers/effective/assets_controller.rb +2 -3
- data/app/models/effective/iframe_upload.rb +13 -0
- data/app/models/effective/snippets/effective_asset.rb +9 -5
- data/app/uploaders/effective_assets_uploader.rb +3 -1
- data/config/effective_assets.rb +1 -0
- data/db/migrate/01_create_effective_assets.rb.erb +4 -0
- data/lib/effective_assets.rb +1 -0
- data/lib/effective_assets/engine.rb +8 -3
- data/lib/effective_assets/version.rb +1 -1
- data/lib/inputs/asset_box.rb +210 -0
- data/lib/inputs/asset_box_form_input.rb +5 -0
- data/lib/inputs/asset_box_formtastic_input.rb +7 -0
- data/{app/models → lib}/inputs/asset_box_input.rb +8 -2
- data/lib/inputs/asset_box_simple_form_input.rb +5 -0
- data/{app/models → lib}/validators/asset_box_length_validator.rb +0 -0
- data/{app/models → lib}/validators/asset_box_presence_validator.rb +0 -0
- metadata +16 -16
- data/app/models/effective/iframe_uploads.rb +0 -27
- data/app/models/inputs/asset_box.rb +0 -213
- data/app/models/inputs/asset_box_form_input.rb +0 -7
- data/app/models/inputs/asset_box_formtastic_input.rb +0 -9
- data/app/models/inputs/asset_box_simple_form_input.rb +0 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 82cfdb81fc92b1b74f6c541a6c5372241e6be602dbb0a28cd9d63481e6b9a61e
|
4
|
+
data.tar.gz: 63c9c06bdd0995ab93ac45956a5d23260a2c702787507a666e68fb184242b6ee
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: aa569d27fc080268b9faa389b9d55e1fc167726a5092dcff4ca7e38709decc675941f1e8bf34af531ceea05a6d2085f5c68098c2748d1580bb4765322312fb9f
|
7
|
+
data.tar.gz: 69c91034760b37ccd07043461d304f77ce1ec5d00eb524e922147c511049326baad6942fd95ab938074960c8d8c6daa3eaa92adb682e68c798cfeb84abb83acc
|
data/MIT-LICENSE
CHANGED
@@ -11,7 +11,7 @@ CKEDITOR.dialog.add 'effective_asset', (editor) ->
|
|
11
11
|
{
|
12
12
|
id: 'iframe-insert',
|
13
13
|
type: 'html',
|
14
|
-
html: "<div><p id='iframe-insert-loading' style='text-align: center;'><br><br><br><br><br><br><
|
14
|
+
html: "<div><p id='iframe-insert-loading' style='text-align: center;'><br><br><br><br><br><br><br><br> Loading...</p><iframe class='effective_assets_iframe' style='width: 100%; height: 100%; min-height: 500px;' src='/effective/assets?only=nonimages'></iframe></div>"
|
15
15
|
onLoad: (evt) ->
|
16
16
|
dialog = evt.sender # This is the CKEditor.dialog
|
17
17
|
iframe = $('#' + dialog.getContentElement('upload', 'iframe-insert').domId).children('iframe').first()
|
@@ -8,8 +8,7 @@ module Effective
|
|
8
8
|
def index # This is the IFRAME modal dialog that is read by CKEDITOR
|
9
9
|
EffectiveAssets.authorized?(self, :index, Effective::Asset.new(:user_id => current_user.try(:id)))
|
10
10
|
|
11
|
-
|
12
|
-
@assets = Effective::Asset.where(id: effective_iframe_uploads)
|
11
|
+
@assets = Effective::Asset.where(user_id: current_user.id)
|
13
12
|
|
14
13
|
if params[:only] == 'images'
|
15
14
|
@assets = @assets.images
|
@@ -21,7 +20,7 @@ module Effective
|
|
21
20
|
@aws_acl = EffectiveAssets.aws_acl
|
22
21
|
end
|
23
22
|
|
24
|
-
@user_uploads =
|
23
|
+
@user_uploads = IframeUpload.new(@assets)
|
25
24
|
|
26
25
|
render :file => 'effective/assets/iframe'
|
27
26
|
end
|
@@ -2,10 +2,14 @@ if defined?(EffectiveRegions)
|
|
2
2
|
module Effective
|
3
3
|
module Snippets
|
4
4
|
class EffectiveAsset < Snippet
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
5
|
+
# attr_accessor :asset_id #, Integer
|
6
|
+
# attr_accessor :html_class #, String
|
7
|
+
# attr_accessor :link_title #, String
|
8
|
+
# attr_accessor :private_url # , Boolean
|
9
|
+
|
10
|
+
def snippet_attributes
|
11
|
+
super + [:asset_id, :html_class, :link_title, :private_url]
|
12
|
+
end
|
9
13
|
|
10
14
|
def asset
|
11
15
|
@asset ||= (Effective::Asset.where(:id => asset_id).first if asset_id)
|
@@ -20,7 +24,7 @@ if defined?(EffectiveRegions)
|
|
20
24
|
end
|
21
25
|
|
22
26
|
def is_private?
|
23
|
-
|
27
|
+
[true, 'true', '1'].include?(private_url)
|
24
28
|
end
|
25
29
|
|
26
30
|
def aws_private?
|
@@ -73,7 +73,9 @@ class EffectiveAssetsUploader < CarrierWave::Uploader::Base
|
|
73
73
|
retval = {}
|
74
74
|
|
75
75
|
self.class.versions.each do |k, v|
|
76
|
-
v[:uploader].processors
|
76
|
+
processors = (v.respond_to?(:processors) ? v.processors : v[:uploader].processors)
|
77
|
+
|
78
|
+
processors.each do |processor|
|
77
79
|
dimensions = processor[1]
|
78
80
|
|
79
81
|
if processor[0].to_s.include?('resize') and dimensions.kind_of?(Array) and dimensions.length == 2
|
data/config/effective_assets.rb
CHANGED
@@ -31,6 +31,10 @@ class CreateEffectiveAssets < ActiveRecord::Migration[4.2]
|
|
31
31
|
t.string :box
|
32
32
|
end
|
33
33
|
|
34
|
+
create_table <%= @iframe_uploads_table_name %> do |t|
|
35
|
+
t.timestamps
|
36
|
+
end
|
37
|
+
|
34
38
|
add_index <%= @attachments_table_name %>, :asset_id
|
35
39
|
add_index <%= @attachments_table_name %>, [:attachable_type, :attachable_id]
|
36
40
|
add_index <%= @attachments_table_name %>, :attachable_id
|
data/lib/effective_assets.rb
CHANGED
@@ -2,7 +2,9 @@ module EffectiveAssets
|
|
2
2
|
class Engine < ::Rails::Engine
|
3
3
|
engine_name 'effective_assets'
|
4
4
|
|
5
|
-
config.autoload_paths += Dir["#{config.root}/
|
5
|
+
config.autoload_paths += Dir["#{config.root}/lib/validators/", "#{config.root}/lib/inputs/"]
|
6
|
+
|
7
|
+
config.eager_load_paths += Dir["#{config.root}/lib/validators/", "#{config.root}/lib/inputs/"]
|
6
8
|
|
7
9
|
# Include acts_as_addressable concern and allow any ActiveRecord object to call it
|
8
10
|
initializer 'effective_assets.active_record' do |app|
|
@@ -13,7 +15,7 @@ module EffectiveAssets
|
|
13
15
|
|
14
16
|
initializer 'effective_assets.action_view' do |app|
|
15
17
|
ActiveSupport.on_load :action_view do
|
16
|
-
ActionView::Helpers::FormBuilder.send(:include,
|
18
|
+
ActionView::Helpers::FormBuilder.send(:include, AssetBoxFormInput)
|
17
19
|
end
|
18
20
|
end
|
19
21
|
|
@@ -23,7 +25,10 @@ module EffectiveAssets
|
|
23
25
|
end
|
24
26
|
|
25
27
|
initializer "effective_assets.append_precompiled_assets" do |app|
|
26
|
-
Rails.application.config.assets.precompile += [
|
28
|
+
Rails.application.config.assets.precompile += [
|
29
|
+
'effective_assets_manifest.js', 'effective_assets.js', 'effective_assets_iframe.js', 'effective_assets_iframe.css',
|
30
|
+
'effective_assets/*', 'mime-types/*'
|
31
|
+
]
|
27
32
|
end
|
28
33
|
|
29
34
|
# ActiveAdmin (optional)
|
@@ -0,0 +1,210 @@
|
|
1
|
+
class AssetBox
|
2
|
+
delegate :content_tag, :render, :current_user, :to => :@template
|
3
|
+
|
4
|
+
def initialize(object, object_name, template, method, opts)
|
5
|
+
@object = object
|
6
|
+
@object_name = object_name
|
7
|
+
@template = template
|
8
|
+
@options = initialize_options(method, opts)
|
9
|
+
end
|
10
|
+
|
11
|
+
def to_html
|
12
|
+
output = ''
|
13
|
+
output += header_html
|
14
|
+
|
15
|
+
if @options[:uploader] == :top
|
16
|
+
output += uploader_html
|
17
|
+
output += attachments_html
|
18
|
+
output += dialog_html if @options[:dialog]
|
19
|
+
else
|
20
|
+
output += attachments_html
|
21
|
+
output += dialog_html if @options[:dialog]
|
22
|
+
output += uploader_html if @options[:uploader]
|
23
|
+
end
|
24
|
+
|
25
|
+
output += footer_html
|
26
|
+
|
27
|
+
output.html_safe
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
|
32
|
+
def header_html
|
33
|
+
"<div id='asset-box-input-#{@options[:uid]}'
|
34
|
+
class='asset-box-input #{@options[:box]}'
|
35
|
+
data-box='#{@options[:box]}'
|
36
|
+
data-uploader='s3_#{@options[:uid]}'
|
37
|
+
data-limit='#{@options[:limit]}'
|
38
|
+
data-attachable-id='#{@options[:attachable_id]}'
|
39
|
+
data-attachable-type='#{@options[:attachable_type]}'
|
40
|
+
data-attachable-object-name='#{@object_name}'
|
41
|
+
data-attachment-style='#{@options[:attachment_style]}'
|
42
|
+
data-attachment-add-to='#{@options[:attachment_add_to]}'
|
43
|
+
data-attachment-actions='#{@options[:attachment_actions].to_json()}'
|
44
|
+
data-attachment-count='#{attachments.length}'
|
45
|
+
data-attachment-links='#{@options[:attachment_links]}'
|
46
|
+
data-over-limit-alerted='false'
|
47
|
+
data-aws-acl='#{@options[:aws_acl]}'
|
48
|
+
>".html_safe
|
49
|
+
end
|
50
|
+
|
51
|
+
def attachments_html
|
52
|
+
if @options[:attachment_style] == :table
|
53
|
+
attachments_table_html
|
54
|
+
elsif @options[:attachment_style] == :list
|
55
|
+
content_tag(:ul, build_values_html, :class => 'attachments')
|
56
|
+
else
|
57
|
+
content_tag(:div, build_values_html, :class => 'row attachments thumbnails')
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
def attachments_table_html
|
62
|
+
content_tag(:table, :class => 'table') do
|
63
|
+
head = attachments_table_head_html if @options[:table_filter_bar]
|
64
|
+
body = content_tag(:tbody, build_values_html, :class => 'attachments')
|
65
|
+
head ? head + body : body
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
def attachments_table_head_html
|
70
|
+
content_tag(:thead) do
|
71
|
+
content_tag(:tr) do
|
72
|
+
content_tag(:th, filter_bar_html, :colspan => 4)
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
def dialog_html
|
78
|
+
render(
|
79
|
+
:partial => 'asset_box_input/dialog',
|
80
|
+
:locals => {
|
81
|
+
:dialog_url => @options[:dialog_url]
|
82
|
+
}
|
83
|
+
).html_safe
|
84
|
+
end
|
85
|
+
|
86
|
+
def uploader_html
|
87
|
+
# Check that we have permission to upload.
|
88
|
+
asset = Effective::Asset.new(user_id: ((current_user.try(:id) || 1) rescue 1), upload_file: 'placeholder')
|
89
|
+
|
90
|
+
unless (EffectiveAssets.authorized?(@template.controller, :create, asset) rescue false)
|
91
|
+
@options[:btn_title] = 'Unable to upload. (cannot :create Effective::Asset)'
|
92
|
+
@options[:disabled] = true
|
93
|
+
end
|
94
|
+
|
95
|
+
html_class = [
|
96
|
+
('drop-files' if @options[:uploader_drop_files]),
|
97
|
+
((@options[:uploader_html] || {})[:class])
|
98
|
+
].compact.join(' ')
|
99
|
+
|
100
|
+
render(
|
101
|
+
:partial => 'asset_box_input/uploader',
|
102
|
+
:locals => {
|
103
|
+
:uid => @options[:uid],
|
104
|
+
:click_submit => @options[:click_submit],
|
105
|
+
:html_class => html_class,
|
106
|
+
:limit => @options[:limit],
|
107
|
+
:disabled => @options[:disabled],
|
108
|
+
:required => (@options[:required] == true && attachments.length == 0),
|
109
|
+
:file_types => @options[:file_types],
|
110
|
+
:progress_bar_partial => @options[:progress_bar_partial],
|
111
|
+
:drop_files => @options[:uploader_drop_files],
|
112
|
+
:drop_files_help_text => @options[:drop_files_help_text],
|
113
|
+
:aws_acl => @options[:aws_acl],
|
114
|
+
:btn_label => @options[:btn_label],
|
115
|
+
:btn_title => @options[:btn_title]
|
116
|
+
}
|
117
|
+
).html_safe
|
118
|
+
end
|
119
|
+
|
120
|
+
def filter_bar_html
|
121
|
+
"<input type='text' class='form-control filter-attachments' placeholder='Filter by title'>".html_safe
|
122
|
+
end
|
123
|
+
|
124
|
+
def build_values_html
|
125
|
+
attachment_partial =
|
126
|
+
case @options[:attachment_style]
|
127
|
+
when :table
|
128
|
+
'attachment_as_table'
|
129
|
+
when :list
|
130
|
+
'attachment_as_list'
|
131
|
+
when :thumbnail
|
132
|
+
'attachment_as_thumbnail'
|
133
|
+
when nil
|
134
|
+
'attachment_as_thumbnail'
|
135
|
+
else
|
136
|
+
raise "unknown AssetBox attachment_style: #{@options[:attachment_style]}. Valid options are :thumbnail, :list and :table"
|
137
|
+
end
|
138
|
+
|
139
|
+
render(
|
140
|
+
:partial => "asset_box_input/#{attachment_partial}",
|
141
|
+
:collection => attachments.reject { |attachment| attachment.marked_for_destruction? },
|
142
|
+
:as => :attachment,
|
143
|
+
:locals => {
|
144
|
+
:attachment_actions => @options[:attachment_actions].map { |action| action.to_s },
|
145
|
+
:attachment_links => @options[:attachment_links],
|
146
|
+
:limit => @options[:limit],
|
147
|
+
:disabled => @options[:disabled],
|
148
|
+
:attachable_object_name => @object_name
|
149
|
+
}
|
150
|
+
)
|
151
|
+
end
|
152
|
+
|
153
|
+
def footer_html
|
154
|
+
"</div>".html_safe
|
155
|
+
end
|
156
|
+
|
157
|
+
def attachments
|
158
|
+
@object.attachments.select { |attachment| attachment.box == @options[:box] }
|
159
|
+
end
|
160
|
+
|
161
|
+
def initialize_options(method, opts)
|
162
|
+
{
|
163
|
+
:uploader => true, # :top, :bottom, true or false
|
164
|
+
:uploader_drop_files => false,
|
165
|
+
:drop_files_help_text => 'Drop files here',
|
166
|
+
:progress_bar_partial => 'asset_box_input/progress_bar_template',
|
167
|
+
:attachment_style => :thumbnail, # :thumbnail, :table, or :list
|
168
|
+
:attachment_links => true,
|
169
|
+
:attachment_add_to => :bottom, # :bottom or :top (of attachments div)
|
170
|
+
:attachment_actions => [:remove], # or :insert, :delete, :remove
|
171
|
+
:table_filter_bar => false,
|
172
|
+
:dialog => false,
|
173
|
+
:dialog_url => @template.effective_assets.effective_assets_path,
|
174
|
+
:disabled => false,
|
175
|
+
:file_types => [:any],
|
176
|
+
:btn_label => 'Upload...',
|
177
|
+
:btn_title => 'Click or drag & drop to upload a file'
|
178
|
+
}.merge(opts).tap do |options|
|
179
|
+
options[:method] = method.to_s
|
180
|
+
options[:box] = method.to_s.pluralize
|
181
|
+
options[:attachable_id] ||= (@object.try(:id) rescue nil)
|
182
|
+
options[:attachable_type] ||= @object.class.name.titleize.gsub(" ", "_").gsub('/', '_').downcase
|
183
|
+
|
184
|
+
# The logic for the AWS ACL is such that:
|
185
|
+
# 1.) If the :private or :aws_acl keys are set on the asset_box input, use those values
|
186
|
+
# 2.) If the :private or :public keys are set on the acts_as_asset_box declaration, use those values
|
187
|
+
# 3.) Fall back to default EffectiveAssets.aws_acl as per config file
|
188
|
+
|
189
|
+
uploader_private = (opts[:private] == true || opts[:public] == false || opts[:aws_acl] == EffectiveAssets::AWS_PRIVATE)
|
190
|
+
uploader_public = (opts[:private] == false || opts[:public] == true || opts[:aws_acl] == EffectiveAssets::AWS_PUBLIC)
|
191
|
+
object_private = ((@object.asset_boxes[method] == :private || @object.asset_boxes[method].first[:private] == true || @object.asset_boxes[method].first[:public] == false) rescue false)
|
192
|
+
object_public = ((@object.asset_boxes[method] == :public || @object.asset_boxes[method].first[:public] == true || @object.asset_boxes[method].first[:private] == false) rescue false)
|
193
|
+
|
194
|
+
if uploader_private
|
195
|
+
options[:aws_acl] = EffectiveAssets::AWS_PRIVATE
|
196
|
+
elsif uploader_public
|
197
|
+
options[:aws_acl] = EffectiveAssets::AWS_PUBLIC
|
198
|
+
elsif object_private
|
199
|
+
options[:aws_acl] = EffectiveAssets::AWS_PRIVATE
|
200
|
+
elsif object_public
|
201
|
+
options[:aws_acl] = EffectiveAssets::AWS_PUBLIC
|
202
|
+
else
|
203
|
+
options[:aws_acl] = EffectiveAssets.aws_acl
|
204
|
+
end
|
205
|
+
|
206
|
+
options[:uid] = "#{options[:attachable_type]}-#{options[:attachable_id]}-#{options[:method]}-#{Time.zone.now.to_f}".parameterize
|
207
|
+
options[:limit] = (options[:method] == options[:box] ? (options[:limit] || 10000) : 1)
|
208
|
+
end
|
209
|
+
end
|
210
|
+
end
|
@@ -4,15 +4,21 @@
|
|
4
4
|
if defined?(SimpleForm)
|
5
5
|
class AssetBoxInput < SimpleForm::Inputs::FileInput
|
6
6
|
def input(wrapper_options = nil)
|
7
|
-
|
7
|
+
AssetBox.new(object, object_name, template, attribute_name, options).to_html
|
8
8
|
end
|
9
9
|
end
|
10
10
|
elsif defined?(Formtastic)
|
11
11
|
class AssetBoxInput < Formtastic::Inputs::FileInput
|
12
12
|
def to_html
|
13
13
|
input_wrapping do
|
14
|
-
label_html <<
|
14
|
+
label_html << AssetBox.new(@object, @object_name, @template, @method, @options).to_html
|
15
15
|
end
|
16
16
|
end
|
17
17
|
end
|
18
|
+
else
|
19
|
+
class AssetBoxInput < Object
|
20
|
+
def to_html
|
21
|
+
'expected simpleform or formtastic'
|
22
|
+
end
|
23
|
+
end
|
18
24
|
end
|
File without changes
|
File without changes
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: effective_assets
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.11.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Code and Effect
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-11-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -133,6 +133,7 @@ files:
|
|
133
133
|
- MIT-LICENSE
|
134
134
|
- README.md
|
135
135
|
- active_admin/effective_assets.rb
|
136
|
+
- app/assets/config/effective_assets_manifest.js
|
136
137
|
- app/assets/images/effective_assets/icon_close.png
|
137
138
|
- app/assets/images/effective_assets/spinner.gif
|
138
139
|
- app/assets/images/mime-types/excel.jpg
|
@@ -142,7 +143,7 @@ files:
|
|
142
143
|
- app/assets/images/mime-types/video.png
|
143
144
|
- app/assets/images/mime-types/word.jpg
|
144
145
|
- app/assets/images/mime-types/zip.png
|
145
|
-
- app/assets/javascripts/effective/snippets/effective_asset.js.coffee
|
146
|
+
- app/assets/javascripts/effective/snippets/effective_asset.js.coffee
|
146
147
|
- app/assets/javascripts/effective_assets.js
|
147
148
|
- app/assets/javascripts/effective_assets/asset_box.js.coffee
|
148
149
|
- app/assets/javascripts/effective_assets/asset_box_dialog.js.coffee
|
@@ -170,15 +171,8 @@ files:
|
|
170
171
|
- app/models/effective/access_denied.rb
|
171
172
|
- app/models/effective/asset.rb
|
172
173
|
- app/models/effective/attachment.rb
|
173
|
-
- app/models/effective/
|
174
|
+
- app/models/effective/iframe_upload.rb
|
174
175
|
- app/models/effective/snippets/effective_asset.rb
|
175
|
-
- app/models/inputs/asset_box.rb
|
176
|
-
- app/models/inputs/asset_box_form_input.rb
|
177
|
-
- app/models/inputs/asset_box_formtastic_input.rb
|
178
|
-
- app/models/inputs/asset_box_input.rb
|
179
|
-
- app/models/inputs/asset_box_simple_form_input.rb
|
180
|
-
- app/models/validators/asset_box_length_validator.rb
|
181
|
-
- app/models/validators/asset_box_presence_validator.rb
|
182
176
|
- app/uploaders/effective_assets_uploader.rb
|
183
177
|
- app/uploaders/test_asset_uploader.rb
|
184
178
|
- app/views/active_admin/effective_assets/_edit.html.haml
|
@@ -201,12 +195,19 @@ files:
|
|
201
195
|
- lib/effective_assets/version.rb
|
202
196
|
- lib/generators/effective_assets/install_generator.rb
|
203
197
|
- lib/generators/templates/asset_uploader.rb
|
198
|
+
- lib/inputs/asset_box.rb
|
199
|
+
- lib/inputs/asset_box_form_input.rb
|
200
|
+
- lib/inputs/asset_box_formtastic_input.rb
|
201
|
+
- lib/inputs/asset_box_input.rb
|
202
|
+
- lib/inputs/asset_box_simple_form_input.rb
|
204
203
|
- lib/tasks/effective_assets_tasks.rake
|
204
|
+
- lib/validators/asset_box_length_validator.rb
|
205
|
+
- lib/validators/asset_box_presence_validator.rb
|
205
206
|
homepage: https://github.com/code-and-effect/effective_assets
|
206
207
|
licenses:
|
207
208
|
- MIT
|
208
209
|
metadata: {}
|
209
|
-
post_install_message:
|
210
|
+
post_install_message:
|
210
211
|
rdoc_options: []
|
211
212
|
require_paths:
|
212
213
|
- lib
|
@@ -221,9 +222,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
221
222
|
- !ruby/object:Gem::Version
|
222
223
|
version: '0'
|
223
224
|
requirements: []
|
224
|
-
|
225
|
-
|
226
|
-
signing_key:
|
225
|
+
rubygems_version: 3.1.2
|
226
|
+
signing_key:
|
227
227
|
specification_version: 4
|
228
228
|
summary: Upload images and files directly to AWS S3 with a custom form input then
|
229
229
|
seamlessly organize and attach them to any ActiveRecord object.
|
@@ -1,27 +0,0 @@
|
|
1
|
-
# This is a class used for the IFrame views
|
2
|
-
|
3
|
-
module Effective
|
4
|
-
class IframeUploads < ActiveRecord::Base
|
5
|
-
acts_as_asset_box :uploads
|
6
|
-
|
7
|
-
def initialize(items = nil)
|
8
|
-
super()
|
9
|
-
@column_types = {}
|
10
|
-
|
11
|
-
add_to_asset_box(:uploads, items)
|
12
|
-
end
|
13
|
-
|
14
|
-
def self.columns
|
15
|
-
@columns ||= []
|
16
|
-
end
|
17
|
-
|
18
|
-
def self.column_defaults
|
19
|
-
{}
|
20
|
-
end
|
21
|
-
|
22
|
-
def self.has_attribute?(*args)
|
23
|
-
false
|
24
|
-
end
|
25
|
-
|
26
|
-
end
|
27
|
-
end
|
@@ -1,213 +0,0 @@
|
|
1
|
-
module Inputs
|
2
|
-
class AssetBox
|
3
|
-
delegate :content_tag, :render, :current_user, :to => :@template
|
4
|
-
|
5
|
-
def initialize(object, object_name, template, method, opts)
|
6
|
-
@object = object
|
7
|
-
@object_name = object_name
|
8
|
-
@template = template
|
9
|
-
@options = initialize_options(method, opts)
|
10
|
-
end
|
11
|
-
|
12
|
-
def to_html
|
13
|
-
output = ''
|
14
|
-
output += header_html
|
15
|
-
|
16
|
-
if @options[:uploader] == :top
|
17
|
-
output += uploader_html
|
18
|
-
output += attachments_html
|
19
|
-
output += dialog_html if @options[:dialog]
|
20
|
-
else
|
21
|
-
output += attachments_html
|
22
|
-
output += dialog_html if @options[:dialog]
|
23
|
-
output += uploader_html if @options[:uploader]
|
24
|
-
end
|
25
|
-
|
26
|
-
output += footer_html
|
27
|
-
|
28
|
-
output.html_safe
|
29
|
-
end
|
30
|
-
|
31
|
-
private
|
32
|
-
|
33
|
-
def header_html
|
34
|
-
"<div id='asset-box-input-#{@options[:uid]}'
|
35
|
-
class='asset-box-input #{@options[:box]}'
|
36
|
-
data-box='#{@options[:box]}'
|
37
|
-
data-uploader='s3_#{@options[:uid]}'
|
38
|
-
data-limit='#{@options[:limit]}'
|
39
|
-
data-attachable-id='#{@options[:attachable_id]}'
|
40
|
-
data-attachable-type='#{@options[:attachable_type]}'
|
41
|
-
data-attachable-object-name='#{@object_name}'
|
42
|
-
data-attachment-style='#{@options[:attachment_style]}'
|
43
|
-
data-attachment-add-to='#{@options[:attachment_add_to]}'
|
44
|
-
data-attachment-actions='#{@options[:attachment_actions].to_json()}'
|
45
|
-
data-attachment-count='#{attachments.length}'
|
46
|
-
data-attachment-links='#{@options[:attachment_links]}'
|
47
|
-
data-over-limit-alerted='false'
|
48
|
-
data-aws-acl='#{@options[:aws_acl]}'
|
49
|
-
>".html_safe
|
50
|
-
end
|
51
|
-
|
52
|
-
def attachments_html
|
53
|
-
if @options[:attachment_style] == :table
|
54
|
-
attachments_table_html
|
55
|
-
elsif @options[:attachment_style] == :list
|
56
|
-
content_tag(:ul, build_values_html, :class => 'attachments')
|
57
|
-
else
|
58
|
-
content_tag(:div, build_values_html, :class => 'row attachments thumbnails')
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
|
-
def attachments_table_html
|
63
|
-
content_tag(:table, :class => 'table') do
|
64
|
-
head = attachments_table_head_html if @options[:table_filter_bar]
|
65
|
-
body = content_tag(:tbody, build_values_html, :class => 'attachments')
|
66
|
-
head ? head + body : body
|
67
|
-
end
|
68
|
-
end
|
69
|
-
|
70
|
-
def attachments_table_head_html
|
71
|
-
content_tag(:thead) do
|
72
|
-
content_tag(:tr) do
|
73
|
-
content_tag(:th, filter_bar_html, :colspan => 4)
|
74
|
-
end
|
75
|
-
end
|
76
|
-
end
|
77
|
-
|
78
|
-
def dialog_html
|
79
|
-
render(
|
80
|
-
:partial => 'asset_box_input/dialog',
|
81
|
-
:locals => {
|
82
|
-
:dialog_url => @options[:dialog_url]
|
83
|
-
}
|
84
|
-
).html_safe
|
85
|
-
end
|
86
|
-
|
87
|
-
def uploader_html
|
88
|
-
# Check that we have permission to upload.
|
89
|
-
asset = Effective::Asset.new(user_id: ((current_user.try(:id) || 1) rescue 1), upload_file: 'placeholder')
|
90
|
-
|
91
|
-
unless (EffectiveAssets.authorized?(@template.controller, :create, asset) rescue false)
|
92
|
-
@options[:btn_title] = 'Unable to upload. (cannot :create Effective::Asset)'
|
93
|
-
@options[:disabled] = true
|
94
|
-
end
|
95
|
-
|
96
|
-
html_class = [
|
97
|
-
('drop-files' if @options[:uploader_drop_files]),
|
98
|
-
((@options[:uploader_html] || {})[:class])
|
99
|
-
].compact.join(' ')
|
100
|
-
|
101
|
-
render(
|
102
|
-
:partial => 'asset_box_input/uploader',
|
103
|
-
:locals => {
|
104
|
-
:uid => @options[:uid],
|
105
|
-
:click_submit => @options[:click_submit],
|
106
|
-
:html_class => html_class,
|
107
|
-
:limit => @options[:limit],
|
108
|
-
:disabled => @options[:disabled],
|
109
|
-
:required => (@options[:required] == true && attachments.length == 0),
|
110
|
-
:file_types => @options[:file_types],
|
111
|
-
:progress_bar_partial => @options[:progress_bar_partial],
|
112
|
-
:drop_files => @options[:uploader_drop_files],
|
113
|
-
:drop_files_help_text => @options[:drop_files_help_text],
|
114
|
-
:aws_acl => @options[:aws_acl],
|
115
|
-
:btn_label => @options[:btn_label],
|
116
|
-
:btn_title => @options[:btn_title]
|
117
|
-
}
|
118
|
-
).html_safe
|
119
|
-
end
|
120
|
-
|
121
|
-
def filter_bar_html
|
122
|
-
"<input type='text' class='form-control filter-attachments' placeholder='Filter by title'>".html_safe
|
123
|
-
end
|
124
|
-
|
125
|
-
def build_values_html
|
126
|
-
attachment_partial =
|
127
|
-
case @options[:attachment_style]
|
128
|
-
when :table
|
129
|
-
'attachment_as_table'
|
130
|
-
when :list
|
131
|
-
'attachment_as_list'
|
132
|
-
when :thumbnail
|
133
|
-
'attachment_as_thumbnail'
|
134
|
-
when nil
|
135
|
-
'attachment_as_thumbnail'
|
136
|
-
else
|
137
|
-
raise "unknown AssetBox attachment_style: #{@options[:attachment_style]}. Valid options are :thumbnail, :list and :table"
|
138
|
-
end
|
139
|
-
|
140
|
-
render(
|
141
|
-
:partial => "asset_box_input/#{attachment_partial}",
|
142
|
-
:collection => attachments.reject { |attachment| attachment.marked_for_destruction? },
|
143
|
-
:as => :attachment,
|
144
|
-
:locals => {
|
145
|
-
:attachment_actions => @options[:attachment_actions].map { |action| action.to_s },
|
146
|
-
:attachment_links => @options[:attachment_links],
|
147
|
-
:limit => @options[:limit],
|
148
|
-
:disabled => @options[:disabled],
|
149
|
-
:attachable_object_name => @object_name
|
150
|
-
}
|
151
|
-
)
|
152
|
-
end
|
153
|
-
|
154
|
-
def footer_html
|
155
|
-
"</div>".html_safe
|
156
|
-
end
|
157
|
-
|
158
|
-
def attachments
|
159
|
-
@object.attachments.select { |attachment| attachment.box == @options[:box] }
|
160
|
-
end
|
161
|
-
|
162
|
-
def initialize_options(method, opts)
|
163
|
-
{
|
164
|
-
:uploader => true, # :top, :bottom, true or false
|
165
|
-
:uploader_drop_files => false,
|
166
|
-
:drop_files_help_text => 'Drop files here',
|
167
|
-
:progress_bar_partial => 'asset_box_input/progress_bar_template',
|
168
|
-
:attachment_style => :thumbnail, # :thumbnail, :table, or :list
|
169
|
-
:attachment_links => true,
|
170
|
-
:attachment_add_to => :bottom, # :bottom or :top (of attachments div)
|
171
|
-
:attachment_actions => [:remove], # or :insert, :delete, :remove
|
172
|
-
:table_filter_bar => false,
|
173
|
-
:dialog => false,
|
174
|
-
:dialog_url => @template.effective_assets.effective_assets_path,
|
175
|
-
:disabled => false,
|
176
|
-
:file_types => [:any],
|
177
|
-
:btn_label => 'Upload...',
|
178
|
-
:btn_title => 'Click or drag & drop to upload a file'
|
179
|
-
}.merge(opts).tap do |options|
|
180
|
-
options[:method] = method.to_s
|
181
|
-
options[:box] = method.to_s.pluralize
|
182
|
-
options[:attachable_id] ||= (@object.try(:id) rescue nil)
|
183
|
-
options[:attachable_type] ||= @object.class.name.titleize.gsub(" ", "_").gsub('/', '_').downcase
|
184
|
-
|
185
|
-
# The logic for the AWS ACL is such that:
|
186
|
-
# 1.) If the :private or :aws_acl keys are set on the asset_box input, use those values
|
187
|
-
# 2.) If the :private or :public keys are set on the acts_as_asset_box declaration, use those values
|
188
|
-
# 3.) Fall back to default EffectiveAssets.aws_acl as per config file
|
189
|
-
|
190
|
-
uploader_private = (opts[:private] == true || opts[:public] == false || opts[:aws_acl] == EffectiveAssets::AWS_PRIVATE)
|
191
|
-
uploader_public = (opts[:private] == false || opts[:public] == true || opts[:aws_acl] == EffectiveAssets::AWS_PUBLIC)
|
192
|
-
object_private = ((@object.asset_boxes[method] == :private || @object.asset_boxes[method].first[:private] == true || @object.asset_boxes[method].first[:public] == false) rescue false)
|
193
|
-
object_public = ((@object.asset_boxes[method] == :public || @object.asset_boxes[method].first[:public] == true || @object.asset_boxes[method].first[:private] == false) rescue false)
|
194
|
-
|
195
|
-
if uploader_private
|
196
|
-
options[:aws_acl] = EffectiveAssets::AWS_PRIVATE
|
197
|
-
elsif uploader_public
|
198
|
-
options[:aws_acl] = EffectiveAssets::AWS_PUBLIC
|
199
|
-
elsif object_private
|
200
|
-
options[:aws_acl] = EffectiveAssets::AWS_PRIVATE
|
201
|
-
elsif object_public
|
202
|
-
options[:aws_acl] = EffectiveAssets::AWS_PUBLIC
|
203
|
-
else
|
204
|
-
options[:aws_acl] = EffectiveAssets.aws_acl
|
205
|
-
end
|
206
|
-
|
207
|
-
options[:uid] = "#{options[:attachable_type]}-#{options[:attachable_id]}-#{options[:method]}-#{Time.zone.now.to_f}".parameterize
|
208
|
-
options[:limit] = (options[:method] == options[:box] ? (options[:limit] || 10000) : 1)
|
209
|
-
end
|
210
|
-
end
|
211
|
-
end
|
212
|
-
end
|
213
|
-
|