activeadmin_reorderable 0.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: e310f082a9ea3570f41763b70f87913ea42d9fe0
4
+ data.tar.gz: 5190b5b7255acfde21b7961a2ba54028319ecb42
5
+ SHA512:
6
+ metadata.gz: b1d34bd9eaea1df4cf8dc937591ccd8d4c160a05f1bae9c57fb537bd5747cf8482b9e1c3452281d6605c28946f90ce04d72787912132c953038d35205b8a5f03
7
+ data.tar.gz: a11e92314ae39121376cdb899f0f6c96d7da846339754e83a66b9a0dcd15cafc0897591dd6ce2a269717a047eaf2d1ed4c283e80e86fe7bc9fbcef9f603a890a
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2013 Viget Labs
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.
data/README.md ADDED
@@ -0,0 +1,54 @@
1
+ # ActiveAdmin Reorderable
2
+
3
+ Drag and drop to reorder your ActiveAdmin tables.
4
+
5
+ ![Drag and drop reordering](https://s3.amazonaws.com/kurtzkloud.com/p/activeadmin_reorderable/screenshot.gif)
6
+
7
+ ## Requirements
8
+ Your resource classes must respond to `insert_at` ala the [`acts_as_list`](https://github.com/swanandp/acts_as_list) API. You don't need to use `acts_as_list`, but if you don't, make sure to define `insert_at`.
9
+
10
+ ## Installation
11
+ - Add `gem 'activeadmin_reorderable'` to `Gemfile`
12
+ - Add `#= require activeadmin_reorderable` to `app/assets/javascripts/active_admin.js.coffee`
13
+ - Add `@import "activeadmin_reorderable";` as the last `@import` statement in `app/assets/stylesheets/active_admin.css.scss`
14
+
15
+ ## Use
16
+ `parts.rb`
17
+ ```ruby
18
+ ActiveAdmin.register Part do
19
+ reorderable # Necessary to support reordering in a subtable within Widget below
20
+ end
21
+ ```
22
+
23
+ `widgets.rb`
24
+ ```ruby
25
+ ActiveAdmin.register Widget do
26
+ config.sort_order = 'position_asc' # assuming Widget.insert_at modifies the `position` attribute
27
+ config.paginate = false
28
+
29
+ reorderable
30
+
31
+ actions :index, :show
32
+
33
+ # Reorderable Index Table
34
+ index as: :reorderable_table do
35
+ column :id
36
+ column :name
37
+ end
38
+
39
+ show do |widget|
40
+ attributes_table do
41
+ row :id
42
+ row :name
43
+ end
44
+
45
+ # Reorderable Subtable
46
+ # Note: you must include `reorderable` in the ActiveAdmin configuration for the resource
47
+ # being sorted. See the `Part` example above this code block.
48
+ reorderable_table_for widget.parts do
49
+ column :name
50
+ column :cost
51
+ end
52
+ end
53
+ end
54
+ ```
@@ -0,0 +1,18 @@
1
+ $:.push File.expand_path("../lib", __FILE__)
2
+
3
+ require "activeadmin_reorderable/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "activeadmin_reorderable"
7
+ s.version = ActiveadminReorderable::VERSION
8
+ s.authors = ["Chris Jones", "Lawson Kurtz"]
9
+ s.email = ["lawson.kurtz@viget.com"]
10
+ s.homepage = "http://www.github.com/vigetlabs/activeadmin_reorderable"
11
+ s.summary = "Drag and drop reordering for ActiveAdmin tables"
12
+ s.description = "Add drag and drop reordering to ActiveAdmin tables."
13
+ s.license = "MIT"
14
+
15
+ s.files = `git ls-files`.split($/)
16
+
17
+ s.add_development_dependency "activeadmin", ">= 0.6"
18
+ end
@@ -0,0 +1,67 @@
1
+ $.fn.reorderable = function(opts) {
2
+ // This helper fixes the table row width collapsing when being dragged
3
+ function reorderableTableHelper(e, ui) {
4
+ console.log(ui);
5
+ ui.children().each(function() {
6
+ var $cell = $(this);
7
+
8
+ $cell.width($cell.width());
9
+ });
10
+
11
+ return ui;
12
+ }
13
+
14
+ // This helper sets the table row placeholder height to the height of the row being moved
15
+ function reorderableTableStart(e, ui) {
16
+ ui.placeholder.height(ui.helper.outerHeight());
17
+
18
+ return ui;
19
+ }
20
+
21
+ function reorderableTableStop(e, ui) {
22
+ var $row = ui.item,
23
+ $rows = $row.parent().children('tr'),
24
+ $table = $row.closest('table'),
25
+ $handle = $row.find('.reorder-handle'),
26
+ url = $handle.data('reorder-url'),
27
+ index = function(i) { return $rows.index(i) + 1; };
28
+
29
+ $table.find('tbody tr').each(function(index) {
30
+ var $row = $(this),
31
+ newClass = ''
32
+
33
+ $row.removeClass('odd').removeClass('even');
34
+
35
+ if ((index + 1) % 2 == 0) {
36
+ newClass = 'even';
37
+ } else {
38
+ newClass = 'odd';
39
+ }
40
+
41
+ $row.addClass(newClass);
42
+ });
43
+
44
+ $rows.each(function() {
45
+ $(this).find('.position').text(index($(this)));
46
+ });
47
+
48
+ $.post(url, { position: index($row) });
49
+ }
50
+
51
+ return this.each(function() {
52
+ var opts = $.extend({
53
+ items: 'tbody tr',
54
+ handle: '.reorder-handle',
55
+ axis: 'y',
56
+ helper: reorderableTableHelper,
57
+ start: reorderableTableStart,
58
+ stop: reorderableTableStop,
59
+ }, opts || {});
60
+
61
+ $(this).sortable(opts);
62
+ });
63
+ };
64
+
65
+ $(function() {
66
+ $('.aa-reorderable').reorderable();
67
+ });
@@ -0,0 +1,6 @@
1
+ .aa-reorderable {
2
+ .reorder-handle {
3
+ @include light-button;
4
+ cursor: move;
5
+ }
6
+ }
@@ -0,0 +1,16 @@
1
+ module ActiveAdmin
2
+ module Reorderable
3
+ module DSL
4
+ private
5
+
6
+ def reorderable(&block)
7
+ body = proc do
8
+ resource.insert_at(params[:position].to_i)
9
+ render :nothing => true
10
+ end
11
+
12
+ member_action(:reorder, :method => :post, &block || body)
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,27 @@
1
+ module ActiveAdmin
2
+ module Reorderable
3
+ module TableMethods
4
+
5
+ def reorder_column
6
+ column '', :class => 'reorder-handle-col' do |resource|
7
+ reorder_handle_for(resource)
8
+ end
9
+ end
10
+
11
+ private
12
+
13
+ def reorder_handle_for(resource)
14
+ url = url_for([:reorder, :admin, resource])
15
+ span(reorder_handle_content, :class => 'reorder-handle', 'data-reorder-url' => url)
16
+ end
17
+
18
+ def reorder_handle_content
19
+ '≡≡'.html_safe
20
+ end
21
+
22
+ end
23
+
24
+ ::ActiveAdmin::Views::TableFor.send(:include, TableMethods)
25
+ end
26
+ end
27
+
@@ -0,0 +1,20 @@
1
+ module ActiveAdmin
2
+ module Views
3
+ class IndexAsReorderableTable < IndexAsTable
4
+
5
+ def self.index_name
6
+ 'reorderable_table'
7
+ end
8
+
9
+ def build(page_presenter, collection)
10
+ add_class 'aa-reorderable'
11
+ super(page_presenter, collection)
12
+ end
13
+
14
+ def table_for(*args, &block)
15
+ insert_tag ReorderableTableFor, *args, &block
16
+ end
17
+
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,17 @@
1
+ module ActiveAdmin
2
+ module Views
3
+ class ReorderableTableFor < IndexAsTable::IndexTableFor
4
+ builder_method :reorderable_table_for
5
+
6
+ def build(collection, options = {}, &block)
7
+ options[:class] = [options[:class], 'aa-reorderable'].compact.join(' ')
8
+
9
+ super(collection, options) do
10
+ reorder_column
11
+ block.call if block.present?
12
+ end
13
+ end
14
+
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,6 @@
1
+ require 'rails/engine'
2
+
3
+ module ActiveadminReorderable
4
+ class Engine < Rails::Engine
5
+ end
6
+ end
@@ -0,0 +1,3 @@
1
+ module ActiveadminReorderable
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,6 @@
1
+ require 'activeadmin'
2
+
3
+ Dir[File.dirname(__FILE__) + '/activeadmin_reorderable/*.rb'].each {|file| require file }
4
+ Dir[File.dirname(__FILE__) + '/active_admin/**/*.rb'].each {|file| require file }
5
+
6
+ ::ActiveAdmin::ResourceDSL.send(:include, ActiveAdmin::Reorderable::DSL)
metadata ADDED
@@ -0,0 +1,73 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: activeadmin_reorderable
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Chris Jones
8
+ - Lawson Kurtz
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2014-04-24 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.6'
21
+ type: :development
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - '>='
26
+ - !ruby/object:Gem::Version
27
+ version: '0.6'
28
+ description: Add drag and drop reordering to ActiveAdmin tables.
29
+ email:
30
+ - lawson.kurtz@viget.com
31
+ executables: []
32
+ extensions: []
33
+ extra_rdoc_files: []
34
+ files:
35
+ - Gemfile
36
+ - MIT-LICENSE
37
+ - README.md
38
+ - activeadmin_reorderable.gemspec
39
+ - app/assets/javascripts/activeadmin_reorderable.js
40
+ - app/assets/stylesheets/activeadmin_reorderable.scss
41
+ - lib/active_admin/reorderable/dsl.rb
42
+ - lib/active_admin/reorderable/table_methods.rb
43
+ - lib/active_admin/views/index_as_reorderable_table.rb
44
+ - lib/active_admin/views/reorderable_table_for.rb
45
+ - lib/activeadmin_reorderable.rb
46
+ - lib/activeadmin_reorderable/engine.rb
47
+ - lib/activeadmin_reorderable/version.rb
48
+ homepage: http://www.github.com/vigetlabs/activeadmin_reorderable
49
+ licenses:
50
+ - MIT
51
+ metadata: {}
52
+ post_install_message:
53
+ rdoc_options: []
54
+ require_paths:
55
+ - lib
56
+ required_ruby_version: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - '>='
59
+ - !ruby/object:Gem::Version
60
+ version: '0'
61
+ required_rubygems_version: !ruby/object:Gem::Requirement
62
+ requirements:
63
+ - - '>='
64
+ - !ruby/object:Gem::Version
65
+ version: '0'
66
+ requirements: []
67
+ rubyforge_project:
68
+ rubygems_version: 2.2.1
69
+ signing_key:
70
+ specification_version: 4
71
+ summary: Drag and drop reordering for ActiveAdmin tables
72
+ test_files: []
73
+ has_rdoc: