rails_admin_state 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +75 -0
- data/Rakefile +1 -0
- data/config/locales/en.rails_admin_state_machine.yml +9 -0
- data/config/locales/ru.rails_admin_state_machine.yml +10 -0
- data/lib/rails_admin_state/action.rb +48 -0
- data/lib/rails_admin_state/configuration.rb +49 -0
- data/lib/rails_admin_state/engine.rb +4 -0
- data/lib/rails_admin_state/field.rb +60 -0
- data/lib/rails_admin_state/version.rb +3 -0
- data/lib/rails_admin_state.rb +10 -0
- data/rails_admin_state.gemspec +23 -0
- metadata +86 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 09ac44bc152c6cf090d4bd5d4a66f37d324a43f5
|
4
|
+
data.tar.gz: b37490a19cd089b568357d88be6bc94214bc9604
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: ae203b672542fb7304d5a5b7fbb4aa13b1bf414aa80e4939e734756a00d2bcbf04385fc5f3d8863ff6ff173c64c73e8ead9100a950e09c94f66ef0fcb9d490b3
|
7
|
+
data.tar.gz: 28955b156fe2892008582a237c5e59b43509087bc1a63afbc88922fbdc1a4c2f6b3928a2e06369ab19767b9f4021a85bd3ce42ead839db20fe61129f378fe49f
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 glebtv
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,75 @@
|
|
1
|
+
# RailsAdminState
|
2
|
+
|
3
|
+
Allows easily sending state_machine events to a model from Rails Admin
|
4
|
+
|
5
|
+
## Installing
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'rails_admin_state'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install rails_admin_state
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
|
22
|
+
Add the set_state action:
|
23
|
+
|
24
|
+
RailsAdmin.config do |config|
|
25
|
+
config.actions do
|
26
|
+
......
|
27
|
+
state
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
Make the field you need display as state_machine:
|
32
|
+
|
33
|
+
rails_admin do
|
34
|
+
list do
|
35
|
+
field :state, :state
|
36
|
+
...
|
37
|
+
end
|
38
|
+
edit do
|
39
|
+
field :state, :state
|
40
|
+
...
|
41
|
+
end
|
42
|
+
...
|
43
|
+
end
|
44
|
+
|
45
|
+
States and event names button classes and I18N:
|
46
|
+
|
47
|
+
rails_admin do
|
48
|
+
list do
|
49
|
+
field :state, :state
|
50
|
+
...
|
51
|
+
end
|
52
|
+
...
|
53
|
+
state({
|
54
|
+
events: {reject: 'btn-warning'}
|
55
|
+
states: {on_moderation: 'btn-warning'}
|
56
|
+
})
|
57
|
+
end
|
58
|
+
|
59
|
+
i18n:
|
60
|
+
|
61
|
+
Just as usual for state_machine, see:
|
62
|
+
|
63
|
+
http://rdoc.info/github/pluginaweek/state_machine/master/StateMachine/Integrations/Mongoid
|
64
|
+
http://rdoc.info/github/pluginaweek/state_machine/master/StateMachine/Integrations/ActiveRecord
|
65
|
+
|
66
|
+
For namespaced models use "/", just as usual: "Blog::Post" is "blog/post"
|
67
|
+
|
68
|
+
|
69
|
+
## Contributing
|
70
|
+
|
71
|
+
1. Fork it
|
72
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
73
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
74
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
75
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,48 @@
|
|
1
|
+
module RailsAdmin
|
2
|
+
module Config
|
3
|
+
module Actions
|
4
|
+
class State < Base
|
5
|
+
RailsAdmin::Config::Actions.register(self)
|
6
|
+
|
7
|
+
# Is the action acting on the root level (Example: /admin/contact)
|
8
|
+
register_instance_option :root? do
|
9
|
+
false
|
10
|
+
end
|
11
|
+
|
12
|
+
register_instance_option :collection? do
|
13
|
+
false
|
14
|
+
end
|
15
|
+
|
16
|
+
# Is the action on an object scope (Example: /admin/team/1/edit)
|
17
|
+
register_instance_option :member? do
|
18
|
+
true
|
19
|
+
end
|
20
|
+
|
21
|
+
register_instance_option :controller do
|
22
|
+
Proc.new do |klass|
|
23
|
+
if params['id'].present?
|
24
|
+
begin
|
25
|
+
obj = @abstract_model.model.find(params['id'])
|
26
|
+
if obj.send("fire_#{params[:attr]}_event".to_sym, params[:event].to_sym)
|
27
|
+
obj.save!
|
28
|
+
flash[:success] = I18n.t('admin.state_machine.event_fired', attr: params[:method], event: params[:event])
|
29
|
+
else
|
30
|
+
flash[:error] = obj.errors.full_messages.join(', ')
|
31
|
+
end
|
32
|
+
rescue Exception => e
|
33
|
+
flash[:error] = I18n.t('admin.state_machine.error', err: e.to_s)
|
34
|
+
end
|
35
|
+
else
|
36
|
+
flash[:error] = I18n.t('admin.state_machine.no_id')
|
37
|
+
end
|
38
|
+
redirect_to :back
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
register_instance_option :http_methods do
|
43
|
+
[:post]
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
module RailsAdminState
|
2
|
+
class Configuration
|
3
|
+
def initialize(abstract_model)
|
4
|
+
@abstract_model = abstract_model
|
5
|
+
end
|
6
|
+
|
7
|
+
def options
|
8
|
+
@options ||= {
|
9
|
+
states: {
|
10
|
+
published: 'label-success',
|
11
|
+
sent: 'label-success',
|
12
|
+
done: 'label-success',
|
13
|
+
cancelled: 'label-important',
|
14
|
+
deleted: 'label-important',
|
15
|
+
trashed: 'label-important',
|
16
|
+
draft: 'label-important',
|
17
|
+
},
|
18
|
+
events: {
|
19
|
+
publish: 'btn-success',
|
20
|
+
confirm: 'btn-success',
|
21
|
+
send: 'btn-success',
|
22
|
+
done: 'btn-success',
|
23
|
+
cancel: 'btn-danger',
|
24
|
+
delete: 'btn-danger',
|
25
|
+
trash: 'btn-danger',
|
26
|
+
},
|
27
|
+
}.merge(config)
|
28
|
+
end
|
29
|
+
|
30
|
+
def state(name)
|
31
|
+
return '' if name.nil?
|
32
|
+
options[:states][name.to_sym] || ''
|
33
|
+
end
|
34
|
+
|
35
|
+
def event(name)
|
36
|
+
return '' if name.nil?
|
37
|
+
options[:events][name.to_sym] || ''
|
38
|
+
end
|
39
|
+
|
40
|
+
protected
|
41
|
+
def config
|
42
|
+
if ::RailsAdmin::Config.model(@abstract_model.model).respond_to? :state
|
43
|
+
::RailsAdmin::Config.model(@abstract_model.model).state
|
44
|
+
else
|
45
|
+
{}
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
require 'builder'
|
2
|
+
|
3
|
+
module RailsAdmin
|
4
|
+
module Config
|
5
|
+
module Fields
|
6
|
+
module Types
|
7
|
+
class State < RailsAdmin::Config::Fields::Base
|
8
|
+
# Register field type for the type loader
|
9
|
+
RailsAdmin::Config::Fields::Types::register(self)
|
10
|
+
include RailsAdmin::Engine.routes.url_helpers
|
11
|
+
|
12
|
+
register_instance_option :partial do
|
13
|
+
:form_enumeration
|
14
|
+
end
|
15
|
+
|
16
|
+
register_instance_option :enum do
|
17
|
+
enum = {}
|
18
|
+
bindings[:object].class.state_machines[name.to_sym].states.each do |state|
|
19
|
+
enum[state.name.to_s] = state.human_name
|
20
|
+
end
|
21
|
+
enum
|
22
|
+
end
|
23
|
+
|
24
|
+
register_instance_option :pretty_value do
|
25
|
+
@state_machine_options = ::RailsAdminState::Configuration.new @abstract_model
|
26
|
+
|
27
|
+
state = bindings[:object].send(name)
|
28
|
+
state_class = @state_machine_options.state(state)
|
29
|
+
s = bindings[:object].class.state_machines[name.to_sym].states[state.to_sym]
|
30
|
+
ret = [
|
31
|
+
'<div class="label ' + state_class + '">' + s.human_name + '</div>',
|
32
|
+
'<div style="height: 10px;"></div>'
|
33
|
+
]
|
34
|
+
|
35
|
+
events = bindings[:object].class.state_machines[name.to_sym].events
|
36
|
+
bindings[:object].send("#{name}_events".to_sym).each do |event|
|
37
|
+
event_class = @state_machine_options.event(event)
|
38
|
+
ret << bindings[:view].link_to(
|
39
|
+
events[event].human_name,
|
40
|
+
state_path(model_name: @abstract_model, id: bindings[:object].id, event: event, attr: name),
|
41
|
+
method: :post,
|
42
|
+
class: "btn btn-mini #{event_class}",
|
43
|
+
style: 'margin-bottom: 5px;'
|
44
|
+
)
|
45
|
+
end
|
46
|
+
('<div style="white-space: normal;">' + ret.join(' ') + '</div>').html_safe
|
47
|
+
end
|
48
|
+
|
49
|
+
register_instance_option :export_value do
|
50
|
+
value.inspect
|
51
|
+
end
|
52
|
+
|
53
|
+
register_instance_option :multiple? do
|
54
|
+
false
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
require "rails_admin_state/version"
|
2
|
+
|
3
|
+
require 'rails_admin/config/actions'
|
4
|
+
require 'rails_admin/config/model'
|
5
|
+
|
6
|
+
require 'rails_admin_state/configuration'
|
7
|
+
require 'rails_admin_state/action'
|
8
|
+
require 'rails_admin_state/field'
|
9
|
+
require 'rails_admin_state/engine'
|
10
|
+
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'rails_admin_state/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "rails_admin_state"
|
8
|
+
spec.version = RailsAdminState::VERSION
|
9
|
+
spec.authors = ["glebtv"]
|
10
|
+
spec.email = ["glebtv@gmail.com"]
|
11
|
+
spec.description = %q{Manage model's state with state_machine and rails_admin}
|
12
|
+
spec.summary = %q{Manage model's state with state_machine and rails_admin}
|
13
|
+
spec.homepage = "https://github.com/rs-pro/rails_admin_state"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
end
|
metadata
ADDED
@@ -0,0 +1,86 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rails_admin_state
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- glebtv
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-09-14 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.3'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.3'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
description: Manage model's state with state_machine and rails_admin
|
42
|
+
email:
|
43
|
+
- glebtv@gmail.com
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- .gitignore
|
49
|
+
- Gemfile
|
50
|
+
- LICENSE.txt
|
51
|
+
- README.md
|
52
|
+
- Rakefile
|
53
|
+
- config/locales/en.rails_admin_state_machine.yml
|
54
|
+
- config/locales/ru.rails_admin_state_machine.yml
|
55
|
+
- lib/rails_admin_state.rb
|
56
|
+
- lib/rails_admin_state/action.rb
|
57
|
+
- lib/rails_admin_state/configuration.rb
|
58
|
+
- lib/rails_admin_state/engine.rb
|
59
|
+
- lib/rails_admin_state/field.rb
|
60
|
+
- lib/rails_admin_state/version.rb
|
61
|
+
- rails_admin_state.gemspec
|
62
|
+
homepage: https://github.com/rs-pro/rails_admin_state
|
63
|
+
licenses:
|
64
|
+
- MIT
|
65
|
+
metadata: {}
|
66
|
+
post_install_message:
|
67
|
+
rdoc_options: []
|
68
|
+
require_paths:
|
69
|
+
- lib
|
70
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - '>='
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '0'
|
75
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
76
|
+
requirements:
|
77
|
+
- - '>='
|
78
|
+
- !ruby/object:Gem::Version
|
79
|
+
version: '0'
|
80
|
+
requirements: []
|
81
|
+
rubyforge_project:
|
82
|
+
rubygems_version: 2.0.6
|
83
|
+
signing_key:
|
84
|
+
specification_version: 4
|
85
|
+
summary: Manage model's state with state_machine and rails_admin
|
86
|
+
test_files: []
|