sortable_tree_rails 0.0.1

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.
@@ -0,0 +1,112 @@
1
+ $cOddRowBackground: #f4f5f5;
2
+ $cRowBorder: #e8e8e8;
3
+ $cRowSelected: #d9e4ec;
4
+ $cRowError: rgb(255,87,87);
5
+
6
+ .ui-sortable > *{
7
+ cursor: move;
8
+ }
9
+
10
+
11
+ .disclose{
12
+ cursor: pointer;
13
+ width: 10px;
14
+ display: none;
15
+ }
16
+
17
+
18
+
19
+ ol.sortable_tree{
20
+ margin: 16px 0px 16px 0px;
21
+ padding-left: 0px;
22
+ }
23
+
24
+ .sortable_tree_wrapper {
25
+ .left {
26
+ float: left !important;
27
+ }
28
+ .right {
29
+ float: right !important;
30
+ }
31
+
32
+ ol {
33
+ list-style-type:none;
34
+
35
+ li {
36
+ cursor: default !important;
37
+
38
+ &.placeholder {
39
+ background: lighten($cOddRowBackground, 10%);
40
+ border: 1px dashed $cRowSelected;
41
+ //.box-sizing(border-box);
42
+ -webkit-box-sizing: border-box;
43
+ -moz-box-sizing: border-box;
44
+ box-sizing: border-box;
45
+
46
+ &.cantdoit {
47
+ border: 1px dashed $cRowError;
48
+ }
49
+ }
50
+
51
+ .item {
52
+ width: 100%;
53
+ border-top: 1px solid $cRowBorder;
54
+ border-bottom: 1px solid $cRowBorder;
55
+
56
+ //.clearfix;
57
+ &::after {
58
+ content: "";
59
+ display: table;
60
+ clear: both;
61
+ }
62
+
63
+ &.even {
64
+ background: white;
65
+ }
66
+
67
+ &.odd {
68
+ background: $cOddRowBackground;
69
+ }
70
+
71
+ &:hover {
72
+ background-color: $cRowSelected;
73
+ cursor: move;
74
+ }
75
+
76
+ .cell {
77
+ margin: 0;
78
+ padding: 10px 12px 8px 12px;
79
+ }
80
+
81
+ h3.cell {
82
+ font-size: 16px;
83
+ line-height: 14px;
84
+ color: black;
85
+ }
86
+ }
87
+ }
88
+
89
+ > li > ol {
90
+ margin-left: 30px;
91
+ }
92
+
93
+ li.mjs-nestedSortable-collapsed > ol {
94
+ display: none;
95
+ }
96
+
97
+ li.mjs-nestedSortable-branch > div > .disclose {
98
+ display: block;
99
+ float: left;
100
+ padding: 10px 5px 8px 5px;
101
+ }
102
+
103
+ li.mjs-nestedSortable-collapsed > div > .disclose > span:before {
104
+ content: '+ ';
105
+ }
106
+
107
+ li.mjs-nestedSortable-expanded > div > .disclose > span:before {
108
+ content: '- ';
109
+ }
110
+ }
111
+ }
112
+
@@ -0,0 +1,7 @@
1
+ module SortableTreeRails
2
+ class Engine < ::Rails::Engine
3
+
4
+
5
+
6
+ end
7
+ end
@@ -0,0 +1,3 @@
1
+ module SortableTreeRails
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,4 @@
1
+ require "sortable_tree_rails/engine"
2
+
3
+ module SortableTreeRails
4
+ end
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :sortable_tree_rails do
3
+ # # Task goes here
4
+ # end
data/readme.md ADDED
@@ -0,0 +1,189 @@
1
+ # SortableTreeRails
2
+
3
+ GUI for sortable tree to manage data organized in tree with ancestry gem.
4
+
5
+ Works with Rails 4.
6
+
7
+
8
+ # Overview
9
+
10
+ The gem uses:
11
+ * [jquery-sortable plugin](https://johnny.github.io/jquery-sortable/) - jQuery Sortable UI
12
+ * [nestedSortable](https://github.com/ilikenwf/nestedSortable) - a jQuery plugin for nested lists which extends jQuery Sortable UI
13
+
14
+ # Demo
15
+ See demo app in the repository (spec/dummy).
16
+ Run page with the tree: `http://localhost:3000/categories/manage`.
17
+
18
+
19
+ # Usage
20
+
21
+
22
+
23
+ ### Gemfile
24
+
25
+ ```
26
+ gem 'ancestry'
27
+ gem 'sortable_tree_rails'
28
+ ```
29
+
30
+
31
+ ### routes
32
+
33
+ ```
34
+ # config/routes.rb
35
+
36
+ resources :categories do
37
+ collection do
38
+ post :sort
39
+ end
40
+ end
41
+
42
+ ```
43
+
44
+ This page (sort_categories_path) will be used by the gem to update data after drag&drop.
45
+
46
+ ### model
47
+
48
+ It assumes that your model has already fields in DB for ancestry.
49
+
50
+ ```
51
+ # app/models/category.rb
52
+
53
+ class Category < ActiveRecord::Base
54
+
55
+ has_ancestry
56
+
57
+ # it uses column ancestry_depth
58
+ # has_ancestry :cache_depth=>true
59
+
60
+ end
61
+
62
+ ```
63
+
64
+
65
+ ### Javascript
66
+
67
+ Include js files in your assets file application.js:
68
+
69
+ ```
70
+ //= require jquery2
71
+ //= require jquery_ujs
72
+
73
+ //=require jquery-ui/sortable
74
+ //=require jquery.mjs.nestedSortable.js
75
+
76
+ ```
77
+
78
+ ### CSS
79
+
80
+ Add CSS file to your styles.
81
+
82
+ for SCSS (app/assets/application.scss):
83
+
84
+ ```
85
+ ... your css here ..
86
+
87
+ @import "sortable_tree";
88
+
89
+
90
+ ```
91
+
92
+
93
+ ### controller
94
+
95
+ ```
96
+ class CategoriesController < ApplicationController
97
+ include SortableTreeController::Sort
98
+ sortable_tree 'Category', {parent_method: 'parent'}
99
+
100
+ def manage
101
+ # get items to show in tree
102
+ @items = Category.all.arrange(:order => :pos)
103
+
104
+ end
105
+
106
+ end
107
+
108
+ ```
109
+
110
+ ### view
111
+
112
+ ```
113
+ # app/views/categories/manage.html.haml
114
+
115
+ = render_sortable_tree(@items, {name_method: :name, sort_url: sort_categories_url, max_levels: 5, controls_partial: 'controls'})
116
+
117
+ ```
118
+
119
+
120
+ ```
121
+ # app/views/categories/_controls.html.haml
122
+
123
+ = link_to 'Edit', edit_category_url(item)
124
+ = link_to 'Delete', category_url(item), :method => :delete, :data => { :confirm => 'Are you sure?' }
125
+
126
+ ```
127
+
128
+
129
+
130
+ # Customize
131
+
132
+ ## Options
133
+
134
+ ### Options for controller
135
+
136
+ in controller:
137
+ ```
138
+
139
+ include SortableTreeController::Sort
140
+ sortable_tree 'ClassName', {_options_here_}
141
+
142
+ ```
143
+
144
+
145
+ * ClassName - class name (camel case). For example, 'Category'.
146
+ * :sorting_attribute - attribute used for sorting (default: 'pos')
147
+ * :parent_method - method used to access parent for the item (default: 'parent')
148
+
149
+
150
+ * If you use ancestry in model - set :parent_method to 'parent':
151
+
152
+ ```
153
+ include SortableTreeController::Sort
154
+ sortable_tree 'ClassName', {parent_method: 'parent', sorting_attribute: 'pos'}
155
+ ```
156
+
157
+ * :controls_partial - specify what partial view to use to show control links for each item in a tree. Set to nil to not show controls.
158
+
159
+ Use local variable `item` in the partial view.
160
+
161
+
162
+ ## Options for view
163
+
164
+ ```
165
+ = render_sortable_tree(@items, {__options_here})
166
+ ```
167
+
168
+ * name_method - defined which model method (usually, a column name) will be used to show name (default: :name)
169
+ * sort_url - URL used to update data after item is moved to a new position
170
+ * max_levels - max levels to show in tree (default: 5)
171
+
172
+
173
+
174
+ # How it works
175
+
176
+ read Wiki
177
+
178
+
179
+ # Similar gems
180
+
181
+ GUI for sortable tree with awesome_nested_set gem:
182
+ * https://github.com/the-teacher/the_sortable_tree
183
+ * https://github.com/winescout/the_sortable_tree
184
+
185
+
186
+ # Credits
187
+ * Some pieces of code was created by inspiration of gem [ActiveAdmin Sortable Tree](https://github.com/maxivak/activeadmin-sortable-tree/)
188
+
189
+
metadata ADDED
@@ -0,0 +1,86 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sortable_tree_rails
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Max Ivak
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-05-28 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rails
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: 4.2.5.2
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: 4.2.5.2
27
+ - !ruby/object:Gem::Dependency
28
+ name: sqlite3
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: GUI for sortable tree to manage data organized in tree with ancestry
42
+ gem.
43
+ email:
44
+ - maxivak@gmail.com
45
+ executables: []
46
+ extensions: []
47
+ extra_rdoc_files: []
48
+ files:
49
+ - MIT-LICENSE
50
+ - Rakefile
51
+ - app/controllers/sortable_tree_controller.rb
52
+ - app/helpers/sortable_tree_helper.rb
53
+ - app/views/sortable_tree/_sortable_tree.html.haml
54
+ - config/routes.rb
55
+ - lib/assets/javascripts/jquery.mjs.nestedSortable.js
56
+ - lib/assets/stylesheets/sortable_tree.scss
57
+ - lib/sortable_tree_rails.rb
58
+ - lib/sortable_tree_rails/engine.rb
59
+ - lib/sortable_tree_rails/version.rb
60
+ - lib/tasks/sortable_tree_rails_tasks.rake
61
+ - readme.md
62
+ homepage: https://github.com/maxivak/sortable_tree_rails
63
+ licenses:
64
+ - MIT
65
+ metadata: {}
66
+ post_install_message:
67
+ rdoc_options: []
68
+ require_paths:
69
+ - lib
70
+ required_ruby_version: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - '>='
73
+ - !ruby/object:Gem::Version
74
+ version: '0'
75
+ required_rubygems_version: !ruby/object:Gem::Requirement
76
+ requirements:
77
+ - - '>='
78
+ - !ruby/object:Gem::Version
79
+ version: '0'
80
+ requirements: []
81
+ rubyforge_project:
82
+ rubygems_version: 2.4.5
83
+ signing_key:
84
+ specification_version: 4
85
+ summary: GUI for sortable tree with ancestry gem
86
+ test_files: []