active_scaffold_sortable 3.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE.txt +20 -0
- data/README.textile +94 -0
- data/frontends/default/stylesheets/sortable.css +6 -0
- data/frontends/default/views/_list_with_header.html.erb +9 -0
- data/frontends/default/views/on_create.js.rjs +10 -0
- data/frontends/default/views/on_update.js.rjs +11 -0
- data/frontends/default/views/reorder.js.rjs +1 -0
- data/lib/active_scaffold/actions/sortable.rb +80 -0
- data/lib/active_scaffold/config/sortable.rb +30 -0
- data/lib/active_scaffold/helpers/sortable_helpers.rb +23 -0
- data/lib/active_scaffold_sortable.rb +39 -0
- data/lib/active_scaffold_sortable/config/core.rb +4 -0
- data/lib/active_scaffold_sortable/core.rb +13 -0
- data/lib/active_scaffold_sortable/version.rb +9 -0
- data/lib/active_scaffold_sortable/view_helpers.rb +11 -0
- data/test/auto_models_controller_test.rb +52 -0
- data/test/config_test.rb +59 -0
- data/test/controllers/auto_models_controller.rb +3 -0
- data/test/controllers/models_controller.rb +3 -0
- data/test/controllers/sortable_models_controller.rb +7 -0
- data/test/models/auto_model.rb +8 -0
- data/test/models/model.rb +2 -0
- data/test/router_test.rb +5 -0
- data/test/schema.rb +9 -0
- data/test/test_helper.rb +48 -0
- metadata +160 -0
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2006 Richard White
|
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.textile
ADDED
@@ -0,0 +1,94 @@
|
|
1
|
+
h1. Drag-Drop Sortable for ActiveScaffold
|
2
|
+
|
3
|
+
Currently, this plugin is compatible with rails 3.x and master branches of vhochstein/ActiveScaffold.
|
4
|
+
|
5
|
+
h2. Overview
|
6
|
+
|
7
|
+
This plugin enables those slicker-than-snot ajax drag-drop sortable elements on your active-scaffold page, with so little configuration you almost get it for free.
|
8
|
+
|
9
|
+
h2. Installation
|
10
|
+
|
11
|
+
You'll need at least vhochstein/ActiveScaffold to use this, and rails 3.x
|
12
|
+
|
13
|
+
|
14
|
+
<pre>
|
15
|
+
script/plugin install clone git://github.com/vhochstein/active_scaffold_sortable.git
|
16
|
+
</pre>
|
17
|
+
|
18
|
+
h2. Usage
|
19
|
+
|
20
|
+
h4. Step 1
|
21
|
+
|
22
|
+
Create a model with a column named 'position':
|
23
|
+
|
24
|
+
<pre>
|
25
|
+
# app/models/entry.rb
|
26
|
+
|
27
|
+
# id integer
|
28
|
+
# title string(255)
|
29
|
+
# birthday date
|
30
|
+
# position integer
|
31
|
+
|
32
|
+
class Entry < ActiveRecord::Base
|
33
|
+
end
|
34
|
+
</pre>
|
35
|
+
|
36
|
+
h4. Step 2
|
37
|
+
|
38
|
+
Create your scaffold controller
|
39
|
+
|
40
|
+
<pre>
|
41
|
+
# app/controllers/entries_controller.rb
|
42
|
+
|
43
|
+
class EntryController < ApplicationController
|
44
|
+
active_scaffold :entries do |config|
|
45
|
+
config.actions << :sortable
|
46
|
+
config.sortable.column = :position
|
47
|
+
end
|
48
|
+
end
|
49
|
+
</pre>
|
50
|
+
|
51
|
+
|
52
|
+
h4. Step 3
|
53
|
+
|
54
|
+
Create your layout
|
55
|
+
|
56
|
+
<pre>
|
57
|
+
# app/views/layouts/application.rhtml
|
58
|
+
<html>
|
59
|
+
<head>
|
60
|
+
<title>active scaffold demo application</title>
|
61
|
+
<%= javascript_include_tag :defaults %>
|
62
|
+
<%= active_scaffold_includes %>
|
63
|
+
</head>
|
64
|
+
<body>
|
65
|
+
<%= yield %>
|
66
|
+
</body>
|
67
|
+
</html>
|
68
|
+
</pre>
|
69
|
+
|
70
|
+
h2. Notice:
|
71
|
+
|
72
|
+
If you are using acts_as_list plugin you can skip the step 3
|
73
|
+
|
74
|
+
h2. Support
|
75
|
+
|
76
|
+
If you have issues installing the plugin, search / post to the "Active Scaffold":http://groups.google.com/group/activescaffold forum or "Create an issue":http://github.com/vhochstein/active_scaffold_sortable/issues
|
77
|
+
|
78
|
+
h2. Contributing
|
79
|
+
|
80
|
+
Fork, hack, push, and request a pull:
|
81
|
+
|
82
|
+
http://github.com/vhochstein/active_scaffold_sortable/
|
83
|
+
|
84
|
+
h2. License
|
85
|
+
|
86
|
+
Released under the MIT license (included).
|
87
|
+
|
88
|
+
h2. Author
|
89
|
+
|
90
|
+
Contact me:
|
91
|
+
<pre>
|
92
|
+
Tim Harper - irb(main):001:0> ( 'tim_see_harperATgmail._see_om'.gsub('_see_', 'c').gsub('AT', '@') )
|
93
|
+
Sergio Cambra - irb(main):001:0> ( 'sergioATentrecables._see_om'.gsub('_see_', 'c').gsub('AT', '@') )
|
94
|
+
</pre>
|
@@ -0,0 +1,9 @@
|
|
1
|
+
<%= render :super %>
|
2
|
+
<% if ActiveScaffold.js_framework == :prototype %>
|
3
|
+
<%= sortable_element *sort_params %>
|
4
|
+
<% elsif ActiveScaffold.js_framework == :jquery %>
|
5
|
+
<% reorder_params = {}
|
6
|
+
reorder_params[:eid] = params[:eid] unless params[:eid].blank?
|
7
|
+
options = {:update => true, :action => 'reorder'} %>
|
8
|
+
<%= javascript_tag "ActiveScaffold.sortable('#{sort_params[0]}', #{url_for(:controller => controller_name).to_json}, #{options.to_json}, #{reorder_params.to_json});" %>
|
9
|
+
<% end %>
|
@@ -0,0 +1,10 @@
|
|
1
|
+
page << render(:super, :locals => {:insert_at => :bottom})
|
2
|
+
unless nested_singular_association?
|
3
|
+
if ActiveScaffold.js_framework == :prototype
|
4
|
+
page.sortable(*sort_params)
|
5
|
+
elsif ActiveScaffold.js_framework == :jquery
|
6
|
+
reorder_params = {}
|
7
|
+
reorder_params[:eid] = params[:eid] unless params[:eid].blank?
|
8
|
+
page << "ActiveScaffold.sortable('#{sort_params[0]}', #{controller_name.to_json}, #{reorder_params.to_json});"
|
9
|
+
end if controller.send :successful?
|
10
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
page << render(:super)
|
2
|
+
# if we are currently editing a nested belongs_to association do not do any sorting stuff
|
3
|
+
unless nested_singular_association?
|
4
|
+
if ActiveScaffold.js_framework == :prototype
|
5
|
+
page.sortable(*sort_params)
|
6
|
+
elsif ActiveScaffold.js_framework == :jquery
|
7
|
+
reorder_params = {}
|
8
|
+
reorder_params[:eid] = params[:eid] unless params[:eid].blank?
|
9
|
+
page << "ActiveScaffold.sortable('#{sort_params[0]}', #{controller_name.to_json}, #{reorder_params.to_json});"
|
10
|
+
end if controller.send :successful?
|
11
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
page << "ActiveScaffold.stripe('#{active_scaffold_tbody_id}');"
|
@@ -0,0 +1,80 @@
|
|
1
|
+
module ActiveScaffold::Actions
|
2
|
+
module Sortable
|
3
|
+
def self.included(base)
|
4
|
+
base.helper ActiveScaffold::Helpers::SortableHelpers
|
5
|
+
base.before_filter :sortable_authorized?, :only => :reorder
|
6
|
+
base.active_scaffold_config.configure do |config|
|
7
|
+
config.list.pagination = false
|
8
|
+
|
9
|
+
# turn sorting off
|
10
|
+
sortable_column = config.sortable.column.name
|
11
|
+
config.columns.each {|c| c.sort = false unless c.name == sortable_column }
|
12
|
+
config.list.sorting = { sortable_column => "asc" }
|
13
|
+
|
14
|
+
config.actions.each do |action_name|
|
15
|
+
action = config.send(action_name)
|
16
|
+
action.columns.exclude(sortable_column) if action.respond_to? :columns
|
17
|
+
end
|
18
|
+
|
19
|
+
dir = File.join(ActiveScaffold::Config::Sortable.plugin_directory, 'frontends')
|
20
|
+
base.add_active_scaffold_path File.join(dir, frontend, 'views') if config.frontend.to_sym != :default
|
21
|
+
base.add_active_scaffold_path File.join(dir, 'default', 'views')
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def reorder
|
26
|
+
model = active_scaffold_config.model
|
27
|
+
|
28
|
+
unless (model.instance_methods & [:nested_set_scope, 'nested_set_scope']).empty?
|
29
|
+
reorder_children_in_tree(model)
|
30
|
+
else
|
31
|
+
if model.respond_to? :ancestry_column
|
32
|
+
reorder_ancestry_tree(model)
|
33
|
+
else
|
34
|
+
reorder_simple_list(model)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
protected
|
40
|
+
def sortable_authorized?
|
41
|
+
authorized_for?(:action => :update)
|
42
|
+
end
|
43
|
+
|
44
|
+
def reorder_ancestry_tree(model)
|
45
|
+
first_record = model.find(params[active_scaffold_tbody_id].first)
|
46
|
+
unless first_record.nil?
|
47
|
+
records = first_record.is_root? ? model.roots: first_record.parent.children
|
48
|
+
reorder_simple_list(model)
|
49
|
+
else
|
50
|
+
Rails.logger.info("Failed to find first record to reorder")
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def reorder_simple_list(model)
|
55
|
+
column_name = active_scaffold_config.sortable.column.name
|
56
|
+
params[active_scaffold_tbody_id].each_with_index do |id, index|
|
57
|
+
model.update_all({column_name => index + 1}, {model.primary_key => id})
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
def reorder_children_in_tree(model)
|
62
|
+
current_order = model.find(params[active_scaffold_tbody_id].first).try(:self_and_siblings)
|
63
|
+
new_order = params[active_scaffold_tbody_id].collect {|item_id| item_id.to_i}
|
64
|
+
new_order.each_with_index do |record_id, new_position|
|
65
|
+
if record_id != current_order[new_position].id
|
66
|
+
current_order = move_child(current_order.find {|child| child.id == record_id}, new_position, current_order)
|
67
|
+
end
|
68
|
+
end if new_order.length == current_order.length
|
69
|
+
end
|
70
|
+
|
71
|
+
def move_child(child, new_position, children)
|
72
|
+
old_position = children.index(child)
|
73
|
+
(old_position - new_position).abs.times do |step|
|
74
|
+
child.send((old_position - new_position) > 0 ? :move_left : :move_right)
|
75
|
+
end
|
76
|
+
child.self_and_siblings
|
77
|
+
end
|
78
|
+
|
79
|
+
end
|
80
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module ActiveScaffold::Config
|
2
|
+
class Sortable < Base
|
3
|
+
def initialize(core_config)
|
4
|
+
@options = {}
|
5
|
+
@core = core_config
|
6
|
+
|
7
|
+
self.column = core_config.model.new.position_column unless (@core.model.instance_methods & [:acts_as_list_class, 'acts_as_list_class']).empty?
|
8
|
+
self.column = core_config.model.new.left_column_name unless (@core.model.instance_methods & [:nested_set_scope, 'nested_set_scope']).empty?
|
9
|
+
if self.column.nil?
|
10
|
+
raise "ActiveScaffoldSortable: Missing sortable attribute '#{core_config.model.new.position_column}' in model '#{core_config.model.to_s}'" if @core.model.instance_methods.include? 'acts_as_list_class'
|
11
|
+
raise "ActiveScaffoldSortable: Missing sortable attribute '#{core_config.model.new.left_column_name}' in model '#{core_config.model.to_s}'" if @core.model.instance_methods.include? 'nested_set_scope'
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
15
|
+
|
16
|
+
cattr_accessor :plugin_directory
|
17
|
+
@@plugin_directory = File.expand_path(__FILE__).match(%{(^.*)/lib/active_scaffold/config/sortable.rb})[1]
|
18
|
+
|
19
|
+
self.crud_type = :update
|
20
|
+
|
21
|
+
attr_reader :column
|
22
|
+
def column=(column_name)
|
23
|
+
@column = @core.columns[column_name]
|
24
|
+
Rails.logger.error("ActiveScaffold Sortable: postion column: #{column_name} not found in model") if @column.nil?
|
25
|
+
@column
|
26
|
+
end
|
27
|
+
|
28
|
+
attr_accessor :options
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module ActiveScaffold::Helpers
|
2
|
+
module SortableHelpers
|
3
|
+
def sort_params
|
4
|
+
options = {
|
5
|
+
:tag => 'tr',
|
6
|
+
:url => {:action => :reorder, :controller => controller_name },
|
7
|
+
:format => '/^[^_-](?:[A-Za-z0-9_-]*)-(.*)-row$/',
|
8
|
+
:with => "Sortable.serialize(#{active_scaffold_tbody_id.to_json})"
|
9
|
+
}
|
10
|
+
additional_params = [:parent_controller, :eid, :controller].reject {|param| params[param].blank?}
|
11
|
+
options[:with] = additional_params.inject(options[:with]) do |string, param|
|
12
|
+
"#{string} + '&#{param}=' + encodeURIComponent('#{escape_javascript params[param]}')"
|
13
|
+
end
|
14
|
+
options.merge! active_scaffold_config.sortable.options
|
15
|
+
|
16
|
+
[active_scaffold_tbody_id, options]
|
17
|
+
end
|
18
|
+
|
19
|
+
def list_row_class(record)
|
20
|
+
'sortable'
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require "active_scaffold_sortable/config/core.rb"
|
2
|
+
require "active_scaffold_sortable/core.rb"
|
3
|
+
require "active_scaffold_sortable/view_helpers.rb"
|
4
|
+
|
5
|
+
|
6
|
+
module ActiveScaffoldSortable
|
7
|
+
def self.root
|
8
|
+
File.dirname(__FILE__) + "/.."
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
module ActiveScaffold
|
13
|
+
module Actions
|
14
|
+
ActiveScaffold.autoload_subdir('actions', self, File.dirname(__FILE__))
|
15
|
+
end
|
16
|
+
|
17
|
+
module Config
|
18
|
+
ActiveScaffold.autoload_subdir('config', self, File.dirname(__FILE__))
|
19
|
+
end
|
20
|
+
|
21
|
+
module Helpers
|
22
|
+
ActiveScaffold.autoload_subdir('helpers', self, File.dirname(__FILE__))
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
ActiveScaffold::Config::Core.send :include, ActiveScaffoldSortable::Core
|
27
|
+
ActionView::Base.send(:include, ActiveScaffoldSortable::ViewHelpers)
|
28
|
+
|
29
|
+
##
|
30
|
+
## Run the install assets script, too, just to make sure
|
31
|
+
## But at least rescue the action in production
|
32
|
+
##
|
33
|
+
Rails::Application.initializer("active_scaffold_sortable.install_assets", :after => "active_scaffold.install_assets") do
|
34
|
+
begin
|
35
|
+
ActiveScaffoldAssets.copy_to_public(ActiveScaffoldSortable.root)
|
36
|
+
rescue
|
37
|
+
raise $! unless Rails.env == 'production'
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module ActiveScaffoldSortable
|
2
|
+
module Core
|
3
|
+
def self.included(base)
|
4
|
+
base.alias_method_chain :initialize, :sortable
|
5
|
+
end
|
6
|
+
|
7
|
+
def initialize_with_sortable(model_id)
|
8
|
+
initialize_without_sortable(model_id)
|
9
|
+
# seems some rubies are returning strings in instance_methods and other symbols...
|
10
|
+
self.actions << :sortable if !(model.instance_methods & ['acts_as_list_class', :acts_as_list_class, 'nested_set_scope', :nested_set_scope]).empty?
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
module ActiveScaffoldSortable
|
2
|
+
module ViewHelpers
|
3
|
+
def self.included(base)
|
4
|
+
base.alias_method_chain :active_scaffold_stylesheets, :sortable
|
5
|
+
end
|
6
|
+
|
7
|
+
def active_scaffold_stylesheets_with_sortable(frontend = :default)
|
8
|
+
active_scaffold_stylesheets_without_sortable(frontend) + [ActiveScaffold::Config::Core.asset_path('sortable.css', frontend)]
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
require 'test_helper.rb'
|
2
|
+
|
3
|
+
class AutoModelsControllerTest < ActionController::TestCase
|
4
|
+
@@sortable_regexp = Regexp.new('Sortable.create\("as_auto_models-tbody", \{format:/\^\[\^_-\]\(\?:\[A-Za-z0-9_-\]\*\)-\(\.\*\)-row\$/, onUpdate:function\(\)\{new Ajax.Request\(\'/auto_models/reorder\', \{asynchronous:true, evalScripts:true, parameters:Sortable.serialize\("as_auto_models-tbody"\) \+ \'&controller=\' \+ encodeURIComponent\(\'auto_models\'\)\}\)\}, tag:\'tr\'\}\)')
|
5
|
+
setup { AutoModel.create :name => 'test', :position => 1 }
|
6
|
+
|
7
|
+
context "reordering" do
|
8
|
+
setup do
|
9
|
+
updates = sequence(:updates)
|
10
|
+
AutoModel.expects(:update_all).with({:position => 1}, 'id' => '2').in_sequence(updates)
|
11
|
+
AutoModel.expects(:update_all).with({:position => 2}, 'id' => '1').in_sequence(updates)
|
12
|
+
xhr :post, :reorder, :'as_auto_models-tbody' => ['2', '1']
|
13
|
+
end
|
14
|
+
should_respond_with :success
|
15
|
+
should_render_template :reorder
|
16
|
+
should "update stripe" do
|
17
|
+
assert_equal 'ActiveScaffold.stripe(\'as_auto_models-tbody\');', @response.body
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
context "listing" do
|
22
|
+
setup { get :index }
|
23
|
+
should "render record with sortable class" do
|
24
|
+
assert_select '.records tr.record.sortable'
|
25
|
+
end
|
26
|
+
should "render sortable script" do
|
27
|
+
assert_select 'script[type=text/javascript]', @@sortable_regexp
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
context "creating" do
|
32
|
+
setup { xhr :post, :create, :record => {:name => 'test2', :position => 2} }
|
33
|
+
should_respond_with :success
|
34
|
+
should "insert at top" do
|
35
|
+
assert_match "$(\"as_auto_models-tbody\").insert(\"as_auto_models-list-#{assigns(:record).id}-row\");", @response.body
|
36
|
+
end
|
37
|
+
should "update stripe" do
|
38
|
+
assert_match 'ActiveScaffold.stripe(\'as_auto_models-tbody\');', @response.body
|
39
|
+
end
|
40
|
+
should "update sortable" do
|
41
|
+
assert_match @@sortable_regexp, @response.body
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
context "updating" do
|
46
|
+
setup { xhr :put, :update, :id => 1, :record => {:name => 'test updated'} }
|
47
|
+
should_respond_with :success
|
48
|
+
should "update sortable" do
|
49
|
+
assert_match @@sortable_regexp, @response.body
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
data/test/config_test.rb
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
require 'test_helper.rb'
|
2
|
+
|
3
|
+
class ConfigTest < Test::Unit::TestCase
|
4
|
+
def test_not_enable_sortable
|
5
|
+
assert !ModelsController.active_scaffold_config.actions.include?(:sortable)
|
6
|
+
end
|
7
|
+
|
8
|
+
def test_auto_enable_sortable
|
9
|
+
assert AutoModelsController.active_scaffold_config.actions.include?(:sortable)
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_manual_enable_sortable
|
13
|
+
assert SortableModelsController.active_scaffold_config.actions.include?(:sortable)
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_position_column
|
17
|
+
assert_equal :position, AutoModelsController.active_scaffold_config.sortable.column.name
|
18
|
+
assert_equal :name, SortableModelsController.active_scaffold_config.sortable.column.name
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_position_column_not_included
|
22
|
+
assert !AutoModelsController.active_scaffold_config.list.columns.include?(:position)
|
23
|
+
assert !AutoModelsController.active_scaffold_config.update.columns.include?(:position)
|
24
|
+
assert !AutoModelsController.active_scaffold_config.create.columns.include?(:position)
|
25
|
+
assert !AutoModelsController.active_scaffold_config.show.columns.include?(:position)
|
26
|
+
assert !AutoModelsController.active_scaffold_config.subform.columns.include?(:position)
|
27
|
+
assert !AutoModelsController.active_scaffold_config.search.columns.include?(:position)
|
28
|
+
|
29
|
+
assert !SortableModelsController.active_scaffold_config.list.columns.include?(:name)
|
30
|
+
assert !SortableModelsController.active_scaffold_config.update.columns.include?(:name)
|
31
|
+
assert !SortableModelsController.active_scaffold_config.create.columns.include?(:name)
|
32
|
+
assert !SortableModelsController.active_scaffold_config.show.columns.include?(:name)
|
33
|
+
end
|
34
|
+
|
35
|
+
def test_sorting
|
36
|
+
assert_equal('"models"."id" ASC', ModelsController.active_scaffold_config.list.sorting.clause)
|
37
|
+
assert ModelsController.active_scaffold_config.columns[:name].sortable?
|
38
|
+
assert ModelsController.active_scaffold_config.columns[:position].sortable?
|
39
|
+
|
40
|
+
assert_equal('"models"."position" ASC', AutoModelsController.active_scaffold_config.list.sorting.clause)
|
41
|
+
assert !AutoModelsController.active_scaffold_config.columns[:name].sortable?
|
42
|
+
|
43
|
+
assert_equal('"models"."name" ASC', SortableModelsController.active_scaffold_config.list.sorting.clause)
|
44
|
+
assert !SortableModelsController.active_scaffold_config.columns[:position].sortable?
|
45
|
+
end
|
46
|
+
|
47
|
+
def test_pagination
|
48
|
+
assert ModelsController.active_scaffold_config.list.pagination
|
49
|
+
assert !AutoModelsController.active_scaffold_config.list.pagination
|
50
|
+
assert !SortableModelsController.active_scaffold_config.list.pagination
|
51
|
+
end
|
52
|
+
|
53
|
+
def test_active_scaffold_paths
|
54
|
+
path = File.join(Rails.root, 'vendor/plugins/active_scaffold_sortable/frontends/default/views')
|
55
|
+
assert !ModelsController.active_scaffold_paths.include?(path)
|
56
|
+
assert AutoModelsController.active_scaffold_paths.include?(path)
|
57
|
+
assert SortableModelsController.active_scaffold_paths.include?(path)
|
58
|
+
end
|
59
|
+
end
|
data/test/router_test.rb
ADDED
data/test/schema.rb
ADDED
data/test/test_helper.rb
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
ENV["RAILS_ENV"] = "test"
|
3
|
+
|
4
|
+
require 'test/unit'
|
5
|
+
# You can use "rake test AR_VERSION=2.0.5" to test against 2.0.5, for example.
|
6
|
+
# The default is to use the latest installed ActiveRecord.
|
7
|
+
if ENV["AR_VERSION"]
|
8
|
+
gem 'activerecord', "#{ENV["AR_VERSION"]}"
|
9
|
+
gem 'actionpack', "#{ENV["AR_VERSION"]}"
|
10
|
+
gem 'activesupport', "#{ENV["AR_VERSION"]}"
|
11
|
+
end
|
12
|
+
require 'rubygems'
|
13
|
+
require 'active_record'
|
14
|
+
require 'action_controller'
|
15
|
+
require 'action_view/test_case'
|
16
|
+
require 'action_mailer'
|
17
|
+
require 'active_support'
|
18
|
+
require 'initializer'
|
19
|
+
ActionController::Base::logger = ActiveSupport::BufferedLogger.new(Tempfile.new('log').path)
|
20
|
+
|
21
|
+
RAILS_ROOT = File.join(File.dirname(__FILE__), '../../../..')
|
22
|
+
Rails.configuration = Rails::Configuration.new
|
23
|
+
|
24
|
+
require 'shoulda'
|
25
|
+
require 'shoulda/rails'
|
26
|
+
require 'mocha'
|
27
|
+
begin
|
28
|
+
require 'redgreen'
|
29
|
+
rescue LoadError
|
30
|
+
end
|
31
|
+
|
32
|
+
ActiveSupport::Dependencies.load_paths = %w(test/models test/controllers lib ../active_scaffold/lib).map {|dir| File.dirname(__FILE__) + "/../#{dir}"}
|
33
|
+
$:.unshift *ActiveSupport::Dependencies.load_paths
|
34
|
+
|
35
|
+
require File.join(File.dirname(__FILE__), '../../active_scaffold/environment')
|
36
|
+
require 'sortable'
|
37
|
+
|
38
|
+
ActionController::Routing::Routes.draw do |map|
|
39
|
+
map.root :controller => 'home'
|
40
|
+
map.resources :sortable_models, :active_scaffold => true
|
41
|
+
map.resources :auto_models, :active_scaffold => true
|
42
|
+
map.resources :models, :active_scaffold => true
|
43
|
+
end
|
44
|
+
|
45
|
+
ActiveRecord::Base.establish_connection :adapter => "sqlite3", :database => ":memory:"
|
46
|
+
silence_stream(STDOUT) do
|
47
|
+
load(File.dirname(__FILE__) + "/schema.rb")
|
48
|
+
end
|
metadata
ADDED
@@ -0,0 +1,160 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: active_scaffold_sortable
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 3
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 3
|
8
|
+
- 0
|
9
|
+
- 2
|
10
|
+
version: 3.0.2
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Sergio Cambra
|
14
|
+
- Volker Hochstein
|
15
|
+
autorequire:
|
16
|
+
bindir: bin
|
17
|
+
cert_chain: []
|
18
|
+
|
19
|
+
date: 2011-09-12 00:00:00 +02:00
|
20
|
+
default_executable:
|
21
|
+
dependencies:
|
22
|
+
- !ruby/object:Gem::Dependency
|
23
|
+
version_requirements: &id001 !ruby/object:Gem::Requirement
|
24
|
+
none: false
|
25
|
+
requirements:
|
26
|
+
- - ">="
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
hash: 3
|
29
|
+
segments:
|
30
|
+
- 0
|
31
|
+
version: "0"
|
32
|
+
requirement: *id001
|
33
|
+
prerelease: false
|
34
|
+
type: :development
|
35
|
+
name: shoulda
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
version_requirements: &id002 !ruby/object:Gem::Requirement
|
38
|
+
none: false
|
39
|
+
requirements:
|
40
|
+
- - ~>
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
hash: 23
|
43
|
+
segments:
|
44
|
+
- 1
|
45
|
+
- 0
|
46
|
+
- 0
|
47
|
+
version: 1.0.0
|
48
|
+
requirement: *id002
|
49
|
+
prerelease: false
|
50
|
+
type: :development
|
51
|
+
name: bundler
|
52
|
+
- !ruby/object:Gem::Dependency
|
53
|
+
version_requirements: &id003 !ruby/object:Gem::Requirement
|
54
|
+
none: false
|
55
|
+
requirements:
|
56
|
+
- - ">="
|
57
|
+
- !ruby/object:Gem::Version
|
58
|
+
hash: 3
|
59
|
+
segments:
|
60
|
+
- 0
|
61
|
+
version: "0"
|
62
|
+
requirement: *id003
|
63
|
+
prerelease: false
|
64
|
+
type: :development
|
65
|
+
name: rcov
|
66
|
+
- !ruby/object:Gem::Dependency
|
67
|
+
version_requirements: &id004 !ruby/object:Gem::Requirement
|
68
|
+
none: false
|
69
|
+
requirements:
|
70
|
+
- - ~>
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
hash: 7
|
73
|
+
segments:
|
74
|
+
- 3
|
75
|
+
- 0
|
76
|
+
version: "3.0"
|
77
|
+
requirement: *id004
|
78
|
+
prerelease: false
|
79
|
+
type: :runtime
|
80
|
+
name: active_scaffold
|
81
|
+
description: Sort Tree or List Structures by Drag n Drop
|
82
|
+
email: activescaffold@googlegroups.com
|
83
|
+
executables: []
|
84
|
+
|
85
|
+
extensions: []
|
86
|
+
|
87
|
+
extra_rdoc_files:
|
88
|
+
- LICENSE.txt
|
89
|
+
- README.textile
|
90
|
+
files:
|
91
|
+
- frontends/default/stylesheets/sortable.css
|
92
|
+
- frontends/default/views/on_create.js.rjs
|
93
|
+
- frontends/default/views/on_update.js.rjs
|
94
|
+
- frontends/default/views/reorder.js.rjs
|
95
|
+
- frontends/default/views/_list_with_header.html.erb
|
96
|
+
- lib/active_scaffold/actions/sortable.rb
|
97
|
+
- lib/active_scaffold/config/sortable.rb
|
98
|
+
- lib/active_scaffold/helpers/sortable_helpers.rb
|
99
|
+
- lib/active_scaffold_sortable.rb
|
100
|
+
- lib/active_scaffold_sortable/config/core.rb
|
101
|
+
- lib/active_scaffold_sortable/core.rb
|
102
|
+
- lib/active_scaffold_sortable/version.rb
|
103
|
+
- lib/active_scaffold_sortable/view_helpers.rb
|
104
|
+
- LICENSE.txt
|
105
|
+
- README.textile
|
106
|
+
- test/auto_models_controller_test.rb
|
107
|
+
- test/config_test.rb
|
108
|
+
- test/controllers/auto_models_controller.rb
|
109
|
+
- test/controllers/models_controller.rb
|
110
|
+
- test/controllers/sortable_models_controller.rb
|
111
|
+
- test/models/auto_model.rb
|
112
|
+
- test/models/model.rb
|
113
|
+
- test/router_test.rb
|
114
|
+
- test/schema.rb
|
115
|
+
- test/test_helper.rb
|
116
|
+
has_rdoc: true
|
117
|
+
homepage: http://github.com/activescaffold/active_scaffold_sortable
|
118
|
+
licenses:
|
119
|
+
- MIT
|
120
|
+
post_install_message:
|
121
|
+
rdoc_options: []
|
122
|
+
|
123
|
+
require_paths:
|
124
|
+
- lib
|
125
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
126
|
+
none: false
|
127
|
+
requirements:
|
128
|
+
- - ">="
|
129
|
+
- !ruby/object:Gem::Version
|
130
|
+
hash: 3
|
131
|
+
segments:
|
132
|
+
- 0
|
133
|
+
version: "0"
|
134
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
135
|
+
none: false
|
136
|
+
requirements:
|
137
|
+
- - ">="
|
138
|
+
- !ruby/object:Gem::Version
|
139
|
+
hash: 3
|
140
|
+
segments:
|
141
|
+
- 0
|
142
|
+
version: "0"
|
143
|
+
requirements: []
|
144
|
+
|
145
|
+
rubyforge_project:
|
146
|
+
rubygems_version: 1.5.2
|
147
|
+
signing_key:
|
148
|
+
specification_version: 3
|
149
|
+
summary: Drag n Drop Sorting for Activescaffold
|
150
|
+
test_files:
|
151
|
+
- test/auto_models_controller_test.rb
|
152
|
+
- test/config_test.rb
|
153
|
+
- test/controllers/auto_models_controller.rb
|
154
|
+
- test/controllers/models_controller.rb
|
155
|
+
- test/controllers/sortable_models_controller.rb
|
156
|
+
- test/models/auto_model.rb
|
157
|
+
- test/models/model.rb
|
158
|
+
- test/router_test.rb
|
159
|
+
- test/schema.rb
|
160
|
+
- test/test_helper.rb
|