activeadmin-sortable 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
@@ -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.
@@ -0,0 +1,54 @@
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
9
+ [acts_as_list](https://github.com/rails/acts_as_list) on any model you want to
10
+ be sortable.
11
+
12
+ ```ruby
13
+ class Page < ActiveRecord::Base
14
+ acts_as_list
15
+ end
16
+ ```
17
+
18
+ ## Usage
19
+
20
+ ### Add it to your Gemfile
21
+
22
+ ```ruby
23
+ gem 'activeadmin-sortable'
24
+ ```
25
+
26
+ ### Include the JavaScript in active_admin.js
27
+
28
+ ```javascript
29
+ //= require activeadmin-sortable
30
+ ```
31
+
32
+ ### Configure your ActiveAdmin Resource
33
+
34
+ ```ruby
35
+ ActiveAdmin.register Page do
36
+ config.sort_order = 'position_asc' # assumes you are using 'position' for your acts_as_list column
37
+ config.paginate = false # optional; drag-and-drop across pages is not supported
38
+
39
+ sortable # creates the controller action which handles the sorting
40
+
41
+ index do
42
+ sortable_handle_column # inserts a drag handle
43
+ # other columns...
44
+ end
45
+ end
46
+ ```
47
+
48
+ ## Contributing
49
+
50
+ 1. Fork it
51
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
52
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
53
+ 4. Push to the branch (`git push origin my-new-feature`)
54
+ 5. Create new Pull Request
@@ -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-sortable"
8
+ gem.version = Activeadmin::Sortable::VERSION
9
+ gem.authors = ["Adam McCrea"]
10
+ gem.email = ["adam@adamlogic.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,24 @@
1
+ //= require jquery-ui
2
+
3
+ (function($) {
4
+ $(document).ready(function() {
5
+ $('.handle').closest('tbody').activeAdminSortable();
6
+ });
7
+
8
+ $.fn.activeAdminSortable = function() {
9
+ this.sortable({
10
+ update: function(event, ui) {
11
+ var url = ui.item.find('[data-sort-url]').data('sort-url');
12
+
13
+ $.ajax({
14
+ url: url,
15
+ type: 'post',
16
+ data: { position: ui.item.index() + 1 },
17
+ success: function() { window.location.reload() }
18
+ });
19
+ }
20
+ });
21
+
22
+ this.disableSelection();
23
+ }
24
+ })(jQuery);
@@ -0,0 +1,36 @@
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
+ resource.insert_at params[:position].to_i
11
+ head 200
12
+ end
13
+ end
14
+ end
15
+
16
+ module TableMethods
17
+ HANDLE = '&#x2195;'.html_safe
18
+
19
+ def sortable_handle_column
20
+ column '' do |resource|
21
+ sort_url = url_for([:sort, :admin, resource])
22
+ content_tag :span, HANDLE, :class => 'handle', 'data-sort-url' => sort_url
23
+ end
24
+ end
25
+ end
26
+
27
+ ::ActiveAdmin::ResourceDSL.send(:include, ControllerActions)
28
+ ::ActiveAdmin::Views::TableFor.send(:include, TableMethods)
29
+
30
+ class Engine < ::Rails::Engine
31
+ # Including an Engine tells Rails that this gem contains assets
32
+ end
33
+ end
34
+ end
35
+
36
+
@@ -0,0 +1,5 @@
1
+ module Activeadmin
2
+ module Sortable
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
metadata ADDED
@@ -0,0 +1,76 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: activeadmin-sortable
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Adam McCrea
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-11-09 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: activeadmin
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '0.4'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: '0.4'
30
+ description: Drag and drop sort interface for ActiveAdmin tables
31
+ email:
32
+ - adam@adamlogic.com
33
+ executables: []
34
+ extensions: []
35
+ extra_rdoc_files: []
36
+ files:
37
+ - .gitignore
38
+ - Gemfile
39
+ - LICENSE.txt
40
+ - README.md
41
+ - Rakefile
42
+ - activeadmin-sortable.gemspec
43
+ - app/assets/javascripts/activeadmin-sortable.js
44
+ - lib/activeadmin-sortable.rb
45
+ - lib/activeadmin-sortable/version.rb
46
+ homepage: https://github.com/newcontext/activeadmin-sortable
47
+ licenses: []
48
+ post_install_message:
49
+ rdoc_options: []
50
+ require_paths:
51
+ - lib
52
+ required_ruby_version: !ruby/object:Gem::Requirement
53
+ none: false
54
+ requirements:
55
+ - - ! '>='
56
+ - !ruby/object:Gem::Version
57
+ version: '0'
58
+ segments:
59
+ - 0
60
+ hash: -1888499648567453647
61
+ required_rubygems_version: !ruby/object:Gem::Requirement
62
+ none: false
63
+ requirements:
64
+ - - ! '>='
65
+ - !ruby/object:Gem::Version
66
+ version: '0'
67
+ segments:
68
+ - 0
69
+ hash: -1888499648567453647
70
+ requirements: []
71
+ rubyforge_project:
72
+ rubygems_version: 1.8.24
73
+ signing_key:
74
+ specification_version: 3
75
+ summary: Drag and drop sort interface for ActiveAdmin tables
76
+ test_files: []