diff options
| author | hukl <contact@smyck.org> | 2009-09-09 15:19:33 +0200 |
|---|---|---|
| committer | hukl <contact@smyck.org> | 2009-09-09 15:19:33 +0200 |
| commit | f7ce8c245fde3f6202103ae614b181c0ba44ed93 (patch) | |
| tree | 4625c54b0dfb31bdc3e71480fb8936fa5a6c0ca5 | |
| parent | f3a8cd8d1e8dfafb987163d95208e0ff2ccbfbc2 (diff) | |
added editing of slugs and moving of nodes. to edit a slug or move a node you edit that node, make your changes and save. the slug and parent node changes get staged and are applied once that revision is published
| -rw-r--r-- | app/controllers/nodes_controller.rb | 1 | ||||
| -rw-r--r-- | app/models/node.rb | 9 | ||||
| -rw-r--r-- | app/views/nodes/edit.html.erb | 22 | ||||
| -rw-r--r-- | db/migrate/20090909113832_add_staged_slug_and_parent_id.rb | 11 | ||||
| -rw-r--r-- | public/javascripts/admin_interface.js | 1 | ||||
| -rw-r--r-- | public/javascripts/admin_search.js | 51 | ||||
| -rw-r--r-- | public/stylesheets/admin.css | 9 | ||||
| -rw-r--r-- | test/functional/nodes_controller_test.rb | 70 |
8 files changed, 173 insertions, 1 deletions
diff --git a/app/controllers/nodes_controller.rb b/app/controllers/nodes_controller.rb index a23354c..0d4a3fe 100644 --- a/app/controllers/nodes_controller.rb +++ b/app/controllers/nodes_controller.rb | |||
| @@ -57,6 +57,7 @@ class NodesController < ApplicationController | |||
| 57 | end | 57 | end |
| 58 | 58 | ||
| 59 | def update | 59 | def update |
| 60 | @node.update_attributes(params[:node]) | ||
| 60 | @draft = @node.find_or_create_draft current_user | 61 | @draft = @node.find_or_create_draft current_user |
| 61 | @draft.tag_list = params[:tag_list] | 62 | @draft.tag_list = params[:tag_list] |
| 62 | if @draft.update_attributes( params[:page] ) | 63 | if @draft.update_attributes( params[:page] ) |
diff --git a/app/models/node.rb b/app/models/node.rb index a870a3a..057248e 100644 --- a/app/models/node.rb +++ b/app/models/node.rb | |||
| @@ -87,6 +87,15 @@ class Node < ActiveRecord::Base | |||
| 87 | self.head = self.draft | 87 | self.head = self.draft |
| 88 | self.head.save! | 88 | self.head.save! |
| 89 | self.draft = nil | 89 | self.draft = nil |
| 90 | |||
| 91 | if staged_slug && (staged_slug != slug) | ||
| 92 | self.slug = staged_slug | ||
| 93 | end | ||
| 94 | |||
| 95 | if staged_parent_id && (staged_parent_id != parent_id) | ||
| 96 | self.parent_id = staged_parent_id | ||
| 97 | end | ||
| 98 | |||
| 90 | self.save! | 99 | self.save! |
| 91 | self.unlock! | 100 | self.unlock! |
| 92 | else | 101 | else |
diff --git a/app/views/nodes/edit.html.erb b/app/views/nodes/edit.html.erb index e41321d..c23381f 100644 --- a/app/views/nodes/edit.html.erb +++ b/app/views/nodes/edit.html.erb | |||
| @@ -18,7 +18,27 @@ | |||
| 18 | </tr> | 18 | </tr> |
| 19 | <tr> | 19 | <tr> |
| 20 | <td class="description">Slug</td> | 20 | <td class="description">Slug</td> |
| 21 | <td><%= f.text_field :slug %></td> | 21 | <td> |
| 22 | <%= | ||
| 23 | f.text_field( | ||
| 24 | :staged_slug, :value => @node.staged_slug || @node.slug | ||
| 25 | ) | ||
| 26 | %> | ||
| 27 | </td> | ||
| 28 | </tr> | ||
| 29 | <tr> | ||
| 30 | <td class="description">parent</td> | ||
| 31 | <td> | ||
| 32 | <%= text_field_tag :move_to_search_term, @node.parent.title rescue "" %> | ||
| 33 | <div id="search_results"> | ||
| 34 | |||
| 35 | </div> | ||
| 36 | <%= f.hidden_field( | ||
| 37 | :staged_parent_id, | ||
| 38 | :value => @node.staged_parent_id || @node.parent_id | ||
| 39 | ) | ||
| 40 | %> | ||
| 41 | </td> | ||
| 22 | </tr> | 42 | </tr> |
| 23 | 43 | ||
| 24 | <% fields_for @draft do |d| %> | 44 | <% fields_for @draft do |d| %> |
diff --git a/db/migrate/20090909113832_add_staged_slug_and_parent_id.rb b/db/migrate/20090909113832_add_staged_slug_and_parent_id.rb new file mode 100644 index 0000000..ab883ca --- /dev/null +++ b/db/migrate/20090909113832_add_staged_slug_and_parent_id.rb | |||
| @@ -0,0 +1,11 @@ | |||
| 1 | class AddStagedSlugAndParentId < ActiveRecord::Migration | ||
| 2 | def self.up | ||
| 3 | add_column :nodes, :staged_slug, :string | ||
| 4 | add_column :nodes, :staged_parent_id, :integer | ||
| 5 | end | ||
| 6 | |||
| 7 | def self.down | ||
| 8 | remove_column :nodes, :staged_slug | ||
| 9 | remove_column :nodes, :staged_parent_id | ||
| 10 | end | ||
| 11 | end | ||
diff --git a/public/javascripts/admin_interface.js b/public/javascripts/admin_interface.js index 95256ee..cf067f0 100644 --- a/public/javascripts/admin_interface.js +++ b/public/javascripts/admin_interface.js | |||
| @@ -4,6 +4,7 @@ $(document).ready(function () { | |||
| 4 | meta_data.initialize(); | 4 | meta_data.initialize(); |
| 5 | menu_item_sorter.initialize(); | 5 | menu_item_sorter.initialize(); |
| 6 | parent_search.initialize_search(); | 6 | parent_search.initialize_search(); |
| 7 | move_to_search.initialize_search(); | ||
| 7 | 8 | ||
| 8 | $(".with_editor").tinymce({ | 9 | $(".with_editor").tinymce({ |
| 9 | script_url : '/javascripts/tiny_mce/tiny_mce.js', | 10 | script_url : '/javascripts/tiny_mce/tiny_mce.js', |
diff --git a/public/javascripts/admin_search.js b/public/javascripts/admin_search.js index c08bdf3..6d3ca93 100644 --- a/public/javascripts/admin_search.js +++ b/public/javascripts/admin_search.js | |||
| @@ -163,3 +163,54 @@ parent_search = { | |||
| 163 | 163 | ||
| 164 | } | 164 | } |
| 165 | } | 165 | } |
| 166 | |||
| 167 | move_to_search = { | ||
| 168 | initialize_search : function() { | ||
| 169 | $("#move_to_search_term").bind("keyup", function() { | ||
| 170 | if ($(this).attr("value")) { | ||
| 171 | $.ajax({ | ||
| 172 | type: "GET", | ||
| 173 | url: "/admin/menu_search", | ||
| 174 | data: "search_term=" + $(this).attr("value"), | ||
| 175 | dataType: "json", | ||
| 176 | success : function(results) { | ||
| 177 | move_to_search.show_results(results); | ||
| 178 | } | ||
| 179 | }); | ||
| 180 | } | ||
| 181 | else { | ||
| 182 | $('#search_results').slideUp(); | ||
| 183 | $('#search_results').empty(); | ||
| 184 | } | ||
| 185 | }); | ||
| 186 | }, | ||
| 187 | |||
| 188 | show_results : function(results) { | ||
| 189 | $("#search_results").empty(); | ||
| 190 | for (result in results) { | ||
| 191 | var link = $(("<a href='#'>"+ results[result].title + "</a>")); | ||
| 192 | $(link).bind("click", move_to_search.link_closure(results[result])); | ||
| 193 | |||
| 194 | |||
| 195 | // Sometimes I don't get jquery; wrap() didn't work *sigh* | ||
| 196 | // Guess I'll need a book someday or another framework | ||
| 197 | var wrapper = $("<div></div>"); | ||
| 198 | $(wrapper).append(link) | ||
| 199 | |||
| 200 | $("#search_results").append(wrapper); | ||
| 201 | |||
| 202 | } | ||
| 203 | }, | ||
| 204 | |||
| 205 | link_closure : function(node) { | ||
| 206 | var barf = function(){ | ||
| 207 | $("#move_to_search_term").attr("value", node.title); | ||
| 208 | $("#node_staged_parent_id").attr("value", node.node_id); | ||
| 209 | $('#search_results').slideUp(); | ||
| 210 | $('#search_results').empty(); | ||
| 211 | return false; | ||
| 212 | } | ||
| 213 | |||
| 214 | return barf; | ||
| 215 | } | ||
| 216 | } \ No newline at end of file | ||
diff --git a/public/stylesheets/admin.css b/public/stylesheets/admin.css index 9fa503b..575ddff 100644 --- a/public/stylesheets/admin.css +++ b/public/stylesheets/admin.css | |||
| @@ -416,3 +416,12 @@ div#image_browser { | |||
| 416 | div#image_browser ul li { | 416 | div#image_browser ul li { |
| 417 | list-style-type: none; | 417 | list-style-type: none; |
| 418 | } | 418 | } |
| 419 | |||
| 420 | input#move_to_search_term, input#node_staged_slug { | ||
| 421 | width: 690px; | ||
| 422 | } | ||
| 423 | |||
| 424 | #tag_list { | ||
| 425 | width: 680px; | ||
| 426 | } | ||
| 427 | |||
diff --git a/test/functional/nodes_controller_test.rb b/test/functional/nodes_controller_test.rb index 7559869..08e50fd 100644 --- a/test/functional/nodes_controller_test.rb +++ b/test/functional/nodes_controller_test.rb | |||
| @@ -127,4 +127,74 @@ class NodesControllerTest < ActionController::TestCase | |||
| 127 | assert_equal "There", test_node.draft.body | 127 | assert_equal "There", test_node.draft.body |
| 128 | assert_equal "Foobar", test_node.draft.template_name | 128 | assert_equal "Foobar", test_node.draft.template_name |
| 129 | end | 129 | end |
| 130 | |||
| 131 | |||
| 132 | test "publish draft with staged_slug unqueal slug" do | ||
| 133 | login_as :quentin | ||
| 134 | |||
| 135 | test_node = Node.create! :slug => "test_node", :staged_slug => "peter_pan" | ||
| 136 | test_node.move_to_child_of Node.root | ||
| 137 | |||
| 138 | put :publish, :id => test_node.id | ||
| 139 | |||
| 140 | test_node.reload | ||
| 141 | assert_equal "peter_pan", test_node.slug | ||
| 142 | assert_equal "peter_pan", test_node.unique_name | ||
| 143 | end | ||
| 144 | |||
| 145 | test "publish draft with staged_slug with more levels of nodes" do | ||
| 146 | login_as :quentin | ||
| 147 | |||
| 148 | test_node = Node.create! :slug => "test_node", :staged_slug => "peter_pan" | ||
| 149 | test_node.move_to_child_of Node.root | ||
| 150 | test_node2 = Node.create! :slug => "test_node2" | ||
| 151 | test_node2.move_to_child_of test_node | ||
| 152 | |||
| 153 | put :publish, :id => test_node.id | ||
| 154 | |||
| 155 | test_node.reload; test_node2.reload | ||
| 156 | assert_equal "peter_pan/test_node2", test_node2.unique_name | ||
| 157 | assert_equal "peter_pan", test_node.unique_name | ||
| 158 | end | ||
| 159 | |||
| 160 | test "publish draft with staged_parent_id" do | ||
| 161 | login_as :quentin | ||
| 162 | |||
| 163 | parent = Node.create! :slug => "parent" | ||
| 164 | parent.move_to_child_of Node.root | ||
| 165 | test_node = Node.create! :slug => "test_node", :staged_parent_id => parent.id | ||
| 166 | test_node.move_to_child_of Node.root | ||
| 167 | test_node2 = Node.create! :slug => "test_node2" | ||
| 168 | test_node2.move_to_child_of test_node | ||
| 169 | |||
| 170 | put :publish, :id => test_node.id | ||
| 171 | |||
| 172 | test_node.reload; test_node2.reload | ||
| 173 | assert_equal "parent/test_node", test_node.unique_name | ||
| 174 | assert_equal "parent/test_node/test_node2", test_node2.unique_name | ||
| 175 | end | ||
| 176 | |||
| 177 | test "publish draft with staged_parent_id and staged_slug" do | ||
| 178 | login_as :quentin | ||
| 179 | |||
| 180 | parent = Node.create! :slug => "parent" | ||
| 181 | parent.move_to_child_of Node.root | ||
| 182 | |||
| 183 | test_node = Node.create!( | ||
| 184 | :slug => "test_node", | ||
| 185 | :staged_parent_id => parent.id, | ||
| 186 | :staged_slug => "peter_pan" | ||
| 187 | ) | ||
| 188 | test_node.move_to_child_of Node.root | ||
| 189 | |||
| 190 | test_node2 = Node.create! :slug => "test_node2" | ||
| 191 | test_node2.move_to_child_of test_node | ||
| 192 | |||
| 193 | put :publish, :id => test_node.id | ||
| 194 | |||
| 195 | test_node.reload; test_node2.reload | ||
| 196 | assert_equal "parent/peter_pan", test_node.unique_name | ||
| 197 | assert_equal "parent/peter_pan/test_node2", test_node2.unique_name | ||
| 198 | end | ||
| 199 | |||
| 130 | end | 200 | end |
