Project

General

Profile

Feature #43631 » add_option_include_subprojects_to_makro_recent_pages.patch

Florian Walchshofer, 2025-12-31 00:40

View differences:

lib/redmine/wiki_formatting/macros.rb (working copy)
"{{recent_pages(days=3)}} -- displays pages updated within the last 3 days\n" +
"{{recent_pages(limit=5)}} -- limits the maximum number of pages to display to 5\n" +
"{{recent_pages(time=true)}} -- displays pages updated within the last 7 days with updated time\n" +
"{{recent_pages(project=identifier)}} -- displays pages updated within the last 7 days from a specific project"
"{{recent_pages(project=identifier)}} -- displays pages updated within the last 7 days from a specific project\n" +
"{{recent_pages(include_subprojects=true)}} -- displays pages updated within the last 7 days from a specific project and all subprojects"
macro :recent_pages do |obj, args|
args, options = extract_macro_options(args, :days, :limit, :time, :project)
args, options = extract_macro_options(args, :days, :limit, :time, :project, :include_subprojects)
if options[:project].presence
project = Project.find_by_identifier(options[:project].to_s) if options[:project].present?
......
days_to_list = (options[:days].presence || 7).to_i
limit = options[:limit].to_i if options[:limit].present?
is_show_time = options[:time].to_s == 'true'
project_ids = if options[:include_subprojects].to_s == 'true'
project.self_and_descendants.pluck(:id)
else
[project.id]
end
pages = WikiPage.
joins(:content, :wiki).
where(["#{Wiki.table_name}.project_id = ? AND #{WikiContent.table_name}.updated_on >= ?", project.id, days_to_list.days.ago]).
order("#{WikiContent.table_name}.updated_on desc, id").
where(["#{Wiki.table_name}.project_id IN (?) AND #{WikiContent.table_name}.updated_on >= ?", project_ids, days_to_list.days.ago]).
order("#{Wiki.table_name}.project_id, #{WikiContent.table_name}.updated_on desc, id").
limit(limit)
tag.ul do
pages.each do |page|
concat(
tag.li do
html = link_to(h(page.pretty_title), project_wiki_page_path(project, page.title))
html = link_to(h(page.pretty_title), project_wiki_page_path(page.project, page.title))
html << " (#{time_ago_in_words(page.content.updated_on)})" if is_show_time
html
end
test/fixtures/wiki_contents.yml (working copy)
version: 1
author_id: 1
comments:
wiki_contents_013:
text: |-
h1. SubWiki CookBook
updated_on: 2007-03-07 00:10:51 +01:00
page_id: 13
id: 13
version: 1
author_id: 1
comments:
wiki_contents_014:
text: |-
h1. SubWiki Child 1
updated_on: 2007-03-07 00:10:51 +01:00
page_id: 14
id: 14
version: 1
author_id: 1
comments:
test/fixtures/wiki_pages.yml (working copy)
wiki_id: 1
protected: false
parent_id: 5
wiki_pages_013:
created_on: 2007-03-07 00:08:07 +01:00
title: SubWiki_CookBook
id: 13
wiki_id: 3
protected: false
parent_id:
wiki_pages_014:
created_on: 2007-03-07 00:08:07 +01:00
title: SubWiki_Child_1
id: 14
wiki_id: 3
protected: false
parent_id: 13
test/fixtures/wikis.yml (working copy)
start_page: Start page
project_id: 2
id: 2
wikis_003:
status: 1
start_page: eCookbook Subproject 1
project_id: 3
id: 3
wikis_005:
status: 1
start_page: Wiki
test/unit/lib/redmine/wiki_formatting/macros_test.rb (working copy)
end
end
end
def test_recent_pages_macro_with_subproject_option
@project = Project.find(1)
project_sub = Project.find(3)
freeze_time do
WikiContent.update_all(updated_on: Time.current)
@project.wiki.pages.each_with_index do |page, i|
page.content.update_attribute(:updated_on, (i + 1).days.ago)
end
project_sub.wiki.pages.each_with_index do |page, i|
page.content.update_attribute(:updated_on, (i + 1).days.ago)
end
with_settings :text_formatting => 'textile' do
result = textilizable('{{recent_pages(project=' + @project.identifier + ',include_subprojects=true)}}')
assert_select_in result, 'ul>li', :count => 9
end
end
end
end
(2-2/2)