activeadmin_jfu_upload 0.1.1 → 0.1.4
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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ca82149adea2d383b8ad383d28c423e21fb59102
|
4
|
+
data.tar.gz: bc3aff2a1535e00a4c5f6a5b5ad4d33b42b78fda
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f98e70bd9749d7eb98fde0011587bc7600d130d87893eb228881afa8c18f92299feddc32b9d4c2c47782109560d99d5e36ba79440b69f8a0bcf63579539ccbda
|
7
|
+
data.tar.gz: 2198662a2d129cc6593cfcbd61caeff65acb7863c9e4af2e88f7f5f6f4a9c3dc243e044c99fce91991e75cd32456958c0de1650374c342eb9ca83f55e02ed9f1
|
data/README.md
CHANGED
@@ -48,11 +48,18 @@ Why 2 separated scripts? In this way you can include a different version of *jQu
|
|
48
48
|
end
|
49
49
|
```
|
50
50
|
|
51
|
+
```ruby
|
52
|
+
# Chuncked upload (chunk size: 100 Kb)
|
53
|
+
f.input :cover, as: :jfu_upload, hint: f.object.cover? ? image_tag( f.object.cover.url ) : '', input_html: { data: { url: jfu_upload_admin_article_path( resource.id ), options: { maxChunkSize: 100000 } } } unless f.object.new_record?
|
54
|
+
```
|
55
|
+
|
51
56
|
## Notes
|
52
57
|
|
53
|
-
|
58
|
+
- The string field for the upload is used to store temp data, so it could be necessary to make it bigger
|
59
|
+
|
60
|
+
- If you want to customize the upload action take a look [here](lib/activeadmin/jfu_upload/engine.rb)
|
54
61
|
|
55
|
-
Tested with CarrierWave uploader gem
|
62
|
+
- Tested only with CarrierWave uploader gem
|
56
63
|
|
57
64
|
## Do you like it? Star it!
|
58
65
|
|
@@ -2,10 +2,19 @@ $(document).ready( function() {
|
|
2
2
|
$('.jfu_upload_input').each(function () {
|
3
3
|
var options = {
|
4
4
|
dataType: 'json',
|
5
|
-
|
5
|
+
add: function(e, data) {
|
6
|
+
data.context = $(e.target).next().html('<li class="jfu_info jfu_loading"> Uploading... </li>');
|
7
|
+
data.submit();
|
8
|
+
data.context.focus();
|
9
|
+
},
|
10
|
+
done: function(e, data) {
|
6
11
|
if( data.result.result == 1 ) {
|
7
|
-
$(e.target).next().html('<li class="
|
12
|
+
$(e.target).next().html('<li class="jfu_info jfu_done"> Upload complete! </li>'); // data.result.file_name
|
8
13
|
}
|
14
|
+
},
|
15
|
+
progressall: function(e, data) {
|
16
|
+
var progress = parseInt(data.loaded / data.total * 100, 10);
|
17
|
+
$(e.target).next().html('<li class="jfu_info jfu_progress" style="width:' + progress + '%"> ' + progress + '% ... </li>');
|
9
18
|
}
|
10
19
|
};
|
11
20
|
options = $.extend({}, options, $(this).data('options'));
|
@@ -10,3 +10,15 @@ body.active_admin form
|
|
10
10
|
.jfu_upload_input
|
11
11
|
padding: 10px
|
12
12
|
width: 100%
|
13
|
+
.jfu_done
|
14
|
+
color: #482
|
15
|
+
.jfu_info
|
16
|
+
box-sizing: border-box
|
17
|
+
display: inline-block
|
18
|
+
padding: 5px 10px
|
19
|
+
.jfu_loading
|
20
|
+
color: #d50
|
21
|
+
.jfu_progress
|
22
|
+
color: #000
|
23
|
+
background: #fb1
|
24
|
+
min-width: 50px
|
@@ -17,12 +17,23 @@ module ActiveAdmin
|
|
17
17
|
if m
|
18
18
|
pos = m[1].to_i
|
19
19
|
if pos == 0
|
20
|
-
resource.update field => param
|
20
|
+
# resource.update field => param
|
21
|
+
dir = Rails.root.join('tmp', 'uploads')
|
22
|
+
dir.mkdir unless File.exists?(dir)
|
23
|
+
field_data = { original_filename: param.original_filename, tempfile: dir.join(param.tempfile).to_s } # alternative: "#{resource.class.to_s.tableize}_#{resource.id}_#{Time.now.to_i}"
|
24
|
+
resource.update_column field, YAML::dump( field_data )
|
21
25
|
else
|
22
|
-
|
26
|
+
field_data = YAML::load resource.read_attribute(field)
|
27
|
+
# File.open( resource.try( field ).try( :path ), 'ab' ) { |f| f.write( param.read ) }
|
23
28
|
end
|
29
|
+
File.open(field_data[:tempfile], 'ab') { |f| f.write(param.read) }
|
24
30
|
if ( m[2].to_i + 1 ) == m[3].to_i
|
25
|
-
|
31
|
+
path = Pathname.new field_data[:tempfile]
|
32
|
+
dst = path.dirname.join(field_data[:original_filename]).to_s
|
33
|
+
File.rename(field_data[:tempfile], dst)
|
34
|
+
resource.send("#{field}=", File.open(dst))
|
35
|
+
resource.save
|
36
|
+
response = { result: 1, pos: m[3].to_i, file_name: resource.try(field).try(:url) }
|
26
37
|
else
|
27
38
|
response = { result: 2, position: pos }
|
28
39
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: activeadmin_jfu_upload
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mattia Roccoberton
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-04-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activeadmin
|