@@ -1,5 +1,5 | |||
|
1 |
# |
|
|
2 |
# Copyright (C) 2006-20 |
|
|
1 | # Redmine - project management software | |
|
2 | # Copyright (C) 2006-2011 Jean-Philippe Lang | |
|
3 | 3 | # |
|
4 | 4 | # This program is free software; you can redistribute it and/or |
|
5 | 5 | # modify it under the terms of the GNU General Public License |
@@ -44,7 +44,14 class WikiController < ApplicationController | |||
|
44 | 44 | |
|
45 | 45 | # List of pages, sorted alphabetically and by parent (hierarchy) |
|
46 | 46 | def index |
|
47 | load_pages_grouped_by_date_without_content | |
|
47 | load_pages_for_index | |
|
48 | @pages_by_parent_id = @pages.group_by(&:parent_id) | |
|
49 | end | |
|
50 | ||
|
51 | # List of page, by last update | |
|
52 | def date_index | |
|
53 | load_pages_for_index | |
|
54 | @pages_by_date = @pages.group_by {|p| p.updated_on.to_date} | |
|
48 | 55 | end |
|
49 | 56 | |
|
50 | 57 | # display a page (in editing mode if it doesn't exist) |
@@ -215,10 +222,6 class WikiController < ApplicationController | |||
|
215 | 222 | redirect_to :action => 'show', :project_id => @project, :id => nil |
|
216 | 223 | end |
|
217 | 224 | end |
|
218 | ||
|
219 | def date_index | |
|
220 | load_pages_grouped_by_date_without_content | |
|
221 | end | |
|
222 | 225 | |
|
223 | 226 | def preview |
|
224 | 227 | page = @wiki.find_page(params[:id]) |
@@ -266,14 +269,8 private | |||
|
266 | 269 | extend helper unless self.instance_of?(helper) |
|
267 | 270 | helper.instance_method(:initial_page_content).bind(self).call(page) |
|
268 | 271 | end |
|
269 | ||
|
270 | # eager load information about last updates, without loading text | |
|
271 | def load_pages_grouped_by_date_without_content | |
|
272 | @pages = @wiki.pages.find :all, :select => "#{WikiPage.table_name}.*, #{WikiContent.table_name}.updated_on", | |
|
273 | :joins => "LEFT JOIN #{WikiContent.table_name} ON #{WikiContent.table_name}.page_id = #{WikiPage.table_name}.id", | |
|
274 | :order => 'title' | |
|
275 | @pages_by_date = @pages.group_by {|p| p.updated_on.to_date} | |
|
276 | @pages_by_parent_id = @pages.group_by(&:parent_id) | |
|
277 | end | |
|
278 | 272 | |
|
273 | def load_pages_for_index | |
|
274 | @pages = @wiki.pages.with_updated_on.all(:order => 'title', :include => {:wiki => :project}) | |
|
275 | end | |
|
279 | 276 | end |
@@ -1,5 +1,5 | |||
|
1 | 1 | # Redmine - project management software |
|
2 |
# Copyright (C) 2006-201 |
|
|
2 | # Copyright (C) 2006-2011 Jean-Philippe Lang | |
|
3 | 3 | # |
|
4 | 4 | # This program is free software; you can redistribute it and/or |
|
5 | 5 | # modify it under the terms of the GNU General Public License |
@@ -194,7 +194,7 module ApplicationHelper | |||
|
194 | 194 | pages[node].each do |page| |
|
195 | 195 | content << "<li>" |
|
196 | 196 | content << link_to(h(page.pretty_title), {:controller => 'wiki', :action => 'show', :project_id => page.project, :id => page.title}, |
|
197 |
:title => (page. |
|
|
197 | :title => (page.updated_on ? l(:label_updated_time, distance_of_time_in_words(Time.now, page.updated_on)) : nil)) | |
|
198 | 198 | content << "\n" + render_page_hierarchy(pages, page.id) if pages[page.id] |
|
199 | 199 | content << "</li>\n" |
|
200 | 200 | end |
@@ -41,6 +41,12 class WikiPage < ActiveRecord::Base | |||
|
41 | 41 | validates_uniqueness_of :title, :scope => :wiki_id, :case_sensitive => false |
|
42 | 42 | validates_associated :content |
|
43 | 43 | |
|
44 | # eager load information about last updates, without loading text | |
|
45 | named_scope :with_updated_on, { | |
|
46 | :select => "#{WikiPage.table_name}.*, #{WikiContent.table_name}.updated_on", | |
|
47 | :joins => "LEFT JOIN #{WikiContent.table_name} ON #{WikiContent.table_name}.page_id = #{WikiPage.table_name}.id" | |
|
48 | } | |
|
49 | ||
|
44 | 50 | # Wiki pages that are protected by default |
|
45 | 51 | DEFAULT_PROTECTED_PAGES = %w(sidebar) |
|
46 | 52 | |
@@ -121,6 +127,18 class WikiPage < ActiveRecord::Base | |||
|
121 | 127 | content.text if content |
|
122 | 128 | end |
|
123 | 129 | |
|
130 | def updated_on | |
|
131 | unless @updated_on | |
|
132 | if time = read_attribute(:updated_on) | |
|
133 | # content updated_on was eager loaded with the page | |
|
134 | @updated_on = Time.parse(time) rescue nil | |
|
135 | else | |
|
136 | @updated_on = content && content.updated_on | |
|
137 | end | |
|
138 | end | |
|
139 | @updated_on | |
|
140 | end | |
|
141 | ||
|
124 | 142 | # Returns true if usr is allowed to edit the page, otherwise false |
|
125 | 143 | def editable_by?(usr) |
|
126 | 144 | !protected? || usr.allowed_to?(:protect_wiki_pages, wiki.project) |
@@ -1,5 +1,5 | |||
|
1 |
# |
|
|
2 |
# Copyright (C) 2006-20 |
|
|
1 | # Redmine - project management software | |
|
2 | # Copyright (C) 2006-2011 Jean-Philippe Lang | |
|
3 | 3 | # |
|
4 | 4 | # This program is free software; you can redistribute it and/or |
|
5 | 5 | # modify it under the terms of the GNU General Public License |
@@ -339,6 +339,7 class WikiControllerTest < ActionController::TestCase | |||
|
339 | 339 | pages = assigns(:pages) |
|
340 | 340 | assert_not_nil pages |
|
341 | 341 | assert_equal Project.find(1).wiki.pages.size, pages.size |
|
342 | assert_equal pages.first.content.updated_on, pages.first.updated_on | |
|
342 | 343 | |
|
343 | 344 | assert_tag :ul, :attributes => { :class => 'pages-hierarchy' }, |
|
344 | 345 | :child => { :tag => 'li', :child => { :tag => 'a', :attributes => { :href => '/projects/ecookbook/wiki/CookBook_documentation' }, |
@@ -1,5 +1,5 | |||
|
1 |
# |
|
|
2 |
# Copyright (C) 2006-20 |
|
|
1 | # Redmine - project management software | |
|
2 | # Copyright (C) 2006-2011 Jean-Philippe Lang | |
|
3 | 3 | # |
|
4 | 4 | # This program is free software; you can redistribute it and/or |
|
5 | 5 | # modify it under the terms of the GNU General Public License |
@@ -121,4 +121,11 class WikiPageTest < ActiveSupport::TestCase | |||
|
121 | 121 | assert_nil child.parent_id |
|
122 | 122 | end |
|
123 | 123 | end |
|
124 | ||
|
125 | def test_updated_on_eager_load | |
|
126 | page = WikiPage.with_updated_on.first | |
|
127 | assert page.is_a?(WikiPage) | |
|
128 | assert_not_nil page.read_attribute(:updated_on) | |
|
129 | assert_equal page.content.updated_on, page.updated_on | |
|
130 | end | |
|
124 | 131 | end |
General Comments 0
You need to be logged in to leave comments.
Login now