##// END OF EJS Templates
Wiki page hierarchy (#528). Parent page can be assigned on Rename screen....
Jean-Philippe Lang -
r1689:60d066f943c6
parent child
Show More
@@ -0,0 +1,9
1 class AddWikiPagesParentId < ActiveRecord::Migration
2 def self.up
3 add_column :wiki_pages, :parent_id, :integer, :default => nil
4 end
5
6 def self.down
7 remove_column :wiki_pages, :parent_id
8 end
9 end
@@ -147,6 +147,7 class WikiController < ApplicationController
147 147 :joins => "LEFT JOIN #{WikiContent.table_name} ON #{WikiContent.table_name}.page_id = #{WikiPage.table_name}.id",
148 148 :order => 'title'
149 149 @pages_by_date = @pages.group_by {|p| p.updated_on.to_date}
150 @pages_by_parent_id = @pages.group_by(&:parent_id)
150 151 # export wiki to a single html file
151 152 when 'export'
152 153 @pages = @wiki.pages.find :all, :order => 'title'
@@ -177,7 +177,8 module ApplicationHelper
177 177 end
178 178
179 179 def breadcrumb(*args)
180 content_tag('p', args.join(' &#187; ') + ' &#187; ', :class => 'breadcrumb')
180 elements = args.flatten
181 elements.any? ? content_tag('p', args.join(' &#187; ') + ' &#187; ', :class => 'breadcrumb') : nil
181 182 end
182 183
183 184 def html_title(*args)
@@ -17,6 +17,22
17 17
18 18 module WikiHelper
19 19
20 def render_page_hierarchy(pages, node=nil)
21 content = ''
22 if pages[node]
23 content << "<ul class=\"pages-hierarchy\">\n"
24 pages[node].each do |page|
25 content << "<li>"
26 content << link_to(h(page.pretty_title), {:action => 'index', :page => page.title},
27 :title => l(:label_updated_time, distance_of_time_in_words(Time.now, page.updated_on)))
28 content << "\n" + render_page_hierarchy(pages, page.id) if pages[page.id]
29 content << "</li>\n"
30 end
31 content << "</ul>\n"
32 end
33 content
34 end
35
20 36 def html_diff(wdiff)
21 37 words = wdiff.words.collect{|word| h(word)}
22 38 words_add = 0
@@ -22,7 +22,8 class WikiPage < ActiveRecord::Base
22 22 belongs_to :wiki
23 23 has_one :content, :class_name => 'WikiContent', :foreign_key => 'page_id', :dependent => :destroy
24 24 has_many :attachments, :as => :container, :dependent => :destroy
25
25 acts_as_tree :order => 'title'
26
26 27 acts_as_event :title => Proc.new {|o| "#{l(:label_wiki)}: #{o.title}"},
27 28 :description => :text,
28 29 :datetime => :created_on,
@@ -110,6 +111,24 class WikiPage < ActiveRecord::Base
110 111 def editable_by?(usr)
111 112 !protected? || usr.allowed_to?(:protect_wiki_pages, wiki.project)
112 113 end
114
115 def parent_title
116 @parent_title || (self.parent && self.parent.pretty_title)
117 end
118
119 def parent_title=(t)
120 @parent_title = t
121 parent_page = t.blank? ? nil : self.wiki.find_page(t)
122 self.parent = parent_page
123 end
124
125 protected
126
127 def validate
128 errors.add(:parent_title, :activerecord_error_invalid) if !@parent_title.blank? && parent.nil?
129 errors.add(:parent_title, :activerecord_error_circular_dependency) if parent && (parent == self || parent.ancestors.include?(self))
130 errors.add(:parent_title, :activerecord_error_not_same_project) if parent && (parent.wiki_id != wiki_id)
131 end
113 132 end
114 133
115 134 class WikiDiff
@@ -4,8 +4,9
4 4
5 5 <% labelled_tabular_form_for :wiki_page, @page, :url => { :action => 'rename' } do |f| %>
6 6 <div class="box">
7 <p><%= f.text_field :title, :required => true, :size => 255 %></p>
7 <p><%= f.text_field :title, :required => true, :size => 100 %></p>
8 8 <p><%= f.check_box :redirect_existing_links %></p>
9 <p><%= f.text_field :parent_title, :size => 100 %></p>
9 10 </div>
10 11 <%= submit_tag l(:button_rename) %>
11 12 <% end %>
@@ -10,6 +10,8
10 10 <%= link_to(l(:label_history), {:action => 'history', :page => @page.title}, :class => 'icon icon-history') %>
11 11 </div>
12 12
13 <%= breadcrumb(@page.ancestors.reverse.collect {|parent| link_to h(parent.pretty_title), {:page => parent.title}}) %>
14
13 15 <% if @content.version != @page.content.version %>
14 16 <p>
15 17 <%= link_to(('&#171; ' + l(:label_previous)), :action => 'index', :page => @page.title, :version => (@content.version - 1)) + " - " if @content.version > 1 %>
@@ -4,11 +4,7
4 4 <p class="nodata"><%= l(:label_no_data) %></p>
5 5 <% end %>
6 6
7 <ul><% @pages.each do |page| %>
8 <li><%= link_to page.pretty_title, {:action => 'index', :page => page.title},
9 :title => l(:label_updated_time, distance_of_time_in_words(Time.now, page.updated_on)) %>
10 </li>
11 <% end %></ul>
7 <%= render_page_hierarchy(@pages_by_parent_id) %>
12 8
13 9 <% content_for :sidebar do %>
14 10 <%= render :partial => 'sidebar' %>
@@ -632,3 +632,4 label_generate_key: Generate a key
632 632 setting_mail_handler_api_enabled: Enable WS for incoming emails
633 633 setting_mail_handler_api_key: API key
634 634 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."
635 field_parent_title: Parent page
@@ -637,3 +637,4 label_generate_key: Generate a key
637 637 setting_mail_handler_api_enabled: Enable WS for incoming emails
638 638 setting_mail_handler_api_key: API key
639 639 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."
640 field_parent_title: Parent page
@@ -634,3 +634,4 label_generate_key: Generate a key
634 634 setting_mail_handler_api_enabled: Enable WS for incoming emails
635 635 setting_mail_handler_api_key: API key
636 636 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."
637 field_parent_title: Parent page
@@ -633,3 +633,4 label_generate_key: Generate a key
633 633 setting_mail_handler_api_enabled: Enable WS for incoming emails
634 634 setting_mail_handler_api_key: API key
635 635 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."
636 field_parent_title: Parent page
@@ -182,6 +182,7 field_time_zone: Time zone
182 182 field_searchable: Searchable
183 183 field_default_value: Default value
184 184 field_comments_sorting: Display comments
185 field_parent_title: Parent page
185 186
186 187 setting_app_title: Application title
187 188 setting_app_subtitle: Application subtitle
@@ -635,3 +635,4 label_generate_key: Generate a key
635 635 setting_mail_handler_api_enabled: Enable WS for incoming emails
636 636 setting_mail_handler_api_key: API key
637 637 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."
638 field_parent_title: Parent page
@@ -632,3 +632,4 label_generate_key: Generate a key
632 632 setting_mail_handler_api_enabled: Enable WS for incoming emails
633 633 setting_mail_handler_api_key: API key
634 634 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."
635 field_parent_title: Parent page
@@ -183,6 +183,7 field_time_zone: Fuseau horaire
183 183 field_searchable: Utilisé pour les recherches
184 184 field_default_value: Valeur par défaut
185 185 field_comments_sorting: Afficher les commentaires
186 field_parent_title: Page parent
186 187
187 188 setting_app_title: Titre de l'application
188 189 setting_app_subtitle: Sous-titre de l'application
@@ -632,3 +632,4 label_generate_key: Generate a key
632 632 setting_mail_handler_api_enabled: Enable WS for incoming emails
633 633 setting_mail_handler_api_key: API key
634 634 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."
635 field_parent_title: Parent page
@@ -633,3 +633,4 label_generate_key: Kulcs generálása
633 633 setting_mail_handler_api_enabled: Web Service engedélyezése a beérkezett levelekhez
634 634 setting_mail_handler_api_key: API kulcs
635 635 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."
636 field_parent_title: Parent page
@@ -632,3 +632,4 label_generate_key: Genera una chiave
632 632 setting_mail_handler_api_enabled: Abilita WS per le e-mail in arrivo
633 633 setting_mail_handler_api_key: chiave API
634 634 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."
635 field_parent_title: Parent page
@@ -633,3 +633,4 label_generate_key: Generate a key
633 633 setting_mail_handler_api_enabled: Enable WS for incoming emails
634 634 setting_mail_handler_api_key: API key
635 635 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."
636 field_parent_title: Parent page
@@ -632,3 +632,4 label_generate_key: Generate a key
632 632 setting_mail_handler_api_enabled: Enable WS for incoming emails
633 633 setting_mail_handler_api_key: API key
634 634 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."
635 field_parent_title: Parent page
@@ -635,3 +635,4 setting_mail_handler_api_enabled: Įgalinti WS įeinantiems laiškams
635 635 setting_mail_handler_api_key: API raktas
636 636
637 637 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."
638 field_parent_title: Parent page
@@ -633,3 +633,4 label_generate_key: Generate a key
633 633 setting_mail_handler_api_enabled: Enable WS for incoming emails
634 634 setting_mail_handler_api_key: API key
635 635 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."
636 field_parent_title: Parent page
@@ -633,3 +633,4 label_generate_key: Generate a key
633 633 setting_mail_handler_api_enabled: Enable WS for incoming emails
634 634 setting_mail_handler_api_key: API key
635 635 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."
636 field_parent_title: Parent page
@@ -632,3 +632,4 label_generate_key: Generate a key
632 632 setting_mail_handler_api_enabled: Enable WS for incoming emails
633 633 setting_mail_handler_api_key: API key
634 634 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."
635 field_parent_title: Parent page
@@ -632,3 +632,4 label_generate_key: Generate a key
632 632 setting_mail_handler_api_enabled: Enable WS for incoming emails
633 633 setting_mail_handler_api_key: API key
634 634 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."
635 field_parent_title: Parent page
@@ -632,3 +632,4 label_generate_key: Generate a key
632 632 setting_mail_handler_api_enabled: Enable WS for incoming emails
633 633 setting_mail_handler_api_key: API key
634 634 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."
635 field_parent_title: Parent page
@@ -632,3 +632,4 label_generate_key: Generate a key
632 632 setting_mail_handler_api_enabled: Enable WS for incoming emails
633 633 setting_mail_handler_api_key: API key
634 634 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."
635 field_parent_title: Parent page
@@ -636,3 +636,4 label_generate_key: Сгенерировать ключ
636 636 setting_mail_handler_api_enabled: Включить веб-сервис для входящих сообщений
637 637 setting_mail_handler_api_key: API ключ
638 638 text_email_delivery_not_configured: "Параметры работы с почтовым сервером не настроены и функция уведомления по email не активна.\nНастроить параметры для вашего SMTP сервера вы можете в файле config/email.yml. Для применения изменений перезапустите приложение."
639 field_parent_title: Parent page
@@ -633,3 +633,4 label_generate_key: Generate a key
633 633 setting_mail_handler_api_enabled: Enable WS for incoming emails
634 634 setting_mail_handler_api_key: API key
635 635 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."
636 field_parent_title: Parent page
@@ -633,3 +633,4 label_generate_key: Generate a key
633 633 setting_mail_handler_api_enabled: Enable WS for incoming emails
634 634 setting_mail_handler_api_key: API key
635 635 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."
636 field_parent_title: Parent page
@@ -635,3 +635,4 label_generate_key: Generate a key
635 635 setting_mail_handler_api_enabled: Enable WS for incoming emails
636 636 setting_mail_handler_api_key: API key
637 637 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."
638 field_parent_title: Parent page
@@ -634,3 +634,4 label_generate_key: Generate a key
634 634 setting_mail_handler_api_enabled: Enable WS for incoming emails
635 635 setting_mail_handler_api_key: API key
636 636 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."
637 field_parent_title: Parent page
@@ -633,3 +633,4 default_activity_development: 開發
633 633 enumeration_issue_priorities: 項目優先權
634 634 enumeration_doc_categories: 文件分類
635 635 enumeration_activities: 活動 (時間追蹤)
636 field_parent_title: Parent page
@@ -633,3 +633,4 enumeration_issue_priorities: 问题优先级
633 633 enumeration_doc_categories: 文档类别
634 634 enumeration_activities: 活动(时间跟踪)
635 635 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."
636 field_parent_title: Parent page
@@ -4,23 +4,27 wiki_pages_001:
4 4 title: CookBook_documentation
5 5 id: 1
6 6 wiki_id: 1
7 protected: true
7 protected: true
8 parent_id:
8 9 wiki_pages_002:
9 10 created_on: 2007-03-08 00:18:07 +01:00
10 11 title: Another_page
11 12 id: 2
12 13 wiki_id: 1
13 14 protected: false
15 parent_id:
14 16 wiki_pages_003:
15 17 created_on: 2007-03-08 00:18:07 +01:00
16 18 title: Start_page
17 19 id: 3
18 20 wiki_id: 2
19 21 protected: false
22 parent_id:
20 23 wiki_pages_004:
21 24 created_on: 2007-03-08 00:18:07 +01:00
22 25 title: Page_with_an_inline_image
23 26 id: 4
24 27 wiki_id: 1
25 28 protected: false
29 parent_id: 1
26 30 No newline at end of file
@@ -163,8 +163,16 class WikiControllerTest < Test::Unit::TestCase
163 163 pages = assigns(:pages)
164 164 assert_not_nil pages
165 165 assert_equal Project.find(1).wiki.pages.size, pages.size
166 assert_tag :tag => 'a', :attributes => { :href => '/wiki/ecookbook/CookBook_documentation' },
167 :content => /CookBook documentation/
166
167 assert_tag :ul, :attributes => { :class => 'pages-hierarchy' },
168 :child => { :tag => 'li', :child => { :tag => 'a', :attributes => { :href => '/wiki/ecookbook/CookBook_documentation' },
169 :content => 'CookBook documentation' },
170 :child => { :tag => 'ul',
171 :child => { :tag => 'li',
172 :child => { :tag => 'a', :attributes => { :href => '/wiki/ecookbook/Page_with_an_inline_image' },
173 :content => 'Page with an inline image' } } } },
174 :child => { :tag => 'li', :child => { :tag => 'a', :attributes => { :href => '/wiki/ecookbook/Another_page' },
175 :content => 'Another page' } }
168 176 end
169 177
170 178 def test_not_found
@@ -48,6 +48,50 class WikiPageTest < Test::Unit::TestCase
48 48 assert page.new_record?
49 49 end
50 50
51 def test_parent_title
52 page = WikiPage.find_by_title('Another_page')
53 assert_nil page.parent_title
54
55 page = WikiPage.find_by_title('Page_with_an_inline_image')
56 assert_equal 'CookBook documentation', page.parent_title
57 end
58
59 def test_assign_parent
60 page = WikiPage.find_by_title('Another_page')
61 page.parent_title = 'CookBook documentation'
62 assert page.save
63 page.reload
64 assert_equal WikiPage.find_by_title('CookBook_documentation'), page.parent
65 end
66
67 def test_unassign_parent
68 page = WikiPage.find_by_title('Page_with_an_inline_image')
69 page.parent_title = ''
70 assert page.save
71 page.reload
72 assert_nil page.parent
73 end
74
75 def test_parent_validation
76 page = WikiPage.find_by_title('CookBook_documentation')
77
78 # A page that doesn't exist
79 page.parent_title = 'Unknown title'
80 assert !page.save
81 assert_equal :activerecord_error_invalid, page.errors.on(:parent_title)
82 # A child page
83 page.parent_title = 'Page_with_an_inline_image'
84 assert !page.save
85 assert_equal :activerecord_error_circular_dependency, page.errors.on(:parent_title)
86 # The page itself
87 page.parent_title = 'CookBook_documentation'
88 assert !page.save
89 assert_equal :activerecord_error_circular_dependency, page.errors.on(:parent_title)
90
91 page.parent_title = 'Another_page'
92 assert page.save
93 end
94
51 95 def test_destroy
52 96 page = WikiPage.find(1)
53 97 page.destroy
General Comments 0
You need to be logged in to leave comments. Login now