rails_admin_dropzone 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 77eb9663a2f6f0bec5c3cc7d426854e591aad18a
4
+ data.tar.gz: 058d9bbdbcbd7ce0cad5addd5952829457c1e213
5
+ SHA512:
6
+ metadata.gz: b238de580f76e9a6fd198b68a9dd29ed3ba159fdf84ebee1fbc7c939a264a6a3c4a58ac84febbad769f521c5a14ddb08818f18b184471ed8368f4d3e3f296b28
7
+ data.tar.gz: ae1e74493516e17de4fc513008383afe78e230e749d1982f49230d2f631a7472a478d15d410659f641c57ff05e5241125faf5fc19bc9de5308bfa084a9a08dbc
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ .bundle/
2
+ log/*.log
3
+ pkg/
4
+ test/dummy/db/*.sqlite3
5
+ test/dummy/log/*.log
6
+ test/dummy/tmp/
7
+ test/dummy/.sass-cache
8
+ test_app/
9
+ .idea/*
data/MIT-LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Luiz Picolo
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,74 @@
1
+ # Custom Action to RailsAdmin with Dropzone.js Multiple File Upload
2
+
3
+ Easy to use integration of drag&drop files upload via dropzone.js for rails_admin
4
+
5
+ # Screenshot
6
+
7
+ #### Dropzone
8
+ ![Imgur](http://i.imgur.com/PbfSMqy.png)
9
+
10
+ #### Upload images
11
+ ![Imgur](http://i.imgur.com/GiVG0YX.png)
12
+
13
+ ## How to use
14
+
15
+ Add in Gemfile
16
+
17
+ ```ruby
18
+ gem 'dropzonejs-rails'
19
+ gem 'rails_admin_dropzone'
20
+ ```
21
+
22
+ ## IMPORTANT:
23
+
24
+ ```ruby
25
+ class Album < ActiveRecord::Base
26
+ has_many :photos
27
+ end
28
+
29
+ class Photo < ActiveRecord::Base
30
+ belongs_to :album
31
+ end
32
+ ```
33
+
34
+ Add this method `create_associated_image` in your model, example `Album`, that will contain the upload images and change the associations and attributes
35
+
36
+ ```ruby
37
+ class Album < ActiveRecord::Base
38
+ has_many :photos
39
+
40
+ # Method
41
+ def create_associated_image(image)
42
+ photos.create(image: image)
43
+ end
44
+ end
45
+ ```
46
+
47
+ Add in `config/initialisers/rails_admin.rb`
48
+
49
+ ```ruby
50
+ RailsAdmin.config do |config|
51
+ config.actions do
52
+ dashboard
53
+ index
54
+ new
55
+
56
+ dropzone do
57
+ only YOUR_MODEL # Example Album
58
+ end
59
+
60
+ show
61
+ edit
62
+ delete
63
+ end
64
+ end
65
+ ```
66
+ and "Voalá"
67
+
68
+ ## Contributing
69
+
70
+ Bug reports and pull requests are welcome on GitHub at https://github.com/luizpicolo/rails_admin_dropzone. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
71
+
72
+ ## License
73
+
74
+ 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,27 @@
1
+ #!/usr/bin/env rake
2
+ begin
3
+ require 'bundler/setup'
4
+ rescue LoadError
5
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
6
+ end
7
+ begin
8
+ require 'rdoc/task'
9
+ rescue LoadError
10
+ require 'rdoc/rdoc'
11
+ require 'rake/rdoctask'
12
+ RDoc::Task = Rake::RDocTask
13
+ end
14
+
15
+ RDoc::Task.new(:rdoc) do |rdoc|
16
+ rdoc.rdoc_dir = 'rdoc'
17
+ rdoc.title = 'RailsAdminMultipleUpload'
18
+ rdoc.options << '--line-numbers'
19
+ rdoc.rdoc_files.include('README.rdoc')
20
+ rdoc.rdoc_files.include('lib/**/*.rb')
21
+ end
22
+
23
+
24
+
25
+
26
+ Bundler::GemHelper.install_tasks
27
+
@@ -0,0 +1,24 @@
1
+ //= require dropzone
2
+
3
+ $(document).on('rails_admin.dom_ready', function() {
4
+ // disable auto discover
5
+ Dropzone.autoDiscover = true;
6
+
7
+ var dropzone = new Dropzone (".dropzone", {
8
+ maxFilesize: 256, // Set the maximum file size to 256 MB
9
+ paramName: "album[second_attr][]", // Rails expects the file upload to be something like model[field_name]
10
+ addRemoveLinks: true, // Don't show remove links on dropzone itself.
11
+
12
+ // Translations
13
+ dictDefaultMessage: "<%= I18n.t('admin.actions.dropzone.dictDefaultMessage') %>",
14
+ dictFallbackMessage: "<%= I18n.t('admin.actions.dropzone.dictFallbackMessage') %>",
15
+ dictFallbackText: "<%= I18n.t('admin.actions.dropzone.dictFallbackText') %>",
16
+ dictFileTooBig: "<%= I18n.t('admin.actions.dropzone.dictFileTooBig') %>",
17
+ dictInvalidFileType: "<%= I18n.t('admin.actions.dropzone.dictInvalidFileType') %>",
18
+ dictResponseError: "<%= I18n.t('admin.actions.dropzone.dictResponseError') %>",
19
+ dictCancelUpload: "<%= I18n.t('admin.actions.dropzone.dictCancelUpload') %>",
20
+ dictCancelUploadConfirmation: "<%= I18n.t('admin.actions.dropzone.dictCancelUploadConfirmation') %>",
21
+ dictRemoveFile: "<%= I18n.t('admin.actions.dropzone.dictRemoveFile') %>",
22
+ dictMaxFilesExceeded: "<%= I18n.t('admin.actions.dropzone.dictMaxFilesExceeded') %>"
23
+ });
24
+ });
@@ -0,0 +1,11 @@
1
+ @import "dropzone/basic";
2
+
3
+ .dropzone.dz-clickable {
4
+ cursor: pointer;
5
+ border: 2px dashed #bbb;;
6
+ }
7
+
8
+ .dz-message {
9
+ padding: 40px;
10
+ text-align: center;
11
+ }
File without changes
@@ -0,0 +1,2 @@
1
+ = simple_form_for(rails_admin.dropzone_url(@abstract_model.to_param, id: @object.id), html: { class: 'dropzone', multipart: true }) do |f|
2
+ = f.input :id, :as => :hidden, :input_html => { :name => "id", :value => @object.id }
@@ -0,0 +1,22 @@
1
+ en:
2
+ admin:
3
+ actions:
4
+ dropzone:
5
+ dictDefaultMessage: "Drop files here to upload"
6
+ dictFallbackMessage: "Your browser does not support drag'n'drop file uploads."
7
+ dictFallbackText: "Please use the fallback form below to upload your files like in the olden days."
8
+ dictFileTooBig: "File is too big ({{filesize}}MiB). Max filesize: {{maxFilesize}}MiB."
9
+ dictInvalidFileType: "You can't upload files of this type."
10
+ dictResponseError: "Server responded with {{statusCode}} code."
11
+ dictCancelUpload: "Cancel upload"
12
+ dictCancelUploadConfirmation: "Are you sure you want to cancel this upload?"
13
+ dictRemoveFile: "Remove file"
14
+ dictMaxFilesExceeded: "You can not upload any more files."
15
+
16
+ title: "Multiple Upload"
17
+ menu: "Multiple Upload for %{model_label} '%{object_label}'"
18
+ breadcrumb: "Multiple Upload"
19
+ link: "Multiple Upload"
20
+ bulk_link: "Multiple Upload selected %{model_label_plural}"
21
+ done: "Multiple Uploaded"
22
+
@@ -0,0 +1,21 @@
1
+ pt-BR:
2
+ admin:
3
+ actions:
4
+ dropzone:
5
+ dictDefaultMessage: "Clique ou arraste arquivos aqui para enviar"
6
+ dictFallbackMessage: "Seu navegador não suporta Drag and Drop para upload de arquivos."
7
+ dictFallbackText: "Por favor, use o formulário abaixo para fazer upload de seus arquivos, como nos velhos tempos."
8
+ dictFileTooBig: "Este arquivo é muito grande ({{filesize}}MiB). Máximo permitído: {{maxFilesize}}MiB."
9
+ dictInvalidFileType: "Você não pode fazer upload deste tipo de arquivo"
10
+ dictResponseError: "O servidor respondeu com o código {{statusCode}}."
11
+ dictCancelUpload: "Cancelar"
12
+ dictCancelUploadConfirmation: "Você esta certo que deseja cancelar este upload?"
13
+ dictRemoveFile: "Remover"
14
+ dictMaxFilesExceeded: "Você não pode fazer upload de mais arquivos"
15
+
16
+ title: "Envio de imagens"
17
+ menu: "Enviar imagens para %{model_label} '%{object_label}'"
18
+ breadcrumb: "Envio de imagens"
19
+ link: "Envio de imagens"
20
+ bulk_link: "Envio de imagens selecionado %{model_label_plural}"
21
+ done: "Imagens enviadas"
@@ -0,0 +1,49 @@
1
+ require "simple_form"
2
+ require "rails_admin_dropzone/engine"
3
+
4
+ module RailsAdminDropzone
5
+ end
6
+
7
+ require 'rails_admin/config/actions'
8
+
9
+ module RailsAdmin
10
+ module Config
11
+ module Actions
12
+ class Dropzone < Base
13
+ RailsAdmin::Config::Actions.register(self)
14
+ register_instance_option :member do
15
+ true
16
+ end
17
+
18
+ register_instance_option :link_icon do
19
+ 'icon-upload'
20
+ end
21
+
22
+ register_instance_option :http_methods do
23
+ [:get, :post]
24
+ end
25
+
26
+ register_instance_option :controller do
27
+ Proc.new do
28
+ @response = {}
29
+
30
+ if request.post?
31
+ @object = @abstract_model.model.find(params[:id])
32
+ @params = params[@abstract_model.param_key]
33
+
34
+ if @params.present?
35
+ @params[:second_attr].each do |image|
36
+ if @object.create_associated_image(image)
37
+ render json: { message: 'success', fileID: '1' }, status: 200
38
+ else
39
+ render json: { error: @object.dropzone_association.errors.full_messages.join(',')}, status: 400
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,4 @@
1
+ module RailsAdminDropzone
2
+ class Engine < ::Rails::Engine
3
+ end
4
+ end
@@ -0,0 +1,3 @@
1
+ module RailsAdminDropzone
2
+ VERSION = "1.0.1"
3
+ end
@@ -0,0 +1,31 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+
5
+ require "rails_admin_dropzone/version"
6
+
7
+ # Describe your gem and declare its dependencies:
8
+ Gem::Specification.new do |s|
9
+ s.name = "rails_admin_dropzone"
10
+ s.version = RailsAdminDropzone::VERSION
11
+ s.authors = ["Luiz Picolo"]
12
+ s.email = ["luizpicolo@gmail.com"]
13
+ s.homepage = "https://github.com/luizpicolo/rails_admin_dropzone"
14
+ s.summary = "RailsAdmin dropzone.js"
15
+ s.description = "Easy to use integration of drag&drop files upload via dropzone.js for ActiveAdmin"
16
+ s.licenses = ['MIT-LICENSE']
17
+
18
+ s.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
19
+ s.bindir = "exe"
20
+ s.executables = s.files.grep(%r{^exe/}) { |f| File.basename(f) }
21
+ s.require_paths = ["lib"]
22
+
23
+ s.add_dependency 'simple_form', '~> 3.2'
24
+ s.add_dependency 'rails', '~> 4.2'
25
+ s.add_dependency "jquery-rails", [">= 3.0", "< 5"]
26
+ s.add_dependency "dropzonejs-rails", "~> 0.4.16"
27
+
28
+ s.add_development_dependency "bundler", "~> 1.11"
29
+ s.add_development_dependency "rake", "~> 10.0"
30
+ s.add_development_dependency "rspec", "~> 3.0"
31
+ end
metadata ADDED
@@ -0,0 +1,163 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rails_admin_dropzone
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Luiz Picolo
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-04-12 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: simple_form
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '3.2'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '3.2'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rails
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '4.2'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '4.2'
41
+ - !ruby/object:Gem::Dependency
42
+ name: jquery-rails
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ - - "<"
49
+ - !ruby/object:Gem::Version
50
+ version: '5'
51
+ type: :runtime
52
+ prerelease: false
53
+ version_requirements: !ruby/object:Gem::Requirement
54
+ requirements:
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ version: '3.0'
58
+ - - "<"
59
+ - !ruby/object:Gem::Version
60
+ version: '5'
61
+ - !ruby/object:Gem::Dependency
62
+ name: dropzonejs-rails
63
+ requirement: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - "~>"
66
+ - !ruby/object:Gem::Version
67
+ version: 0.4.16
68
+ type: :runtime
69
+ prerelease: false
70
+ version_requirements: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - "~>"
73
+ - !ruby/object:Gem::Version
74
+ version: 0.4.16
75
+ - !ruby/object:Gem::Dependency
76
+ name: bundler
77
+ requirement: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - "~>"
80
+ - !ruby/object:Gem::Version
81
+ version: '1.11'
82
+ type: :development
83
+ prerelease: false
84
+ version_requirements: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - "~>"
87
+ - !ruby/object:Gem::Version
88
+ version: '1.11'
89
+ - !ruby/object:Gem::Dependency
90
+ name: rake
91
+ requirement: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - "~>"
94
+ - !ruby/object:Gem::Version
95
+ version: '10.0'
96
+ type: :development
97
+ prerelease: false
98
+ version_requirements: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - "~>"
101
+ - !ruby/object:Gem::Version
102
+ version: '10.0'
103
+ - !ruby/object:Gem::Dependency
104
+ name: rspec
105
+ requirement: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - "~>"
108
+ - !ruby/object:Gem::Version
109
+ version: '3.0'
110
+ type: :development
111
+ prerelease: false
112
+ version_requirements: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - "~>"
115
+ - !ruby/object:Gem::Version
116
+ version: '3.0'
117
+ description: Easy to use integration of drag&drop files upload via dropzone.js for
118
+ ActiveAdmin
119
+ email:
120
+ - luizpicolo@gmail.com
121
+ executables: []
122
+ extensions: []
123
+ extra_rdoc_files: []
124
+ files:
125
+ - ".gitignore"
126
+ - MIT-LICENSE
127
+ - README.md
128
+ - Rakefile
129
+ - app/assets/javascripts/rails_admin/custom/ui.js.erb
130
+ - app/assets/stylesheets/rails_admin/custom/theming.scss
131
+ - app/views/.gitkeep
132
+ - app/views/rails_admin/main/dropzone.html.haml
133
+ - config/locales/multiple_upload.en.yml
134
+ - config/locales/multiple_upload.pt-BR.yml
135
+ - lib/rails_admin_dropzone.rb
136
+ - lib/rails_admin_dropzone/engine.rb
137
+ - lib/rails_admin_dropzone/version.rb
138
+ - rails_admin_dropzone.gemspec
139
+ homepage: https://github.com/luizpicolo/rails_admin_dropzone
140
+ licenses:
141
+ - MIT-LICENSE
142
+ metadata: {}
143
+ post_install_message:
144
+ rdoc_options: []
145
+ require_paths:
146
+ - lib
147
+ required_ruby_version: !ruby/object:Gem::Requirement
148
+ requirements:
149
+ - - ">="
150
+ - !ruby/object:Gem::Version
151
+ version: '0'
152
+ required_rubygems_version: !ruby/object:Gem::Requirement
153
+ requirements:
154
+ - - ">="
155
+ - !ruby/object:Gem::Version
156
+ version: '0'
157
+ requirements: []
158
+ rubyforge_project:
159
+ rubygems_version: 2.4.8
160
+ signing_key:
161
+ specification_version: 4
162
+ summary: RailsAdmin dropzone.js
163
+ test_files: []