activeadmin-qiniu_input 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 +7 -0
- data/MIT-LICENSE +20 -0
- data/README.md +85 -0
- data/Rakefile +36 -0
- data/app/assets/images/active_admin/qiniu_input/upload.png +0 -0
- data/app/assets/javascripts/active_admin/qiniu_input/index.js +2 -0
- data/app/assets/javascripts/active_admin/qiniu_input/upload_image.js +62 -0
- data/app/assets/javascripts/active_admin/qiniu_input/upload_video.js +120 -0
- data/app/assets/stylesheets/active_admin/qiniu_input/index.scss +2 -0
- data/app/assets/stylesheets/active_admin/qiniu_input/upload_image.scss +67 -0
- data/app/assets/stylesheets/active_admin/qiniu_input/upload_video.scss +91 -0
- data/config/locales/en.yml +10 -0
- data/config/locales/zh-CN.yml +10 -0
- data/lib/active_admin/inputs/qiniu_image_input.rb +29 -0
- data/lib/active_admin/inputs/qiniu_video_input.rb +41 -0
- data/lib/active_admin/qiniu_input/engine.rb +6 -0
- data/lib/active_admin/qiniu_input/extend.rb +35 -0
- data/lib/active_admin/qiniu_input/version.rb +5 -0
- data/lib/activeadmin-qiniu_input.rb +14 -0
- data/lib/generators/active_admin/qiniu_input/install/install_generator.rb +38 -0
- data/lib/generators/active_admin/qiniu_input/install/templates/initializer.rb +2 -0
- metadata +124 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 23b9c21c27aaa7396f9b86c702bd3f426326da4a
|
4
|
+
data.tar.gz: 5df7c9794bb81d394aec7ef644e00e6a47309d9a
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 15c2bc8b65aa9b956d84fc77423f8dd9b8654be5b7a9945c705c1bf9b9c3bdb1a8c566a2eaa0dc5555e15ef56b033ab920ebe435de3babc6b8edf6c2df6dac3d
|
7
|
+
data.tar.gz: c9eac3e0105f838c79c41d76e86d5c5015ceafd13aba426d851b95b151a36fb913788639fdf06c3a41e8a978b9814f1d4f99cfd2c87727a622cf93e78351b246
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2017 roger
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,85 @@
|
|
1
|
+
# ActiveAdmin::QiniuInput
|
2
|
+
|
3
|
+
ActiveAdmin::QiniuInput provides two inputs for [activeadmin](https://github.com/activeadmin/activeadmin) when we using [qiniu](https://github.com/qiniu/ruby-sdk). They have been used in our company [Beansmile](http://www.beansmile.com/) for several times. And now we open-source them, hoping they can help you.
|
4
|
+
|
5
|
+
* qiniu_image
|
6
|
+
|
7
|
+

|
8
|
+
|
9
|
+
* qiniu_video
|
10
|
+
|
11
|
+

|
12
|
+
|
13
|
+
## Installation
|
14
|
+
Add this line to your application's Gemfile:
|
15
|
+
|
16
|
+
```ruby
|
17
|
+
gem 'activeadmin-qiniu_input'
|
18
|
+
```
|
19
|
+
|
20
|
+
And then execute:
|
21
|
+
```bash
|
22
|
+
$ bundle
|
23
|
+
```
|
24
|
+
|
25
|
+
Or install it yourself as:
|
26
|
+
```bash
|
27
|
+
$ gem install activeadmin-qiniu_input
|
28
|
+
```
|
29
|
+
|
30
|
+
## Usage
|
31
|
+
|
32
|
+
* Run the generator:
|
33
|
+
|
34
|
+
```bash
|
35
|
+
$ rails g active_admin:qiniu_input:install
|
36
|
+
```
|
37
|
+
Check [here](docs/install_generator.md) to see more information about this generator.
|
38
|
+
|
39
|
+
* To use this gem, we need you to implement your API with which we can fetch the [Qiniu meta](https://developer.qiniu.com/kodo/manual/1208/upload-token). With the use of [Qiniu gem](https://github.com/qiniu/ruby-sdk), it should be easy. Please refer to our [test controller code](test/dummy/app/controllers/application_controller.rb).
|
40
|
+
|
41
|
+
* Use your api to change `qiniu_meta_url` in `config/initializers/active_admin/qiniu_input.rb`.
|
42
|
+
|
43
|
+
```ruby
|
44
|
+
ActiveAdmin::QiniuInput.qiniu_meta_url = "/your_qiniu_meta_url"
|
45
|
+
```
|
46
|
+
|
47
|
+
* use our inputs in your ActiveAdmin form. Use them like this:
|
48
|
+
|
49
|
+
```ruby
|
50
|
+
form do |f|
|
51
|
+
f.inputs do
|
52
|
+
f.input :image_url, as: :qiniu_image
|
53
|
+
f.input :video_url, as: :qiniu_video
|
54
|
+
end
|
55
|
+
f.actions
|
56
|
+
end
|
57
|
+
```
|
58
|
+
|
59
|
+
* we also add `qiniu_image_column`, `qiniu_video_column`, `qiniu_image_row` and `qiniu_video_row` dsl to show images and videos.
|
60
|
+
|
61
|
+
```ruby
|
62
|
+
index do
|
63
|
+
column :title
|
64
|
+
qiniu_image_column :image_url
|
65
|
+
qiniu_video_column :video_url
|
66
|
+
actions
|
67
|
+
end
|
68
|
+
|
69
|
+
show do
|
70
|
+
attributes_table do
|
71
|
+
row :id
|
72
|
+
row :title
|
73
|
+
qiniu_image_row :image_url
|
74
|
+
qiniu_video_row :video_url
|
75
|
+
row :created_at
|
76
|
+
row :updated_at
|
77
|
+
end
|
78
|
+
end
|
79
|
+
```
|
80
|
+
|
81
|
+
## Contributing
|
82
|
+
Please open an issue or a pull request to Contribute.
|
83
|
+
|
84
|
+
## License
|
85
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
begin
|
2
|
+
require 'bundler/setup'
|
3
|
+
rescue LoadError
|
4
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
5
|
+
end
|
6
|
+
|
7
|
+
require 'rdoc/task'
|
8
|
+
|
9
|
+
RDoc::Task.new(:rdoc) do |rdoc|
|
10
|
+
rdoc.rdoc_dir = 'rdoc'
|
11
|
+
rdoc.title = 'ActiveAdmin::QiniuInput'
|
12
|
+
rdoc.options << '--line-numbers'
|
13
|
+
rdoc.rdoc_files.include('README.md')
|
14
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
15
|
+
end
|
16
|
+
|
17
|
+
APP_RAKEFILE = File.expand_path("../test/dummy/Rakefile", __FILE__)
|
18
|
+
load 'rails/tasks/engine.rake'
|
19
|
+
|
20
|
+
|
21
|
+
load 'rails/tasks/statistics.rake'
|
22
|
+
|
23
|
+
|
24
|
+
|
25
|
+
require 'bundler/gem_tasks'
|
26
|
+
|
27
|
+
require 'rake/testtask'
|
28
|
+
|
29
|
+
Rake::TestTask.new(:test) do |t|
|
30
|
+
t.libs << 'test'
|
31
|
+
t.pattern = 'test/**/*_test.rb'
|
32
|
+
t.verbose = false
|
33
|
+
end
|
34
|
+
|
35
|
+
|
36
|
+
task default: :test
|
Binary file
|
@@ -0,0 +1,62 @@
|
|
1
|
+
$(document).ready(function() {
|
2
|
+
var changeHandler = function(event) {
|
3
|
+
if (event.target.files[0]) {
|
4
|
+
var _that = this;
|
5
|
+
$(_that).siblings('.upload-span').text($(_that).data('uploading-text'));
|
6
|
+
getQiniuMeta(_that, event);
|
7
|
+
}
|
8
|
+
};
|
9
|
+
|
10
|
+
$(document).on('change', '.add-single-picture .add-image', changeHandler)
|
11
|
+
|
12
|
+
function getQiniuMeta(_that, event) {
|
13
|
+
$.ajax({
|
14
|
+
type: 'GET',
|
15
|
+
url: $(_that).data('qiniu-meta-url'),
|
16
|
+
success: function(data) {
|
17
|
+
var token = data.token;
|
18
|
+
var bucketDomain = data.bucket_domain;
|
19
|
+
var bucketDomain = data.bucket_domain;
|
20
|
+
if (token !== "") {
|
21
|
+
uploadImageToQiniu(token, event, function(response) {
|
22
|
+
var url = "http://" + bucketDomain + "/" + response.key;
|
23
|
+
var imageShowEle = $(_that).parent().find('.image-show');
|
24
|
+
$(_that).siblings('.upload-span').text($(_that).data('upload-span-text'));
|
25
|
+
if(imageShowEle.length > 0) {
|
26
|
+
imageShowEle.attr('src', url);
|
27
|
+
} else {
|
28
|
+
$(_that).before("<img src='" + url + "' class='image-show'/>");
|
29
|
+
}
|
30
|
+
$(_that).parent().find(".single-image").val(url);
|
31
|
+
});
|
32
|
+
}
|
33
|
+
}
|
34
|
+
});
|
35
|
+
}
|
36
|
+
|
37
|
+
function uploadImageToQiniu(token, event, callbackFunc) {
|
38
|
+
var formData = new FormData();
|
39
|
+
formData.append('token', token);
|
40
|
+
formData.append('file', event.target.files[0]);
|
41
|
+
|
42
|
+
$.ajax({
|
43
|
+
url: "http://up-z2.qiniu.com",
|
44
|
+
data: formData,
|
45
|
+
dataType: "json",
|
46
|
+
processData: false,
|
47
|
+
contentType: false,
|
48
|
+
type: 'POST',
|
49
|
+
xhr: function() {
|
50
|
+
var xhr = $.ajaxSettings.xhr();
|
51
|
+
xhr.upload.onprogress = function (evt) {
|
52
|
+
if (evt.lengthComputable) {
|
53
|
+
// setProgressbar($progressbar, evt.loaded, evt.total);
|
54
|
+
console.log(evt.total)
|
55
|
+
}
|
56
|
+
};
|
57
|
+
return xhr;
|
58
|
+
},
|
59
|
+
success: callbackFunc
|
60
|
+
});
|
61
|
+
}
|
62
|
+
})
|
@@ -0,0 +1,120 @@
|
|
1
|
+
$(document).ready(function() {
|
2
|
+
|
3
|
+
$(document).on('click', '.upload_video', function(e){
|
4
|
+
e.preventDefault();
|
5
|
+
fileUpload($(this).siblings(".video_file"), afterFileUpload);
|
6
|
+
})
|
7
|
+
|
8
|
+
$(document).on('change', '.video_file', function() {
|
9
|
+
var file = $(this)[0].files[0];
|
10
|
+
$(this).siblings('.file-name').text(file.name);
|
11
|
+
$(this).siblings(".upload_video").removeAttr('disabled');
|
12
|
+
});
|
13
|
+
|
14
|
+
function afterFileUpload ($self, url) {
|
15
|
+
loadVideo($self, url);
|
16
|
+
fetchDuration($self, url);
|
17
|
+
}
|
18
|
+
|
19
|
+
function fetchDuration($self, url) {
|
20
|
+
var videoName = $self.siblings('.video_field').attr('name')
|
21
|
+
if (videoName.indexOf('[chapters_attributes]') >= 0) {
|
22
|
+
var durationName = videoName.replace('[video_url]', '[duration]')
|
23
|
+
var durationInput = $('input[name="' + durationName + '"]')
|
24
|
+
if (durationInput.length == 1) {
|
25
|
+
$.get(url + '?avinfo', function(info) {
|
26
|
+
durationInput.val(info.format.duration)
|
27
|
+
})
|
28
|
+
}
|
29
|
+
}
|
30
|
+
}
|
31
|
+
|
32
|
+
function loadVideo($self, url) {
|
33
|
+
$self.siblings('.video_field').val(url);
|
34
|
+
$hints = $self.parents('.video-wrapper').find('.inline-hints');
|
35
|
+
if ($hints.find('.video').length > 1) {
|
36
|
+
$hints.find('.video').attr('src', url);
|
37
|
+
} else {
|
38
|
+
$hints.html("<video src=" + url + " controls='controls' controlsList='nodownload' preload='auto'></video>")
|
39
|
+
}
|
40
|
+
}
|
41
|
+
|
42
|
+
function fileUpload($self, callback) {
|
43
|
+
var $progressbar = $self.parents('.upload-btn').next('.progressbar');
|
44
|
+
var files = $self[0].files;
|
45
|
+
var accept = $self.attr("accept").split("/")[0]
|
46
|
+
if (files.length > 0){
|
47
|
+
var file = files[0];
|
48
|
+
if(file.type.startsWith(accept)) {
|
49
|
+
$self.attr("disabled", true);
|
50
|
+
initProgressbar($progressbar, file);
|
51
|
+
|
52
|
+
$.ajax({
|
53
|
+
type: 'GET',
|
54
|
+
data: { type: $self.data('type') },
|
55
|
+
url: $self.data('qiniu-meta-url'),
|
56
|
+
success: function(data) {
|
57
|
+
var token = data.token;
|
58
|
+
var bucketDomain = data.bucket_domain;
|
59
|
+
if (token !== "") {
|
60
|
+
qiniuUpload(file, token, bucketDomain, $self, $progressbar, callback);
|
61
|
+
}
|
62
|
+
}
|
63
|
+
});
|
64
|
+
} else {
|
65
|
+
alert($self.data('unsupported-format'));
|
66
|
+
}
|
67
|
+
}
|
68
|
+
}
|
69
|
+
|
70
|
+
function qiniuUpload(f, token, bucketDomain, $self, $progressbar, callback) {
|
71
|
+
var formData;
|
72
|
+
formData = new FormData();
|
73
|
+
formData.append('token', token);
|
74
|
+
formData.append('file', f);
|
75
|
+
|
76
|
+
$.ajax({
|
77
|
+
url: "http://up-z2.qiniu.com",
|
78
|
+
data: formData,
|
79
|
+
dataType: "json",
|
80
|
+
processData: false,
|
81
|
+
contentType: false,
|
82
|
+
type: 'POST',
|
83
|
+
xhr: function() {
|
84
|
+
var xhr = $.ajaxSettings.xhr();
|
85
|
+
xhr.upload.onprogress = function (evt) {
|
86
|
+
if (evt.lengthComputable) {
|
87
|
+
setProgressbar($progressbar, evt.loaded, evt.total);
|
88
|
+
}
|
89
|
+
};
|
90
|
+
return xhr;
|
91
|
+
},
|
92
|
+
success: function(data) {
|
93
|
+
$progressbar.fadeOut();
|
94
|
+
$self.removeAttr("disabled");
|
95
|
+
$(this).siblings(".upload_video").attr('disabled', 'disabled');
|
96
|
+
var url = "http://" + bucketDomain + "/" + data.key;
|
97
|
+
callback($self, url);
|
98
|
+
}
|
99
|
+
});
|
100
|
+
}
|
101
|
+
|
102
|
+
function initProgressbar($progressbar, file) {
|
103
|
+
$progressbar.find('.name').text(file.name);
|
104
|
+
$progressbar.find('.file-size').text(calculateFileSize(file.size));
|
105
|
+
$progressbar.find('.bar').css('width', '0px');
|
106
|
+
$progressbar.fadeIn();
|
107
|
+
}
|
108
|
+
|
109
|
+
function setProgressbar($progressbar, loaded, total) {
|
110
|
+
var loadedText = calculateFileSize(loaded);
|
111
|
+
var percentComplete = Math.round(loaded * 100 / total) + '%';
|
112
|
+
$progressbar.find('.percentage').text(percentComplete);
|
113
|
+
$progressbar.find('.loaded').text(loadedText);
|
114
|
+
$progressbar.find('.bar').css('width', percentComplete);
|
115
|
+
}
|
116
|
+
|
117
|
+
function calculateFileSize(size) {
|
118
|
+
return (Math.round(size * 100 / (1024 * 1024)) / 100).toString()
|
119
|
+
}
|
120
|
+
})
|
@@ -0,0 +1,67 @@
|
|
1
|
+
.qiniu-image-input {
|
2
|
+
.size-hints {
|
3
|
+
margin-left: 20%;
|
4
|
+
color: #8494a8;
|
5
|
+
}
|
6
|
+
|
7
|
+
.add-single-picture {
|
8
|
+
height: 150px;
|
9
|
+
line-height: 210px;
|
10
|
+
width: 150px;
|
11
|
+
background-color: white;
|
12
|
+
text-align: center;
|
13
|
+
display: inline-block;
|
14
|
+
border-radius: 10px;
|
15
|
+
border: 1px solid #eee;
|
16
|
+
position: relative;
|
17
|
+
vertical-align: top;
|
18
|
+
img {
|
19
|
+
width: 100%;
|
20
|
+
height: 100%;
|
21
|
+
&:hover {
|
22
|
+
cursor: pointer;
|
23
|
+
};
|
24
|
+
}
|
25
|
+
.hidden-input {
|
26
|
+
display: none;
|
27
|
+
}
|
28
|
+
&:hover {
|
29
|
+
background-color: black;
|
30
|
+
opacity: 0.4;
|
31
|
+
border-radius: 10px;
|
32
|
+
span {
|
33
|
+
color: white;
|
34
|
+
}
|
35
|
+
.add-images, .add-image {
|
36
|
+
cursor: pointer;
|
37
|
+
}
|
38
|
+
}
|
39
|
+
.add-images, .add-image {
|
40
|
+
opacity: 0;
|
41
|
+
display: inline-block;
|
42
|
+
width: 100%;
|
43
|
+
height: 100%;
|
44
|
+
vertical-align: top;
|
45
|
+
position: absolute;
|
46
|
+
z-index: 999;
|
47
|
+
left: 0;
|
48
|
+
}
|
49
|
+
.upload-icon {
|
50
|
+
left: 50%;
|
51
|
+
top: 50%;
|
52
|
+
width: 36px;
|
53
|
+
height: 36px;
|
54
|
+
position: absolute;
|
55
|
+
display: inline-block;
|
56
|
+
background-size: 122px;
|
57
|
+
transform: translate(-50%, -50%);
|
58
|
+
background: image-url("active_admin/qiniu_input/upload.png") no-repeat left top;
|
59
|
+
}
|
60
|
+
.upload-span {
|
61
|
+
left: 50%;
|
62
|
+
top: 60%;
|
63
|
+
position: absolute;
|
64
|
+
transform: translate(-50%, -50%);
|
65
|
+
}
|
66
|
+
}
|
67
|
+
}
|
@@ -0,0 +1,91 @@
|
|
1
|
+
.video-wrapper {
|
2
|
+
.hidden-input {
|
3
|
+
display: none;
|
4
|
+
}
|
5
|
+
|
6
|
+
.inline-hints {
|
7
|
+
margin-top: 10px;
|
8
|
+
video {
|
9
|
+
max-height: 450px;
|
10
|
+
max-width: 960px;
|
11
|
+
}
|
12
|
+
}
|
13
|
+
|
14
|
+
.upload-btn {
|
15
|
+
width: 80%;
|
16
|
+
margin-left: 20%;
|
17
|
+
position: relative;
|
18
|
+
|
19
|
+
.video_file {
|
20
|
+
opacity: 0;
|
21
|
+
display: inline-block;
|
22
|
+
width: 12%;
|
23
|
+
height: 100%;
|
24
|
+
vertical-align: top;
|
25
|
+
position: absolute;
|
26
|
+
z-index: 999;
|
27
|
+
left: 0;
|
28
|
+
}
|
29
|
+
|
30
|
+
.file-select {
|
31
|
+
background: #fff;
|
32
|
+
color: #000;
|
33
|
+
padding: 5px 12px;
|
34
|
+
border: 1px solid #dbdfe2;
|
35
|
+
border-radius: 4px;
|
36
|
+
}
|
37
|
+
|
38
|
+
.file-name {
|
39
|
+
margin: 0px 20px;
|
40
|
+
}
|
41
|
+
|
42
|
+
}
|
43
|
+
|
44
|
+
.upload_video {
|
45
|
+
background: #5ea3d3;
|
46
|
+
box-shadow: none;
|
47
|
+
color: #fff;
|
48
|
+
border: solid 1px;
|
49
|
+
border-radius: 6px;
|
50
|
+
padding: 5px 12px;
|
51
|
+
|
52
|
+
&:hover {
|
53
|
+
background: #72aed8;
|
54
|
+
}
|
55
|
+
}
|
56
|
+
|
57
|
+
button[disabled] {
|
58
|
+
background: #8b9297;
|
59
|
+
&:hover {
|
60
|
+
background: #8b9297;
|
61
|
+
}
|
62
|
+
}
|
63
|
+
|
64
|
+
.progressbar {
|
65
|
+
margin-top: 5px;
|
66
|
+
margin-left: 20%;
|
67
|
+
width: calc(80% - 22px);
|
68
|
+
border: 1px solid #dbdfe2;
|
69
|
+
background: #fafbfc;
|
70
|
+
padding: 10px;
|
71
|
+
|
72
|
+
.header, .progress {
|
73
|
+
margin-bottom: 5px;
|
74
|
+
}
|
75
|
+
|
76
|
+
.percentage {
|
77
|
+
float: right;
|
78
|
+
color: #5188ef;
|
79
|
+
}
|
80
|
+
.progress {
|
81
|
+
background: #dadada;
|
82
|
+
width: 100%;
|
83
|
+
height: 5px;
|
84
|
+
|
85
|
+
.bar {
|
86
|
+
height: 5px;
|
87
|
+
background: #2a75ed;
|
88
|
+
}
|
89
|
+
}
|
90
|
+
}
|
91
|
+
}
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module ActiveAdmin
|
2
|
+
module Inputs
|
3
|
+
class QiniuImageInput
|
4
|
+
include Formtastic::Inputs::Base
|
5
|
+
|
6
|
+
def to_html
|
7
|
+
input_wrapping do
|
8
|
+
label_html <<
|
9
|
+
<<-HTML
|
10
|
+
<div class="qiniu-image-input">
|
11
|
+
<div class="add-single-picture">
|
12
|
+
<input type="file" name="file" class="add-image"
|
13
|
+
data-uploading-text="#{I18n.t('active_admin.qiniu_input.uploading')}"
|
14
|
+
data-upload-span-text="#{I18n.t('active_admin.qiniu_input.upload_span')}"
|
15
|
+
data-qiniu-meta-url="#{ActiveAdmin::QiniuInput.qiniu_meta_url}" />
|
16
|
+
<input name="#{object_name}[#{input_name}]" class="hidden-input single-image" value="#{object.try(method)}"/>
|
17
|
+
#{object.try(method).present? ? "<img src=\"#{object.try(method)}\" class=\"image-show\" />" : ''}
|
18
|
+
<span class="upload-icon"></span>
|
19
|
+
<span class="upload-span">#{I18n.t('active_admin.qiniu_input.upload_span')}</span>
|
20
|
+
</div>
|
21
|
+
<p class='size-hints'>(#{options[:hint] || I18n.t('active_admin.qiniu_input.upload_image_hint')})</p>
|
22
|
+
</div>
|
23
|
+
HTML
|
24
|
+
.html_safe
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
module ActiveAdmin
|
2
|
+
module Inputs
|
3
|
+
class QiniuVideoInput
|
4
|
+
include Formtastic::Inputs::Base
|
5
|
+
|
6
|
+
def to_html
|
7
|
+
input_wrapping do
|
8
|
+
value = object.try(method)
|
9
|
+
label_html <<
|
10
|
+
<<-HTML
|
11
|
+
<div class="video-wrapper">
|
12
|
+
<div class="upload-btn">
|
13
|
+
<input name="#{object_name}[#{input_name}]" class="hidden-input video_field" value="#{value}"/>
|
14
|
+
<input accept="video/mp4" class="video_file" type="file" data-unsupported-format="#{I18n.t('active_admin.qiniu_input.unsupported_format')}" data-qiniu-meta-url="#{ActiveAdmin::QiniuInput.qiniu_meta_url}" >
|
15
|
+
<span class='file-select'>#{I18n.t('active_admin.qiniu_input.choose_file')}</span>
|
16
|
+
<span class='file-name'></span>
|
17
|
+
<button class='upload_video' disabled="disabled">#{I18n.t('active_admin.qiniu_input.upload')}</button>
|
18
|
+
</div>
|
19
|
+
<div class='progressbar' hidden>
|
20
|
+
<div class='header'>
|
21
|
+
<span class="name"></span>
|
22
|
+
<span class="percentage">0%</span>
|
23
|
+
</div>
|
24
|
+
<div class='progress'>
|
25
|
+
<div class="bar"></div>
|
26
|
+
</div>
|
27
|
+
<div class='footer'>
|
28
|
+
#{I18n.t('active_admin.qiniu_input.uploaded')}: <span class='loaded'> 0M</span>M/<span class='file-size'> 0</span>M
|
29
|
+
</div>
|
30
|
+
</div>
|
31
|
+
<p class="inline-hints">
|
32
|
+
#{value.present? ? template.video_tag(value, controls: true, preload: 'auto', controlsList: 'nodownload') : ''}
|
33
|
+
</p>
|
34
|
+
</div>
|
35
|
+
HTML
|
36
|
+
.html_safe
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
ActiveAdmin::Views::TableFor.class_eval do
|
2
|
+
def qiniu_image_column(attribute)
|
3
|
+
column attribute do |model|
|
4
|
+
url = model.try(attribute)
|
5
|
+
url.present? ? image_tag(url, width: '100') : url
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
def qiniu_video_column(attribute)
|
10
|
+
column attribute do |model|
|
11
|
+
url = model.try(attribute)
|
12
|
+
url.present? ?
|
13
|
+
video_tag(url, width: 150, controls: true, preload: 'auto', controlsList: 'nodownload') :
|
14
|
+
url
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
ActiveAdmin::Views::AttributesTable.class_eval do
|
20
|
+
def qiniu_image_row(attribute)
|
21
|
+
row attribute do |model|
|
22
|
+
url = model.try(attribute)
|
23
|
+
url.present? ? image_tag(url, width: '180') : url
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def qiniu_video_row(attribute)
|
28
|
+
row attribute do |model|
|
29
|
+
url = model.try(attribute)
|
30
|
+
url.present? ?
|
31
|
+
video_tag(url, width: 300, controls: true, preload: 'auto', controlsList: 'nodownload') :
|
32
|
+
url
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'activeadmin'
|
2
|
+
require 'qiniu'
|
3
|
+
require 'active_admin/qiniu_input/engine'
|
4
|
+
require 'active_admin/qiniu_input/version'
|
5
|
+
require 'active_admin/qiniu_input/extend'
|
6
|
+
require 'active_admin/inputs/qiniu_image_input'
|
7
|
+
require 'active_admin/inputs/qiniu_video_input'
|
8
|
+
|
9
|
+
module ActiveAdmin
|
10
|
+
module QiniuInput
|
11
|
+
mattr_accessor :qiniu_meta_url
|
12
|
+
self.qiniu_meta_url = '/qiniu_meta'
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
module ActiveAdmin
|
2
|
+
module QiniuInput
|
3
|
+
module Generators
|
4
|
+
class InstallGenerator < Rails::Generators::Base
|
5
|
+
source_root File.expand_path('../templates', __FILE__)
|
6
|
+
|
7
|
+
def create_initializer
|
8
|
+
template "initializer.rb", "config/initializers/active_admin/qiniu_input.rb"
|
9
|
+
end
|
10
|
+
|
11
|
+
def add_javascripts
|
12
|
+
file_path = 'app/assets/javascripts/active_admin'
|
13
|
+
line_to_add = "#= require active_admin/qiniu_input\n"
|
14
|
+
reference = "#= require active_admin/base\n"
|
15
|
+
|
16
|
+
begin
|
17
|
+
inject_into_file("#{file_path}.js.coffee", line_to_add, after: reference)
|
18
|
+
rescue Errno::ENOENT
|
19
|
+
line_to_add = "//= require active_admin/qiniu_input\n"
|
20
|
+
reference = "//= require active_admin/base\n"
|
21
|
+
inject_into_file("#{file_path}.js", line_to_add, after: reference)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def add_stylesheets
|
26
|
+
file_path = 'app/assets/stylesheets/active_admin'
|
27
|
+
line_to_add = "//= require active_admin/qiniu_input\n"
|
28
|
+
|
29
|
+
begin
|
30
|
+
prepend_file("#{file_path}.scss", line_to_add)
|
31
|
+
rescue Errno::ENOENT
|
32
|
+
prepend_file("#{file_path}.css.scss", line_to_add)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
metadata
ADDED
@@ -0,0 +1,124 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: activeadmin-qiniu_input
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Cain
|
8
|
+
- Jayce
|
9
|
+
- Roger
|
10
|
+
autorequire:
|
11
|
+
bindir: bin
|
12
|
+
cert_chain: []
|
13
|
+
date: 2018-01-03 00:00:00.000000000 Z
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: rails
|
17
|
+
requirement: !ruby/object:Gem::Requirement
|
18
|
+
requirements:
|
19
|
+
- - ">="
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '5.1'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
requirements:
|
26
|
+
- - ">="
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
version: '5.1'
|
29
|
+
- !ruby/object:Gem::Dependency
|
30
|
+
name: activeadmin
|
31
|
+
requirement: !ruby/object:Gem::Requirement
|
32
|
+
requirements:
|
33
|
+
- - ">="
|
34
|
+
- !ruby/object:Gem::Version
|
35
|
+
version: '1.1'
|
36
|
+
type: :runtime
|
37
|
+
prerelease: false
|
38
|
+
version_requirements: !ruby/object:Gem::Requirement
|
39
|
+
requirements:
|
40
|
+
- - ">="
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
version: '1.1'
|
43
|
+
- !ruby/object:Gem::Dependency
|
44
|
+
name: qiniu
|
45
|
+
requirement: !ruby/object:Gem::Requirement
|
46
|
+
requirements:
|
47
|
+
- - ">="
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: '6.9'
|
50
|
+
type: :runtime
|
51
|
+
prerelease: false
|
52
|
+
version_requirements: !ruby/object:Gem::Requirement
|
53
|
+
requirements:
|
54
|
+
- - ">="
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: '6.9'
|
57
|
+
- !ruby/object:Gem::Dependency
|
58
|
+
name: sqlite3
|
59
|
+
requirement: !ruby/object:Gem::Requirement
|
60
|
+
requirements:
|
61
|
+
- - "~>"
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
version: '1.3'
|
64
|
+
type: :development
|
65
|
+
prerelease: false
|
66
|
+
version_requirements: !ruby/object:Gem::Requirement
|
67
|
+
requirements:
|
68
|
+
- - "~>"
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
version: '1.3'
|
71
|
+
description: " ActiveAdmin Inputs for using qiniu to upload image or video.\n"
|
72
|
+
email:
|
73
|
+
- cain@beansmile.com
|
74
|
+
- jayce@beansmile.com
|
75
|
+
- roger@beansmile.com
|
76
|
+
executables: []
|
77
|
+
extensions: []
|
78
|
+
extra_rdoc_files: []
|
79
|
+
files:
|
80
|
+
- MIT-LICENSE
|
81
|
+
- README.md
|
82
|
+
- Rakefile
|
83
|
+
- app/assets/images/active_admin/qiniu_input/upload.png
|
84
|
+
- app/assets/javascripts/active_admin/qiniu_input/index.js
|
85
|
+
- app/assets/javascripts/active_admin/qiniu_input/upload_image.js
|
86
|
+
- app/assets/javascripts/active_admin/qiniu_input/upload_video.js
|
87
|
+
- app/assets/stylesheets/active_admin/qiniu_input/index.scss
|
88
|
+
- app/assets/stylesheets/active_admin/qiniu_input/upload_image.scss
|
89
|
+
- app/assets/stylesheets/active_admin/qiniu_input/upload_video.scss
|
90
|
+
- config/locales/en.yml
|
91
|
+
- config/locales/zh-CN.yml
|
92
|
+
- lib/active_admin/inputs/qiniu_image_input.rb
|
93
|
+
- lib/active_admin/inputs/qiniu_video_input.rb
|
94
|
+
- lib/active_admin/qiniu_input/engine.rb
|
95
|
+
- lib/active_admin/qiniu_input/extend.rb
|
96
|
+
- lib/active_admin/qiniu_input/version.rb
|
97
|
+
- lib/activeadmin-qiniu_input.rb
|
98
|
+
- lib/generators/active_admin/qiniu_input/install/install_generator.rb
|
99
|
+
- lib/generators/active_admin/qiniu_input/install/templates/initializer.rb
|
100
|
+
homepage: https://github.com/beansmile/activeadmin-qiniu_input
|
101
|
+
licenses:
|
102
|
+
- MIT
|
103
|
+
metadata: {}
|
104
|
+
post_install_message:
|
105
|
+
rdoc_options: []
|
106
|
+
require_paths:
|
107
|
+
- lib
|
108
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
109
|
+
requirements:
|
110
|
+
- - ">="
|
111
|
+
- !ruby/object:Gem::Version
|
112
|
+
version: '0'
|
113
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
requirements: []
|
119
|
+
rubyforge_project:
|
120
|
+
rubygems_version: 2.6.14
|
121
|
+
signing_key:
|
122
|
+
specification_version: 4
|
123
|
+
summary: ActiveAdmin Inputs for using qiniu to upload image or video.
|
124
|
+
test_files: []
|