activeadmin-mongoid-reorder 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +3 -0
- data/README.md +47 -0
- data/Rakefile +7 -0
- data/activeadmin-mongoid-reorder.gemspec +22 -0
- data/lib/active_admin/views/index_as_reorder_table.rb +22 -0
- data/lib/activeadmin-mongoid-reorder.rb +10 -1
- data/lib/activeadmin-mongoid-reorder/engine.rb +8 -0
- data/vendor/assets/javascripts/activeadmin_reorder_table.js.coffee +32 -0
- metadata +9 -2
data/.gitignore
ADDED
data/README.md
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
## activeadmin-mongoid-reorder
|
2
|
+
|
3
|
+
Helper method to add reorder rows functionality to active admin index table view.
|
4
|
+
|
5
|
+
## Setup
|
6
|
+
|
7
|
+
Add gem to Gemfile:
|
8
|
+
|
9
|
+
```gem activeadmin-mongoid-reorder```
|
10
|
+
|
11
|
+
Add ```Monogoid::Reorder``` to the model declaration you want to be reordarable. This will add ```reorder_objects``` class method, ```_position``` field and set default sorting order to ```:_position => :desc``` - so haviest goes first.
|
12
|
+
|
13
|
+
Example:
|
14
|
+
```
|
15
|
+
class Page
|
16
|
+
include Mongoid::Document
|
17
|
+
include Mongoid::Reorder
|
18
|
+
|
19
|
+
# Fields
|
20
|
+
field :title, :type => String
|
21
|
+
field :content, :type => String
|
22
|
+
end
|
23
|
+
```
|
24
|
+
|
25
|
+
To the end of admin registration method of each reordarable model add the following generic helper:
|
26
|
+
```
|
27
|
+
collection_action :reorder, :method => :put do
|
28
|
+
render :text => resource_class.reorder_objects(params[:ids])
|
29
|
+
end
|
30
|
+
```
|
31
|
+
|
32
|
+
Reorder table type should be specified for ```index``` view, here is an example how this should look like:
|
33
|
+
|
34
|
+
```
|
35
|
+
index :as => :reorder_table do
|
36
|
+
column :title
|
37
|
+
default_actions
|
38
|
+
end
|
39
|
+
```
|
40
|
+
|
41
|
+
And finally enable sorting js functionality. jQuery-ui is included by activeadmin by default, so all you need is to include ```activeadmin_reoder_table``` in ```active_admin.js.coffee```:
|
42
|
+
|
43
|
+
```#= require activeadmin_reorder_table```
|
44
|
+
|
45
|
+
## The End
|
46
|
+
|
47
|
+
That's it.
|
data/Rakefile
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.name = 'activeadmin-mongoid-reorder'
|
6
|
+
gem.version = '0.2.0'
|
7
|
+
gem.summary = 'Reorder index table rows plugin for activeadmin.'
|
8
|
+
gem.description = ''
|
9
|
+
gem.license = 'MIT'
|
10
|
+
|
11
|
+
gem.authors = ['Alex Kravets']
|
12
|
+
gem.email = 'santyor@gmail.com'
|
13
|
+
gem.homepage = 'https://github.com/alexkravets/activeadmin-mongoid-reorder'
|
14
|
+
|
15
|
+
gem.files = `git ls-files`.split("\n")
|
16
|
+
gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
17
|
+
gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
18
|
+
gem.require_paths = ["lib"]
|
19
|
+
|
20
|
+
# Supress the warning about no rubyforge project
|
21
|
+
gem.rubyforge_project = 'nowarning'
|
22
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module ActiveAdmin
|
2
|
+
module Views
|
3
|
+
class IndexAsReorderTable < ActiveAdmin::Views::IndexAsTable
|
4
|
+
def build(page_presenter, collection)
|
5
|
+
table_options = {
|
6
|
+
#:id => active_admin_config.resource_name.plural,
|
7
|
+
# for some reason here plural is missing
|
8
|
+
:id => active_admin_config.resource_name.pluralize.downcase,
|
9
|
+
:sortable => false,
|
10
|
+
:class => "index_table index reorder",
|
11
|
+
:i18n => active_admin_config.resource_class,
|
12
|
+
:paginator => page_presenter[:paginator] != false
|
13
|
+
}
|
14
|
+
|
15
|
+
table_for collection, table_options do |t|
|
16
|
+
table_config_block = page_presenter.block || default_table
|
17
|
+
instance_exec(t, &table_config_block)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
$ ->
|
2
|
+
window.sortable_options = (url) ->
|
3
|
+
options =
|
4
|
+
stop: (e, ui) ->
|
5
|
+
# Select object ids from the table rows
|
6
|
+
# -------------------------------------
|
7
|
+
ids = []
|
8
|
+
$(this).find('tr').each ->
|
9
|
+
id_attr = $(this).attr('id')
|
10
|
+
if id_attr
|
11
|
+
id = id_attr.split("_").last()
|
12
|
+
ids.push(id)
|
13
|
+
|
14
|
+
params =
|
15
|
+
ids: ids
|
16
|
+
_method: "put"
|
17
|
+
authenticity_token: $('meta[name=csrf-token]').attr('content')
|
18
|
+
|
19
|
+
$.post url, params, (data) ->
|
20
|
+
if data != "ok"
|
21
|
+
alert 'Error happended. Please contact devs.'
|
22
|
+
return options
|
23
|
+
|
24
|
+
reorder_table = $(".index_table.reorder")
|
25
|
+
|
26
|
+
if reorder_table.length > 0
|
27
|
+
id = reorder_table.attr('id')
|
28
|
+
reorder_method_url = "/admin/#{id}/reorder"
|
29
|
+
|
30
|
+
reorder_table.find("tbody")
|
31
|
+
.sortable(sortable_options(reorder_method_url))
|
32
|
+
.disableSelection()
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: activeadmin-mongoid-reorder
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -17,8 +17,15 @@ executables: []
|
|
17
17
|
extensions: []
|
18
18
|
extra_rdoc_files: []
|
19
19
|
files:
|
20
|
+
- .gitignore
|
21
|
+
- README.md
|
22
|
+
- Rakefile
|
23
|
+
- activeadmin-mongoid-reorder.gemspec
|
24
|
+
- lib/active_admin/views/index_as_reorder_table.rb
|
20
25
|
- lib/activeadmin-mongoid-reorder.rb
|
26
|
+
- lib/activeadmin-mongoid-reorder/engine.rb
|
21
27
|
- lib/mongoid/reorder.rb
|
28
|
+
- vendor/assets/javascripts/activeadmin_reorder_table.js.coffee
|
22
29
|
homepage: https://github.com/alexkravets/activeadmin-mongoid-reorder
|
23
30
|
licenses:
|
24
31
|
- MIT
|
@@ -43,5 +50,5 @@ rubyforge_project: nowarning
|
|
43
50
|
rubygems_version: 1.8.24
|
44
51
|
signing_key:
|
45
52
|
specification_version: 3
|
46
|
-
summary:
|
53
|
+
summary: Reorder index table rows plugin for activeadmin.
|
47
54
|
test_files: []
|