activeadmin-orderable 0.1.0
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 +3 -0
- data/LICENSE.txt +22 -0
- data/README.md +91 -0
- data/Rakefile +1 -0
- data/activeadmin-sortable.gemspec +21 -0
- data/app/assets/javascripts/activeadmin-sortable.js +35 -0
- data/app/assets/stylesheets/activeadmin-sortable.css +1 -0
- data/lib/activeadmin-sortable/version.rb +5 -0
- data/lib/activeadmin-sortable.rb +48 -0
- metadata +69 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: db3cb9d78ede847bf343cb0768841f673b109f00
|
4
|
+
data.tar.gz: fc77b3de9768a1972aa84280a257fdced9b7a3fa
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: e8c400ad28ffe89d636178e14d8eadffff1e5f300ec5087cae9589de64b3ca21f3fe5fbf8a9efec63ae6fd97d3a46006583a5b2f39bd9fd8dc0359aa2b4df3a7
|
7
|
+
data.tar.gz: e6970545c6951e49e69b0a0ec1c77e8c21d8c337f66c3862e9de36f47500acd0ce2b3f82e61073e9033b8f9d6bb981463584c725248af9d7f4c432c066509ddc
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Adam McCrea
|
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,91 @@
|
|
1
|
+
# Active Admin Sortable
|
2
|
+
|
3
|
+
This gem extends ActiveAdmin so that your index page's table rows can be
|
4
|
+
sortable via a drag-and-drop interface.
|
5
|
+
|
6
|
+
## Prerequisites
|
7
|
+
|
8
|
+
This extension assumes that you're using one of the following on any model you want to be sortable.
|
9
|
+
|
10
|
+
#### ActiveRecord
|
11
|
+
|
12
|
+
[acts_as_list](https://github.com/swanandp/acts_as_list)
|
13
|
+
|
14
|
+
```ruby
|
15
|
+
class Page < ActiveRecord::Base
|
16
|
+
acts_as_list
|
17
|
+
end
|
18
|
+
```
|
19
|
+
|
20
|
+
#### Mongoid
|
21
|
+
|
22
|
+
[mongoid_orderable](https://github.com/pyromaniac/mongoid_orderable)
|
23
|
+
|
24
|
+
```ruby
|
25
|
+
class Page < ActiveRecord::Base
|
26
|
+
include Mongoid::Orderable
|
27
|
+
orderable
|
28
|
+
end
|
29
|
+
```
|
30
|
+
|
31
|
+
## Usage
|
32
|
+
|
33
|
+
### Add it to your Gemfile
|
34
|
+
|
35
|
+
```ruby
|
36
|
+
gem "activeadmin-sortable"
|
37
|
+
```
|
38
|
+
|
39
|
+
### Include the JavaScript in active_admin.js.coffee
|
40
|
+
|
41
|
+
```javascript
|
42
|
+
#= require activeadmin-sortable
|
43
|
+
```
|
44
|
+
|
45
|
+
### Include the Stylesheet in active_admin.css.scss
|
46
|
+
```scss
|
47
|
+
@import "activeadmin-sortable"
|
48
|
+
```
|
49
|
+
|
50
|
+
### Configure your ActiveAdmin Resource
|
51
|
+
|
52
|
+
```ruby
|
53
|
+
ActiveAdmin.register Page do
|
54
|
+
config.sort_order = 'position_asc' # assumes you are using 'position' for your acts_as_list column
|
55
|
+
config.paginate = false # optional; drag-and-drop across pages is not supported
|
56
|
+
|
57
|
+
sortable # creates the controller action which handles the sorting
|
58
|
+
|
59
|
+
index do
|
60
|
+
sortable_handle_column # inserts a drag handle
|
61
|
+
# use a user-defined URL for sorting
|
62
|
+
sortable_handle_column url: :sort_admin_section_path
|
63
|
+
# alternative form with lambda
|
64
|
+
sortable_handle_column url: -> (resource) { compute_url_from_resource(resource) }
|
65
|
+
# other columns...
|
66
|
+
end
|
67
|
+
|
68
|
+
show do |c|
|
69
|
+
attributes_table do
|
70
|
+
row :id
|
71
|
+
row :name
|
72
|
+
end
|
73
|
+
|
74
|
+
panel 'Contents' do
|
75
|
+
table_for c.collection_memberships do
|
76
|
+
sortable_handle_column
|
77
|
+
column :position
|
78
|
+
column :collectable
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
```
|
84
|
+
|
85
|
+
## Contributing
|
86
|
+
|
87
|
+
1. Fork it
|
88
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
89
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
90
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
91
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'activeadmin-sortable/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = "activeadmin-orderable"
|
8
|
+
gem.version = Activeadmin::Sortable::VERSION
|
9
|
+
gem.authors = ["Adam McCrea", "Jonathan Gertig"]
|
10
|
+
gem.email = ["adam@adamlogic.com", "jcgertig@gmail.com"]
|
11
|
+
gem.description = %q{Drag and drop sort interface for ActiveAdmin tables}
|
12
|
+
gem.summary = %q{Drag and drop sort interface for ActiveAdmin tables}
|
13
|
+
gem.homepage = "https://github.com/newcontext/activeadmin-sortable"
|
14
|
+
|
15
|
+
gem.files = `git ls-files`.split($/)
|
16
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
17
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
18
|
+
gem.require_paths = ["lib"]
|
19
|
+
|
20
|
+
gem.add_dependency 'activeadmin', '>= 0.4'
|
21
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
(function($) {
|
2
|
+
$(document).ready(function() {
|
3
|
+
$('.handle').closest('tbody').activeAdminSortable();
|
4
|
+
});
|
5
|
+
|
6
|
+
$.fn.activeAdminSortable = function() {
|
7
|
+
this.sortable({
|
8
|
+
update: function(event, ui) {
|
9
|
+
var item = ui.item.find('[data-sort-url]');
|
10
|
+
var url = item.data('sort-url');
|
11
|
+
var actionOnSuccess = item.data('sort-success-action');
|
12
|
+
var customParams = {};
|
13
|
+
if (typeof item.data('sort-custom-params') === 'object') {
|
14
|
+
customParams = item.data('sort-custom-params');
|
15
|
+
}
|
16
|
+
|
17
|
+
$.ajax({
|
18
|
+
url: url,
|
19
|
+
type: 'post',
|
20
|
+
data: $.extend(customParams, { position: ui.item.index() + 1 }),
|
21
|
+
error: function() { console.error('Saving sortable error'); },
|
22
|
+
success: function() {
|
23
|
+
if (actionOnSuccess === 'noting') { return; }
|
24
|
+
|
25
|
+
$("tr", $('.handle').closest('tbody')).removeClass('even odd');
|
26
|
+
$("tr", $('.handle').closest('tbody')).filter(":even").addClass('odd');
|
27
|
+
$("tr", $('.handle').closest('tbody')).filter(":odd").addClass('even');
|
28
|
+
}
|
29
|
+
});
|
30
|
+
}
|
31
|
+
});
|
32
|
+
|
33
|
+
this.disableSelection();
|
34
|
+
}
|
35
|
+
})(jQuery);
|
@@ -0,0 +1 @@
|
|
1
|
+
.activeadmin-sortable .handle { cursor: ns-resize; }
|
@@ -0,0 +1,48 @@
|
|
1
|
+
require 'activeadmin-sortable/version'
|
2
|
+
require 'activeadmin'
|
3
|
+
require 'rails/engine'
|
4
|
+
|
5
|
+
module ActiveAdmin
|
6
|
+
module Sortable
|
7
|
+
module ControllerActions
|
8
|
+
def sortable
|
9
|
+
member_action :sort, :method => :post do
|
10
|
+
if defined?(::Mongoid::Orderable) &&
|
11
|
+
resource.class.included_modules.include?(::Mongoid::Orderable)
|
12
|
+
resource.move_to! params[:position].to_i
|
13
|
+
else
|
14
|
+
resource.insert_at params[:position].to_i
|
15
|
+
end
|
16
|
+
head 200
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
module TableMethods
|
22
|
+
HANDLE = '↕'.html_safe
|
23
|
+
|
24
|
+
def sortable_handle_column options = {}
|
25
|
+
column '', :class => "activeadmin-sortable" do |resource|
|
26
|
+
sort_url = if options[:url].is_a? Symbol
|
27
|
+
send options[:url], resource
|
28
|
+
elsif options[:url].respond_to? :call
|
29
|
+
options[:url].call resource
|
30
|
+
else
|
31
|
+
sort_url, query_params = resource_path(resource).split '?', 2
|
32
|
+
sort_url += "/sort"
|
33
|
+
sort_url += "?" + query_params if query_params
|
34
|
+
sort_url
|
35
|
+
end
|
36
|
+
content_tag :span, HANDLE, :class => 'handle', 'data-sort-url' => sort_url
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
::ActiveAdmin::ResourceDSL.send(:include, ControllerActions)
|
42
|
+
::ActiveAdmin::Views::TableFor.send(:include, TableMethods)
|
43
|
+
|
44
|
+
class Engine < ::Rails::Engine
|
45
|
+
# Including an Engine tells Rails that this gem contains assets
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
metadata
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: activeadmin-orderable
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Adam McCrea
|
8
|
+
- Jonathan Gertig
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2015-06-27 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: activeadmin
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - ">="
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: '0.4'
|
21
|
+
type: :runtime
|
22
|
+
prerelease: false
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - ">="
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
version: '0.4'
|
28
|
+
description: Drag and drop sort interface for ActiveAdmin tables
|
29
|
+
email:
|
30
|
+
- adam@adamlogic.com
|
31
|
+
- jcgertig@gmail.com
|
32
|
+
executables: []
|
33
|
+
extensions: []
|
34
|
+
extra_rdoc_files: []
|
35
|
+
files:
|
36
|
+
- ".gitignore"
|
37
|
+
- Gemfile
|
38
|
+
- LICENSE.txt
|
39
|
+
- README.md
|
40
|
+
- Rakefile
|
41
|
+
- activeadmin-sortable.gemspec
|
42
|
+
- app/assets/javascripts/activeadmin-sortable.js
|
43
|
+
- app/assets/stylesheets/activeadmin-sortable.css
|
44
|
+
- lib/activeadmin-sortable.rb
|
45
|
+
- lib/activeadmin-sortable/version.rb
|
46
|
+
homepage: https://github.com/newcontext/activeadmin-sortable
|
47
|
+
licenses: []
|
48
|
+
metadata: {}
|
49
|
+
post_install_message:
|
50
|
+
rdoc_options: []
|
51
|
+
require_paths:
|
52
|
+
- lib
|
53
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
54
|
+
requirements:
|
55
|
+
- - ">="
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
version: '0'
|
58
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - ">="
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '0'
|
63
|
+
requirements: []
|
64
|
+
rubyforge_project:
|
65
|
+
rubygems_version: 2.4.5
|
66
|
+
signing_key:
|
67
|
+
specification_version: 4
|
68
|
+
summary: Drag and drop sort interface for ActiveAdmin tables
|
69
|
+
test_files: []
|