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)
225 225
             "{{recent_pages(days=3)}} -- displays pages updated within the last 3 days\n" +
226 226
             "{{recent_pages(limit=5)}} -- limits the maximum number of pages to display to 5\n" +
227 227
             "{{recent_pages(time=true)}} -- displays pages updated within the last 7 days with updated time\n" +
228
             "{{recent_pages(project=identifier)}} -- displays pages updated within the last 7 days from a specific project"
228
             "{{recent_pages(project=identifier)}} -- displays pages updated within the last 7 days from a specific project\n" +
229
             "{{recent_pages(include_subprojects=true)}} -- displays pages updated within the last 7 days from a specific project and all subprojects"
229 230

  
230 231
      macro :recent_pages do |obj, args|
231
        args, options = extract_macro_options(args, :days, :limit, :time, :project)
232
        args, options = extract_macro_options(args, :days, :limit, :time, :project, :include_subprojects)
232 233

  
233 234
        if options[:project].presence
234 235
          project = Project.find_by_identifier(options[:project].to_s) if options[:project].present?
......
242 243
        days_to_list = (options[:days].presence || 7).to_i
243 244
        limit = options[:limit].to_i if options[:limit].present?
244 245
        is_show_time = options[:time].to_s == 'true'
246
        project_ids = if options[:include_subprojects].to_s == 'true'
247
                        project.self_and_descendants.pluck(:id)
248
                      else
249
                        [project.id]
250
                      end
245 251

  
246 252
        pages = WikiPage.
247 253
          joins(:content, :wiki).
248
          where(["#{Wiki.table_name}.project_id = ? AND #{WikiContent.table_name}.updated_on >= ?", project.id, days_to_list.days.ago]).
249
          order("#{WikiContent.table_name}.updated_on desc, id").
254
          where(["#{Wiki.table_name}.project_id IN (?) AND #{WikiContent.table_name}.updated_on >= ?", project_ids, days_to_list.days.ago]).
255
          order("#{Wiki.table_name}.project_id, #{WikiContent.table_name}.updated_on desc, id").
250 256
          limit(limit)
251 257

  
252 258
        tag.ul do
253 259
          pages.each do |page|
254 260
            concat(
255 261
              tag.li do
256
                html = link_to(h(page.pretty_title), project_wiki_page_path(project, page.title))
262
                html = link_to(h(page.pretty_title), project_wiki_page_path(page.project, page.title))
257 263
                html << " (#{time_ago_in_words(page.content.updated_on)})" if is_show_time
258 264
                html
259 265
              end
test/fixtures/wiki_contents.yml (working copy)
134 134
  version: 1
135 135
  author_id: 1
136 136
  comments: 
137
wiki_contents_013: 
138
  text: |-
139
    h1. SubWiki CookBook
140
  updated_on: 2007-03-07 00:10:51 +01:00
141
  page_id: 13
142
  id: 13
143
  version: 1
144
  author_id: 1
145
  comments:
146
wiki_contents_014: 
147
  text: |-
148
    h1. SubWiki Child 1
149
  updated_on: 2007-03-07 00:10:51 +01:00
150
  page_id: 14
151
  id: 14
152
  version: 1
153
  author_id: 1
154
  comments:
test/fixtures/wiki_pages.yml (working copy)
83 83
  wiki_id: 1
84 84
  protected: false
85 85
  parent_id: 5
86
wiki_pages_013: 
87
  created_on: 2007-03-07 00:08:07 +01:00
88
  title: SubWiki_CookBook
89
  id: 13
90
  wiki_id: 3
91
  protected: false
92
  parent_id: 
93
wiki_pages_014: 
94
  created_on: 2007-03-07 00:08:07 +01:00
95
  title: SubWiki_Child_1
96
  id: 14
97
  wiki_id: 3
98
  protected: false
99
  parent_id: 13
test/fixtures/wikis.yml (working copy)
9 9
  start_page: Start page
10 10
  project_id: 2
11 11
  id: 2
12
wikis_003: 
13
  status: 1
14
  start_page: eCookbook Subproject 1
15
  project_id: 3
16
  id: 3
12 17
wikis_005:
13 18
  status: 1
14 19
  start_page: Wiki
test/unit/lib/redmine/wiki_formatting/macros_test.rb (working copy)
633 633
      end
634 634
    end
635 635
  end
636

  
637
  def test_recent_pages_macro_with_subproject_option
638
    @project = Project.find(1)
639
    project_sub = Project.find(3)
640
    freeze_time do
641
      WikiContent.update_all(updated_on: Time.current)
642
      @project.wiki.pages.each_with_index do |page, i|
643
        page.content.update_attribute(:updated_on, (i + 1).days.ago)
644
      end
645
      project_sub.wiki.pages.each_with_index do |page, i|
646
        page.content.update_attribute(:updated_on, (i + 1).days.ago)
647
      end
648
      with_settings :text_formatting => 'textile' do
649
        result = textilizable('{{recent_pages(project=' + @project.identifier + ',include_subprojects=true)}}')
650
        assert_select_in result, 'ul>li', :count => 9
651
      end
652
    end
653
  end
636 654
end
(2-2/2)