effective_assets 1.9.0 → 1.9.1
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 +4 -4
- data/app/assets/javascripts/effective_assets/asset_box_initialize.js.coffee +15 -0
- data/app/assets/stylesheets/effective_assets/_asset_box_input.scss +6 -0
- data/app/controllers/effective/s3_uploads_controller.rb +3 -3
- data/app/helpers/effective_assets_s3_helper.rb +10 -3
- data/app/models/inputs/asset_box.rb +13 -3
- data/app/uploaders/effective_assets_uploader.rb +1 -1
- data/app/views/asset_box_input/_progress_bar_template.html.haml +3 -3
- data/app/views/asset_box_input/_uploader.html.haml +8 -23
- data/lib/effective_assets/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 366a2e6fe96f2009b7a8b5fde08d6c3bcb0ab73c
|
4
|
+
data.tar.gz: e4a72c773c655f15c672fce235e20858ee9343d0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 95e1c356d67092ef2c5cd95cebc822e2d9809e38d2683885d9d35959abd6bbc951a0fd8509d2a5f1ca95db3f6c56f8575f4378a36c9bcb1e462997c657ac211f
|
7
|
+
data.tar.gz: 7e0fb528bc1c149f315a4048268fe9c2634ae518bab0580baf2d2a38c712c73d6e2cc35a9afa59308c74705a1ecd221537d735502fa208ed1d753716cc15e362
|
@@ -0,0 +1,15 @@
|
|
1
|
+
initialize = ->
|
2
|
+
$('div.asset-box-uploader:not(.initialized)').each (i, element) ->
|
3
|
+
element = $(element)
|
4
|
+
options = element.data('input-js-options') || {}
|
5
|
+
|
6
|
+
options['progress_bar_target'] = $(element).siblings('.uploads').first()
|
7
|
+
options['progress_bar_template'] = $(element).children("script[type='text/x-tmpl']").first()
|
8
|
+
options['dropZone'] = $(element).parent()
|
9
|
+
|
10
|
+
element.addClass('initialized').S3Uploader(options)
|
11
|
+
|
12
|
+
$ -> initialize()
|
13
|
+
$(document).on 'page:change', -> initialize()
|
14
|
+
$(document).on 'turbolinks:load', -> initialize()
|
15
|
+
$(document).on 'cocoon:after-insert', -> initialize()
|
@@ -14,14 +14,14 @@ module Effective
|
|
14
14
|
|
15
15
|
def create
|
16
16
|
# Here we initialize an empty placeholder Asset, so we can reserve the ID
|
17
|
-
@asset = Effective::Asset.new(:
|
17
|
+
@asset = Effective::Asset.new(user_id: ((current_user.try(:id) || 1) rescue 1), upload_file: 'placeholder')
|
18
18
|
@asset.extra = params[:extra] if params[:extra].kind_of?(Hash)
|
19
19
|
|
20
20
|
EffectiveAssets.authorized?(self, :create, @asset)
|
21
21
|
|
22
22
|
begin
|
23
23
|
@asset.save!
|
24
|
-
render(:
|
24
|
+
render(body: {:id => @asset.id, :s3_key => asset_s3_key(@asset)}.to_json, :status => 200)
|
25
25
|
rescue => e
|
26
26
|
render(:body => e.message, :status => 500)
|
27
27
|
end
|
@@ -30,7 +30,7 @@ module Effective
|
|
30
30
|
def update
|
31
31
|
@asset = Effective::Asset.find(params[:id])
|
32
32
|
|
33
|
-
EffectiveAssets.authorized?(self, :
|
33
|
+
EffectiveAssets.authorized?(self, :create, @asset)
|
34
34
|
|
35
35
|
unless params[:skip_update] # This is useful for the acts_as_asset_box Attach action
|
36
36
|
if update_placeholder_asset(@asset, params) == false
|
@@ -2,12 +2,19 @@ module EffectiveAssetsS3Helper
|
|
2
2
|
|
3
3
|
def s3_uploader_fields(options = {})
|
4
4
|
S3Uploader.new(options).fields.map do |name, value|
|
5
|
-
hidden_field_tag(name, value, :
|
5
|
+
hidden_field_tag(name, value, disabled: 'disabled')
|
6
6
|
end.join.html_safe
|
7
7
|
end
|
8
8
|
|
9
|
-
def
|
10
|
-
|
9
|
+
def s3_uploader_input_js_options(options = {})
|
10
|
+
{
|
11
|
+
url: (Effective::Asset.s3_base_path.chomp('/') + '/'),
|
12
|
+
remove_completed_progress_bar: true,
|
13
|
+
allow_multiple_files: (options[:limit].to_i > 1),
|
14
|
+
file_types: Array(options[:file_types]).flatten.join('|').to_s,
|
15
|
+
create_asset_url: effective_assets.s3_uploads_url,
|
16
|
+
update_asset_url: "#{effective_assets.s3_uploads_url}/:id",
|
17
|
+
}.to_json()
|
11
18
|
end
|
12
19
|
|
13
20
|
# Copied and modified from https://github.com/waynehoover/s3_direct_upload/blob/master/lib/s3_direct_upload/form_helper.rb
|
@@ -1,6 +1,6 @@
|
|
1
1
|
module Inputs
|
2
2
|
class AssetBox
|
3
|
-
delegate :content_tag, :render, :to => :@template
|
3
|
+
delegate :content_tag, :render, :current_user, :to => :@template
|
4
4
|
|
5
5
|
def initialize(object, object_name, template, method, opts)
|
6
6
|
@object = object
|
@@ -85,6 +85,14 @@ module Inputs
|
|
85
85
|
end
|
86
86
|
|
87
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
|
+
|
88
96
|
render(
|
89
97
|
:partial => 'asset_box_input/uploader',
|
90
98
|
:locals => {
|
@@ -97,7 +105,8 @@ module Inputs
|
|
97
105
|
:drop_files => @options[:uploader_drop_files],
|
98
106
|
:drop_files_help_text => @options[:drop_files_help_text],
|
99
107
|
:aws_acl => @options[:aws_acl],
|
100
|
-
:btn_label => @options[:btn_label]
|
108
|
+
:btn_label => @options[:btn_label],
|
109
|
+
:btn_title => @options[:btn_title]
|
101
110
|
}
|
102
111
|
).html_safe
|
103
112
|
end
|
@@ -158,7 +167,8 @@ module Inputs
|
|
158
167
|
:dialog_url => @template.effective_assets.effective_assets_path,
|
159
168
|
:disabled => false,
|
160
169
|
:file_types => [:any],
|
161
|
-
:btn_label =>
|
170
|
+
:btn_label => 'Upload...',
|
171
|
+
:btn_title => 'Click or drag & drop to upload a file'
|
162
172
|
}.merge(opts).tap do |options|
|
163
173
|
options[:method] = method.to_s
|
164
174
|
options[:box] = method.to_s.pluralize
|
@@ -52,7 +52,7 @@ class EffectiveAssetsUploader < CarrierWave::Uploader::Base
|
|
52
52
|
end
|
53
53
|
|
54
54
|
def image?(new_file)
|
55
|
-
new_file.present?
|
55
|
+
new_file.present? && (new_file.uploader.model.image? rescue false)
|
56
56
|
end
|
57
57
|
|
58
58
|
def calculate_versions_info
|
@@ -1,8 +1,8 @@
|
|
1
|
-
%script{:
|
1
|
+
%script{type: 'text/x-tmpl'}
|
2
2
|
.upload
|
3
3
|
= "{%=o.name%}"
|
4
4
|
.progress
|
5
5
|
%span
|
6
|
-
= image_tag('effective_assets/spinner.gif', :
|
6
|
+
= image_tag('effective_assets/spinner.gif', class: 'spinner')
|
7
7
|
Uploading...
|
8
|
-
.bar{:
|
8
|
+
.bar{style: 'width: 0%'}
|
@@ -1,37 +1,22 @@
|
|
1
1
|
.uploads
|
2
|
-
.asset-box-uploader{:
|
3
|
-
= s3_uploader_fields(:
|
2
|
+
.asset-box-uploader{id: "s3_#{uid}", class: ('drop-files' if drop_files), 'data-input-js-options': s3_uploader_input_js_options(limit: limit, file_types: file_types) }
|
3
|
+
= s3_uploader_fields(aws_acl: aws_acl)
|
4
4
|
|
5
5
|
- if drop_files
|
6
6
|
%p= drop_files_help_text
|
7
7
|
|
8
|
-
%span.btn.btn-default.fileinput-button
|
8
|
+
%span.btn.btn-default.fileinput-button{class: ('disabled' if disabled)}
|
9
9
|
%i.glyphicon.glyphicon-upload
|
10
10
|
%span= btn_label
|
11
11
|
- if limit > 1
|
12
12
|
- if required
|
13
|
-
%input.asset-box-uploader-fileinput{type: 'file', name: 'file', id: uid, multiple: 'multiple', disabled: disabled, required: true}
|
13
|
+
%input.asset-box-uploader-fileinput{type: 'file', name: 'file', id: uid, multiple: 'multiple', disabled: disabled, required: true, title: btn_title}
|
14
14
|
- else
|
15
|
-
%input.asset-box-uploader-fileinput{type: 'file', name: 'file', id: uid, multiple: 'multiple', disabled: disabled}
|
15
|
+
%input.asset-box-uploader-fileinput{type: 'file', name: 'file', id: uid, multiple: 'multiple', disabled: disabled, title: btn_title}
|
16
16
|
- else
|
17
17
|
- if required
|
18
|
-
%input.asset-box-uploader-fileinput{type: 'file', name: 'file', id: uid, disabled: disabled, required: true}
|
18
|
+
%input.asset-box-uploader-fileinput{type: 'file', name: 'file', id: uid, disabled: disabled, required: true, title: btn_title}
|
19
19
|
- else
|
20
|
-
%input.asset-box-uploader-fileinput{type: 'file', name: 'file', id: uid, disabled: disabled}
|
20
|
+
%input.asset-box-uploader-fileinput{type: 'file', name: 'file', id: uid, disabled: disabled, title: btn_title}
|
21
21
|
|
22
|
-
= render :
|
23
|
-
|
24
|
-
%script{:type => 'text/javascript'}
|
25
|
-
:erb
|
26
|
-
|
27
|
-
$("#s3_<%= uid %>").S3Uploader({
|
28
|
-
url: '<%= s3_uploader_url %>',
|
29
|
-
progress_bar_target: $("#s3_<%= uid %>").siblings('.uploads').first(),
|
30
|
-
progress_bar_template: $("#s3_<%= uid %>").children("script[type='text/x-tmpl']").first(),
|
31
|
-
remove_completed_progress_bar: true,
|
32
|
-
allow_multiple_files: <%= limit > 1 %>,
|
33
|
-
file_types: '<%= [file_types].flatten.join('|').to_s %>',
|
34
|
-
create_asset_url: '<%= effective_assets.s3_uploads_url %>',
|
35
|
-
update_asset_url: '<%= effective_assets.s3_uploads_url %>/:id',
|
36
|
-
dropZone: $("#s3_<%= uid %>").parent()
|
37
|
-
});
|
22
|
+
= render partial: progress_bar_partial
|
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.9.
|
4
|
+
version: 1.9.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Code and Effect
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-01-
|
11
|
+
date: 2017-01-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -162,6 +162,7 @@ files:
|
|
162
162
|
- app/assets/javascripts/effective_assets/asset_box_dialog.js.coffee
|
163
163
|
- app/assets/javascripts/effective_assets/asset_box_drag_and_drop.js.coffee
|
164
164
|
- app/assets/javascripts/effective_assets/asset_box_filtering.js.coffee
|
165
|
+
- app/assets/javascripts/effective_assets/asset_box_initialize.js.coffee
|
165
166
|
- app/assets/javascripts/effective_assets/asset_box_sorting.js.coffee
|
166
167
|
- app/assets/javascripts/effective_assets/cocoon.js.coffee
|
167
168
|
- app/assets/javascripts/effective_assets/jquery_ui_sortable.js
|