You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

wiki_helper.rb 2.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. # frozen_string_literal: true
  2. # Redmine - project management software
  3. # Copyright (C) 2006-2021 Jean-Philippe Lang
  4. #
  5. # This program is free software; you can redistribute it and/or
  6. # modify it under the terms of the GNU General Public License
  7. # as published by the Free Software Foundation; either version 2
  8. # of the License, or (at your option) any later version.
  9. #
  10. # This program is distributed in the hope that it will be useful,
  11. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. # GNU General Public License for more details.
  14. #
  15. # You should have received a copy of the GNU General Public License
  16. # along with this program; if not, write to the Free Software
  17. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  18. module WikiHelper
  19. include Redmine::Export::PDF::WikiPdfHelper
  20. def wiki_page_options_for_select(pages, selected = nil, parent = nil, level = 0)
  21. pages = pages.group_by(&:parent) unless pages.is_a?(Hash)
  22. s = (+'').html_safe
  23. if pages.has_key?(parent)
  24. pages[parent].each do |page|
  25. attrs = +"value='#{page.id}'"
  26. attrs << " selected='selected'" if selected == page
  27. indent = (level > 0) ? ('&nbsp;' * level * 2 + '&#187; ') : ''
  28. s << content_tag('option', (indent + h(page.pretty_title)).html_safe, :value => page.id.to_s, :selected => selected == page) +
  29. wiki_page_options_for_select(pages, selected, page, level + 1)
  30. end
  31. end
  32. s
  33. end
  34. def wiki_page_wiki_options_for_select(page)
  35. projects = Project.allowed_to(:rename_wiki_pages).joins(:wiki).preload(:wiki).to_a
  36. projects << page.project unless projects.include?(page.project)
  37. project_tree_options_for_select(projects, :selected => page.project) do |project|
  38. wiki_id = project.wiki.try(:id)
  39. {:value => wiki_id, :selected => wiki_id == page.wiki_id}
  40. end
  41. end
  42. def wiki_page_breadcrumb(page)
  43. breadcrumb(
  44. page.ancestors.reverse.collect do |parent|
  45. link_to(
  46. h(parent.pretty_title),
  47. {:controller => 'wiki', :action => 'show',
  48. :id => parent.title, :project_id => parent.project,
  49. :version => nil}
  50. )
  51. end
  52. )
  53. end
  54. # Returns the path for the Cancel link when editing a wiki page
  55. def wiki_page_edit_cancel_path(page)
  56. if page.new_record?
  57. if parent = page.parent
  58. project_wiki_page_path(parent.project, parent.title)
  59. else
  60. project_wiki_index_path(page.project)
  61. end
  62. else
  63. project_wiki_page_path(page.project, page.title)
  64. end
  65. end
  66. def wiki_content_update_info(content)
  67. l(:label_updated_time_by, :author => link_to_user(content.author), :age => time_tag(content.updated_on)).html_safe
  68. end
  69. end