: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'
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)
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
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,
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
<% 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 %>
<%= 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 %>
<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' %>
--- /dev/null
+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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
setting_mail_handler_api_enabled: Enable WS for incoming emails\r
setting_mail_handler_api_key: API key\r
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."\r
+field_parent_title: Parent page\r
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
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
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
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
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
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
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
enumeration_issue_priorities: 項目優先權
enumeration_doc_categories: 文件分類
enumeration_activities: 活動 (時間追蹤)
+field_parent_title: Parent page
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
title: CookBook_documentation\r
id: 1\r
wiki_id: 1\r
- protected: true \r
+ protected: true\r
+ parent_id: \r
wiki_pages_002: \r
created_on: 2007-03-08 00:18:07 +01:00\r
title: Another_page\r
id: 2\r
wiki_id: 1\r
protected: false\r
+ parent_id: \r
wiki_pages_003: \r
created_on: 2007-03-08 00:18:07 +01:00\r
title: Start_page\r
id: 3\r
wiki_id: 2\r
protected: false\r
+ parent_id: \r
wiki_pages_004: \r
created_on: 2007-03-08 00:18:07 +01:00\r
title: Page_with_an_inline_image\r
id: 4\r
wiki_id: 1\r
protected: false\r
+ parent_id: 1\r
\ No newline at end of file
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
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