Skip to content

Commit 2204e7b

Browse files
committed
init commit
0 parents  commit 2204e7b

File tree

15 files changed

+333
-0
lines changed

15 files changed

+333
-0
lines changed

.gitignore

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
.bundle/
2+
log/*.log
3+
pkg/
4+
/db/*.sqlite3
5+
/db/*.sqlite3-journal
6+
7+
/log/*
8+
!/log/.keep
9+
/tmp
10+
.idea/
11+
.rbenv-gemsets

.rubocop.yml

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
AllCops:
2+
Exclude:
3+
- 'bin/**/*'
4+
- 'db/schema.rb'
5+
- 'tmp/**/*'
6+
- 'vendor/bundle/**/*'
7+
8+
Metrics/AbcSize:
9+
Max: 15
10+
11+
Metrics/BlockNesting:
12+
Max: 3
13+
14+
Metrics/ClassLength:
15+
CountComments: false
16+
Max: 100
17+
18+
Metrics/CyclomaticComplexity:
19+
Max: 6
20+
21+
Metrics/LineLength:
22+
AllowURI: true
23+
Enabled: false
24+
25+
Metrics/MethodLength:
26+
CountComments: false
27+
Max: 15
28+
29+
Metrics/ModuleLength:
30+
Max: 100
31+
32+
Metrics/ParameterLists:
33+
Max: 4
34+
CountKeywordArgs: true
35+
36+
Metrics/PerceivedComplexity:
37+
Max: 7
38+
39+
Style/AccessModifierIndentation:
40+
EnforcedStyle: outdent
41+
42+
Style/CollectionMethods:
43+
PreferredMethods:
44+
map: 'collect'
45+
reduce: 'inject'
46+
find: 'detect'
47+
find_all: 'select'
48+
49+
Style/Documentation:
50+
Enabled: false
51+
52+
Style/DotPosition:
53+
EnforcedStyle: trailing
54+
55+
Style/DoubleNegation:
56+
Enabled: false
57+
58+
Style/EachWithObject:
59+
Enabled: false
60+
61+
Style/Encoding:
62+
Enabled: false
63+
64+
Style/FileName:
65+
Exclude:
66+
- 'lib/rails_admin/bootstrap-sass.rb'
67+
68+
Style/Lambda:
69+
Enabled: false
70+
71+
Style/RaiseArgs:
72+
EnforcedStyle: compact
73+
74+
Style/SpaceInsideHashLiteralBraces:
75+
EnforcedStyle: no_space
76+
77+
Style/TrailingCommaInLiteral:
78+
EnforcedStyleForMultiline: 'comma'

MIT-LICENSE

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
Copyright 2016 KOVACS Nicolas
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.

README.md

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
[WIP] - RailsAdmin Rollincode Sortable Section
2+
--------------------
3+
4+
Screenshot soon !
5+
6+
This section provides the behavior of sortable model in rails_admin.
7+
Jquery UI sortable is used.
8+
9+
10+
Example `config/initializers/rails_admin.rb`
11+
12+
````
13+
config.actions do
14+
dashboard # mandatory
15+
index # mandatory
16+
new
17+
18+
sortable
19+
20+
export
21+
bulk_delete
22+
show
23+
edit
24+
delete
25+
26+
27+
## With an audit adapter, you can add:
28+
#history_index
29+
#history_show
30+
end
31+
````
32+
33+
In model config you have to specify your methods
34+
35+
````
36+
sortable do
37+
label_method 'code'
38+
position_method 'row_order'
39+
end
40+
````
41+
42+
`label_method` is used for showing the model name (eg: title, etc)
43+
44+
`position_method` is used for the model position method

Rakefile

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
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 = 'RailsAdminSortable'
12+
rdoc.options << '--line-numbers'
13+
rdoc.rdoc_files.include('README.rdoc')
14+
rdoc.rdoc_files.include('lib/**/*.rb')
15+
end
16+
17+
18+
19+
load 'rails/tasks/statistics.rake'
20+
21+
22+
23+
Bundler::GemHelper.install_tasks
24+

app/views/.keep

Whitespace-only changes.
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<legend><%= t 'title_section' %></legend>
2+
3+
<ul id="sortable">
4+
<% @abstract_model.all.each do |o| %>
5+
<li class="sortable-container">
6+
<span class="ref_number">
7+
<% unless @sortable_section.position_method.nil? %>
8+
<%= o.send(@sortable_section.position_method) %>
9+
<% end %>
10+
</span>
11+
<span class="li_sortable_label">
12+
<% if @sortable_section.label_method.nil? %>
13+
<%= o.to_s %>
14+
<% else %>
15+
<%= o.send(@sortable_section.label_method) %>
16+
<% end %>
17+
</span>
18+
</li>
19+
<% end %>
20+
</ul>
21+
22+
<script type="text/javascript" charset="utf-8">
23+
$(function () {
24+
$("#sortable").sortable({
25+
placeholder: "ui-state-highlight"
26+
});
27+
$("#sortable").disableSelection();
28+
$('.ref_number').each(function (i, elem) {
29+
$(this).html(i + 1);
30+
})
31+
});
32+
</script>

bin/rails

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#!/usr/bin/env ruby
2+
# This command will automatically be run when you run "rails" with Rails 4 gems installed from the root of your application.
3+
4+
ENGINE_ROOT = File.expand_path('../..', __FILE__)
5+
ENGINE_PATH = File.expand_path('../../lib/rails_admin_sortable/engine', __FILE__)
6+
7+
# Set up gems listed in the Gemfile.
8+
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
9+
require 'bundler/setup' if File.exist?(ENV['BUNDLE_GEMFILE'])
10+
11+
require 'rails/all'
12+
require 'rails/engine/commands'

config/locales/sortable.en.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
en:
2+
admin:
3+
actions:
4+
sortable:
5+
title: "Sortable"
6+
menu: "Sort"
7+
breadcrumb: "Sortable"
8+
link: "Sortable"
9+
done: "Sorted"
10+
title_section: Make a sort

config/locales/sortable.fr.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
fr:
2+
admin:
3+
actions:
4+
sortable:
5+
title: "Trier"
6+
menu: "Trier"
7+
breadcrumb: "Sortable"
8+
link: "Trier"
9+
done: "Trié"
10+
title_section: Effectuer un tri

lib/rails_admin_sortable.rb

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
require "rails_admin_sortable/engine"
2+
3+
module RailsAdminSortable
4+
end
5+
6+
require 'rails_admin_sortable/config/sections/sortable'
7+
require 'rails_admin/config/actions'
8+
require 'rails_admin/config/actions/base'
9+
10+
module RailsAdmin
11+
module Config
12+
module Actions
13+
class Sortable < RailsAdmin::Config::Actions::Base
14+
RailsAdmin::Config::Actions.register(self)
15+
16+
register_instance_option :controller do
17+
Proc.new do
18+
@sortable_section = model_config.sortable
19+
end
20+
end
21+
22+
register_instance_option :object_level do
23+
false
24+
end
25+
26+
register_instance_option :collection? do
27+
true
28+
end
29+
30+
register_instance_option :bulkable? do
31+
false
32+
end
33+
34+
register_instance_option :link_icon do
35+
'fa fa-list-ol'
36+
end
37+
38+
register_instance_option :pjax? do
39+
false
40+
end
41+
42+
end
43+
end
44+
end
45+
end
46+
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
require 'rails_admin/config/sections/base'
2+
3+
module RailsAdmin
4+
module Config
5+
module Sections
6+
class Sortable < RailsAdmin::Config::Sections::Base
7+
8+
register_instance_option :label_method do
9+
nil
10+
end
11+
12+
register_instance_option :position_method do
13+
nil
14+
end
15+
16+
end
17+
end
18+
end
19+
end

lib/rails_admin_sortable/engine.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
module RailsAdminSortable
2+
class Engine < ::Rails::Engine
3+
end
4+
end

lib/rails_admin_sortable/version.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module RailsAdminSortable
2+
VERSION = "0.0.1"
3+
end

rails_admin_sortable.gemspec

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
$:.push File.expand_path("../lib", __FILE__)
2+
3+
# Maintain your gem's version:
4+
require "rails_admin_sortable/version"
5+
6+
# Describe your gem and declare its dependencies:
7+
Gem::Specification.new do |s|
8+
s.name = "rails_admin_sortable"
9+
s.version = RailsAdminSortable::VERSION
10+
s.authors = ["KOVACS Nicolas"]
11+
s.email = ["perso.nkovacs@gmail.com"]
12+
s.homepage = "https://github.com/rollincode/rails_admin_sortable"
13+
s.summary = "RailsAdminSortable."
14+
s.description = "RailsAdminSortable collection action. Easy drag and drog sortable model."
15+
s.license = "MIT"
16+
17+
s.files = Dir["{app,config,db,lib}/**/*", "MIT-LICENSE", "Rakefile", "README.rdoc"]
18+
19+
s.add_dependency "rails", "~> 4.2.5"
20+
end

0 commit comments

Comments
 (0)