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.

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. # frozen_string_literal: true
  2. # Redmine - project management software
  3. # Copyright (C) 2006-2023 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 Redmine
  19. module MyPage
  20. include Redmine::I18n
  21. CORE_GROUPS = ['top', 'left', 'right']
  22. CORE_BLOCKS = {
  23. 'issuesassignedtome' => {:label => :label_assigned_to_me_issues},
  24. 'issuesreportedbyme' => {:label => :label_reported_issues},
  25. 'issuesupdatedbyme' => {:label => :label_updated_issues},
  26. 'issueswatched' => {:label => :label_watched_issues},
  27. 'issuequery' => {:label => :label_issue_plural, :max_occurs => 3},
  28. 'news' => {:label => :label_news_latest},
  29. 'calendar' => {:label => :label_calendar},
  30. 'documents' => {:label => :label_document_plural},
  31. 'timelog' => {:label => :label_spent_time},
  32. 'activity' => {:label => :label_activity}
  33. }
  34. def self.groups
  35. CORE_GROUPS.dup.freeze
  36. end
  37. # Returns the available blocks
  38. def self.blocks
  39. CORE_BLOCKS.merge(additional_blocks).freeze
  40. end
  41. def self.block_options(blocks_in_use=[])
  42. options = []
  43. blocks.each do |block, block_options|
  44. indexes = blocks_in_use.filter_map do |n|
  45. if n =~ /\A#{block}(__(\d+))?\z/
  46. $2.to_i
  47. end
  48. end
  49. occurs = indexes.size
  50. block_id = indexes.any? ? "#{block}__#{indexes.max + 1}" : block
  51. disabled = (occurs >= (Redmine::MyPage.blocks[block][:max_occurs] || 1))
  52. block_id = nil if disabled
  53. label = block_options[:label]
  54. options << [l("my.blocks.#{label}", :default => [label, label.to_s.humanize]), block_id]
  55. end
  56. options
  57. end
  58. def self.valid_block?(block, blocks_in_use=[])
  59. block.present? && block_options(blocks_in_use).map(&:last).include?(block)
  60. end
  61. def self.find_block(block)
  62. block.to_s =~ /\A(.*?)(__\d+)?\z/
  63. name = $1
  64. blocks.has_key?(name) ? blocks[name].merge(:name => name) : nil
  65. end
  66. # Returns the additional blocks that are defined by plugin partials
  67. def self.additional_blocks
  68. @@additional_blocks ||=
  69. Dir.glob(
  70. "#{Redmine::Plugin.directory}/*/app/views/my/blocks/_*.{rhtml,erb}"
  71. ).inject({}) do |h, file|
  72. name = File.basename(file).split('.').first.gsub(/^_/, '')
  73. h[name] = {:label => name.to_sym, :partial => "my/blocks/#{name}"}
  74. h
  75. end
  76. end
  77. # Returns the default layout for My Page
  78. def self.default_layout
  79. {
  80. 'left' => ['issuesassignedtome'],
  81. 'right' => ['issuesreportedbyme']
  82. }
  83. end
  84. end
  85. end