Ticket #45: sortable_pages.mental.diff
| File sortable_pages.mental.diff, 16.0 kB (added by jlong, 2 years ago) |
|---|
-
test/functional/admin/page_controller_test.rb
old new 219 219 assert_equal pages(:homepage).children, assigns(:children) 220 220 end 221 221 222 def test_reorder__post 223 pages = [pages(:books), pages(:documentation), pages(:textile)] 224 order = pages.map(&:id).join(',') 225 post :reorder, :id => 1, :sort_order => order 226 pages.each(&:reload) 227 assert_equal 0, pages[0].position 228 assert_equal 1, pages[1].position 229 assert_equal 2, pages[2].position 230 assert_redirected_to page_index_url 231 end 232 222 233 def test_tag_reference 223 234 xml_http_request :get, :tag_reference, :class_name => "Page" 224 235 assert_response :success -
app/helpers/admin/page_helper.rb
old new 27 27 end 28 28 end 29 29 30 def page_icon(page) 31 icon = page.virtual? ? "virtual-page" : "page" 32 image(icon, :class => "icon", :alt => 'page-icon', :title => '', :align => 'center') 33 end 34 30 35 def homepage 31 36 @homepage ||= Page.find_by_parent_id(nil) 32 37 end -
app/models/page.rb
old new 8 8 before_save :update_published_at, :update_virtual 9 9 10 10 # Associations 11 acts_as_tree :order => ' virtual DESC, title ASC'11 acts_as_tree :order => 'position ASC, virtual DESC, title ASC' 12 12 has_many :parts, :class_name => 'PagePart', :order => 'id', :dependent => :destroy 13 13 belongs_to :_layout, :class_name => 'Layout', :foreign_key => 'layout_id' 14 14 belongs_to :created_by, :class_name => 'User', :foreign_key => 'created_by' -
app/controllers/admin/page_controller.rb
old new 60 60 render(:layout => false) 61 61 end 62 62 63 def reorder 64 if request.post? 65 sort_order = params[:sort_order].to_s.split(',').map { |i| Integer(i) rescue nil }.compact 66 sort_order.each_with_index do |id, index| 67 Page.update(id, :position => index) 68 end 69 redirect_to page_index_url 70 else 71 @page = Page.find(params[:id]) 72 @children = @page.children 73 end 74 end 75 63 76 def tag_reference 64 77 @class_name = params[:class_name] 65 78 @display_name = @class_name.constantize.display_name -
app/views/admin/page/reorder.rhtml
old new 1 <% content_for :page_css do %> 2 .page { 3 font-size: 120%; 4 font-weight: bold; 5 position: relative; 6 padding: 10px; 7 padding-left: 30px; 8 border-top: 1px solid #eaeaea; 9 } 10 .page .icon { 11 position: absolute; 12 margin-top: -7px; 13 left: 0px; 14 } 15 ul.pages, 16 ul.pages li { 17 list-style: none; 18 margin: 0; 19 padding: 0 20 } 21 ul.pages { 22 border-bottom: 1px solid #eaeaea; 23 } 24 ul.pages li { 25 font-size: 105%; 26 font-weight: normal; 27 padding: 10px; 28 padding-left: 52px; 29 } 30 ul.page .icon, 31 ul.pages .icon { 32 position: absolute; 33 margin-top: -7px; 34 left: 22px; 35 } 36 <% end %> 37 38 <h1 id="reorder_pages">Reorder Pages</h1> 39 40 <p>Drag and drop pages to reorder. Click <strong>Finished</strong> when you are done.</p> 41 42 <div id="page" class="page"> 43 <%= page_icon(@page) %> <%= @page.title %> 44 </div> 45 46 <ul id="children" class="pages"> 47 <% for child in @children -%> 48 <li id="item_<%= child.id %>" class="page"><%= page_icon(child) %> <%= child.title %></li> 49 <% end -%> 50 </ul> 51 52 <script type="text/javascript"> 53 //<![CDATA[ 54 Sortable.create("children", { onUpdate:function(){ $('sort_order').value = Sortable.sequence('children').join(',') } }); 55 //]]> 56 </script> 57 58 <% form_tag do %> 59 <p class="buttons"><%= submit_tag "Finished", :class => 'button' %> or <%= link_to 'Cancel', page_index_url %></p> 60 <div><%= hidden_field_tag "sort_order" %></div> 61 <% end %> -
app/views/admin/page/_node.rhtml
old new 5 5 padding_left = (level * 22) + 4 6 6 7 7 children_class = children ? (expanded ? ' children-visible' : ' children-hidden') : ' no-children' 8 virtual_class = page.virtual? ? " virtual" : ""8 virtual_class = page.virtual? ? " virtual" : "" 9 9 10 10 expander = children ? image((expanded ? "collapse" : "expand"), :class => "expander", :alt => 'toggle children', :title => '', :align => 'center') : "" 11 11 12 icon_name = page.virtual? ? "virtual-page" : "page" 13 icon = image(icon_name, :class => "icon", :alt => 'page-icon', :title => '', :align => 'center') 12 icon = page_icon(page) 14 13 15 14 title = %{<span class="title">#{ page.title }</span>} 16 15 … … 34 33 </td> 35 34 <% unless simple -%> 36 35 <td class="status <%= page.status.name.downcase %>-status"><%= page.status.name %></td> 37 <td class="add-child"><%= link_to image('add-child', :alt => 'add child '), page_new_url(:parent_id => page) %></td>36 <td class="add-child"><%= link_to image('add-child', :alt => 'add child page'), page_new_url(:parent_id => page) %></td> 38 37 <td class="remove"><%= link_to image('remove', :alt => 'remove page'), page_remove_url(:id => page) %></td> 38 <td class="reorder"><%= page.children.empty? ? '' : link_to(image('reorder', :alt => 'reorder children'), page_reorder_children_url(:id => page)) %></td> 39 39 <% end -%> 40 40 </tr> 41 41 <% level = level + 1 -%> -
app/views/admin/page/index.rhtml
old new 6 6 <tr> 7 7 <th class="page">Page</th> 8 8 <th class="status">Status</th> 9 <th class="modify" colspan=" 2">Modify</th>9 <th class="modify" colspan="3">Modify</th> 10 10 </tr> 11 11 </thead> 12 12 <tbody> -
db/schema.rb
old new 2 2 # migrations feature of ActiveRecord to incrementally modify your database, and 3 3 # then regenerate this schema definition. 4 4 5 ActiveRecord::Schema.define(:version => 1 3) do5 ActiveRecord::Schema.define(:version => 14) do 6 6 7 7 create_table "config", :force => true do |t| 8 8 t.column "key", :string, :limit => 40, :default => "", :null => false … … 48 48 t.column "created_by", :integer 49 49 t.column "updated_by", :integer 50 50 t.column "virtual", :boolean, :default => false, :null => false 51 t.column "position", :integer 51 52 end 52 53 53 54 create_table "snippets", :force => true do |t| -
db/migrate/014_add_position_column_to_page.rb
old new 1 class AddPositionColumnToPage < ActiveRecord::Migration 2 def self.up 3 add_column "pages", "position", :integer 4 end 5 6 def self.down 7 remove_column "pages", "position" 8 end 9 end -
config/routes.rb
old new 2 2 3 3 # Admin Routes 4 4 map.with_options(:controller => 'admin/welcome') do |welcome| 5 welcome.admin 'admin', :action => 'index'6 welcome.welcome 'admin/welcome', :action => 'index'7 welcome.login 'admin/login', :action => 'login'8 welcome.logout 'admin/logout', :action => 'logout'5 welcome.admin 'admin', :action => 'index' 6 welcome.welcome 'admin/welcome', :action => 'index' 7 welcome.login 'admin/login', :action => 'login' 8 welcome.logout 'admin/logout', :action => 'logout' 9 9 end 10 10 11 11 # Export Routes 12 12 map.with_options(:controller => 'admin/export') do |export| 13 export.export 'admin/export',:action => 'yaml'14 export.export_yaml 'admin/export/yaml',:action => 'yaml'13 export.export 'admin/export', :action => 'yaml' 14 export.export_yaml 'admin/export/yaml', :action => 'yaml' 15 15 end 16 16 17 17 # Page Routes 18 18 map.with_options(:controller => 'admin/page') do |page| 19 page.page_index 'admin/pages', :action => 'index' 20 page.page_edit 'admin/pages/edit/:id', :action => 'edit' 21 page.page_new 'admin/pages/:parent_id/child/new', :action => 'new' 22 page.homepage_new 'admin/pages/new/homepage', :action => 'new', :slug => '/', :breadcrumb => 'Home' 23 page.page_remove 'admin/pages/remove/:id', :action => 'remove' 24 page.page_add_part 'admin/ui/pages/part/add', :action => 'add_part' 25 page.page_children 'admin/ui/pages/children/:id/:level', :action => 'children', :level => '1' 26 page.tag_reference 'admin/ui/pages/tag_reference', :action => 'tag_reference' 27 page.clear_cache 'admin/pages/cache/clear', :action => 'clear_cache' 19 page.page_index 'admin/pages', :action => 'index' 20 page.page_edit 'admin/pages/edit/:id', :action => 'edit' 21 page.page_new 'admin/pages/:parent_id/child/new', :action => 'new' 22 page.homepage_new 'admin/pages/new/homepage', :action => 'new', :slug => '/', :breadcrumb => 'Home' 23 page.page_remove 'admin/pages/remove/:id', :action => 'remove' 24 page.page_add_part 'admin/ui/pages/part/add', :action => 'add_part' 25 page.page_children 'admin/ui/pages/children/:id/:level', :action => 'children', :level => '1' 26 page.page_reorder_children 'admin/pages/reorder/:id', :action => 'reorder' 27 page.tag_reference 'admin/ui/pages/tag_reference', :action => 'tag_reference' 28 page.clear_cache 'admin/pages/cache/clear', :action => 'clear_cache' 28 29 end 29 30 30 31 # Layouts Routes 31 32 map.with_options(:controller => 'admin/layout') do |layout| 32 layout.layout_index 'admin/layouts', :action => 'index'33 layout.layout_edit 'admin/layouts/edit/:id', :action => 'edit'34 layout.layout_new 'admin/layouts/new', :action => 'new'35 layout.layout_remove 'admin/layouts/remove/:id', :action => 'remove'33 layout.layout_index 'admin/layouts', :action => 'index' 34 layout.layout_edit 'admin/layouts/edit/:id', :action => 'edit' 35 layout.layout_new 'admin/layouts/new', :action => 'new' 36 layout.layout_remove 'admin/layouts/remove/:id', :action => 'remove' 36 37 end 37 38 38 39 # Snippets Routes 39 40 map.with_options(:controller => 'admin/snippet') do |snippet| 40 snippet.snippet_index 'admin/snippets', :action => 'index'41 snippet.snippet_edit 'admin/snippets/edit/:id', :action => 'edit'42 snippet.snippet_new 'admin/snippets/new', :action => 'new'43 snippet.snippet_remove 'admin/snippets/remove/:id', :action => 'remove'41 snippet.snippet_index 'admin/snippets', :action => 'index' 42 snippet.snippet_edit 'admin/snippets/edit/:id', :action => 'edit' 43 snippet.snippet_new 'admin/snippets/new', :action => 'new' 44 snippet.snippet_remove 'admin/snippets/remove/:id', :action => 'remove' 44 45 end 45 46 46 47 # Users Routes 47 48 map.with_options(:controller => 'admin/user') do |user| 48 user.user_index 'admin/users', :action => 'index'49 user.user_edit 'admin/users/edit/:id', :action => 'edit'50 user.user_new 'admin/users/new', :action => 'new'51 user.user_remove 'admin/users/remove/:id', :action => 'remove'52 user.user_preferences 'admin/preferences', :action => 'preferences'49 user.user_index 'admin/users', :action => 'index' 50 user.user_edit 'admin/users/edit/:id', :action => 'edit' 51 user.user_new 'admin/users/new', :action => 'new' 52 user.user_remove 'admin/users/remove/:id', :action => 'remove' 53 user.user_preferences 'admin/preferences', :action => 'preferences' 53 54 end 54 55 55 56 # Extension Routes 56 57 map.with_options(:controller => 'admin/extension') do |extension| 57 extension.extension_index 'admin/extensions',:action => 'index'58 extension.extension_update 'admin/extensions/update',:action => 'update'58 extension.extension_index 'admin/extensions', :action => 'index' 59 extension.extension_update 'admin/extensions/update', :action => 'update' 59 60 end 60 61 61 62 # Site URLs 62 63 map.with_options(:controller => 'site') do |site| 63 site.homepage '', :action => 'show_page', :url => '/'64 site.not_found 'error/404', :action => 'not_found'65 site.error 'error/500', :action => 'error'64 site.homepage '', :action => 'show_page', :url => '/' 65 site.not_found 'error/404', :action => 'not_found' 66 site.error 'error/500', :action => 'error' 66 67 67 68 # Everything else 68 site.connect '*url', :action => 'show_page'69 site.connect '*url', :action => 'show_page' 69 70 end 70 71 71 72 end -
public/stylesheets/admin/global.css
old new 182 182 color: #0c0; 183 183 } 184 184 #content table.index .add-child { 185 width: 100px;185 width: 77px; 186 186 padding-left: 0; 187 187 } 188 188 #content table.index .remove { 189 width: 100px;189 width: 69px; 190 190 padding-left: 0; 191 191 } 192 #content table.index .reorder { 193 width: 70px; 194 padding-left: 0; 195 } 192 196 #content table.index .node .layout, 193 197 #content table.index .node .snippet, 194 198 #content table.index .node .user {
