]> source.dussan.org Git - redmine.git/commitdiff
Option to set parent automatically for new wiki pages (#3108).
authorJean-Philippe Lang <jp_lang@yahoo.fr>
Sat, 17 Dec 2011 11:44:04 +0000 (11:44 +0000)
committerJean-Philippe Lang <jp_lang@yahoo.fr>
Sat, 17 Dec 2011 11:44:04 +0000 (11:44 +0000)
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@8255 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/controllers/wiki_controller.rb
app/helpers/application_helper.rb
app/views/wiki/edit.html.erb
test/functional/wiki_controller_test.rb
test/unit/helpers/application_helper_test.rb

index 2f4724f38e7df52113687b6613eaf403233c31b8..1aaff407186a7f146d37c30aa10e128bda725165 100644 (file)
@@ -95,7 +95,12 @@ class WikiController < ApplicationController
   # edit an existing page or a new one
   def edit
     return render_403 unless editable?
-    @page.content = WikiContent.new(:page => @page) if @page.new_record?
+    if @page.new_record?
+      @page.content = WikiContent.new(:page => @page)
+      if params[:parent].present?
+        @page.parent = @page.wiki.find_page(params[:parent].to_s)
+      end
+    end
 
     @content = @page.content_for_version(params[:version])
     @content.text = initial_page_content(@page) if @content.text.blank?
@@ -143,6 +148,9 @@ class WikiController < ApplicationController
       @content.text = @text
     end
     @content.author = User.current
+    if @page.new_record? && params[:page]
+      @page.parent_id = params[:page][:parent_id]
+    end
     # if page is new @page.save will also save content, but not if page isn't a new record
     if (@page.new_record? ? @page.save : @content.save)
       attachments = Attachment.attach_files(@page, params[:attachments])
index 1232a81267089df9101d5a82f2d32de3361459e4..84c7678d169cac611dba186499f8a49a6da5e0fb 100644 (file)
@@ -596,7 +596,9 @@ module ApplicationHelper
             when :anchor; "##{page.present? ? Wiki.titleize(page) : title}" + (anchor.present? ? "_#{anchor}" : '') # used for single-file wiki export
             else
               wiki_page_id = page.present? ? Wiki.titleize(page) : nil
-              url_for(:only_path => only_path, :controller => 'wiki', :action => 'show', :project_id => link_project, :id => wiki_page_id, :anchor => anchor)
+              parent = wiki_page.nil? && obj.is_a?(WikiContent) && obj.page && project == link_project ? obj.page.title : nil
+              url_for(:only_path => only_path, :controller => 'wiki', :action => 'show', :project_id => link_project, 
+               :id => wiki_page_id, :anchor => anchor, :parent => parent)
             end
           end
           link_to(title.present? ? title.html_safe : h(page), url, :class => ('wiki-page' + (wiki_page ? '' : ' new')))
index d7c97c17791fdedf9b0a1e9fe3ff9e39ee954755..8c20e264d496a2cb6d36d7db7e810521061152c2 100644 (file)
 <div class="box tabular">
 <%= text_area_tag 'content[text]', @text, :cols => 100, :rows => 25, :class => 'wiki-edit', :accesskey => accesskey(:edit) %>
 
+<% if @page.new_record? && @page.parent %>
+<p><label><%= check_box_tag 'page[parent_id]', @page.parent.id %> <%= l(:field_parent_title) %></label> <%=h @page.parent.pretty_title %></p>
+<% end %>
+
 <p><label><%= l(:field_comments) %></label><%= f.text_field :comments, :size => 120 %></p>
 <p><label><%=l(:label_attachment_plural)%></label><%= render :partial => 'attachments/form' %></p>
 </div>
index 70dc20668d6ceeb4edbef86708d329338677b4fc..80a0311f620dae6e4fa3befb15ef2cfbfa17ce61 100644 (file)
@@ -81,11 +81,6 @@ class WikiControllerTest < ActionController::TestCase
     assert_tag :tag => 'div', :attributes => {:id => 'sidebar'},
                               :content => /Side bar content for test_show_with_sidebar/
   end
-
-  def test_show_unexistent_page_without_edit_right
-    get :show, :project_id => 1, :id => 'Unexistent page'
-    assert_response 404
-  end
   
   def test_show_should_display_section_edit_links
     @request.session[:user_id] = 2
@@ -119,11 +114,25 @@ class WikiControllerTest < ActionController::TestCase
     }
   end
 
+  def test_show_unexistent_page_without_edit_right
+    get :show, :project_id => 1, :id => 'Unexistent page'
+    assert_response 404
+  end
+
   def test_show_unexistent_page_with_edit_right
     @request.session[:user_id] = 2
     get :show, :project_id => 1, :id => 'Unexistent page'
     assert_response :success
     assert_template 'edit'
+    assert_no_tag 'input', :attributes => {:name => 'page[parent_id]'}
+  end
+
+  def test_show_unexistent_page_with_parent
+    @request.session[:user_id] = 2
+    get :show, :project_id => 1, :id => 'Unexistent page', :parent => 'Another_page'
+    assert_response :success
+    assert_template 'edit'
+    assert_tag 'input', :attributes => {:name => 'page[parent_id]', :value => '2'}
   end
 
   def test_show_should_not_show_history_without_permission
@@ -135,15 +144,20 @@ class WikiControllerTest < ActionController::TestCase
 
   def test_create_page
     @request.session[:user_id] = 2
-    put :update, :project_id => 1,
-                :id => 'New page',
-                :content => {:comments => 'Created the page',
-                             :text => "h1. New page\n\nThis is a new page",
-                             :version => 0}
+    assert_difference 'WikiPage.count' do
+      assert_difference 'WikiContent.count' do
+        put :update, :project_id => 1,
+                    :id => 'New page',
+                    :content => {:comments => 'Created the page',
+                                 :text => "h1. New page\n\nThis is a new page",
+                                 :version => 0}
+      end
+    end
     assert_redirected_to :action => 'show', :project_id => 'ecookbook', :id => 'New_page'
     page = Project.find(1).wiki.find_page('New page')
     assert !page.new_record?
     assert_not_nil page.content
+    assert_nil page.parent
     assert_equal 'Created the page', page.content.comments
   end
 
@@ -164,6 +178,17 @@ class WikiControllerTest < ActionController::TestCase
     assert_equal 'testfile.txt', page.attachments.first.filename
   end
 
+  def test_create_page_with_parent
+    @request.session[:user_id] = 2
+    assert_difference 'WikiPage.count' do
+      put :update, :project_id => 1, :id => 'New page',
+        :content => {:text => "h1. New page\n\nThis is a new page", :version => 0},
+        :page => {:parent_id => 2}
+    end
+    page = Project.find(1).wiki.find_page('New page')
+    assert_equal WikiPage.find(2), page.parent
+  end
+
   def test_edit_page
     @request.session[:user_id] = 2
     get :edit, :project_id => 'ecookbook', :id => 'Another_page'
index 07038567a1f6653ddc3b07309adecd4f926ab019..2b9d3848df98829a8c43f0b814e18e8f4921e6e8 100644 (file)
@@ -502,10 +502,10 @@ RAW
       '[[Another page#anchor]]' => '<a href="#anchor" class="wiki-page">Another page</a>',
       '[[Another page#anchor|Page]]' => '<a href="#anchor" class="wiki-page">Page</a>',
       # page that doesn't exist
-      '[[Unknown page]]' => '<a href="/projects/ecookbook/wiki/Unknown_page" class="wiki-page new">Unknown page</a>',
-      '[[Unknown page|404]]' => '<a href="/projects/ecookbook/wiki/Unknown_page" class="wiki-page new">404</a>',
-      '[[Unknown page#anchor]]' => '<a href="/projects/ecookbook/wiki/Unknown_page#anchor" class="wiki-page new">Unknown page</a>',
-      '[[Unknown page#anchor|404]]' => '<a href="/projects/ecookbook/wiki/Unknown_page#anchor" class="wiki-page new">404</a>',
+      '[[Unknown page]]' => '<a href="/projects/ecookbook/wiki/Unknown_page?parent=Another_page" class="wiki-page new">Unknown page</a>',
+      '[[Unknown page|404]]' => '<a href="/projects/ecookbook/wiki/Unknown_page?parent=Another_page" class="wiki-page new">404</a>',
+      '[[Unknown page#anchor]]' => '<a href="/projects/ecookbook/wiki/Unknown_page?parent=Another_page#anchor" class="wiki-page new">Unknown page</a>',
+      '[[Unknown page#anchor|404]]' => '<a href="/projects/ecookbook/wiki/Unknown_page?parent=Another_page#anchor" class="wiki-page new">404</a>',
     }
 
     @project = Project.find(1)