active_admin-sortable_tree 0.0.1 → 0.1.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4f09566c21b921af0c4bcb3745a383e874b62a07
4
- data.tar.gz: a339d4935ff0540a849f5f7b59bd3b96a3922347
3
+ metadata.gz: ac55f045f6a238adde6b30d6487a128ad22b8c2c
4
+ data.tar.gz: d8286fb520dec0970a45b4d8fb088a61d6a26c06
5
5
  SHA512:
6
- metadata.gz: 6324e646b2016b28626d43053404d991d47fb2bf73e17288971d58c0ce596655804acdfd5904e472ebf460d3fd4252467807b0cc58e46bf66bef1718face2b45
7
- data.tar.gz: 1c361bd2c79389830cf871b14c8c10134e9cba8285ca894ee741fce1ad8c23da868ceade03f52856ca1aaa358fa97a46439409d9e371a1a6d4fb9c6837653335
6
+ metadata.gz: 4c83e8ddf44cb139cfcfc3c1c2fd2a6d8d40fa34efc0f94129b0bfdb54826fe2826b9c535d33cc60f56ccb953118e8f054bf795def3beb8c656379616a12dc7f
7
+ data.tar.gz: ae9d44a4607574d7cf7ea35ab1bf85cbc0500bc0652d871b853f68c2ba5cbcb58e345f1d7193d9b084a801df6ec28e141af93552bb6c3aad6a3a7367ad123da7
@@ -1,8 +1,9 @@
1
1
  language: ruby
2
2
  rvm:
3
3
  - "1.9.3"
4
- - "2.1.0"
4
+ - "2.1.2"
5
5
  env:
6
6
  matrix:
7
7
  - RAILS_VERSION=3.2
8
8
  - RAILS_VERSION=4.0
9
+ - RAILS_VERSION=4.1
@@ -0,0 +1,9 @@
1
+ # Changelog
2
+
3
+ ## 0.1.0 - 2014-11-19
4
+
5
+ - Add option to disable sorting: `sortable: false`, which causes the index view
6
+ to be a static tree view.
7
+ - Ensure the default actions honor authorization checks
8
+ ([#43](https://github.com/nebirhos/activeadmin-sortable-tree/pull/43)).
9
+
data/README.md CHANGED
@@ -1,10 +1,12 @@
1
1
  # ActiveAdmin::SortableTree
2
2
 
3
+ [![Gem Version](https://badge.fury.io/rb/active_admin-sortable_tree.svg)](http://badge.fury.io/rb/active_admin-sortable_tree)
3
4
  [![Build Status](https://travis-ci.org/zorab47/active_admin-sortable_tree.svg?branch=master)](https://travis-ci.org/zorab47/active_admin-sortable_tree)
4
5
 
5
6
  This gem adds a tree and a list view to your ActiveAdmin resource index, both
6
7
  sortable via drag'n'drop.
7
8
 
9
+ ![Sortable Tree Demo](http://zorab47.github.io/active_admin-sortable_tree/images/sortable_tree.gif)
8
10
 
9
11
  ## Installation
10
12
 
@@ -13,9 +15,6 @@ sortable via drag'n'drop.
13
15
  gem "active_admin-sortable_tree"
14
16
  ```
15
17
 
16
- *WARNING!* Not compatible with neo/activeadmin-sortable[https://github.com/neo/activeadmin-sortable]
17
-
18
-
19
18
  ## Usage (Tree)
20
19
 
21
20
  **Admin**:
@@ -32,9 +31,9 @@ ActiveAdmin.register Page do
32
31
  end
33
32
  ```
34
33
 
35
- **Model**: activeadmin-sortable-tree is agnostic to the tree implementation. All
36
- you have to do is expose a sorting attribute and a few tree methods (:parent,
37
- :children and :roots). Let's say you use
34
+ **Model**: ActiveAdmin::SortableTree is agnostic to the tree implementation. All
35
+ you have to do is expose a sorting attribute and a few tree methods (`:parent`,
36
+ `:children` and `:roots`). Let's say you use
38
37
  [Ancestry](https://github.com/stefankroes/ancestry):
39
38
 
40
39
  ```ruby
@@ -54,7 +53,7 @@ ActiveAdmin.register Page do
54
53
  children_method: :children,
55
54
  roots_method: :roots,
56
55
  roots_collection: proc { current_user.pages.roots }
57
- # ...
56
+ #
58
57
  end
59
58
  ```
60
59
 
@@ -66,6 +65,7 @@ in `roots_method`.
66
65
  ## Usage (List)
67
66
 
68
67
  **Admin**:
68
+
69
69
  ```ruby
70
70
  # app/admin/page.rb
71
71
  ActiveAdmin.register Page do
@@ -85,7 +85,7 @@ Of course it's configurable:
85
85
  ActiveAdmin.register Page do
86
86
  sortable tree: false, # default
87
87
  sorting_attribute: :my_position_field
88
- ...
88
+ # …
89
89
  end
90
90
  ```
91
91
 
@@ -97,7 +97,6 @@ Currently supports only IndexAsBlock, more to come!
97
97
  **Admin**:
98
98
  ```ruby
99
99
  # app/admin/page.rb
100
-
101
100
  ActiveAdmin.register Page do
102
101
  sortable
103
102
 
@@ -109,7 +108,6 @@ end
109
108
 
110
109
  **Model**: Same as list view (see above)
111
110
 
112
-
113
111
  ## Customization
114
112
 
115
113
  ### Full options list with defaults
@@ -124,6 +122,7 @@ ActiveAdmin.register Page do
124
122
  children_method: :children,
125
123
  roots_method: :roots,
126
124
  roots_collection: nil, # proc to specifiy retrieval of roots
125
+ sortable: true, # Disable sorting (use only 'tree' functionality)
127
126
  collapsible: false, # show +/- buttons to collapse children
128
127
  start_collapsed: false, # when collapsible, start with all roots collapsed
129
128
  end
@@ -156,8 +155,12 @@ ActiveAdminSortableEvent.add('ajaxDone', function (){
156
155
  })
157
156
  ```
158
157
 
158
+ ## Alternatives
159
+
160
+ - [Active Admin Sortable](https://github.com/neo/activeadmin-sortable)
161
+
159
162
  ## Copyright
160
163
 
161
164
  Copyright © 2013 Francesco Disperati, Cantiere Creativo. See the file
162
165
  MIT-LICENSE for details. See the full list list of
163
- [contributors](https://github.com/nebirhos/activeadmin-sortable-tree/graphs/contributors).
166
+ [contributors](http://github.com/zorab47/active_admin-sortable_tree/graphs/contributors).
data/Rakefile CHANGED
@@ -12,6 +12,8 @@ rescue LoadError
12
12
  RDoc::Task = Rake::RDocTask
13
13
  end
14
14
 
15
+ ENV['RAILS_VERSION'] ||= '4.0'
16
+
15
17
  RDoc::Task.new(:rdoc) do |rdoc|
16
18
  rdoc.rdoc_dir = 'rdoc'
17
19
  rdoc.title = 'ActiveAdmin::SortableTree'
@@ -23,28 +23,9 @@ $ ->
23
23
  $('.disclose').bind 'click', (event) ->
24
24
  $(this).closest('li').toggleClass('mjs-nestedSortable-collapsed').toggleClass('mjs-nestedSortable-expanded')
25
25
 
26
- $("[data-sortable-type=plain]").each ->
27
- $this = $(@)
28
- $this.sortable
29
- revert: 250
30
- update: ->
31
- $this.sortable("disable")
32
- $.ajax
33
- url: $this.data("sortable-url")
34
- type: "post"
35
- data: $this.sortable("serialize")
36
- .always ->
37
- $this.sortable("enable")
38
- ActiveAdminSortableEvent.trigger('ajaxAlways')
39
- .done ->
40
- ActiveAdminSortableEvent.trigger('ajaxDone')
41
- .fail ->
42
- ActiveAdminSortableEvent.trigger('ajaxFail')
43
-
44
- .disableSelection()
45
-
46
26
  $(".index_as_sortable [data-sortable-type]").each ->
47
27
  $this = $(@)
28
+
48
29
  if $this.data('sortable-type') == "tree"
49
30
  max_levels = $this.data('max-levels')
50
31
  tab_hack = 20 # nestedSortable default
@@ -6,10 +6,6 @@ $cRowError: rgb(255,87,87)
6
6
  @import bourbon
7
7
 
8
8
  body.active_admin
9
- .index_content
10
- .ui-sortable > *
11
- cursor: move
12
-
13
9
  .disclose
14
10
  cursor: pointer
15
11
  width: 10px
@@ -46,10 +42,6 @@ body.active_admin
46
42
  &.odd
47
43
  background: $cOddRowBackground
48
44
 
49
- &:hover
50
- background-color: $cRowSelected
51
- cursor: move
52
-
53
45
  .cell
54
46
  margin: 0
55
47
  padding: 10px 12px 8px 12px
@@ -59,6 +51,11 @@ body.active_admin
59
51
  line-height: 14px
60
52
  color: black
61
53
 
54
+ &.ui-sortable
55
+ li .item:hover
56
+ cursor: move
57
+ background-color: $cRowSelected
58
+
62
59
  > li > ol
63
60
  margin-left: 30px
64
61
 
@@ -73,7 +70,5 @@ body.active_admin
73
70
  li.mjs-nestedSortable-collapsed > div > .disclose > span:before
74
71
  content: '+ '
75
72
 
76
- li.mjs-nestedSortable-expanded > div > .disclose > span:before
73
+ li.mjs-nestedSortable-expanded > div > .disclose > span:before
77
74
  content: '- '
78
-
79
-
@@ -0,0 +1,10 @@
1
+ gem 'jquery-rails'
2
+ gem 'jquery-ui-rails'
3
+ gem 'ancestry'
4
+ gem 'sqlite3'
5
+
6
+ # ActiveAdmin 1.0.0pre
7
+ gem 'activeadmin', github: 'gregbell/active_admin'
8
+ gem 'devise'
9
+ gem 'rails', '~> 4.1'
10
+ gem 'sass-rails', '~> 4.0.2'
@@ -12,7 +12,8 @@ module ActiveAdmin::SortableTree
12
12
  :max_levels => 0,
13
13
  :protect_root => false,
14
14
  :collapsible => false, #hides +/- buttons
15
- :start_collapsed => false
15
+ :start_collapsed => false,
16
+ :sortable => true
16
17
 
17
18
  # BAD BAD BAD FIXME: don't pollute original class
18
19
  @sortable_options = options
@@ -1,5 +1,5 @@
1
1
  module ActiveAdmin
2
2
  module SortableTree
3
- VERSION = "0.0.1"
3
+ VERSION = "0.1.0"
4
4
  end
5
5
  end
@@ -76,28 +76,40 @@ module ActiveAdmin
76
76
  @other_actions = block
77
77
  end
78
78
 
79
-
80
79
  protected
81
80
 
82
81
  def build_list
83
82
  resource_selection_toggle_panel if active_admin_config.batch_actions.any?
83
+
84
+ ol sortable_data_options do
85
+ @collection.each do |item|
86
+ build_nested_item(item)
87
+ end
88
+ end
89
+ end
90
+
91
+ def sortable_data_options
92
+ return {} if !sortable?
93
+
84
94
  sort_url = if (( sort_url_block = options[:sort_url] ))
85
95
  sort_url_block.call(self)
86
96
  else
87
97
  url_for(:action => :sort)
88
98
  end
89
- data_options = {
90
- "data-sortable-type" => (tree? ? "tree" : "list"),
91
- "data-sortable-url" => sort_url,
99
+ {
100
+ "data-sortable-type" => tree? ? "tree" : "list",
101
+ "data-sortable-url" => sort_url,
102
+ "data-max-levels" => options[:max_levels],
103
+ "data-start-collapsed" => options[:start_collapsed],
104
+ "data-protect-root" => options[:protect_root],
92
105
  }
93
- data_options["data-max-levels"] = options[:max_levels]
94
- data_options["data-start-collapsed"] = options[:start_collapsed]
95
- data_options["data-protect-root"] = true if options[:protect_root]
106
+ end
96
107
 
97
- ol data_options do
98
- @collection.each do |item|
99
- build_nested_item(item)
100
- end
108
+ def sortable?
109
+ if (sortable = options[:sortable]).respond_to? :call
110
+ controller.instance_exec(&sortable)
111
+ else
112
+ sortable
101
113
  end
102
114
  end
103
115
 
@@ -134,13 +146,13 @@ module ActiveAdmin
134
146
  def build_actions(resource)
135
147
  links = ''.html_safe
136
148
  if @default_actions
137
- if controller.action_methods.include?('show')
149
+ if controller.action_methods.include?('show') && authorized?(ActiveAdmin::Auth::READ, resource)
138
150
  links << link_to(I18n.t('active_admin.view'), resource_path(resource), :class => "member_link view_link")
139
151
  end
140
- if controller.action_methods.include?('edit')
152
+ if controller.action_methods.include?('edit') && authorized?(ActiveAdmin::Auth::UPDATE, resource)
141
153
  links << link_to(I18n.t('active_admin.edit'), edit_resource_path(resource), :class => "member_link edit_link")
142
154
  end
143
- if controller.action_methods.include?('destroy')
155
+ if controller.action_methods.include?('destroy') && authorized?(ActiveAdmin::Auth::DESTROY, resource)
144
156
  links << link_to(I18n.t('active_admin.delete'), resource_path(resource), :method => :delete, :data => {:confirm => I18n.t('active_admin.delete_confirmation')}, :class => "member_link delete_link")
145
157
  end
146
158
  end
@@ -1,7 +1,7 @@
1
1
  ActiveAdmin.register Category do
2
2
  sortable
3
3
 
4
- permit_params :name, :ancestry, :description, :position if ENV['RAILS_VERSION'] == '4'
4
+ permit_params :name, :ancestry, :description, :position if Float(ENV['RAILS_VERSION']) >= 4.0
5
5
 
6
6
  index as: :sortable do
7
7
  label :name
@@ -0,0 +1,15 @@
1
+ ActiveAdmin.register Category, as: "CategoryDisabledSort" do
2
+ sortable sortable: false
3
+
4
+ permit_params :name, :ancestry, :description, :position if Float(ENV['RAILS_VERSION']) >= 4.0
5
+
6
+ index as: :sortable do
7
+ label :name
8
+ actions
9
+ end
10
+
11
+ form do |f|
12
+ f.inputs :name, :description
13
+ f.actions
14
+ end
15
+ end
@@ -1,4 +1,4 @@
1
1
  class Category < ActiveRecord::Base
2
2
  has_ancestry
3
- attr_accessible :ancestry, :description, :name, :position if ENV['RAILS_VERSION'] == "3.2"
3
+ attr_accessible :ancestry, :description, :name, :position if Float(ENV['RAILS_VERSION']) < 4
4
4
  end
@@ -51,8 +51,46 @@ RSpec.describe "ActiveAdmin::SortableTree", type: :feature do
51
51
  end
52
52
  end
53
53
 
54
+ context "with option `sortable: false`" do
55
+ it "disables sorting by excluding sortable data attributes" do
56
+ bottom = Category.create! name: "bottom", position: 0
57
+ top = Category.create! name: "top", position: 1
58
+ middle = Category.create! name: "middle", position: 2
59
+
60
+ visit admin_category_disabled_sorts_path
61
+
62
+ expect(page).to have_css(".index_as_sortable")
63
+ expect(page).not_to have_css("[data-sortable-type]")
64
+ expect(page).not_to have_css("[data-sortable-url]")
65
+ end
66
+
67
+ context "with a proc returning false as sortable option" do
68
+ it "disables sorting" do
69
+ proc_evaluated_within_controller = false
70
+
71
+ sortable_options_for("CategoryDisabledSort")[:sortable] = proc do
72
+ proc_evaluated_within_controller = self.is_a?(ActiveAdmin::ResourceController)
73
+ false
74
+ end
75
+
76
+ bottom = Category.create! name: "bottom", position: 0
77
+
78
+ visit admin_category_disabled_sorts_path
79
+
80
+ expect(page).to have_css(".index_as_sortable")
81
+ expect(page).not_to have_css("[data-sortable-type]")
82
+ expect(proc_evaluated_within_controller).to be true
83
+ end
84
+ end
85
+ end
86
+
54
87
  def drag_element(selector, options)
55
88
  options.reverse_merge! moves: 20
56
89
  page.execute_script(%Q($("#{selector}").simulate("drag", #{options.to_json} )))
57
90
  end
91
+
92
+ def sortable_options_for(resource)
93
+ resource_config = ActiveAdmin.application.namespace(:admin).resource_for(resource)
94
+ resource_config.dsl.sortable_options
95
+ end
58
96
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_admin-sortable_tree
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Francesco Disperati
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-08-07 00:00:00.000000000 Z
12
+ date: 2014-11-19 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
@@ -134,6 +134,7 @@ extra_rdoc_files: []
134
134
  files:
135
135
  - ".gitignore"
136
136
  - ".travis.yml"
137
+ - Changelog.md
137
138
  - Gemfile
138
139
  - MIT-LICENSE
139
140
  - README.md
@@ -144,6 +145,7 @@ files:
144
145
  - bin/rails
145
146
  - gemfiles/3.2.gemfile
146
147
  - gemfiles/4.0.gemfile
148
+ - gemfiles/4.1.gemfile
147
149
  - lib/active_admin/sortable_tree.rb
148
150
  - lib/active_admin/sortable_tree/controller_actions.rb
149
151
  - lib/active_admin/sortable_tree/engine.rb
@@ -155,6 +157,7 @@ files:
155
157
  - spec/dummy/README.rdoc
156
158
  - spec/dummy/Rakefile
157
159
  - spec/dummy/app/admin/category.rb
160
+ - spec/dummy/app/admin/category_sort_disabled.rb
158
161
  - spec/dummy/app/admin/category_tree.rb
159
162
  - spec/dummy/app/admin/dashboard.rb
160
163
  - spec/dummy/app/assets/javascripts/active_admin.js