-# redMine - project management software
-# Copyright (C) 2006-2007 Jean-Philippe Lang
+# Redmine - project management software
+# Copyright (C) 2006-2011 Jean-Philippe Lang
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# List of pages, sorted alphabetically and by parent (hierarchy)
def index
- load_pages_grouped_by_date_without_content
+ load_pages_for_index
+ @pages_by_parent_id = @pages.group_by(&:parent_id)
+ end
+
+ # List of page, by last update
+ def date_index
+ load_pages_for_index
+ @pages_by_date = @pages.group_by {|p| p.updated_on.to_date}
end
# display a page (in editing mode if it doesn't exist)
redirect_to :action => 'show', :project_id => @project, :id => nil
end
end
-
- def date_index
- load_pages_grouped_by_date_without_content
- end
def preview
page = @wiki.find_page(params[:id])
extend helper unless self.instance_of?(helper)
helper.instance_method(:initial_page_content).bind(self).call(page)
end
-
- # eager load information about last updates, without loading text
- def load_pages_grouped_by_date_without_content
- @pages = @wiki.pages.find :all, :select => "#{WikiPage.table_name}.*, #{WikiContent.table_name}.updated_on",
- :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)
- end
+ def load_pages_for_index
+ @pages = @wiki.pages.with_updated_on.all(:order => 'title', :include => {:wiki => :project})
+ end
end
# Redmine - project management software
-# Copyright (C) 2006-2010 Jean-Philippe Lang
+# Copyright (C) 2006-2011 Jean-Philippe Lang
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
pages[node].each do |page|
content << "<li>"
content << link_to(h(page.pretty_title), {:controller => 'wiki', :action => 'show', :project_id => page.project, :id => page.title},
- :title => (page.respond_to?(:updated_on) ? l(:label_updated_time, distance_of_time_in_words(Time.now, page.updated_on)) : nil))
+ :title => (page.updated_on ? l(:label_updated_time, distance_of_time_in_words(Time.now, page.updated_on)) : nil))
content << "\n" + render_page_hierarchy(pages, page.id) if pages[page.id]
content << "</li>\n"
end
validates_uniqueness_of :title, :scope => :wiki_id, :case_sensitive => false
validates_associated :content
+ # eager load information about last updates, without loading text
+ named_scope :with_updated_on, {
+ :select => "#{WikiPage.table_name}.*, #{WikiContent.table_name}.updated_on",
+ :joins => "LEFT JOIN #{WikiContent.table_name} ON #{WikiContent.table_name}.page_id = #{WikiPage.table_name}.id"
+ }
+
# Wiki pages that are protected by default
DEFAULT_PROTECTED_PAGES = %w(sidebar)
content.text if content
end
+ def updated_on
+ unless @updated_on
+ if time = read_attribute(:updated_on)
+ # content updated_on was eager loaded with the page
+ @updated_on = Time.parse(time) rescue nil
+ else
+ @updated_on = content && content.updated_on
+ end
+ end
+ @updated_on
+ end
+
# Returns true if usr is allowed to edit the page, otherwise false
def editable_by?(usr)
!protected? || usr.allowed_to?(:protect_wiki_pages, wiki.project)
-# redMine - project management software
-# Copyright (C) 2006-2007 Jean-Philippe Lang
+# Redmine - project management software
+# Copyright (C) 2006-2011 Jean-Philippe Lang
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
pages = assigns(:pages)
assert_not_nil pages
assert_equal Project.find(1).wiki.pages.size, pages.size
+ assert_equal pages.first.content.updated_on, pages.first.updated_on
assert_tag :ul, :attributes => { :class => 'pages-hierarchy' },
:child => { :tag => 'li', :child => { :tag => 'a', :attributes => { :href => '/projects/ecookbook/wiki/CookBook_documentation' },
-# redMine - project management software
-# Copyright (C) 2006-2007 Jean-Philippe Lang
+# Redmine - project management software
+# Copyright (C) 2006-2011 Jean-Philippe Lang
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
assert_nil child.parent_id
end
end
+
+ def test_updated_on_eager_load
+ page = WikiPage.with_updated_on.first
+ assert page.is_a?(WikiPage)
+ assert_not_nil page.read_attribute(:updated_on)
+ assert_equal page.content.updated_on, page.updated_on
+ end
end