Wiki page hierarchy (#528). Parent page can be assigned on Rename screen.
git-svn-id: http://redmine.rubyforge.org/svn/trunk@1698 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
parent
b68fd4c04b
commit
60d066f943
|
@ -147,6 +147,7 @@ class WikiController < ApplicationController
|
|||
:joins => "LEFT JOIN #{WikiContent.table_name} ON #{WikiContent.table_name}.page_id = #{WikiPage.table_name}.id",
|
||||
:order => 'title'
|
||||
@pages_by_date = @pages.group_by {|p| p.updated_on.to_date}
|
||||
@pages_by_parent_id = @pages.group_by(&:parent_id)
|
||||
# export wiki to a single html file
|
||||
when 'export'
|
||||
@pages = @wiki.pages.find :all, :order => 'title'
|
||||
|
|
|
@ -177,7 +177,8 @@ module ApplicationHelper
|
|||
end
|
||||
|
||||
def breadcrumb(*args)
|
||||
content_tag('p', args.join(' » ') + ' » ', :class => 'breadcrumb')
|
||||
elements = args.flatten
|
||||
elements.any? ? content_tag('p', args.join(' » ') + ' » ', :class => 'breadcrumb') : nil
|
||||
end
|
||||
|
||||
def html_title(*args)
|
||||
|
|
|
@ -17,6 +17,22 @@
|
|||
|
||||
module WikiHelper
|
||||
|
||||
def render_page_hierarchy(pages, node=nil)
|
||||
content = ''
|
||||
if pages[node]
|
||||
content << "<ul class=\"pages-hierarchy\">\n"
|
||||
pages[node].each do |page|
|
||||
content << "<li>"
|
||||
content << link_to(h(page.pretty_title), {:action => 'index', :page => page.title},
|
||||
:title => l(:label_updated_time, distance_of_time_in_words(Time.now, page.updated_on)))
|
||||
content << "\n" + render_page_hierarchy(pages, page.id) if pages[page.id]
|
||||
content << "</li>\n"
|
||||
end
|
||||
content << "</ul>\n"
|
||||
end
|
||||
content
|
||||
end
|
||||
|
||||
def html_diff(wdiff)
|
||||
words = wdiff.words.collect{|word| h(word)}
|
||||
words_add = 0
|
||||
|
|
|
@ -22,7 +22,8 @@ class WikiPage < ActiveRecord::Base
|
|||
belongs_to :wiki
|
||||
has_one :content, :class_name => 'WikiContent', :foreign_key => 'page_id', :dependent => :destroy
|
||||
has_many :attachments, :as => :container, :dependent => :destroy
|
||||
|
||||
acts_as_tree :order => 'title'
|
||||
|
||||
acts_as_event :title => Proc.new {|o| "#{l(:label_wiki)}: #{o.title}"},
|
||||
:description => :text,
|
||||
:datetime => :created_on,
|
||||
|
@ -110,6 +111,24 @@ class WikiPage < ActiveRecord::Base
|
|||
def editable_by?(usr)
|
||||
!protected? || usr.allowed_to?(:protect_wiki_pages, wiki.project)
|
||||
end
|
||||
|
||||
def parent_title
|
||||
@parent_title || (self.parent && self.parent.pretty_title)
|
||||
end
|
||||
|
||||
def parent_title=(t)
|
||||
@parent_title = t
|
||||
parent_page = t.blank? ? nil : self.wiki.find_page(t)
|
||||
self.parent = parent_page
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
def validate
|
||||
errors.add(:parent_title, :activerecord_error_invalid) if !@parent_title.blank? && parent.nil?
|
||||
errors.add(:parent_title, :activerecord_error_circular_dependency) if parent && (parent == self || parent.ancestors.include?(self))
|
||||
errors.add(:parent_title, :activerecord_error_not_same_project) if parent && (parent.wiki_id != wiki_id)
|
||||
end
|
||||
end
|
||||
|
||||
class WikiDiff
|
||||
|
|
|
@ -4,8 +4,9 @@
|
|||
|
||||
<% labelled_tabular_form_for :wiki_page, @page, :url => { :action => 'rename' } do |f| %>
|
||||
<div class="box">
|
||||
<p><%= f.text_field :title, :required => true, :size => 255 %></p>
|
||||
<p><%= f.text_field :title, :required => true, :size => 100 %></p>
|
||||
<p><%= f.check_box :redirect_existing_links %></p>
|
||||
<p><%= f.text_field :parent_title, :size => 100 %></p>
|
||||
</div>
|
||||
<%= submit_tag l(:button_rename) %>
|
||||
<% end %>
|
||||
|
|
|
@ -10,6 +10,8 @@
|
|||
<%= link_to(l(:label_history), {:action => 'history', :page => @page.title}, :class => 'icon icon-history') %>
|
||||
</div>
|
||||
|
||||
<%= breadcrumb(@page.ancestors.reverse.collect {|parent| link_to h(parent.pretty_title), {:page => parent.title}}) %>
|
||||
|
||||
<% if @content.version != @page.content.version %>
|
||||
<p>
|
||||
<%= link_to(('« ' + l(:label_previous)), :action => 'index', :page => @page.title, :version => (@content.version - 1)) + " - " if @content.version > 1 %>
|
||||
|
|
|
@ -4,11 +4,7 @@
|
|||
<p class="nodata"><%= l(:label_no_data) %></p>
|
||||
<% end %>
|
||||
|
||||
<ul><% @pages.each do |page| %>
|
||||
<li><%= link_to page.pretty_title, {:action => 'index', :page => page.title},
|
||||
:title => l(:label_updated_time, distance_of_time_in_words(Time.now, page.updated_on)) %>
|
||||
</li>
|
||||
<% end %></ul>
|
||||
<%= render_page_hierarchy(@pages_by_parent_id) %>
|
||||
|
||||
<% content_for :sidebar do %>
|
||||
<%= render :partial => 'sidebar' %>
|
||||
|
|
|
@ -0,0 +1,9 @@
|
|||
class AddWikiPagesParentId < ActiveRecord::Migration
|
||||
def self.up
|
||||
add_column :wiki_pages, :parent_id, :integer, :default => nil
|
||||
end
|
||||
|
||||
def self.down
|
||||
remove_column :wiki_pages, :parent_id
|
||||
end
|
||||
end
|
|
@ -632,3 +632,4 @@ label_generate_key: Generate a key
|
|||
setting_mail_handler_api_enabled: Enable WS for incoming emails
|
||||
setting_mail_handler_api_key: API key
|
||||
text_email_delivery_not_configured: "Email delivery is not configured, and notifications are disabled.\nConfigure your SMTP server in config/email.yml and restart the application to enable them."
|
||||
field_parent_title: Parent page
|
||||
|
|
|
@ -637,3 +637,4 @@ label_generate_key: Generate a key
|
|||
setting_mail_handler_api_enabled: Enable WS for incoming emails
|
||||
setting_mail_handler_api_key: API key
|
||||
text_email_delivery_not_configured: "Email delivery is not configured, and notifications are disabled.\nConfigure your SMTP server in config/email.yml and restart the application to enable them."
|
||||
field_parent_title: Parent page
|
||||
|
|
|
@ -634,3 +634,4 @@ label_generate_key: Generate a key
|
|||
setting_mail_handler_api_enabled: Enable WS for incoming emails
|
||||
setting_mail_handler_api_key: API key
|
||||
text_email_delivery_not_configured: "Email delivery is not configured, and notifications are disabled.\nConfigure your SMTP server in config/email.yml and restart the application to enable them."
|
||||
field_parent_title: Parent page
|
||||
|
|
|
@ -633,3 +633,4 @@ label_generate_key: Generate a key
|
|||
setting_mail_handler_api_enabled: Enable WS for incoming emails
|
||||
setting_mail_handler_api_key: API key
|
||||
text_email_delivery_not_configured: "Email delivery is not configured, and notifications are disabled.\nConfigure your SMTP server in config/email.yml and restart the application to enable them."
|
||||
field_parent_title: Parent page
|
||||
|
|
|
@ -182,6 +182,7 @@ field_time_zone: Time zone
|
|||
field_searchable: Searchable
|
||||
field_default_value: Default value
|
||||
field_comments_sorting: Display comments
|
||||
field_parent_title: Parent page
|
||||
|
||||
setting_app_title: Application title
|
||||
setting_app_subtitle: Application subtitle
|
||||
|
|
|
@ -635,3 +635,4 @@ label_generate_key: Generate a key
|
|||
setting_mail_handler_api_enabled: Enable WS for incoming emails
|
||||
setting_mail_handler_api_key: API key
|
||||
text_email_delivery_not_configured: "Email delivery is not configured, and notifications are disabled.\nConfigure your SMTP server in config/email.yml and restart the application to enable them."
|
||||
field_parent_title: Parent page
|
||||
|
|
|
@ -632,3 +632,4 @@ label_generate_key: Generate a key
|
|||
setting_mail_handler_api_enabled: Enable WS for incoming emails
|
||||
setting_mail_handler_api_key: API key
|
||||
text_email_delivery_not_configured: "Email delivery is not configured, and notifications are disabled.\nConfigure your SMTP server in config/email.yml and restart the application to enable them."
|
||||
field_parent_title: Parent page
|
||||
|
|
|
@ -183,6 +183,7 @@ field_time_zone: Fuseau horaire
|
|||
field_searchable: Utilisé pour les recherches
|
||||
field_default_value: Valeur par défaut
|
||||
field_comments_sorting: Afficher les commentaires
|
||||
field_parent_title: Page parent
|
||||
|
||||
setting_app_title: Titre de l'application
|
||||
setting_app_subtitle: Sous-titre de l'application
|
||||
|
|
|
@ -632,3 +632,4 @@ label_generate_key: Generate a key
|
|||
setting_mail_handler_api_enabled: Enable WS for incoming emails
|
||||
setting_mail_handler_api_key: API key
|
||||
text_email_delivery_not_configured: "Email delivery is not configured, and notifications are disabled.\nConfigure your SMTP server in config/email.yml and restart the application to enable them."
|
||||
field_parent_title: Parent page
|
||||
|
|
|
@ -633,3 +633,4 @@ label_generate_key: Kulcs generálása
|
|||
setting_mail_handler_api_enabled: Web Service engedélyezése a beérkezett levelekhez
|
||||
setting_mail_handler_api_key: API kulcs
|
||||
text_email_delivery_not_configured: "Az E-mail küldés nincs konfigurálva, és az értesítések ki vannak kapcsolva.\nÁllítsd be az SMTP szervert a config/email.yml fájlban és indítsd újra az alkalmazást, hogy érvénybe lépjen."
|
||||
field_parent_title: Parent page
|
||||
|
|
|
@ -632,3 +632,4 @@ label_generate_key: Genera una chiave
|
|||
setting_mail_handler_api_enabled: Abilita WS per le e-mail in arrivo
|
||||
setting_mail_handler_api_key: chiave API
|
||||
text_email_delivery_not_configured: "La consegna via e-mail non è configurata e le notifiche sono disabilitate.\nConfigura il tuo server SMTP in config/email.yml e riavvia l'applicazione per abilitarle."
|
||||
field_parent_title: Parent page
|
||||
|
|
|
@ -633,3 +633,4 @@ label_generate_key: Generate a key
|
|||
setting_mail_handler_api_enabled: Enable WS for incoming emails
|
||||
setting_mail_handler_api_key: API key
|
||||
text_email_delivery_not_configured: "Email delivery is not configured, and notifications are disabled.\nConfigure your SMTP server in config/email.yml and restart the application to enable them."
|
||||
field_parent_title: Parent page
|
||||
|
|
|
@ -632,3 +632,4 @@ label_generate_key: Generate a key
|
|||
setting_mail_handler_api_enabled: Enable WS for incoming emails
|
||||
setting_mail_handler_api_key: API key
|
||||
text_email_delivery_not_configured: "Email delivery is not configured, and notifications are disabled.\nConfigure your SMTP server in config/email.yml and restart the application to enable them."
|
||||
field_parent_title: Parent page
|
||||
|
|
|
@ -635,3 +635,4 @@ setting_mail_handler_api_enabled: Įgalinti WS įeinantiems laiškams
|
|||
setting_mail_handler_api_key: API raktas
|
||||
|
||||
text_email_delivery_not_configured: "Email delivery is not configured, and notifications are disabled.\nConfigure your SMTP server in config/email.yml and restart the application to enable them."
|
||||
field_parent_title: Parent page
|
||||
|
|
|
@ -633,3 +633,4 @@ label_generate_key: Generate a key
|
|||
setting_mail_handler_api_enabled: Enable WS for incoming emails
|
||||
setting_mail_handler_api_key: API key
|
||||
text_email_delivery_not_configured: "Email delivery is not configured, and notifications are disabled.\nConfigure your SMTP server in config/email.yml and restart the application to enable them."
|
||||
field_parent_title: Parent page
|
||||
|
|
|
@ -633,3 +633,4 @@ label_generate_key: Generate a key
|
|||
setting_mail_handler_api_enabled: Enable WS for incoming emails
|
||||
setting_mail_handler_api_key: API key
|
||||
text_email_delivery_not_configured: "Email delivery is not configured, and notifications are disabled.\nConfigure your SMTP server in config/email.yml and restart the application to enable them."
|
||||
field_parent_title: Parent page
|
||||
|
|
|
@ -632,3 +632,4 @@ label_generate_key: Generate a key
|
|||
setting_mail_handler_api_enabled: Enable WS for incoming emails
|
||||
setting_mail_handler_api_key: API key
|
||||
text_email_delivery_not_configured: "Email delivery is not configured, and notifications are disabled.\nConfigure your SMTP server in config/email.yml and restart the application to enable them."
|
||||
field_parent_title: Parent page
|
||||
|
|
|
@ -632,3 +632,4 @@ label_generate_key: Generate a key
|
|||
setting_mail_handler_api_enabled: Enable WS for incoming emails
|
||||
setting_mail_handler_api_key: API key
|
||||
text_email_delivery_not_configured: "Email delivery is not configured, and notifications are disabled.\nConfigure your SMTP server in config/email.yml and restart the application to enable them."
|
||||
field_parent_title: Parent page
|
||||
|
|
|
@ -632,3 +632,4 @@ label_generate_key: Generate a key
|
|||
setting_mail_handler_api_enabled: Enable WS for incoming emails
|
||||
setting_mail_handler_api_key: API key
|
||||
text_email_delivery_not_configured: "Email delivery is not configured, and notifications are disabled.\nConfigure your SMTP server in config/email.yml and restart the application to enable them."
|
||||
field_parent_title: Parent page
|
||||
|
|
|
@ -632,3 +632,4 @@ label_generate_key: Generate a key
|
|||
setting_mail_handler_api_enabled: Enable WS for incoming emails
|
||||
setting_mail_handler_api_key: API key
|
||||
text_email_delivery_not_configured: "Email delivery is not configured, and notifications are disabled.\nConfigure your SMTP server in config/email.yml and restart the application to enable them."
|
||||
field_parent_title: Parent page
|
||||
|
|
|
@ -636,3 +636,4 @@ label_generate_key: Сгенерировать ключ
|
|||
setting_mail_handler_api_enabled: Включить веб-сервис для входящих сообщений
|
||||
setting_mail_handler_api_key: API ключ
|
||||
text_email_delivery_not_configured: "Параметры работы с почтовым сервером не настроены и функция уведомления по email не активна.\nНастроить параметры для вашего SMTP сервера вы можете в файле config/email.yml. Для применения изменений перезапустите приложение."
|
||||
field_parent_title: Parent page
|
||||
|
|
|
@ -633,3 +633,4 @@ label_generate_key: Generate a key
|
|||
setting_mail_handler_api_enabled: Enable WS for incoming emails
|
||||
setting_mail_handler_api_key: API key
|
||||
text_email_delivery_not_configured: "Email delivery is not configured, and notifications are disabled.\nConfigure your SMTP server in config/email.yml and restart the application to enable them."
|
||||
field_parent_title: Parent page
|
||||
|
|
|
@ -633,3 +633,4 @@ label_generate_key: Generate a key
|
|||
setting_mail_handler_api_enabled: Enable WS for incoming emails
|
||||
setting_mail_handler_api_key: API key
|
||||
text_email_delivery_not_configured: "Email delivery is not configured, and notifications are disabled.\nConfigure your SMTP server in config/email.yml and restart the application to enable them."
|
||||
field_parent_title: Parent page
|
||||
|
|
|
@ -635,3 +635,4 @@ label_generate_key: Generate a key
|
|||
setting_mail_handler_api_enabled: Enable WS for incoming emails
|
||||
setting_mail_handler_api_key: API key
|
||||
text_email_delivery_not_configured: "Email delivery is not configured, and notifications are disabled.\nConfigure your SMTP server in config/email.yml and restart the application to enable them."
|
||||
field_parent_title: Parent page
|
||||
|
|
|
@ -634,3 +634,4 @@ label_generate_key: Generate a key
|
|||
setting_mail_handler_api_enabled: Enable WS for incoming emails
|
||||
setting_mail_handler_api_key: API key
|
||||
text_email_delivery_not_configured: "Email delivery is not configured, and notifications are disabled.\nConfigure your SMTP server in config/email.yml and restart the application to enable them."
|
||||
field_parent_title: Parent page
|
||||
|
|
|
@ -633,3 +633,4 @@ default_activity_development: 開發
|
|||
enumeration_issue_priorities: 項目優先權
|
||||
enumeration_doc_categories: 文件分類
|
||||
enumeration_activities: 活動 (時間追蹤)
|
||||
field_parent_title: Parent page
|
||||
|
|
|
@ -633,3 +633,4 @@ enumeration_issue_priorities: 问题优先级
|
|||
enumeration_doc_categories: 文档类别
|
||||
enumeration_activities: 活动(时间跟踪)
|
||||
text_email_delivery_not_configured: "Email delivery is not configured, and notifications are disabled.\nConfigure your SMTP server in config/email.yml and restart the application to enable them."
|
||||
field_parent_title: Parent page
|
||||
|
|
|
@ -4,23 +4,27 @@ wiki_pages_001:
|
|||
title: CookBook_documentation
|
||||
id: 1
|
||||
wiki_id: 1
|
||||
protected: true
|
||||
protected: true
|
||||
parent_id:
|
||||
wiki_pages_002:
|
||||
created_on: 2007-03-08 00:18:07 +01:00
|
||||
title: Another_page
|
||||
id: 2
|
||||
wiki_id: 1
|
||||
protected: false
|
||||
parent_id:
|
||||
wiki_pages_003:
|
||||
created_on: 2007-03-08 00:18:07 +01:00
|
||||
title: Start_page
|
||||
id: 3
|
||||
wiki_id: 2
|
||||
protected: false
|
||||
parent_id:
|
||||
wiki_pages_004:
|
||||
created_on: 2007-03-08 00:18:07 +01:00
|
||||
title: Page_with_an_inline_image
|
||||
id: 4
|
||||
wiki_id: 1
|
||||
protected: false
|
||||
parent_id: 1
|
||||
|
|
@ -163,8 +163,16 @@ class WikiControllerTest < Test::Unit::TestCase
|
|||
pages = assigns(:pages)
|
||||
assert_not_nil pages
|
||||
assert_equal Project.find(1).wiki.pages.size, pages.size
|
||||
assert_tag :tag => 'a', :attributes => { :href => '/wiki/ecookbook/CookBook_documentation' },
|
||||
:content => /CookBook documentation/
|
||||
|
||||
assert_tag :ul, :attributes => { :class => 'pages-hierarchy' },
|
||||
:child => { :tag => 'li', :child => { :tag => 'a', :attributes => { :href => '/wiki/ecookbook/CookBook_documentation' },
|
||||
:content => 'CookBook documentation' },
|
||||
:child => { :tag => 'ul',
|
||||
:child => { :tag => 'li',
|
||||
:child => { :tag => 'a', :attributes => { :href => '/wiki/ecookbook/Page_with_an_inline_image' },
|
||||
:content => 'Page with an inline image' } } } },
|
||||
:child => { :tag => 'li', :child => { :tag => 'a', :attributes => { :href => '/wiki/ecookbook/Another_page' },
|
||||
:content => 'Another page' } }
|
||||
end
|
||||
|
||||
def test_not_found
|
||||
|
|
|
@ -48,6 +48,50 @@ class WikiPageTest < Test::Unit::TestCase
|
|||
assert page.new_record?
|
||||
end
|
||||
|
||||
def test_parent_title
|
||||
page = WikiPage.find_by_title('Another_page')
|
||||
assert_nil page.parent_title
|
||||
|
||||
page = WikiPage.find_by_title('Page_with_an_inline_image')
|
||||
assert_equal 'CookBook documentation', page.parent_title
|
||||
end
|
||||
|
||||
def test_assign_parent
|
||||
page = WikiPage.find_by_title('Another_page')
|
||||
page.parent_title = 'CookBook documentation'
|
||||
assert page.save
|
||||
page.reload
|
||||
assert_equal WikiPage.find_by_title('CookBook_documentation'), page.parent
|
||||
end
|
||||
|
||||
def test_unassign_parent
|
||||
page = WikiPage.find_by_title('Page_with_an_inline_image')
|
||||
page.parent_title = ''
|
||||
assert page.save
|
||||
page.reload
|
||||
assert_nil page.parent
|
||||
end
|
||||
|
||||
def test_parent_validation
|
||||
page = WikiPage.find_by_title('CookBook_documentation')
|
||||
|
||||
# A page that doesn't exist
|
||||
page.parent_title = 'Unknown title'
|
||||
assert !page.save
|
||||
assert_equal :activerecord_error_invalid, page.errors.on(:parent_title)
|
||||
# A child page
|
||||
page.parent_title = 'Page_with_an_inline_image'
|
||||
assert !page.save
|
||||
assert_equal :activerecord_error_circular_dependency, page.errors.on(:parent_title)
|
||||
# The page itself
|
||||
page.parent_title = 'CookBook_documentation'
|
||||
assert !page.save
|
||||
assert_equal :activerecord_error_circular_dependency, page.errors.on(:parent_title)
|
||||
|
||||
page.parent_title = 'Another_page'
|
||||
assert page.save
|
||||
end
|
||||
|
||||
def test_destroy
|
||||
page = WikiPage.find(1)
|
||||
page.destroy
|
||||
|
|
Loading…
Reference in New Issue